Commits

Anonymous committed b960a7d

Force PyRad to foreground, when it is called.

Comments (0)

Files changed (2)

     from rad import Rad
     return Rad
 
-# Then commandline arguments and handling
-from PyKDE4.kdecore import KCmdLineArgs, KCmdLineOptions
-# And AboutData - moved here, so we don't need to pull in GUI stuff to check if we're the first instance
-from PyKDE4.kdecore import ki18n, KAboutData
+# We also do the other imports in functions to facilitate profiling. 
+def importKdeCmdLine(): 
+    # Then commandline arguments and handling
+    from PyKDE4.kdecore import KCmdLineArgs, KCmdLineOptions
+    return KCmdLineArgs, KCmdLineOptions
+KCmdLineArgs, KCmdLineOptions = importKdeCmdLine()
+def importKdeAbout(): 
+    # And AboutData - moved here, so we don't need to pull in GUI stuff to check if we're the first instance
+    from PyKDE4.kdecore import ki18n, KAboutData
+    return ki18n, KAboutData
+ki18n, KAboutData = importKdeAbout()
 
-# KApplication for basics
-from PyKDE4.kdeui import KUniqueApplication
+
+def importKUniqueApplication():
+    # KApplication for basics
+    from PyKDE4.kdeui import KUniqueApplication
+    return KUniqueApplication
+KUniqueApplication = importKUniqueApplication()
 
 # and exiting.
 from sys import exit as exit_
         if args.isSet("quit"):
             self.rad.close()
             self.quit()
+            return 0
         self.rad.setup()
+        self.rad.show()
+        self.rad.toForeground()
         ret = super(KUniqueCaller, self).newInstance()
+        #self.rad.close()
         return ret
 
 ### Runner ###
 from PyKDE4.kdeui import KIconLoader
 # And a basic dialog class for the edit item dialog.
 from PyKDE4.kdeui import KDialog
+# also the KWindowSystem, so we can get ourselves to the foreground
+from PyKDE4.kdeui import KWindowSystem
 
 
 ### Constants ###
         # Setup the circle - TODO: Call it via KUniqueApplication.newInstance
         self.setup()
 
+    def toForeground(self):
+        """Get into the foreground, so the user can click us."""
+        self.activateWindow()
+        KWindowSystem.forceActiveWindow(self.winId())
+
     def setup(self): 
         """Setup the items in the circle - used to show the app anew.
 
         # but we only initialize it when we really need it. 
         self.editor = None # ItemEditor(self)
 
-        # Show the app
-        self.show()
-
 
     def focusOutEvent(self, event):
-        """Close when we lose the focus and the mouse isn't inside the window."""
+        """Hide when we lose the focus and the mouse isn't inside the window."""
         # If we don't want to die on focus out, we just return None
         if not self.die_on_focus_out:
             return None
         if event.reason() == Qt.ActiveWindowFocusReason and self.isInside(QPointF(QCursor.pos()), self):
             return None
         # if we lose focus, the wheel disappears
-        self.close()
+        self.hide()
 
     def mouseReleaseEvent(self, event):
-        """Close when we get a mouse release on a final item."""
+        """Hide when we get a mouse release on a final item."""
         # Get the position
         pos = event.pos()
 
                 else: # other buttons are ignored
                     break
 
-                # Otherwise we can close the pyRad
-                for label in self.circle:
-                    label.destroy()
-                self.close()
+                # Otherwise we can hide the pyRad
+                self.hide()
                 
     def addLabelAfter(self, label): # -> open message box -> set item.icon and item.action. -> save_config()
         """Edit a label. A click on the center item promts for adding a new label."""
-        # Don't close when the dialog pops up
+        # Don't hide when the dialog pops up
         self.die_on_focus_lost = False
         # add a new label.
         # starttime optimization: Only initialize the editor, when we need it. 
 
     def editLabel(self, label): # -> open message box -> set item.icon and item.action. -> save_config()
         """Edit a label. A click on the center item promts for adding a new label."""
-        # Don't close when the dialog pops up
+        # Don't hide when the dialog pops up
         self.die_on_focus_lost = False
         # starttime optimization: Only initialize the editor, when we need it. 
         if self.editor is None: