From 9bb8ca8cc26b609cc3a5301b8891cfc74b2bc733 Mon Sep 17 00:00:00 2001 From: Nico Alt <nicoalt@posteo.org> Date: Sun, 2 Jun 2019 20:55:42 +0200 Subject: [PATCH] Show back button in chats --- data/ui/app.briar.gtk.gresource.xml | 1 + data/ui/toolbar_start.ui | 29 +++++++++++++++++++++++++ src/briar/gtk/toolbar.py | 33 +++++++++++++++++++++++++++++ src/briar/gtk/window.py | 18 ++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 data/ui/toolbar_start.ui create mode 100644 src/briar/gtk/toolbar.py diff --git a/data/ui/app.briar.gtk.gresource.xml b/data/ui/app.briar.gtk.gresource.xml index f330074..e5baeff 100644 --- a/data/ui/app.briar.gtk.gresource.xml +++ b/data/ui/app.briar.gtk.gresource.xml @@ -6,5 +6,6 @@ <file compressed="true" preprocess="xml-stripblanks">ui/login.ui</file> <file compressed="true" preprocess="xml-stripblanks">ui/main.ui</file> <file compressed="true" preprocess="xml-stripblanks">ui/setup.ui</file> + <file compressed="true" preprocess="xml-stripblanks">ui/toolbar_start.ui</file> </gresource> </gresources> diff --git a/data/ui/toolbar_start.ui b/data/ui/toolbar_start.ui new file mode 100644 index 0000000..c4994a4 --- /dev/null +++ b/data/ui/toolbar_start.ui @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> +<!-- Based on https://gitlab.gnome.org/World/lollypop/blob/1.0.12/data/ToolbarPlayback.ui --> +<interface> + <requires lib="gtk+" version="3.10"/> + <object class="GtkImage" id="back_image"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="icon_name">go-previous-symbolic</property> + </object> + <object class="GtkBox" id="toolbar_start"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">5</property> + <child> + <object class="GtkButton" id="back_button"> + <property name="visible">False</property> + <property name="valign">center</property> + <property name="image">back_image</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> +</interface> + diff --git a/src/briar/gtk/toolbar.py b/src/briar/gtk/toolbar.py new file mode 100644 index 0000000..c2e167b --- /dev/null +++ b/src/briar/gtk/toolbar.py @@ -0,0 +1,33 @@ +# Copyright (c) 2019 Nico Alt +# Copyright (c) 2014-2019 Cedric Bellegarde <cedric.bellegarde@adishatz.org> +# SPDX-License-Identifier: AGPL-3.0-only +# License-Filename: LICENSE.md +# +# Initial version based on GNOME Lollypop +# https://gitlab.gnome.org/World/lollypop/blob/1.0.12/lollypop/toolbar.py + +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + + +class Toolbar(Gtk.HeaderBar): + + def __init__(self): + super().__init__() + self._builder = Gtk.Builder() + self._builder.add_from_resource("/app/briar/gtk/ui/toolbar_start.ui") + toolbar_start = self._builder.get_object("toolbar_start") + self.set_title("Briar") + self.pack_start(toolbar_start) + + def show_back_button(self, show, callback=None): + back_button = self._builder.get_object("back_button") + if not show: + back_button.hide() + return + if callback is None: + raise Exception("Callback needed when showing back button") + back_button.show() + back_button.connect("clicked", callback) + diff --git a/src/briar/gtk/window.py b/src/briar/gtk/window.py index 39bc13b..e2e3a46 100644 --- a/src/briar/gtk/window.py +++ b/src/briar/gtk/window.py @@ -6,6 +6,7 @@ from briar.gtk.containers.chat import ChatContainer from briar.gtk.containers.main import MainContainer from briar.gtk.containers.startup import StartupContainer from briar.gtk.define import App +from briar.gtk.toolbar import Toolbar import gi gi.require_version('Gtk', '3.0') @@ -23,8 +24,13 @@ class Window(Gtk.ApplicationWindow): def container(self): return self.__container + @property + def toolbar(self): + return self.__toolbar + def __setup_content(self): self.__setup_size((600, 400)) # TODO: do properly (constants, save) + self.__setup_toolbar() self.__setup_grid() self.__setup_startup_container() @@ -34,6 +40,12 @@ class Window(Gtk.ApplicationWindow): isinstance(size[1], int): self.resize(size[0], size[1]) + def __setup_toolbar(self): + self.__toolbar = Toolbar() + self.__toolbar.show() + self.__toolbar.set_show_close_button(True) + self.set_titlebar(self.__toolbar) + def __setup_grid(self): self.__grid = Gtk.Grid() self.__grid.set_orientation(Gtk.Orientation.HORIZONTAL) @@ -66,4 +78,10 @@ class Window(Gtk.ApplicationWindow): self.__container = ChatContainer(contact_id) self.__container.show() self.__grid.add(self.__container) + self.__toolbar.show_back_button(True, self.__back_to_main) + def __back_to_main(self, widget): + self.__grid.destroy() + self.__setup_grid() + self.__toolbar.show_back_button(False) + self.__setup_main_container() -- GitLab