Commits

Anonymous committed fc1f6b8

Refactoring to prepare for save functionality.

  • Participants
  • Parent commits 6256789

Comments (0)

Files changed (1)

 DEFAULT_CONFIG = '''# v0.1 keep this line!
 [
     ("''' + CENTER_ICON + '''", None), # the center item: (icon, action); action == None means "quit"
-    ("kate","kate"), ("kmail","kmail"), ("kmix","kmix"), ("wesnoth","wesnoth"), # normal items
-    ("krita","""[("''' + CENTER_ICON + '''", None), ("gimp","gimp")]""") # a folder with the center icon and only one real item
+    ("konsole","konsole"), ("kontact","kontact"), 
+("konqueror","konqueror"), ("wesnoth","wesnoth"), # normal items
+    ("krita","""[("''' + CENTER_ICON + '''", None), ("amarok", "amarok"), ("gimp","gimp")]""") # a folder with the center icon and only one real item
 ]
 '''
 
-
-
-# If there's no config, we use standard items
-if not isfile(join(home, CONFIG_FILE_NAME)): 
-    #: The items the menu should show in top-level (via folders this contains the whole of the wheel menu). 
-    ITEMS = eval(DEFAULT_CONFIG)
-    # also create the config file -> this is an initial run
-    f = open(join(home, CONFIG_FILE_NAME), "w")
-    f.write(DEFAULT_CONFIG)
-    f.close()
-else:
-    # if a config file is present, we load the items from there.
-    f = open(join(home, CONFIG_FILE_NAME))
-    config = f.read()
-    assert(config.startswith("# v0.1"))
-    ITEMS = eval(config)
-    f.close()
-    del f
-    del config
-
-
 ### About the Program ###
 
 # This also allows our users to use DrKonqui for crash recovery.
 	icon = QIcon(self.iconloader.loadIcon(PROGRAM_ICON, 0))
 	self.setWindowIcon(icon)
 	
+	# Load the items from the config file. 
+	items = self.load_config()
+	
         # Add a circle-list for all items
 	self.circle = []
 
-        # And arrange them in a circle
-     	self.arrange_in_circle(ITEMS)
+        # And arrange them as labels in a circle
+     	self.arrange_in_circle(items)
 	
 
     def focusOutEvent(self, event):
                 
         for i in self.circle[:]: 
 	    if self.isInside(pos, i):
-                if i.action is not None and i.action[0] == "[":
-                    # then it's a folder!
-                    # get its contents
-                    items = eval(i.action)
-                    # and store the current items in the new center.
-                    # as long as the user didn't click the center
-                    if not i == self.circle[0]: 
-                        items[0] = ( CENTER_ICON , str([(i.icon, i.action) for i in self.circle]) )
-                    self.arrange_in_circle(items)
-                    # We don't do anything else in that case. 
-                    return None
-                # if it's no folder and not None, we start the program
-                # if this fails, the code ends here 
-                # and the circle stays visible.
-                if i.action is not None: 
-                    Popen(i.action)
+		# If pyRad didn't reach a final action, we stop here. 
+                if self.labelClicked(i) is None: 
+		    return None
 
                 # Otherwise we can close the pyRad
                 for label in self.circle: 
                 self.close()
 
 
+    def labelClicked(self, label): 
+	"""React to a label being clicked.
+	
+	@return: True if the circle reached an end, None if it should continue existing."""
+	if label.action is None: 
+	    return True
+	if label.action is not None and label.action[0] == "[":
+	    # then it's a folder!
+	    # get its contents
+	    items = eval(label.action)
+	    # and store the current items in the new center.
+	    # as long as the user didn't click the center
+	    if not label == self.circle[0]: 
+		items[0] = ( CENTER_ICON , str([(i.icon, i.action) for i in self.circle]) )
+	    self.arrange_in_circle(items)
+	    # We don't do anything else in that case. 
+	    return None
+	# if it's no folder and not None, we start the program
+	# if this fails, the code ends here 
+	# and the circle stays visible.
+	if label.action is not None: 
+	    try: 
+		Popen(label.action)
+		return True
+	    except: 
+		return None
+	
+	
+
     def isInside(self, point, thing):
 	"""Check, if the point is inside the thing."""
 	if point.x() > thing.x() and point.x() < thing.x() + thing.width() and point.y() > thing.y() and point.y() < thing.y() + thing.height():
             label.destroy()
 
         # Then create the circle list
-        self.circle = []
-        for icon, action in items: 
-	    label = QLabel(self)
-	    label.icon = icon
-            label.action = action
-            label.setToolTip(str(action))
-	    label.setPixmap(self.iconloader.loadIcon(icon, 0))
-	    self.circle.append(label)
+        self.circle = self.items_to_circle(items)
 
         # Now set the center icon
         self.circle[0].move(0.5*self.width() - 0.25*self.circle[0].width(), 0.5*self.height() - 0.75*self.circle[0].height())
         # Finally show the new circle
         for i in self.circle: 
             i.show()
+    
+    def items_to_circle(self, items): 
+	"""Create the circle list from the given items.
+	@return: circle (list of labels)"""
+	circle = []
+        for icon, action in items: 
+	    label = QLabel(self)
+	    label.icon = icon
+            label.action = action
+            label.setToolTip(str(action))
+	    label.setPixmap(self.iconloader.loadIcon(icon, 0))
+	    circle.append(label)
+	
+	return circle
+	
+    
+    def load_config(self): 
+	"""Load the items from the config file.
+	
+	@return: items (list)"""
+	# If there's no config, we use standard items
+	if not isfile(join(home, CONFIG_FILE_NAME)): 
+	    #: The items the menu should show in top-level (via folders this contains the whole of the wheel menu). 
+	    items = eval(DEFAULT_CONFIG)
+	    # also create the config file -> this is an initial run
+	    f = open(join(home, CONFIG_FILE_NAME), "w")
+	    f.write(DEFAULT_CONFIG)
+	    f.close()
+	else:
+	    # if a config file is present, we load the items from there.
+	    f = open(join(home, CONFIG_FILE_NAME))
+	    config = f.read()
+	    assert(config.startswith("# v0.1"))
+	    items = eval(config)
+	    f.close()
+	    del f
+	    del config
+	
+	return items
+    
+    def save_config(self): 
+	"""Save the current wheel layout to the config file."""
+	pass