[X2Go-Commits] [pyhoca-gui] 06/09: Port to wxPython 4.0.x.

git-admin at x2go.org git-admin at x2go.org
Mon Dec 2 17:16:16 CET 2019


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository pyhoca-gui.

commit fa352bca6b3e422af069a8a258235351a0626f36
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Mon Dec 2 10:27:43 2019 +0100

    Port to wxPython 4.0.x.
---
 pyhoca/wxgui/about.py         |  7 ++++++-
 pyhoca/wxgui/frontend.py      | 43 +++++++++++++++++++++++++------------------
 pyhoca/wxgui/launcher.py      |  6 ++++--
 pyhoca/wxgui/menus_taskbar.py | 32 +++++++++++++++++++++++++++++++-
 pyhoca/wxgui/splash.py        | 26 ++++++++++++++++++--------
 pyhoca/wxgui/taskbar.py       | 20 ++++++++++++++++----
 6 files changed, 100 insertions(+), 34 deletions(-)

diff --git a/pyhoca/wxgui/about.py b/pyhoca/wxgui/about.py
index ceadb65..414d5e5 100644
--- a/pyhoca/wxgui/about.py
+++ b/pyhoca/wxgui/about.py
@@ -29,6 +29,8 @@ import x2go
 # wxPython
 import wx
 
+wx_major = int(wx.__version__.split('.')[0])
+
 # PyHoca-GUI modules
 from . import basepath
 
@@ -114,7 +116,10 @@ class PyHocaGUI_AboutFrame(wx.Frame):
             icon_file = '%s/%s/%s/%s' % (basepath.icons_basepath, icon_folder, icon_size, icon_name)
 
         img = wx.Image(icon_file)
-        icon = wx.IconFromBitmap(img.ConvertToBitmap())
+        if wx_major < 4:
+            icon = wx.IconFromBitmap(img.ConvertToBitmap())
+        else:
+            icon = wx.Icon(img.ConvertToBitmap())
         self.icon = self.SetIcon(icon)
 
         self.CenterOnScreen()
diff --git a/pyhoca/wxgui/frontend.py b/pyhoca/wxgui/frontend.py
index e65b227..dfc1e76 100644
--- a/pyhoca/wxgui/frontend.py
+++ b/pyhoca/wxgui/frontend.py
@@ -23,6 +23,7 @@ modules ={}
 
 import os
 import re
+import sys
 
 # Python X2Go
 import x2go
@@ -51,7 +52,9 @@ from . import sessiontitle
 from . import listdesktops
 from . import serverinfo
 
-wx.SetDefaultPyEncoding("utf-8")
+wx_major = int(wx.__version__.split('.')[0])
+if wx_major < 4:
+    wx.SetDefaultPyEncoding("utf-8")
 
 #def SetExitHandler(func):
 #    """\
@@ -276,11 +279,11 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
             gevent.sleep(self.gevent_sleep_when_idle)
         except KeyboardInterrupt:
             self._pyhoca_logger('Received Ctrl-C keyboard interrupt... Wait till %s has exited cleanly.' % self.appname, loglevel=x2go.loglevel_NOTICE)
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
         except SystemExit:
             self._pyhoca_logger('Received SIGTERM signal... Wait till %s has exited cleanly.' % self.appname, loglevel=x2go.loglevel_NOTICE)
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
         evt.RequestMore()
         return True
@@ -319,8 +322,12 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         self.about_pythonx2go.Show(False)
 
         self.taskbar = taskbar.PyHocaGUI_TaskBarIcon(self.about)
-        self.taskbar.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, lambda _Show: self.about.Show(True))
-        self.taskbar.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.taskbar.CreateSessionManagerPopupMenu)
+        if wx_major < 4:
+            self.taskbar.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, lambda _Show: self.about.Show(True))
+            self.taskbar.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.taskbar.CreateSessionManagerPopupMenu)
+        else:
+            self.taskbar.Bind(wx.adv.EVT_TASKBAR_LEFT_DCLICK, lambda _Show: self.about.Show(True))
+            self.taskbar.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.taskbar.CreateSessionManagerPopupMenu)
 
         if x2go.X2GOCLIENT_OS in ('Linux', 'Mac'):
             if notify.notification_service_available():
