From 7ed0ba1097624c18613755e571848c05946ac139 Mon Sep 17 00:00:00 2001 From: somas95 Date: Wed, 21 Mar 2018 00:20:49 +0100 Subject: [PATCH] Window refactoring Signed-off-by: somas95 --- data/ui/App_menu.ui | 38 + data/ui/UberwriterWindow.ui | 1647 ++++++++++++++++---------------- data/ui/uberwriter_window.xml | 2 +- uberwriter/UberwriterWindow.py | 9 +- uberwriter/__init__.py | 4 +- uberwriter_lib/AppWindow.py | 106 ++ uberwriter_lib/Window.py | 22 +- 7 files changed, 969 insertions(+), 859 deletions(-) create mode 100644 data/ui/App_menu.ui create mode 100644 uberwriter_lib/AppWindow.py diff --git a/data/ui/App_menu.ui b/data/ui/App_menu.ui new file mode 100644 index 0000000..416efc0 --- /dev/null +++ b/data/ui/App_menu.ui @@ -0,0 +1,38 @@ + + + +
+ Change label + + + String 1 + + + String 2 + + + String 3 + +
+
+ + win.maximize + Maximize + +
+
+ + app.about + _About + + + app.quit + _Quit + <Primary>q + +
+
+
diff --git a/data/ui/UberwriterWindow.ui b/data/ui/UberwriterWindow.ui index 460a6ac..2ef1285 100644 --- a/data/ui/UberwriterWindow.ui +++ b/data/ui/UberwriterWindow.ui @@ -2,7 +2,6 @@ - @@ -26,6 +25,806 @@ False format-text-capitalize + + True + False + + + True + False + + + True + False + + + True + False + + + True + False + False + + + + + + + True + False + False + + + + + + + True + False + + + + + True + False + False + + + True + False + + + True + False + + + + + + + + + + True + False + + + + + True + False + False + + + + + + + True + False + False + + + + + + + True + False + + + + + True + False + False + + + + + + True + False + False + + + + + + True + False + False + + + + + + True + False + + + + + + True + False + + + + + True + False + + + + + + True + False + + + + + True + False + False + + + + + + + + + + True + False + + + True + False + + + True + False + + + + + + + True + False + + + + + + + False + + + + + + True + False + Light text on a dark background + + + + + + True + False + Switch to preview mode + + + + + + + True + False + Open Search and Replace + + + + + + + False + + + + + False + True + True + + + + + + False + + + + + False + True + + + + + + + + + + + True + False + + + True + False + + + True + False + + + + + + True + False + + + + + True + False + + + + + + True + False + + + + + + True + False + + + + + + True + False + + + + + + True + False + + + + + True + False + False + + + + + + + + + 0 + 0 + + + + + True + True + True + + + 200 + True + False + start + vertical + + + + + + + + + + + + False + True + + + + + True + False + True + + + 500 + True + True + True + True + adjustment1 + never + + + True + False + 5 + True + True + natural + natural + none + + + True + False + center + + + + + + + + + + 0 + 0 + + + + + True + False + crossfade + 750 + True + + + True + False + + + Focus Mode + 15 + True + True + False + True + True + Go into focus mode + Go into focus mode + center + none + + + + 0 + 0 + + + + + Fullscreen + True + True + False + True + True + Go into fullscreen mode + Go into fullscreen mode + start + none + + + + 1 + 0 + + + + + Preview + True + True + False + True + True + Show HTML preview + Show HTML preview + start + none + + + + 2 + 0 + + + + + True + False + end + True + Words: + + + 3 + 0 + + + + + True + False + end + 0 + right + 4 + 1 + + + 4 + 0 + + + + + True + False + end + 10 + 10 + 10 + 10 + vertical + + + 5 + 0 + + + + + True + False + end + Characters: + + + 6 + 0 + + + + + True + False + end + 11 + 11 + 0 + 6 + 1 + + + 7 + 0 + + + + + + + 0 + 1 + + + + + False + False + + + + + 0 + 2 + + + + + True + False + + + True + False + True + True + + + True + False + none + True + + + True + False + vertical + + + True + False + 6 + + + + + + True + False + + + True + True + edit-find-symbolic + False + False + + + False + True + 0 + + + + + True + True + True + Previous Match + amunt + + + False + True + 1 + + + + + True + True + True + avall + + + False + True + 2 + + + + + + False + True + 1 + + + + + + + + True + False + + + True + True + True + Case Sensitive + case_sensitiv + + + False + True + 0 + + + + + True + True + True + regex1 + + + False + True + 1 + + + + + True + True + True + reemplaza + + + False + True + 2 + + + + + + False + True + 3 + + + + + + + + False + True + 0 + + + + + True + False + + + True + False + 6 + 6 + + + + + + True + False + + + True + True + True + gtk-find-and-replace + + + True + True + 0 + + + + + + False + True + 1 + + + + + + + + True + False + + + Replace + True + True + True + ortografia1 + + + False + True + 0 + + + + + Replace all + True + True + True + reemplaza1 + + + False + True + 1 + + + + + + False + True + 3 + + + + + + + + + + False + True + 1 + + + + + + + + + + + 0 + 1 + + + True False @@ -54,850 +853,4 @@ Activate Regex find-location-symbolic - - True - 800 - 500 - ../media/uberwriter.svg - - - True - False - - - True - False - - - True - False - _File - True - - - True - False - - - _New - True - False - True - False - - - - - - - _Open - True - False - True - False - - - - - - - True - False - Open Recent File - True - - - - - Open examples - True - False - False - - - True - False - - - True - False - _Quick markdown tutorial - True - - - - - - - - - - True - False - - - - - _Save - True - False - True - False - - - - - - - Save _As - True - False - True - False - - - - - - - True - False - - - - - Export as HTML - True - False - False - - - - - - Export as PDF - True - False - False - - - - - - Export as ODT - True - False - False - - - - - - True - False - Advanced Export... - True - - - - - - True - False - - - - - True - False - Copy Raw HTML to Clipboard - True - - - - - - True - False - - - - - _Quit - True - False - True - False - - - - - - - - - - True - False - _View - True - - - True - False - - - True - False - Focus Mode - - - - - - - True - False - Fullscreen - - - - - - - False - Sidebar - - - - - - True - False - Light text on a dark background - Dark Mode - - - - - - True - False - Switch to preview mode - Preview - - - - - - - True - False - Open Search and Replace - Search and Replace ... - True - - - - - - - False - - - - - False - Use Typewritermode (experimental) - True - True - - - - - - False - - - - - False - Auto _Spellcheck - True - True - - - - - - - - - - - True - False - _Help - True - - - True - False - - - True - False - Contents - - - - - - True - False - - - - - True - False - Short Markdown Tutorial - - - - - - True - False - Open Pandoc Online Markdown Help ... - - - - - - True - False - Get Help Online... - True - - - - - - True - False - Translate This Application... - True - - - - - - True - False - - - - - gtk-about - True - False - True - False - - - - - - - - - 0 - 0 - - - - - True - True - True - - - 200 - True - False - start - vertical - - - False - True - - - - - True - False - True - - - 500 - True - True - True - True - adjustment1 - never - - - True - False - 5 - True - True - natural - natural - none - - - True - False - center - - - - - - - - - - 0 - 0 - - - - - True - False - crossfade - 750 - True - - - True - False - - - Focus Mode - 15 - True - True - False - True - True - Go into focus mode - Go into focus mode - center - none - - - - 0 - 0 - - - - - Fullscreen - True - True - False - True - True - Go into fullscreen mode - Go into fullscreen mode - start - none - - - - 1 - 0 - - - - - Preview - True - True - False - True - True - Show HTML preview - Show HTML preview - start - none - - - - 2 - 0 - - - - - True - False - end - True - Words: - - - 3 - 0 - - - - - True - False - end - 0 - right - 4 - 1 - - - 4 - 0 - - - - - True - False - end - 10 - 10 - vertical - - - 5 - 0 - - - - - True - False - end - Characters: - - - 6 - 0 - - - - - True - False - end - 11 - 0 - 6 - 1 - - - 7 - 0 - - - - - - - 0 - 1 - - - - - False - False - - - - - 0 - 2 - - - - - True - False - - - True - False - True - True - - - True - False - none - True - - - True - False - vertical - - - True - False - 6 - - - - - - True - False - - - True - True - edit-find-symbolic - False - False - - - False - True - 0 - - - - - True - True - True - Previous Match - amunt - - - False - True - 1 - - - - - True - True - True - avall - - - False - True - 2 - - - - - - False - True - 1 - - - - - - - - True - False - - - True - True - True - Case Sensitive - case_sensitiv - - - False - True - 0 - - - - - True - True - True - regex1 - - - False - True - 1 - - - - - True - True - True - reemplaza - - - False - True - 2 - - - - - - False - True - 3 - - - - - - - - False - True - 0 - - - - - True - False - - - True - False - 6 - 6 - - - - - - True - False - - - True - True - True - gtk-find-and-replace - - - True - True - 0 - - - - - - False - True - 1 - - - - - - - - True - False - - - Replace - True - True - True - ortografia1 - - - False - True - 0 - - - - - Replace all - True - True - True - reemplaza1 - - - False - True - 1 - - - - - - False - True - 3 - - - - - - - - - - False - True - 1 - - - - - - - - - - - 0 - 1 - - - - - - - - diff --git a/data/ui/uberwriter_window.xml b/data/ui/uberwriter_window.xml index 108255b..364c697 100644 --- a/data/ui/uberwriter_window.xml +++ b/data/ui/uberwriter_window.xml @@ -2,7 +2,7 @@ depends="gtk+" version="3.26"> diff --git a/uberwriter/UberwriterWindow.py b/uberwriter/UberwriterWindow.py index 1e91575..2d328e6 100644 --- a/uberwriter/UberwriterWindow.py +++ b/uberwriter/UberwriterWindow.py @@ -58,7 +58,8 @@ try: except: APT_ENABLED = False -from uberwriter_lib import Window +#from uberwriter_lib import Window +from uberwriter_lib import AppWindow from uberwriter_lib import helpers from .AboutUberwriterDialog import AboutUberwriterDialog from .UberwriterAdvancedExportDialog import UberwriterAdvancedExportDialog @@ -70,9 +71,11 @@ from .UberwriterAdvancedExportDialog import UberwriterAdvancedExportDialog CONFIG_PATH = os.path.expanduser("~/.config/uberwriter/") # See texteditor_lib.Window.py for more details about how this class works -class UberwriterWindow(Window): +class UberwriterWindow(AppWindow.Application): - __gtype_name__ = "UberwriterWindow" + #__gtype_name__ = "UberwriterWindow" + + print("hahah") __gsignals__ = { 'save-file': (GObject.SIGNAL_ACTION, None, ()), diff --git a/uberwriter/__init__.py b/uberwriter/__init__.py index eea85e2..0ab4dce 100644 --- a/uberwriter/__init__.py +++ b/uberwriter/__init__.py @@ -58,5 +58,5 @@ def main(): window = UberwriterWindow.UberwriterWindow() if options.experimental_features: window.use_experimental_features(True) - window.show() - Gtk.main() + window.run() + #Gtk.main() diff --git a/uberwriter_lib/AppWindow.py b/uberwriter_lib/AppWindow.py new file mode 100644 index 0000000..662717c --- /dev/null +++ b/uberwriter_lib/AppWindow.py @@ -0,0 +1,106 @@ +import sys + +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import GLib, Gio, Gtk + +from . helpers import get_builder, show_uri, get_help_uri + +class UberwriterWindow(Gtk.ApplicationWindow): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # This will be in the windows group and have the "win" prefix + max_action = Gio.SimpleAction.new_stateful("maximize", None, + GLib.Variant.new_boolean(False)) + max_action.connect("change-state", self.on_maximize_toggle) + self.add_action(max_action) + + # Keep it in sync with the actual state + self.connect("notify::is-maximized", + lambda obj, pspec: max_action.set_state( + GLib.Variant.new_boolean(obj.props.is_maximized))) + + self.default_width = 800 + self.defaul_height = 500 + self.set_icon_from_file("data/media/uberwriter.svg") + + builder = get_builder('UberwriterWindow') + new_object = builder.get_object("grid1") + + + self.builder = builder + self.ui = builder.get_ui(self, True) + self.PreferencesDialog = None # class + self.preferences_dialog = None # instance + self.AboutDialog = None # class + + self.contents = new_object + self.add(self.contents) + + self.finish_initializing(self.builder) + + + def on_maximize_toggle(self, action, value): + action.set_state(value) + if value.get_boolean(): + self.maximize() + else: + self.unmaximize() + +class Application(Gtk.Application): + + def __init__(self, *args, **kwargs): + super().__init__(*args, application_id="de.wolfvollprecht.UberWriter", + flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE, + **kwargs) + self.window = None + + self.add_main_option("test", ord("t"), GLib.OptionFlags.NONE, + GLib.OptionArg.NONE, "Command line test", None) + + def do_startup(self): + Gtk.Application.do_startup(self) + + # ~ action = Gio.SimpleAction.new("about", None) + # ~ action.connect("activate", self.on_about) + # ~ self.add_action(action) + + action = Gio.SimpleAction.new("quit", None) + action.connect("activate", self.on_quit) + self.add_action(action) + + builder = get_builder('App_menu') + self.set_app_menu(builder.get_object("app-menu")) + + def do_activate(self): + # We only allow a single window and raise any existing ones + if not self.window: + # Windows are associated with the application + # when the last one is closed the application shuts down + self.window = UberwriterWindow(application=self, title="UberWriter") + + self.window.present() + + def do_command_line(self, command_line): + options = command_line.get_options_dict() + + if options.contains("test"): + # This is printed on the main instance + print("Test argument recieved") + + self.activate() + return 0 + + # TODO + # ~ def on_about(self, action, param): + # ~ about_dialog = Gtk.AboutDialog(transient_for=self.window, modal=True) + # ~ about_dialog.present() + + def on_quit(self, action, param): + self.quit() + +if __name__ == "__main__": + app = Application() + app.run(sys.argv) diff --git a/uberwriter_lib/Window.py b/uberwriter_lib/Window.py index fc22d40..a474121 100644 --- a/uberwriter_lib/Window.py +++ b/uberwriter_lib/Window.py @@ -24,7 +24,7 @@ from . helpers import get_builder, show_uri, get_help_uri # This class is meant to be subclassed by UberwriterWindow. It provides # common functions and some boilerplate. -class Window(Gtk.ApplicationWindow): +class Window(Gtk.Application): __gtype_name__ = "Window" # To construct a new instance of this method, the following notable @@ -43,11 +43,19 @@ class Window(Gtk.ApplicationWindow): Returns a fully instantiated BaseUberwriterWindow object. """ + App = Gtk.Application() + window = Gtk.ApplicationWindow() + + builder = get_builder('UberwriterWindow') - new_object = builder.get_object("uberwriter_window") - new_object.finish_initializing(builder) - return new_object - + new_object = builder.get_object("grid1") + window.add(new_object) + App.window = window + App.window.present() + #window.finish_initializing(builder) + + return App + def finish_initializing(self, builder): """Called while initializing this instance in __new__ @@ -61,7 +69,7 @@ class Window(Gtk.ApplicationWindow): self.PreferencesDialog = None # class self.preferences_dialog = None # instance self.AboutDialog = None # class - + # self.settings = Gio.Settings("net.launchpad.uberwriter") # self.settings.connect('changed', self.on_preferences_changed) @@ -77,6 +85,8 @@ class Window(Gtk.ApplicationWindow): self.indicator = indicator.new_application_indicator(self) except ImportError: pass + + def on_mnu_contents_activate(self, widget, data=None): show_uri(self, "ghelp:%s" % get_help_uri())