new design for adding apps

This commit is contained in:
Bilal Elmoussaoui 2016-06-01 16:59:11 +02:00
parent 96383ba922
commit 16391c835e
4 changed files with 46 additions and 126 deletions

View file

@ -5,7 +5,6 @@ app_PYTHON = \
confirmation.py \
listrow.py \
authenticator_logo.py \
change_password.py \
icon_finder.py \
change_password.py \
settings.py \
window.py

View file

@ -3,7 +3,6 @@ require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
import logging
from TwoFactorAuth.widgets.authenticator_logo import AuthenticatorLogoChooser
from TwoFactorAuth.widgets.icon_finder import IconFinderWindow
from TwoFactorAuth.models.code import Code
from TwoFactorAuth.models.authenticator import Authenticator
from gettext import gettext as _
@ -19,6 +18,7 @@ class AddAuthenticator(Gtk.Window):
name_entry = Gtk.Entry()
logo_finder_window = None
provided_icons_window = None
def __init__(self, window):
self.parent = window
@ -31,9 +31,9 @@ class AddAuthenticator(Gtk.Window):
Gtk.Window.__init__(self, title=_("Add a new application"),
modal=True, destroy_with_parent=True)
self.connect("delete-event", self.close_window)
self.resize(300, 100)
self.resize(430, 350)
self.set_border_width(18)
self.set_size_request(300, 100)
self.set_size_request(430, 350)
self.set_position(Gtk.WindowPosition.CENTER)
self.set_resizable(False)
self.set_transient_for(self.parent)
@ -91,7 +91,7 @@ class AddAuthenticator(Gtk.Window):
"""
Generate window components
"""
main_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
logo_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
hbox_title = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=18)
@ -108,13 +108,25 @@ class AddAuthenticator(Gtk.Window):
hbox_two_factor.pack_start(two_factor_label, False, True, 0)
hbox_two_factor.pack_end(self.secret_code, False, True, 0)
self.hbox_icon_name = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=18)
icon_name_label = Gtk.Label()
self.icon_name_entry = Gtk.Entry()
icon_name_label.set_text(_("Icon name"))
self.icon_name_entry.connect("changed", self.validate_icon_name)
self.hbox_icon_name.pack_start(icon_name_label, False, True, 0)
self.hbox_icon_name.pack_end(self.icon_name_entry, False, True, 0)
self.hbox_icon_name.set_visible(False)
self.hbox_icon_name.set_no_show_all(True)
logo_event = Gtk.EventBox()
auth_icon = Authenticator.get_auth_icon("image-missing", self.parent.app.pkgdatadir)
self.logo_image.set_from_pixbuf(auth_icon)
self.logo_image.get_style_context().add_class("application-logo-add")
logo_event.add(self.logo_image)
logo_event.connect("button-press-event", self.select_logo)
logo_box.pack_start(logo_event, False, False, 6)
logo_box.pack_start(logo_event, True, False, 6)
logo_box.set_property("margin-bottom", 20)
self.popover.get_style_context().add_class("choose-popover")
self.popover.set_relative_to(self.logo_image)
@ -139,10 +151,22 @@ class AddAuthenticator(Gtk.Window):
vbox.add(hbox_title)
vbox.add(hbox_two_factor)
vbox.add(self.hbox_icon_name)
main_box.pack_start(logo_box, False, True, 6)
main_box.pack_start(vbox, False, True, 6)
self.add(main_box)
def validate_icon_name(self, entry):
icon_name = entry.get_text()
theme = Gtk.IconTheme.get_default()
if theme.has_icon(icon_name):
icon = theme.load_icon(icon_name, 48, 0)
self.selected_image = icon_name
else:
icon = theme.load_icon("image-missing", 48, 0)
self.logo_image.clear()
self.logo_image.set_from_pixbuf(icon)
def validate_ascii_code(self, entry):
"""
Validate if the typed secret code is a valid ascii one
@ -159,7 +183,10 @@ class AddAuthenticator(Gtk.Window):
"""
Select an icon from provided ones
"""
AuthenticatorLogoChooser(self)
if self.provided_icons_window:
self.provided_icons_window.show()
else:
self.provided_icons_window = AuthenticatorLogoChooser(self)
def on_file_clicked(self, *args):
""""
@ -181,10 +208,10 @@ class AddAuthenticator(Gtk.Window):
Shows icon finder window
select icon by icon name
"""
if not self.logo_finder_window:
self.logo_finder_window = IconFinderWindow(self)
else:
self.logo_finder_window.show()
is_visible = self.hbox_icon_name.get_no_show_all()
self.hbox_icon_name.set_visible(is_visible)
self.hbox_icon_name.set_no_show_all(not is_visible)
self.hbox_icon_name.show_all()
def add_filters(self, dialog):
"""
@ -226,4 +253,5 @@ class AddAuthenticator(Gtk.Window):
"""
Close the window
"""
self.destroy()
self.hide()
return True

