diff options
| author | Eero Tamminen <oak@helsinkinet.fi> | 2020-12-18 21:13:18 (GMT) |
|---|---|---|
| committer | Eero Tamminen <oak@helsinkinet.fi> | 2020-12-18 21:26:54 (GMT) |
| commit | d7598c49053155cf3ae54341508345c25a780133 (patch) | |
| tree | 6a03e93fa4331ae152f84188d0ee247360298945 | |
| parent | 0ffdf29371c813107493791e4c9b894fb643d8fc (diff) | |
| download | hatari-d7598c49053155cf3ae54341508345c25a780133.zip hatari-d7598c49053155cf3ae54341508345c25a780133.tar.gz | |
Use Glib functions in Python UI instead of deprecated GObject ones
"hatariui.py" changes are from Jens Guenther, thanks!
Also update docs accordingly (while python2 may still work, it's
not tested, so don't mention it any more in README).
| -rw-r--r-- | doc/authors.txt | 3 | ||||
| -rw-r--r-- | python-ui/README | 4 | ||||
| -rw-r--r-- | python-ui/TODO | 1 | ||||
| -rwxr-xr-x | python-ui/hatariui.py | 21 | ||||
| -rwxr-xr-x | python-ui/tests/gtk-hatari-embed-test.py | 4 | ||||
| -rw-r--r-- | python-ui/uihelpers.py | 4 |
6 files changed, 21 insertions, 16 deletions
diff --git a/doc/authors.txt b/doc/authors.txt index 34ead99..f7ee00b 100644 --- a/doc/authors.txt +++ b/doc/authors.txt @@ -158,6 +158,9 @@ random order - and if someone is missing here, please remind us!): Patch to improve clearing borders in fullscreen mode. Patch to fix PNG header alignment when recording AVI files. +- Jens Guenther : extra info on Python UI embedding issue and fixes + for PyGtk deprecations warnings in Python UI + See also "thanks.txt" for people who've helped Hatari development in other ways than code contributions. diff --git a/python-ui/README b/python-ui/README index 373c8d0..f0438cb 100644 --- a/python-ui/README +++ b/python-ui/README @@ -21,8 +21,8 @@ replaced or going anywhere! Requirements ------------ -- Python2 >= 2.7, or python3 >= 3.5 -- python-gi (Python GObject Introspection) +- python3 >= 3.5 +- python3-gi (Python GObject Introspection) - Gtk >= v3.22 and its gir bindings (gir1.2-gtk-3.0) Hatari UI is included with the Hatari sources: diff --git a/python-ui/TODO b/python-ui/TODO index d0e3d6d..85f0a2a 100644 --- a/python-ui/TODO +++ b/python-ui/TODO @@ -9,7 +9,6 @@ its sources). - Menus & ActionGroups -> Application framework - Table -> Grid layout in dialogs - Positional -> named arguments - - GObject -> Glib * Interface between UI and Hatari so that Hatari will forward error and other dialog texts to UI for showing, and waits until user has diff --git a/python-ui/hatariui.py b/python-ui/hatariui.py index af72fd5..5b06db6 100755 --- a/python-ui/hatariui.py +++ b/python-ui/hatariui.py @@ -2,7 +2,7 @@ # # A Python Gtk UI for Hatari that can embed the Hatari emulator window. # -# Requires Gtk 3.x and Python GObject Introspection libraries. +# Requires Gtk 3.x and Python GLib Introspection libraries. # # Copyright (C) 2008-2020 by Eero Tamminen # @@ -25,7 +25,7 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gdk -from gi.repository import GObject +from gi.repository import GLib from debugui import HatariDebugUI from hatari import Hatari, HatariConfigMapping @@ -158,7 +158,10 @@ class UICallbacks: socket.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("black")) socket.set_events(Gdk.EventMask.ALL_EVENTS_MASK) # set max Hatari window size = desktop size - self.config.set_desktop_size(Gdk.Screen.width(), Gdk.Screen.height()) + monitor = Gdk.Display.get_default().get_primary_monitor() + geometry = monitor.get_geometry() + scale = monitor.get_scale_factor() + self.config.set_desktop_size(scale * geometry.width, scale * geometry.height) # set initial embedded hatari size width, height = self.config.get_window_size() socket.set_size_request(width, height) @@ -168,7 +171,7 @@ class UICallbacks: # ------- run callback ----------- def _socket_cb(self, fd, event): - if event != GObject.IO_IN: + if event != GLib.IO_IN: # hatari process died, make sure Hatari instance notices self.hatari.kill() return False @@ -185,7 +188,7 @@ class UICallbacks: if not self.killdialog.run(self.hatari): return if self.io_id: - GObject.source_remove(self.io_id) + GLib.source_remove(self.io_id) args = ["--configfile"] # whether to use Hatari config or unsaved Hatari UI config? if self.config.is_changed(): @@ -202,8 +205,8 @@ class UICallbacks: # get notifications of Hatari window size changes self.hatari.enable_embed_info() socket = self.hatari.get_control_socket().fileno() - events = GObject.IO_IN | GObject.IO_HUP | GObject.IO_ERR - self.io_id = GObject.io_add_watch(socket, events, self._socket_cb) + events = GLib.IO_IN | GLib.IO_HUP | GLib.IO_ERR + self.io_id = GLib.io_add_watch(socket, events, self._socket_cb) # all keyboard events should go to Hatari window self.hatariwin.grab_focus() else: @@ -223,7 +226,7 @@ class UICallbacks: if not self.killdialog.run(self.hatari): return True if self.io_id: - GObject.source_remove(self.io_id) + GLib.source_remove(self.io_id) Gtk.main_quit() if os.path.exists(self.tmpconfpath): os.unlink(self.tmpconfpath) @@ -669,7 +672,7 @@ class UIActions: # ugly, Hatari socket window ID can be gotten only # after Socket window is realized by gtk_main() - GObject.idle_add(self.callbacks.run) + GLib.idle_add(self.callbacks.run) Gtk.main() diff --git a/python-ui/tests/gtk-hatari-embed-test.py b/python-ui/tests/gtk-hatari-embed-test.py index d732d9b..6dbbcf2 100755 --- a/python-ui/tests/gtk-hatari-embed-test.py +++ b/python-ui/tests/gtk-hatari-embed-test.py @@ -33,7 +33,7 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GdkX11 -from gi.repository import GObject +from gi.repository import GLib def usage(error): print("\nusage: %s <widget> <embed method>\n" % sys.argv[0].split(os.path.sep)[-1]) @@ -68,7 +68,7 @@ class AppUI(): self.window.show_all() # wait a while before starting Hatari to make # sure parent window has been realized - GObject.timeout_add(500, self.timeout_cb) + GLib.timeout_add(500, self.timeout_cb) def create_window(self): window = Gtk.Window(Gtk.WindowType.TOPLEVEL) diff --git a/python-ui/uihelpers.py b/python-ui/uihelpers.py index 027b337..42ba7ee 100644 --- a/python-ui/uihelpers.py +++ b/python-ui/uihelpers.py @@ -19,7 +19,7 @@ import gi # use correct version of gtk gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from gi.repository import GObject +from gi.repository import GLib # leak debugging @@ -169,7 +169,7 @@ class HatariTextInsert: self.pressed = False self.hatari = hatari print("OUTPUT '%s'" % text) - GObject.timeout_add(100, _text_insert_cb, self) + GLib.timeout_add(100, _text_insert_cb, self) # callback to insert text object to Hatari character at the time # (first key down, on next call up), at given interval |
