Commits

Anonymous committed 556d442

Now import and initialize the Rad in the __init__ part of the KUniqueApplication -> only gets imported if no instance is running in background.

  • Participants
  • Parent commits a094872

Comments (0)

Files changed (1)

 # encoding: utf-8
 
 """pyRadKDE - a wheel type command interface for KDE, inspired by Kommando (KDE 3) and Neverwinternights.
+"""
 
+# additional documentation - gets added to the docstring by hand, so I can more easily use it in user output
+
+__install__ = """
 installation and setup:
 
 - easy_install pyRadKDE
 - Add a mouse gesture for "pyrad.py": go into KDE systemsettings -> keyboard shortcuts -> add a gesture with the action "pyrad.py" (you might have to enable gestures in the settings, too - in the shortcuts-window you should find a settings button).
-- customize the menu by editing the file "~/.pyradrc" or right-clicking items. 
+- customize the menu by editing the file "~/.pyradrc" or right-clicking items.
+"""
 
+__usage__ = """
 usage:
 
 - Just use your gesture to call up the command wheel when you want to call one of your included programs.
-- Right-click an item to edit it. Right-click the center to add a new item.
-- Make folders by using the action [("kreversi", None), ("icon", "action"), ("icon2", "action2"), ...]
-- Actions are simply the commands you'd use on the commandline.
+- Right-click an item to edit it. Middle-click an item to add a new one after it (clockwise).
+- Make folders by using the action [("kreversi", None), ("icon", "action"), ("icon2", "action2"), ...].
+  Actions are simply the commands you'd use on the commandline.
+- call "pyrad.py --quit" to shutdown the process in the background. "pyrad.py --help" shows the usage.
 
+"""
+
+__plans__ = """
 plan for 0.3:
 
 - new command scheme: right-click always edits, middle-click adds a new item. -done
 - first run of new version shows image as usage guide. -todo
 - register a global shortcut / gesture in KDE from within the program -> usable as soon as it's installed. -todo
 - make it show faster. -todo
-
-
+"""
+__ideas__ = """
 ideas:
 
 - use plasma.
 - adjust icon size to the numbers of icons in the circle. 
 
 PyPI url: http://pypi.python.org/pypi/pyRadKDE
+"""
 
-"""
+__doc__ += __install__ + __usage__ + __plans__ + __ideas__
+
 
 ### Basic Data ###
 
     along with this program.  If not, see <http://www.gnu.org/licenses/>
 """
 
+### Constants ###
+
+#: The PyRad version identifier
+__version__ = "0.2.0"
+
+### Commandline handling ###
+# we do this here to have the maximum reaction time. 
+from sys import argv
+if "--help" in argv:
+    print __usage__
+    exit()
+
 ### Imports ###
 
 # First the GUI class and the Data about the program
-from rad import Rad
-#from rad import aboutData
-# Also SIGNAL and SLOT, so we doon't call PyQt4 directly from here.
-from rad import SIGNAL, SLOT
+# we use an import function, so we can easily delay the import.
+def importRad():
+    """Import the Rad GUI."""
+    from rad import Rad
+    return Rad
 
 # Then commandline arguments and handling
-from sys import argv
-from PyKDE4.kdecore import KCmdLineArgs
+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
 
 # KApplication for basics
 from PyKDE4.kdeui import KUniqueApplication
-    
 
 # and exiting.
 from sys import exit as exit_
 
-### Constants ###
+### Class for modifying KUniqueApplication ###
 
-#: The PyRad version identifier
-__version__ = "0.2.0"
+class KUniqueCaller(KUniqueApplication):
+    def __init__(self, *args, **kwds):
+        """Initialize the App and import all GUI elements.
 
+        This gets only called when there's no already existing instance of the app."""
+        super(KUniqueCaller, self).__init__(*args, **kwds)
+        # And get and show the GUI
+        Rad = importRad()
+        self.rad = Rad()
+
+    def newInstance(self):
+        """Get a new instance -> in reality only check if there's already an instance and tell the GUI to run."""
+        # if we get the quit arg ("pyrad.py --quit"), we close and shutdown
+        args = KCmdLineArgs.parsedArgs()
+        if args.isSet("quit"):
+            self.rad.close()
+            self.quit()
+        self.rad.setup()
+        ret = super(KUniqueCaller, self).newInstance()
+        return ret
 
 ### Runner ###
 
     aboutData = createAboutData()
     # Now we need to compile the commandline args for KDE programs
     KCmdLineArgs.init (argv, aboutData)
+    # Add an option to quit the app
+    opts = KCmdLineOptions()
+    opts.add("quit", ki18n("Shutdown the background program"))
+    KCmdLineArgs.addCmdLineOptions(opts)
     # Then do basic initializing
-    app = KUniqueApplication()
+    app = KUniqueCaller()
     # And get and show the GUI
     return app
 
     # Then do basic initializing
     #app = KApplication()
     app = initKApp()
-    # And get and show the GUI
-    rad = Rad()
     #rad.close()
     # Finally we execute the program - and return the exit code from the program.
     return app.exec_()