@@ -450,7 +457,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         Currently unused.
 
         """
-        self.WakeUpIdle()
+        if wx_major < 4: self.WakeUpIdle()
         self.ExitMainLoop()
 
     # wx.App's OnExit method
@@ -499,7 +506,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
                     else:
                         self.notifier.send(self.appname, _('Exiting application...'), icon='application-exit', timeout=10000)
             self._eventid_profilenames_map[evt.GetId()] = self.args.session_profile
-        self.WakeUpIdle()
+        if wx_major < 4: self.WakeUpIdle()
         self.ExitMainLoop()
 
     def _init_pubapp_session(self, session_uuid=None, profile_name=None):
@@ -791,7 +798,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
                 raise
 
         if connect_failed and self.exit_on_disconnect:
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
 
         self._remember_shared_folders[profile_name] = self.get_profile_config(profile_name, 'restoreexports')
@@ -1132,7 +1139,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
 
         if self.exit_on_disconnect:
             self._pyhoca_logger('Exiting %s because %s got disconnected.' % (self.appname, profile_name), loglevel=x2go.loglevel_NOTICE)
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
         else:
             self.notifier.send(_('%s - disconnect') % profile_name, _('X2Go Profile is now disconnected.'), icon='auth_disconnect', timeout=4000)
@@ -1616,7 +1623,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         except KeyError:
             pass
         if self.exit_on_disconnect:
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
 
     def HOOK_on_failing_SFTP_client(self, profile_name='UNKNOWN', **kwargs):
@@ -1634,7 +1641,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         except KeyError:
             pass
         if self.exit_on_disconnect:
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
 
     def HOOK_session_startup_failed(self, profile_name='UNKNOWN', **kwargs):
@@ -1647,7 +1654,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         """
         self.notifier.send(_('%s - session failure') % profile_name, _('The session startup failed.'), icon='session_error', timeout=10000)
         if self.exit_on_disconnect:
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
 
     def session_registration_failed(self, profile_name='UNKNOWN', **kwargs):
@@ -1660,7 +1667,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         """
         self.notifier.send(_('%s - session failure') % profile_name, _('The session initialization failed.'), icon='session_error', timeout=10000)
         if self.exit_on_disconnect:
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
 
     def HOOK_desktop_sharing_denied(self, profile_name='UNKNOWN', **kwargs):
@@ -1673,7 +1680,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         """
         self.notifier.send(_('%s - desktop sharing failure') % profile_name, _('Desktop sharing was denied by the other user or\nboth of you have insufficient privileges to share one another\'s desktop.'), icon='session_error', timeout=10000)
         if self.exit_on_disconnect:
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
 
     def HOOK_list_desktops_timeout(self, profile_name='UNKNOWN', **kwargs):
@@ -1698,7 +1705,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         """
         self.notifier.send(_('%s - desktop sharing failed') % profile_name, _('The desktop %s is not available for sharing (anymore).') % desktop, icon='session_warning', timeout=10000)
         if self.exit_on_disconnect:
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
 
     def HOOK_no_such_command(self, cmd, profile_name='UNKNOWN', session_name='UNKNOWN', **kwargs):
@@ -1718,7 +1725,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         else:
             self.notifier.send(_('%s - session failure') % profile_name, _('The command ,,%s\'\' is not available on X2Go server\n%s.') % (cmd, session_name), icon='session_error', timeout=10000)
         if self.exit_on_disconnect:
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
 
     def HOOK_rforward_request_denied(self, profile_name='UNKNOWN', session_name='UNKNOWN', server_port=0, **kwargs):
@@ -1735,7 +1742,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         """
         self.notifier.send(_('%s - session warning') % profile_name, _('Reverse TCP port forwarding request for session %s to server port %s has been denied.') % (session_name, server_port), icon='session_warning', timeout=10000)
         if self.exit_on_disconnect:
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
 
     def HOOK_forwarding_tunnel_setup_failed(self, profile_name='UNKNOWN', session_name='UNKNOWN', chain_host='UNKNOWN', chain_port=0, subsystem=None, **kwargs):
@@ -1770,7 +1777,7 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
         except ValueError:
             pass
         if self.exit_on_disconnect:
-            self.WakeUpIdle()
+            if wx_major < 4: self.WakeUpIdle()
             self.ExitMainLoop()
 
     def HOOK_pulseaudio_not_supported_in_RDPsession(self, **kwargs):
diff --git a/pyhoca/wxgui/launcher.py b/pyhoca/wxgui/launcher.py
index 91e2d94..3cbd4ad 100644
--- a/pyhoca/wxgui/launcher.py
+++ b/pyhoca/wxgui/launcher.py
@@ -31,6 +31,8 @@ import copy
 
 import wx
 
+wx_major = int(wx.__version__.split('.')[0])
+
 # we need to register a wx.App() instance before we load any
 # of the X2Go modules. When importing x2go.*, gevent.monkey_patch_all()
 # is called which seems to break wxPython 3.0...
@@ -403,11 +405,11 @@ VERSION: %s
             thisPyHocaGUI.MainLoop()
         except KeyboardInterrupt:
             if thisPyHocaGUI is not None:
-                thisPyHocaGUI.WakeUpIdle()
+                if wx_major < 4: thisPyHocaGUI.WakeUpIdle()
                 thisPyHocaGUI.ExitMainLoop()
         except SystemExit:
             if thisPyHocaGUI is not None:
-                thisPyHocaGUI.WakeUpIdle()
+                if wx_major < 4: thisPyHocaGUI.WakeUpIdle()
                 thisPyHocaGUI.ExitMainLoop()
 
         self.remove_pidfile()
diff --git a/pyhoca/wxgui/menus_taskbar.py b/pyhoca/wxgui/menus_taskbar.py
index c0b1519..93bee28 100644
--- a/pyhoca/wxgui/menus_taskbar.py
+++ b/pyhoca/wxgui/menus_taskbar.py
@@ -29,6 +29,14 @@ import x2go.x2go_exceptions
 
 from . import basepath
 
+wx_major = int(wx.__version__.split('.')[0])
+
+def _legacy_wrap_AppendMenu(instance, *args, **kwargs):
+    if wx_major < 4:
+        return wx.Menu.AppendMenu(instance, *args, **kwargs)
+    else:
+        return wx.Menu.Append(instance, *args, **kwargs)
+
 class PyHocaGUI_Menu_TaskbarManageProfile(wx.Menu):
     """\
     Individual profile management submenu: copy, use as template or delete session profile.
@@ -84,6 +92,12 @@ class PyHocaGUI_Menu_TaskbarManageProfile(wx.Menu):
                 self.Append(ID_DELETEPROFILE, _("Delete Profile"))
                 self._PyHocaGUI.Bind(wx.EVT_MENU, self._PyHocaGUI.OnProfileDelete, id=ID_DELETEPROFILE)
 
+    def AppendMenu(self, *args, **kwargs):
+        if wx_major < 4:
+            return wx.Menu.AppendMenu(self, *args, **kwargs)
+        else:
+            return wx.Menu.Append(self, *args, **kwargs)
+
 
 class PyHocaGUI_Menu_TaskbarOptionsManager(wx.Menu):
     """\
@@ -170,6 +184,9 @@ class PyHocaGUI_Menu_TaskbarOptionsManager(wx.Menu):
         self.Append(ID_EXIT, _("E&xit"))
         self._PyHocaGUI.Bind(wx.EVT_MENU, self._PyHocaGUI.OnTaskbarExit, id=ID_EXIT)
 
