ui: update edit account to use Gtk.Template

This commit is contained in:
Bilal Elmoussaoui 2019-02-10 23:44:58 +01:00
parent 2ef6f9ebe3
commit 87aff34fa8
5 changed files with 69 additions and 36 deletions

View file

@ -13,6 +13,7 @@
<file compressed="true" preprocess="xml-stripblanks" alias="about_dialog.ui">about_dialog.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="account_config.ui">ui/account_config.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="account_add.ui">ui/account_add.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="account_edit.ui">ui/account_edit.ui</file>
<!-- Default pre-shipped icons -->
<file alias="amazon.svg">icons/hicolor/48x48/apps/amazon.svg</file>

46
data/ui/account_edit.ui Normal file
View file

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<template class="EditAccountWindow" parent="GtkWindow">
<property name="can_focus">False</property>
<property name="type">popup</property>
<property name="window_position">center-on-parent</property>
<property name="default_width">350</property>
<property name="default_height">500</property>
<child>
<placeholder/>
</child>
<child type="titlebar">
<object class="GtkHeaderBar" id="headerbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="close_btn">
<property name="label" translatable="yes">Close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="close_btn_clicked" swapped="no"/>
</object>
</child>
<child>
<object class="GtkButton" id="save_btn">
<property name="label" translatable="yes">Save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="save_btn_clicked" swapped="no"/>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</template>
</interface>

View file

@ -88,6 +88,8 @@ class Account(GObject.GObject):
:param username: the account's username
:param provider: the account's provider
"""
self.username = username
self.provider = provider
Database.get_default().update(username, provider, self.id)
def remove(self):

View file

@ -25,40 +25,31 @@ from gi.repository import Gtk, Gdk, GObject
from .add import AccountConfig
@Gtk.Template(resource_path='/com/github/bilelmoussaoui/Authenticator/account_edit.ui')
class EditAccountWindow(Gtk.Window, GObject.GObject):
__gsignals__ = {
'updated': (GObject.SignalFlags.RUN_LAST, None, (str, str,)),
}
def __init__(self, account):
Gtk.Window.__init__(self)
GObject.GObject.__init__(self)
self._account = account
self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
self.set_size_request(400, 600)
self.resize(400, 600)
self.connect('key_press_event', self._on_key_press)
self._build_widgets()
__gtype_name__ = 'EditAccountWindow'
def _build_widgets(self):
headerbar = Gtk.Template.Child()
save_btn = Gtk.Template.Child()
def __init__(self, account):
super(EditAccountWindow, self).__init__()
self.init_template('EditAccountWindow')
GObject.GObject.__init__(self)
self._account = account
self.__init_widgets()
def __init_widgets(self):
header_bar = Gtk.HeaderBar()
header_bar.set_show_close_button(False)
header_bar.set_title(_("Edit {} - {}".format(self._account.username,
self._account.provider)))
self.set_titlebar(header_bar)
# Save btn
self.save_btn = Gtk.Button()
self.save_btn.set_label(_("Save"))
self.save_btn.connect("clicked", self._on_save)
self.save_btn.get_style_context().add_class("suggested-action")
header_bar.pack_end(self.save_btn)
self.close_btn = Gtk.Button()
self.close_btn.set_label(_("Close"))
self.close_btn.connect("clicked", self._on_quit)
header_bar.pack_start(self.close_btn)
self.headerbar.set_title(_("Edit {} - {}".format(self._account.username,
self._account.provider)))
self.account_config = AccountConfig(edit=True, account=self._account)
self.account_config.connect("changed", self._on_account_config_changed)
@ -75,6 +66,7 @@ class EditAccountWindow(Gtk.Window, GObject.GObject):
"""
self.save_btn.set_sensitive(state)
@Gtk.Template.Callback('save_btn_clicked')
def _on_save(self, *_):
"""
Save Button clicked signal handler.
@ -92,16 +84,9 @@ class EditAccountWindow(Gtk.Window, GObject.GObject):
ac_widget.update_provider(self._account, provider)
self._on_quit()
@Gtk.Template.Callback('close_btn_clicked')
def _on_quit(self, *_):
"""
Close the window.
"""
self.destroy()
def _on_key_press(self, _, event):
"""
KeyPress event handler.
"""
_, key_val = event.get_keyval()
if key_val == Gdk.KEY_Escape:
self._on_quit()

View file

@ -46,8 +46,7 @@ class Window(Gtk.ApplicationWindow, GObject.GObject):
def __init__(self):
Gtk.ApplicationWindow.__init__(self, type=Gtk.WindowType.TOPLEVEL)
self.set_icon_name("@APP_ID@")
self.get_style_context().add_class("authenticator-window")
self.resize(550, 600)
self.resize(350, 500)
self.connect("locked", self.__on_locked)
self.connect("unlocked", self.__on_unlocked)
self.key_press_signal = None