Merge branch 'plugins' into 'master'

Merge Plugins branch into master: this allow gnome-layouts-switcher to work as a plugin.

See merge request applications/manjaro-hello!72
fhdk-master-patch-98229
Stefano Capitani 2020-01-30 12:22:26 +01:00
commit db5194a319
3 changed files with 126 additions and 37 deletions

View File

@ -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

View File

@ -13,20 +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"""
@ -73,7 +137,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
@ -104,12 +168,9 @@ class Hello(Gtk.Window):
self.builder.get_object("install").set_visible(True)
# 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)
manager = EmbedManager(EmbedBrowser(), EmbedLayouts())
manager.get_modules(self)
manager.display(self)
self.window.show()
@ -333,12 +394,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'

View File

@ -503,17 +503,53 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
</packing>
</child>
<child>
<object class="GtkButton" id="appBrowser">
<property name="label" translatable="yes">Applications</property>
<property name="name">appBrowser</property>
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Common application selection</property>
<signal name="clicked" handler="on_btn_clicked" swapped="no"/>
<property name="visible">True</property>
<property name="name">boxPlugins</property>
<property name="spacing">0</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton" id="appBrowser">
<property name="label" translatable="yes">Applications</property>
<property name="name">appBrowser</property>
<property name="visible">False</property>
<property name="can_focus">False</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Common application selection</property>
<property name="margin_left">15</property>
<property name="margin_right">15</property>
<signal name="clicked" handler="on_btn_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="appLayouts">
<property name="label" translatable="yes">Gnome Layouts Manager</property>
<property name="name">appLayouts</property>
<property name="visible">False</property>
<property name="can_focus">False</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Manjaro Gnone config tool</property>
<property name="margin_left">15</property>
<property name="margin_right">15</property>
<signal name="clicked" handler="on_btn_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="left_attach">0</property>
<property name="top_attach">8</property>
<property name="width">3</property>
</packing>
</child>
<child>
@ -522,12 +558,6 @@ We, the Manjaro Developers, hope that you will enjoy using Manjaro as much as we
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="name">homepage</property>