View file

@ -1,112 +0,0 @@
from gi import require_version
require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
from TwoFactorAuth.models.authenticator import Authenticator
from gettext import gettext as _
class IconFinderWindow(Gtk.Window):
selected_image = None
hb = Gtk.HeaderBar()
apply_button = Gtk.Button.new_with_label(_("Select"))
logo_image = Gtk.Image(xalign=0)
icon_entry = Gtk.Entry()
def __init__(self, window):
self.parent = window
self.generate_window()
self.generate_components()
self.generate_header_bar()
self.show_all()
def generate_window(self):
Gtk.Window.__init__(self, modal=True, destroy_with_parent=True)
self.connect("delete-event", self.close_window)
self.resize(200, 100)
self.set_border_width(18)
self.set_size_request(200, 100)
self.set_position(Gtk.WindowPosition.CENTER)
self.set_resizable(False)
self.set_transient_for(self.parent)
self.connect("key_press_event", self.on_key_press)
def on_key_press(self, key, key_event):
"""
Keyboard Listener handler
"""
if Gdk.keyval_name(key_event.keyval) == "Escape":
self.close_window()
def generate_components(self):
"""
Generate all the components
"""
main_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
logo_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
auth_icon = Authenticator.get_auth_icon("image-missing",
self.parent.parent.app.pkgdatadir)
self.logo_image.set_from_pixbuf(auth_icon)
self.logo_image.get_style_context().add_class("application-logo-add")
logo_box.pack_start(self.logo_image, False, False, 0)
box_entry = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.icon_entry.set_margin_top(10)
self.icon_entry.connect("changed", self.update_icon)
box_entry.pack_start(self.icon_entry, False, False, 0)
main_box.pack_start(logo_box, False, True, 6)
main_box.pack_end(box_entry, False, True, 6)
self.add(main_box)
def update_icon(self, entry):
"""
Update icon image on changed event
"""
icon_name = entry.get_text()
theme = Gtk.IconTheme.get_default()
apply_button = self.hb.get_children()[1].get_children()[0]
if theme.has_icon(icon_name):
icon = theme.load_icon(icon_name, 48, 0)
apply_button.set_sensitive(True)
else:
icon = theme.load_icon("image-missing", 48, 0)
apply_button.set_sensitive(False)
self.logo_image.clear()
self.logo_image.set_from_pixbuf(icon)
def update_logo(self, *args):
"""
Update application logo and close the window
"""
self.parent.update_logo(self.icon_entry.get_text().strip())
self.close_window()
def generate_header_bar(self):
"""
Generate header bar box
"""
left_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
right_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
cancel_button = Gtk.Button.new_with_label(_("Cancel"))
cancel_button.connect("clicked", self.close_window)
cancel_button.get_style_context().add_class("destructive-action")
left_box.add(cancel_button)
self.apply_button.get_style_context().add_class("suggested-action")
self.apply_button.connect("clicked", self.update_logo)
self.apply_button.set_sensitive(False)
right_box.add(self.apply_button)
self.hb.pack_start(left_box)
self.hb.pack_end(right_box)
self.set_titlebar(self.hb)
def close_window(self, *args):
"""
Close the window
"""
self.hide()
return True

View file

@ -23,6 +23,8 @@ class Window(Gtk.ApplicationWindow):
apps_list_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
apps_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
add_application_window = None
list_box = Gtk.ListBox()
search_button = Gtk.ToggleButton()
add_button = Gtk.Button()
@ -358,7 +360,10 @@ class Window(Gtk.ApplicationWindow):
"""
Create add application window
"""
AddAuthenticator(self)
if self.add_application_window:
self.add_application_window.show()
else:
self.add_application_window = AddAuthenticator(self)
def toggle_search_box(self, *args):
"""