Commits

Anonymous committed 631263c

Blind Cleanup (currently no PyKDE4)

  • Participants
  • Parent commits 9627cff

Comments (0)

Files changed (1)

 - Make the window transparent, without background, border and menubar. 
 - Show icons in a circle
 - make the icons clickable
-- add folder-icons
+- add folder-icons: the action is simply a list with all contained items => starts with [
+- store the previous layout (buttons) directly in the name of the central icon => same list format.
+
 - Implement registering a global shortcut in KDE within the program. 
 
 ideas: 
 
 __copyright__ = "GPLv3 or later" # TODO: Proper copyright info
 
-### Imports # TODO: Only import what we need
+### Imports ### TODO: Only import what we need
 
+# basic graphics stuff
 from PyQt4.QtGui import QWidget, QCursor, QApplication, QIcon, QLabel
 from PyQt4.QtGui import QGraphicsScene, QGraphicsView, QGraphicsEllipseItem
-from PyQt4.QtCore import Qt, QPointF, SIGNAL, SLOT
+# basic datatypes
+from PyQt4.QtCore import Qt, QPointF
+# Basics for KDE integration
 from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs, KStandardDirs
 from PyKDE4.kdeui import KApplication, KIconLoader
-import sys
-# for circles
+# Commandline arguments 
+from sys import argv
+# For circles
 from math import sin, cos, pi
-# For starting programs
+# And for starting programs
 from subprocess import Popen
 
-### Constants
+### Constants ###
 
 WINDOW_WIDTH = 250
 WINDOW_HEIGHT = 250
 CIRCLE_RADIUS = 80
+PROGRAM_ICON = "kreversi"
+CENTER_ICON = "kreversi"
 
-### Window
+### About Info ###
+
+appName     = "pyRad"
+catalog     = ""
+programName = ki18n ("Rad")
+version     = "1.0"
+description = ki18n ("KApplication/KMainWindow/KAboutData example")
+license     = KAboutData.License_GPL
+copyright   = ki18n ("(c) 2009 Arne Babenhauserheide")
+text        = ki18n ("none")
+homePage    = "www.draketo.de"
+bugEmail    = "arne_bab@web.de"
+
+aboutData   = KAboutData (appName, catalog, programName, version, description,
+                        license, copyright, text, homePage, bugEmail)
+
+### Window ###
 
 # The first step is just using the example from TechBase
 # http://techbase.kde.org/Development/Tutorials/Plasma/Python/GettingStarted
 	
 	# Move below the cursor
         self.move_to_cursor()
-        self.setWindowTitle("pyRad")
+        self.setWindowTitle(programName)
 	
         self.setFocusPolicy(Qt.StrongFocus)
 	
 	# Add an icon
 	self.iconloader = KIconLoader()
-	icon = QIcon(self.iconloader.loadIcon("kreversi", 0))
+	icon = QIcon(self.iconloader.loadIcon(PROGRAM_ICON, 0))
 	self.setWindowIcon(icon)
 	
-	# Add a circle-list for all the icons
+		
+	self.center = QLabel(self)
+	self.center.action = None
+	self.center.setPixmap(self.iconloader.loadIcon(CENTER_ICON, 0))
+        self.center.move(0.5*self.width() - 0.25*self.center.width(), 0.5*self.height() - 0.75*self.center.height())
+        
+        # Add a circle-list for all the icons
 	self.circle = []
+
+        items = [("kate","kate"), ("kmail","kmail"), ("kmix","kmix"), ("wesnoth","wesnoth"),
+                 ("krita","[('gimp','gimp')]")]
+		    
+	self.arrange_in_circle(items)
 	
-	self.center = QLabel(self)
-	self.center.action = "center"
-	self.center.setPixmap(self.iconloader.loadIcon("kreversi", 0))
-	
-        for icon, action in [("kopete","kopete"), ("kmail","kmail"), ("kmix","kmix"), ("wesnoth","wesnoth"), ("kate","kate")]: 
-	    label = QLabel(self)
-	    label.icon = icon
-            label.action = action
-	    label.setPixmap(self.iconloader.loadIcon(icon, 0))
-	    self.circle.append(label)
-	    
-	self.arrange_in_circle()
-	
-        
+ 
     def focusOutEvent(self, event):
         """Close when we lose the focus."""
         self.close()
 
         TODO: Only close when the mouse is released on a final item or outside.
         """
-	for i in self.circle: 
-	    if self.isInside(event.pos(), i): 
-		    # start the program
-		    # if this fails, the code ends here 
-		    # and the circle stays visible. 
-		    Popen(i.action)
-        # TODO: Add folders which change the circle 
-        # but don't destroy everything.
-	for label in self.circle: 
-            label.destroy()
-        self.close()
-		    
-		    
+        for i in self.circle[:]: 
+	    if self.isInside(event.pos(), i):
+                if i.action[0] == "[":
+                    # then it's a folder!
+                    items = eval(i.action)
+                    self.arrange_in_circle(items)
+                    # We don't do anything else in that case. 
+                    return None
+                # if it's no folder, we start the program
+                # if this fails, the code ends here 
+                # and the circle stays visible. 
+                Popen(i.action)
+                for label in self.circle: 
+                    label.destroy()
+                self.close()
 		    
 		    
     def isInside(self, point, thing):
     def move_to_cursor(self):
         """Move the Window to the position of the mouse cursor."""
         # We set the position to the Cursor
-        width = self.size().width()
-        height = self.size().height()
         pos = QPointF(QCursor.pos())
-        # center on the cursor
-        x = pos.x() - 0.5*width
-        y = pos.y() - 0.5*height
-        #self.setGeometry(x, y, width, height)
+        # center on the cursor (reduce by half window width and height)
+        x = pos.x() - 0.5*self.size().width()
+        y = pos.y() - 0.5*self.size().height()
 	self.move(x, y)
 
-    def arrange_in_circle(self): 
+    def arrange_in_circle(self, items): 
 	"""Arrange all icons in a circle, withthe zeroth in the middle."""
-	# The middle icon first
-	self.circle[0].move(0.5*self.width() - 0.25*self.circle[0].width(), 0.5*self.height() - 0.75*self.circle[0].height())
-	
-	# Now all others: 
-	for i in self.circle[1:]: 
+        # First remove the previous circle
+        for label in self.circle[:]:
+            label.destroy()
+
+        # Then create the circle list
+        self.circle = []
+        for icon, action in items: 
+	    label = QLabel(self)
+	    label.icon = icon
+            label.action = action
+	    label.setPixmap(self.iconloader.loadIcon(icon, 0))
+	    self.circle.append(label)
+
+	# Finally arrange the items into a circle around the center. 
+	for i in self.circle: 
 	    angle = 2 * pi * (self.circle.index(i) -1 ) / len(self.circle[1:])
 	    x_displacement = sin(angle)*CIRCLE_RADIUS
 	    y_displacement = cos(angle)*CIRCLE_RADIUS
 	            
 
 
-### About Info ###
-
-appName     = "pyRad"
-catalog     = ""
-programName = ki18n ("Rad")
-version     = "1.0"
-description = ki18n ("KApplication/KMainWindow/KAboutData example")
-license     = KAboutData.License_GPL
-copyright   = ki18n ("(c) 2009 Arne Babenhauserheide")
-text        = ki18n ("none")
-homePage    = "www.draketo.de"
-bugEmail    = "arne_bab@web.de"
-
-aboutData   = KAboutData (appName, catalog, programName, version, description,
-                        license, copyright, text, homePage, bugEmail)
-
 ### Self Test ###
 
 if __name__ == "__main__":
-    KCmdLineArgs.init (sys.argv, aboutData)
+    KCmdLineArgs.init (argv, aboutData)
     app = KApplication()
     rad = Rad()
     rad.show()