+    def AppendMenu(self, *args, **kwargs):
+        _legacy_wrap_AppendMenu(self, *args, **kwargs)
+
 
 class PyHocaGUI_Menu_TaskbarSessionActions(wx.Menu):
     """\
@@ -310,6 +327,9 @@ class PyHocaGUI_Menu_TaskbarSessionActions(wx.Menu):
         self._PyHocaGUI.Bind(wx.EVT_MENU, self._PyHocaGUI.OnSessionSuspend, id=ID_SUSPENDSESSION)
         self._PyHocaGUI.Bind(wx.EVT_MENU, self._PyHocaGUI.OnSessionTerminate, id=ID_TERMINATESESSION)
 
+    def AppendMenu(self, *args, **kwargs):
+        _legacy_wrap_AppendMenu(self, *args, **kwargs)
+
 
 class PyHocaGUI_Menu_TaskbarProfileSharedFolders(wx.Menu):
     """\
@@ -425,6 +445,9 @@ class PyHocaGUI_Menu_LaunchSingleApplication(wx.Menu):
             self.Append(_app_id, _available_applications[application])
             self._PyHocaGUI.Bind(wx.EVT_MENU, self._PyHocaGUI.OnApplicationStart, id=_app_id)
 
+    def AppendMenu(self, *args, **kwargs):
+        _legacy_wrap_AppendMenu(self, *args, **kwargs)
+
 
 def _generate_Menu_PublishedApplications(_PyHocaGUI, caller=None, profile_name=None, session_name=None):
     """\
@@ -861,6 +884,9 @@ class PyHocaGUI_Menu_TaskbarSessionProfile(wx.Menu):
                 self.Append(ID_EXIT, _("E&xit"))
                 self._PyHocaGUI.Bind(wx.EVT_MENU, self._PyHocaGUI.OnTaskbarExit, id=ID_EXIT)
 
+    def AppendMenu(self, *args, **kwargs):
+        _legacy_wrap_AppendMenu(self, *args, **kwargs)
+
 
 class PyHocaGUI_Menu_TaskbarProfileNames(wx.Menu):
     """\
@@ -1019,6 +1045,9 @@ class PyHocaGUI_Menu_TaskbarProfileNames(wx.Menu):
             self._pyhoca_logger('Updating UI, re-enabling session profile %s' % profile_name)
             self.Enable(id=evt.GetId(), enable=True)
 
+    def AppendMenu(self, *args, **kwargs):
+        _legacy_wrap_AppendMenu(self, *args, **kwargs)
+
 
 class PyHocaGUI_Menu_TaskbarSessionManager(wx.Menu):
     """\
@@ -1086,4 +1115,5 @@ class PyHocaGUI_Menu_TaskbarSessionManager(wx.Menu):
         self.Append(ID_EXIT, _("E&xit"))
         self._PyHocaGUI.Bind(wx.EVT_MENU, self._PyHocaGUI.OnTaskbarExit, id=ID_EXIT)
 
-
+    def AppendMenu(self, *args, **kwargs):
+        _legacy_wrap_AppendMenu(self, *args, **kwargs)
diff --git a/pyhoca/wxgui/splash.py b/pyhoca/wxgui/splash.py
index c741560..46c202d 100644
--- a/pyhoca/wxgui/splash.py
+++ b/pyhoca/wxgui/splash.py
@@ -22,10 +22,20 @@
 import wx
 import os
 
+wx_major = int(wx.__version__.split('.')[0])
+if wx_major < 4:
+    from wx import SplashScreen as _SplashScreen
+    _wx_SPLASH_CENTRE_ON_SCREEN = wx.SPLASH_CENTRE_ON_SCREEN
+    _wx_SPLASH_TIMEOUT = wx.SPLASH_TIMEOUT
+else:
+    from wx.adv import SplashScreen as _SplashScreen
+    _wx_SPLASH_CENTRE_ON_SCREEN = wx.adv.SPLASH_CENTRE_ON_SCREEN
+    _wx_SPLASH_TIMEOUT = wx.adv.SPLASH_TIMEOUT
+
 # PyHoca-GUI modules
 from . import basepath
 
-class PyHocaGUI_SplashScreen(wx.SplashScreen):
+class PyHocaGUI_SplashScreen(_SplashScreen):
     """\
     L{PyHocaGUI} splash screen that gets shown an application startup.
 
