diff --git a/mocha-python/src/mocha-python/barista/BaristaEditor.py b/mocha-python/src/mocha-python/barista/BaristaEditor.py index 23fb89a..55dcd48 100644 --- a/mocha-python/src/mocha-python/barista/BaristaEditor.py +++ b/mocha-python/src/mocha-python/barista/BaristaEditor.py @@ -23,6 +23,11 @@ from BaristaSettings import BaristaSettings class BaristaEditor(Gtk.Box): + def set_filename(self, filename : str): + self._filename = filename + def get_filename(self): + return self._filename + def on_search(self, entry : Gtk.SearchEntry): query = entry.get_text() self.treeview_filter.update(query) @@ -88,7 +93,7 @@ class BaristaEditor(Gtk.Box): gid = str(inst.get_instance_key()) self.lookup_instance_key(gid) def lookup_instance_key(self, key : str): - url = "https://" + self.parent.toolbar.get_selected_suv() + "/super/d/inst/" + key + ".htmld" + url = self.parent.toolbar.get_selected_suv() + "/super/d/inst/" + key + ".htmld" import subprocess subprocess.run(["xdg-open", url]) @@ -327,6 +332,8 @@ class BaristaEditor(Gtk.Box): def __init__(self, parent, om : McxObjectModel): super().__init__(orientation=Gtk.Orientation.VERTICAL) + + self._filename = None self.row_items = dict() self.parent = parent self.settings = parent.settings diff --git a/mocha-python/src/mocha-python/barista/BaristaToolbar.py b/mocha-python/src/mocha-python/barista/BaristaToolbar.py index 1d5a592..f1433ca 100644 --- a/mocha-python/src/mocha-python/barista/BaristaToolbar.py +++ b/mocha-python/src/mocha-python/barista/BaristaToolbar.py @@ -22,13 +22,44 @@ class BaristaToolbar (Gtk.Box): def __init__(self, parent): super().__init__(orientation=Gtk.Orientation.HORIZONTAL) - self.suvs = [ - - ( "i-0708947a3b88c3f6.privatesuv.com", "i-0708947a3b88c3f6.privatesuv.com", False ), - ( " SPOT : ", "", False ), - ( "quovii.com", "quovii.com", True ) + self.suvs = [ ] + + cfg = parent.application.suv_manager_config + if cfg is not None: + if "suvs" in cfg: + for i in range(0, len(cfg["suvs"])): + suv = cfg["suvs"][i] + suv_id = "" + suv_title = "" + suv_url = "" + running = None + + if "id" in suv: + suv_id = suv["id"] + if "title" in suv: + suv_title = suv["title"] + if "url" in suv: + suv_url = suv["url"] + if "external" in suv: + if suv["external"]: + running = True + + if running is None: + import subprocess + out = "" + + try: + out = subprocess.run(executable="mocha", args=["", "suv", "shell", suv_id,"cat /etc/mocha/suvstart"],capture_output=True,timeout=1).stdout + except subprocess.TimeoutExpired: + pass + + if len(out) == 0: + running = False + else: + running = True + + self.suvs.append((suv_title, suv_url, running)) - ] self.suvs_menus = dict() self.selected_suv = None diff --git a/mocha-python/src/mocha-python/barista/MainWindow.py b/mocha-python/src/mocha-python/barista/MainWindow.py index 969a59b..9e4ba9f 100644 --- a/mocha-python/src/mocha-python/barista/MainWindow.py +++ b/mocha-python/src/mocha-python/barista/MainWindow.py @@ -24,11 +24,15 @@ from BaristaEditor import BaristaEditor from BaristaToolbar import BaristaToolbar from BaristaSettings import BaristaSettings +from framework.desktop import DesktopApplication + class MainWindow (Gtk.ApplicationWindow): - def __init__(self): + def __init__(self, app : DesktopApplication + ): super().__init__() + self.application = app self.settings = BaristaSettings() self.settings.show_entity_definitions = False self.current_editor = None @@ -41,9 +45,83 @@ class MainWindow (Gtk.ApplicationWindow): self.set_title('Barista - []') box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) - accel_group = Gtk.AccelGroup() - self.add_accel_group(accel_group) + box.pack_start(self.build_menu(), False, False, 0) + self.toolbar = BaristaToolbar(self) + box.pack_start(self.toolbar, False, False, 0) + + + self.tabs = Gtk.Notebook() + self.tabs.connect("switch-page", self.tabs_switch_page) + self.tabs.show() + + box.pack_start(self.tabs, True, True, 0) + + box.show() + + self.add(box) + + def tabs_switch_page(self, notebook : Gtk.Notebook, page : Gtk.Widget, page_num : int): + import os + + filename = page.get_filename() + if filename is None: + return + + filetitle = os.path.basename(filename) + self.set_title("Barista - [" + filetitle + "]") + self.current_editor = page + + def create_editor_tab_label(self, filename : str): + from os.path import basename, dirname + + tab_label = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + label = Gtk.Label(label=basename(filename)) + label2 = Gtk.Label(label=dirname(filename)) + label2.set_sensitive(False) + label2.set_ellipsize(Pango.EllipsizeMode.MIDDLE) + + lst = Pango.AttrList() + lst.insert(Pango.attr_size_new_absolute(Pango.SCALE * 10)) + + label2.set_attributes(lst) + tab_label.pack_start(label, True, True, 0) + label.show() + + tab_label.pack_start(label2, True, True, 0) + label2.show() + + tab_label.show() + return tab_label + + def open_file(self, filename : str): + self.add_editor_tab (filename) + + def add_editor_tab(self, filename : str): + + f = open(filename, 'rb') + + df = McxDataFormat() + om = McxObjectModel() + df.load(om, f) + + print("barista: creating editor") + box = self.create_editor(om) + box.set_filename(filename) + + self.tabs.add(box) + box.show() + + self.tabs.set_tab_label(box, self.create_editor_tab_label(filename)) + f.close() + + def create_editor(self, om : McxObjectModel) -> BaristaEditor: + box = BaristaEditor(self, om) + self.current_editor = box + self.current_editor.settings = self.settings + return box + + def build_menu(self): menu = Gtk.MenuBar() Gtk.AccelMap.add_entry("/FileOpen", Gdk.KEY_O, Gdk.ModifierType.CONTROL_MASK) Gtk.AccelMap.add_entry("/FileQuit", Gdk.KEY_Q, Gdk.ModifierType.CONTROL_MASK) @@ -52,7 +130,7 @@ class MainWindow (Gtk.ApplicationWindow): mnuFile.set_label("_File") mnuFile.set_use_underline(True) mnuFile.set_submenu(Gtk.Menu()) - mnuFile.get_submenu().set_accel_group(accel_group) + mnuFile.get_submenu().set_accel_group(self.application.app_accel_group) mnuFileOpen = Gtk.MenuItem() mnuFileOpen.set_accel_path("/FileOpen") @@ -103,68 +181,8 @@ class MainWindow (Gtk.ApplicationWindow): mnuHelp.get_submenu().add(mnuHelpAbout) menu.add(mnuHelp) - menu.show() - - box.pack_start(menu, False, False, 0) - - self.toolbar = BaristaToolbar(self) - box.pack_start(self.toolbar, False, False, 0) - - - self.tabs = Gtk.Notebook() - self.tabs.show() - - box.pack_start(self.tabs, True, True, 0) - - box.show() - - self.add(box) - - def create_editor_tab_label(self, filename : str): - from os.path import basename, dirname - - tab_label = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) - label = Gtk.Label(label=basename(filename)) - label2 = Gtk.Label(label=dirname(filename)) - label2.set_sensitive(False) - label2.set_ellipsize(Pango.EllipsizeMode.MIDDLE) - - lst = Pango.AttrList() - lst.insert(Pango.attr_size_new_absolute(Pango.SCALE * 10)) - - label2.set_attributes(lst) - tab_label.pack_start(label, True, True, 0) - label.show() - - tab_label.pack_start(label2, True, True, 0) - label2.show() - - tab_label.show() - return tab_label - - def add_editor_tab(self, filename : str): - - f = open(filename, 'rb') - - df = McxDataFormat() - om = McxObjectModel() - df.load(om, f) - - print("barista: creating editor") - box = self.create_editor(om) - - self.tabs.add(box) - box.show() - - self.tabs.set_tab_label(box, self.create_editor_tab_label(filename)) - f.close() - - def create_editor(self, om : McxObjectModel) -> BaristaEditor: - box = BaristaEditor(self, om) - self.current_editor = box - self.current_editor.settings = self.settings - return box - + return menu + def mnuFileOpen_activate(self, args): dlg = Gtk.FileChooserDialog(title="Open File", action=Gtk.FileChooserAction.OPEN) dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, @@ -183,7 +201,7 @@ class MainWindow (Gtk.ApplicationWindow): if ret == Gtk.ResponseType.OK: for filename in filenames: - self.add_editor_tab (filename) + self.open_file(filename) def mnuFileClose_activate(self, args): if self.tabs.get_n_pages() <= 1: @@ -216,3 +234,19 @@ class MainWindow (Gtk.ApplicationWindow): dlg.set_comments("View and manipulate compiled Mocha class library packages") dlg.run() dlg.destroy() + + def build_menu2(self): + menu = Gio.Menu() + + mnuFile = Gio.MenuItem() + mnuFile.set_label("_File") + + menu2 = Gio.Menu() + mnuQuit = Gio.MenuItem() + mnuQuit.set_label("_Quit") + menu2.append_item(mnuQuit) + + mnuFile.set_submenu(menu2) + + menu.append_item(mnuFile) + return menu diff --git a/mocha-python/src/mocha-python/barista/barista.py b/mocha-python/src/mocha-python/barista/barista.py index aa2ec05..7512ed6 100644 --- a/mocha-python/src/mocha-python/barista/barista.py +++ b/mocha-python/src/mocha-python/barista/barista.py @@ -3,7 +3,7 @@ from framework.desktop import DesktopApplication import gi gi.require_version('Gtk', '3.0') -from gi.repository import Gtk, Pango +from gi.repository import Gtk, Gdk, Gio, Pango from mocha.lib.mcx.dataformats.McxDataFormat import McxDataFormat from mocha.lib.mcx.objectmodels.McxObjectModel import McxObjectModel @@ -15,13 +15,39 @@ class Program (DesktopApplication): def __init__(self): super().__init__('com.mochapowered.python.barista') + self.app_accel_group = Gtk.AccelGroup() + self.current_window = None + + import json, os + from pathlib import Path + fs = str(Path.home()) + "/.config/mocha/barista/suv-manager.json" + if os.path.exists(fs): + self.suv_manager_config = json.load(open(fs)) + else: + self.suv_manager_config = None + def startup(self, args): from gi.repository import GLib GLib.set_prgname('barista') + + def wnd_focus(self, widget, direction_type): + self.current_window = widget + print("wndow focus") def activate(self, args): - wnd = MainWindow() + wnd = MainWindow(self) + wnd.connect("focus", self.wnd_focus) + wnd.add_accel_group(self.app_accel_group) + + # menu = self.build_menu2() + # self.app.set_menubar(menu) + + import sys + files = sys.argv[1:] + for file in files: + wnd.open_file(file) + wnd.app = self self.app.add_window(wnd) diff --git a/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/applications/net.alcetech.Mocha.Barista.desktop b/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/applications/net.alcetech.Mocha.Barista.desktop new file mode 100644 index 0000000..aae00c8 --- /dev/null +++ b/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/applications/net.alcetech.Mocha.Barista.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Version=1.0 +Name=Barista +Comment=Edit Mocha compiled library packages +Type=Application +Exec=/usr/bin/barista +Icon=barista +Terminal=false +StartupNotify=true +Categories=TextEditor;Development;GTK; +MimeType=application/x-mocha-mcx diff --git a/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/icons/Adwaita/scalable/mimetypes/application-x-mocha-mcs.svg b/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/icons/Adwaita/scalable/mimetypes/application-x-mocha-mcs.svg new file mode 100644 index 0000000..ff504ee --- /dev/null +++ b/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/icons/Adwaita/scalable/mimetypes/application-x-mocha-mcs.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + diff --git a/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/icons/Adwaita/scalable/mimetypes/application-x-mocha-mcx.svg b/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/icons/Adwaita/scalable/mimetypes/application-x-mocha-mcx.svg new file mode 100644 index 0000000..de3e60f --- /dev/null +++ b/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/icons/Adwaita/scalable/mimetypes/application-x-mocha-mcx.svg @@ -0,0 +1,618 @@ + + + + + + + + + + + + + + + + + + diff --git a/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/icons/Adwaita/scalable/mimetypes/package-x-mocha-mcz.svg b/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/icons/Adwaita/scalable/mimetypes/package-x-mocha-mcz.svg new file mode 100644 index 0000000..5cbc35a --- /dev/null +++ b/mocha-python/src/mocha-python/barista/desktop-integration/gnome/usr/share/icons/Adwaita/scalable/mimetypes/package-x-mocha-mcz.svg @@ -0,0 +1,567 @@ + + + +