From 7687a572797426090ac95309424afbe6a7c6971d Mon Sep 17 00:00:00 2001 From: papajoker Date: Sun, 24 Nov 2019 16:26:25 +0100 Subject: [PATCH 1/4] simplify code --- src/manjaro_hello.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/manjaro_hello.py b/src/manjaro_hello.py index e4b229a..0837857 100644 --- a/src/manjaro_hello.py +++ b/src/manjaro_hello.py @@ -333,12 +333,10 @@ def get_lsb_infos(): for line in lsb_release: if "=" in line: var, arg = line.rstrip().split("=") - if var.startswith("DISTRIB_"): - var = var[8:] - if arg.startswith("\"") and arg.endswith("\""): - arg = arg[1:-1] - if arg: - lsb[var] = arg + if not arg: + continue + var = var.replace("DISTRIB_","") + lsb[var] = arg.strip('"') except (OSError, KeyError) as error: print(error) return 'not Manjaro', '0.0' From 6c63bfe2a613868e039c1c04d17429298dbd0653 Mon Sep 17 00:00:00 2001 From: papajoker Date: Sun, 24 Nov 2019 19:08:24 +0100 Subject: [PATCH 2/4] add gnome switch layout --- launch.sh | 2 +- src/manjaro_hello.py | 8 ++++++++ ui/manjaro-hello.glade | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/launch.sh b/launch.sh index 7200f96..243ae3e 100755 --- a/launch.sh +++ b/launch.sh @@ -2,7 +2,7 @@ # Script to generate mo files in a temp locale folder # Use it only for testing purpose export PLUGIN_HELLO=True -export PYTHONPATH="/home/fh/Data/projects/application-utility" +export PYTHONPATH="$HOME/test/gnome-layout-switcher/bin:$HOME/Data/projects/application-utility" rm -rf locale mkdir locale cd po diff --git a/src/manjaro_hello.py b/src/manjaro_hello.py index 0837857..af88ac8 100644 --- a/src/manjaro_hello.py +++ b/src/manjaro_hello.py @@ -23,6 +23,7 @@ except ModuleNotFoundError as e: APPS_PLUGIN = False print(f"Warning: Application Browser plugin not found : {e}") + gi.require_version("Gtk", "3.0") from gi.repository import Gtk, GdkPixbuf @@ -110,6 +111,13 @@ class Hello(Gtk.Window): # create page install Applications self.builder.get_object("stack").add_named(app_browser, "appBrowserpage") self.builder.get_object("appBrowser").set_visible(True) + try: + from layoutswitcherlib.layoutsbox import LayoutBox + app_layout = LayoutBox(self, usehello=True) + self.builder.get_object("stack").add_named(app_layout, "appLayoutspage") + self.builder.get_object("appLayouts").set_visible(True) # show btn in UI + except ModuleNotFoundError as e: + print(f"Info: Application Gnome Layout Switcher plugin not found : {e}") self.window.show() diff --git a/ui/manjaro-hello.glade b/ui/manjaro-hello.glade index e06be9d..519b181 100644 --- a/ui/manjaro-hello.glade +++ b/ui/manjaro-hello.glade @@ -511,6 +511,14 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we Common application selection + + Layouts switcher + appLayouts + False + True + Manjaro Gnone config tool + + 1 8 From f63252cd97a28d3c5467f1c05ba7c7696bba7697 Mon Sep 17 00:00:00 2001 From: papajoker Date: Wed, 27 Nov 2019 21:44:44 +0100 Subject: [PATCH 3/4] set UI btns with one or 2 plugins --- src/manjaro_hello.py | 33 ++++++++++++++++------ ui/manjaro-hello.glade | 64 ++++++++++++++++++++++++++++-------------- 2 files changed, 67 insertions(+), 30 deletions(-) diff --git a/src/manjaro_hello.py b/src/manjaro_hello.py index af88ac8..67ae21a 100644 --- a/src/manjaro_hello.py +++ b/src/manjaro_hello.py @@ -74,7 +74,7 @@ class Hello(Gtk.Window): widget.get_image_position() is Gtk.PositionType.RIGHT: img = Gtk.Image.new_from_file( self.preferences["data_path"] + "img/external-link.png") - img.set_margin_left(2) + img.set_margin_start(2) widget.set_image(img) # Create pages @@ -106,18 +106,33 @@ class Hello(Gtk.Window): # Installed systems else: if APPS_PLUGIN: - conf = HelloConfig(application="manjaro-hello") - app_browser = ApplicationBrowser(conf, self) - # create page install Applications - self.builder.get_object("stack").add_named(app_browser, "appBrowserpage") - self.builder.get_object("appBrowser").set_visible(True) + try: + conf = HelloConfig(application="manjaro-hello") + app_browser = ApplicationBrowser(conf, self) + # create page install Applications + self.builder.get_object("stack").add_named(app_browser, "appBrowserpage") + self.builder.get_object("appBrowser").set_visible(True) + except Exception as err: + print("Error Application utility:", err) try: + #self.builder.get_object("appBrowser").set_visible(True) # for test with 2 btns from layoutswitcherlib.layoutsbox import LayoutBox - app_layout = LayoutBox(self, usehello=True) - self.builder.get_object("stack").add_named(app_layout, "appLayoutspage") - self.builder.get_object("appLayouts").set_visible(True) # show btn in UI + try: + app_layout = LayoutBox(self, usehello=True) + self.builder.get_object("stack").add_named(app_layout, "appLayoutspage") + if not self.builder.get_object("appBrowser").props.visible: #if APPS_PLUGIN: + btn = self.builder.get_object("appLayouts") + btn.set_margin_start(200) + btn.set_margin_end(200) + self.builder.get_object("appLayouts").set_visible(True) # show btn in UI + except Exception as err: + print("Error Gnome Manager:", err) except ModuleNotFoundError as e: print(f"Info: Application Gnome Layout Switcher plugin not found : {e}") + if self.builder.get_object("appBrowser").props.visible and not self.builder.get_object("appLayouts").props.visible: #if : + btn = self.builder.get_object("appBrowser") + btn.set_margin_start(200) + btn.set_margin_end(200) self.window.show() diff --git a/ui/manjaro-hello.glade b/ui/manjaro-hello.glade index 519b181..00f31da 100644 --- a/ui/manjaro-hello.glade +++ b/ui/manjaro-hello.glade @@ -503,25 +503,53 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we - - Applications - appBrowser + False - True - Common application selection - - - - Layouts switcher - appLayouts - False - True - Manjaro Gnone config tool - + True + boxPlugins + 0 + True + + + Applications + appBrowser + False + False + True + Common application selection + 15 + 15 + + + + True + True + 0 + + + + + Gnome Layouts Manager + appLayouts + False + False + True + Manjaro Gnone config tool + 15 + 15 + + + + False + True + 1 + + - 1 + 0 8 + 3 @@ -530,12 +558,6 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we - - - - - - homepage From 4d48ea0f8706f4996c2bfda65f02e5c5144eb83c Mon Sep 17 00:00:00 2001 From: papajoker Date: Tue, 3 Dec 2019 09:18:22 +0100 Subject: [PATCH 4/4] refactoring: use class, embed app more as plugins --- src/manjaro_hello.py | 116 ++++++++++++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 39 deletions(-) diff --git a/src/manjaro_hello.py b/src/manjaro_hello.py index 67ae21a..412b6c1 100644 --- a/src/manjaro_hello.py +++ b/src/manjaro_hello.py @@ -13,21 +13,84 @@ import subprocess import sys import webbrowser -try: - from application_utility.browser.application_browser import ApplicationBrowser - from application_utility.browser.exceptions import NoAppInIsoError - from application_utility.config.hello_config import HelloConfig - APPS_PLUGIN = True - -except ModuleNotFoundError as e: - APPS_PLUGIN = False - print(f"Warning: Application Browser plugin not found : {e}") - - gi.require_version("Gtk", "3.0") from gi.repository import Gtk, GdkPixbuf +class EmbedManager: + """manage included applications""" + def __init__(self, *args): + self.apps = [] + self.count = 0 + for app in args: + self.apps.append(app) + + def get_modules(self, window: Gtk.Window): + for app in self.apps: + app.load(window) + self.count = sum((1 for x in self.apps if x.loaded)) + + def display(self, window: Gtk.Window): + for app in self.apps: + app.display(window) + if app.loaded: + btn = window.builder.get_object(app.name) + if self.count < 2: + btn.set_margin_start(200) + btn.set_margin_end(200) + #TODO if self.count>2 !!! ??? + + +class Embed: + """abstact class for include app""" + def __init__(self): + """ abstact class initialisation """ + self.name = "app" + self.__class__.__name__[5:] + self.loaded = False + self.box = None + + def load(self, window: Gtk.Window) -> bool: + """ load modules if installed""" + raise Exception('abstract method') + + def display(self, window: Gtk.Window): + """ show btn and add page""" + window.builder.get_object(self.name).set_visible(self.loaded) + if self.loaded: + window.builder.get_object("stack").add_named(self.box, self.name + "page") + +class EmbedLayouts(Embed): + """Gnome layout switcher""" + def load(self, window: Gtk.Window) -> bool: + try: + from layoutswitcherlib.layoutsbox import LayoutBox + try: + self.box = LayoutBox(window, usehello=True) + except Exception as err: + print("Error in Embled application:", err) + except ModuleNotFoundError as err: + print(f"Info: Gnome-layout-switcher not installed") + self.loaded = self.box is not None + return self.loaded + +class EmbedBrowser(Embed): + """Application-utility""" + def load(self, window: Gtk.Window) -> bool: + try: + from application_utility.browser.application_browser import ApplicationBrowser + from application_utility.browser.exceptions import NoAppInIsoError + from application_utility.config.hello_config import HelloConfig + try: + conf = HelloConfig(application="manjaro-hello") + self.box = ApplicationBrowser(conf, window) + except Exception as err: + print("Error in Embled application:", err) + except ModuleNotFoundError as err: + print(f"Info: Application-utility not installed") + self.loaded = self.box is not None + return self.loaded + + class Hello(Gtk.Window): """Hello""" @@ -105,34 +168,9 @@ class Hello(Gtk.Window): self.builder.get_object("install").set_visible(True) # Installed systems else: - if APPS_PLUGIN: - try: - conf = HelloConfig(application="manjaro-hello") - app_browser = ApplicationBrowser(conf, self) - # create page install Applications - self.builder.get_object("stack").add_named(app_browser, "appBrowserpage") - self.builder.get_object("appBrowser").set_visible(True) - except Exception as err: - print("Error Application utility:", err) - try: - #self.builder.get_object("appBrowser").set_visible(True) # for test with 2 btns - from layoutswitcherlib.layoutsbox import LayoutBox - try: - app_layout = LayoutBox(self, usehello=True) - self.builder.get_object("stack").add_named(app_layout, "appLayoutspage") - if not self.builder.get_object("appBrowser").props.visible: #if APPS_PLUGIN: - btn = self.builder.get_object("appLayouts") - btn.set_margin_start(200) - btn.set_margin_end(200) - self.builder.get_object("appLayouts").set_visible(True) # show btn in UI - except Exception as err: - print("Error Gnome Manager:", err) - except ModuleNotFoundError as e: - print(f"Info: Application Gnome Layout Switcher plugin not found : {e}") - if self.builder.get_object("appBrowser").props.visible and not self.builder.get_object("appLayouts").props.visible: #if : - btn = self.builder.get_object("appBrowser") - btn.set_margin_start(200) - btn.set_margin_end(200) + manager = EmbedManager(EmbedBrowser(), EmbedLayouts()) + manager.get_modules(self) + manager.display(self) self.window.show()