@@ -57,13 +67,13 @@ class PyHocaGUI_SplashScreen(wx.SplashScreen):
             splash_wximage.Rescale(400, int(float(400)/splash_wximage.Width*splash_wximage.Height))
 
             splash_wxbitmap = splash_wximage.ConvertToBitmap()
-            wx.SplashScreen.__init__(self,
-                                     splash_wxbitmap,
-                                     splashStyle=wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT,
-                                     milliseconds=5000,
-                                     parent=None,
-                                     style=wx.SIMPLE_BORDER|wx.STAY_ON_TOP|wx.FRAME_NO_TASKBAR
-                                    )
+            _SplashScreen.__init__(self,
+                                   splash_wxbitmap,
+                                   splashStyle=_wx_SPLASH_CENTRE_ON_SCREEN|_wx_SPLASH_TIMEOUT,
+                                   milliseconds=5000,
+                                   parent=None,
+                                   style=wx.SIMPLE_BORDER|wx.STAY_ON_TOP|wx.FRAME_NO_TASKBAR
+                                  )
             self.Bind(wx.EVT_CLOSE, self.OnClose)
 
     def OnClose(self, evt):
diff --git a/pyhoca/wxgui/taskbar.py b/pyhoca/wxgui/taskbar.py
index 23eeab1..5985979 100644
--- a/pyhoca/wxgui/taskbar.py
+++ b/pyhoca/wxgui/taskbar.py
@@ -25,6 +25,12 @@ modules ={}
 import x2go
 
 import wx
+wx_major = int(wx.__version__.split('.')[0])
+if wx_major < 4:
+    from wx import TaskBarIcon as _TaskBarIcon
+else:
+    from wx.adv import TaskBarIcon as _TaskBarIcon
+
 import os
 
 # Warning: If pyflakes says you should delete these 2 lines,
@@ -77,11 +83,14 @@ def MakeIcon(icon_name, fallback_name='PyHoca-GUI_trayicon.png', appname="PyHoca
         icon_file = '%s/%s/%s/%s' % (_icons_location, icon_folder, icon_size, fallback_name)
 
     img = wx.Image(icon_file)
-    icon = wx.IconFromBitmap(img.ConvertToBitmap())
+    if wx_major < 4:
+        icon = wx.IconFromBitmap(img.ConvertToBitmap())
+    else:
+        icon = wx.Icon(img.ConvertToBitmap())
     return icon
 
 
-class PyHocaGUI_TaskBarIcon(wx.TaskBarIcon):
+class PyHocaGUI_TaskBarIcon(_TaskBarIcon):
     """\
     Class for the L{PyHocaGUI} taskbar icon.
 
@@ -96,7 +105,7 @@ class PyHocaGUI_TaskBarIcon(wx.TaskBarIcon):
         @type about: C{obj}
 
         """
-        wx.TaskBarIcon.__init__(self)
+        _TaskBarIcon.__init__(self)
         self._PyHocaGUI = about._PyHocaGUI
         self._pyhoca_logger = self._PyHocaGUI._pyhoca_logger
         self._pyhoca_logger('start TaskBarIcon of type: %s' % (wx.PlatformInfo, ), loglevel=x2go.loglevel_INFO)
@@ -175,7 +184,10 @@ class PyHocaGUI_TaskBarIcon(wx.TaskBarIcon):
         @rtype: C{obj}
 
         """
-        self.menu_optionsmanager = self.PopupMenu(menus_taskbar.PyHocaGUI_Menu_TaskbarOptionsManager(self._PyHocaGUI, caller=self,))
+        if wx_major < 4:
+            self.menu_optionsmanager = self.PopupMenu(menus_taskbar.PyHocaGUI_Menu_TaskbarOptionsManager(self._PyHocaGUI, caller=self,))
+        else:
+            self.menu_optionsmanager = menus_taskbar.PyHocaGUI_Menu_TaskbarOptionsManager(self._PyHocaGUI, caller=self,)
         return self.menu_optionsmanager
 
     def Close(self):

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/pyhoca-gui.git


More information about the x2go-commits mailing list