Commits

Arne Babenhauserheide  committed 1952980

Begun adding an edit window.

  • Participants
  • Parent commits fc760a0

Comments (0)

Files changed (1)

 ### Imports ### 
 
 # basic graphical stuff
-from PyQt4.QtGui import QWidget, QCursor, QIcon, QLabel
+from PyQt4.QtGui import QWidget, QDialog, QCursor, QIcon, QLabel, QVBoxLayout
 # basic definitions and datatypes
 from PyQt4.QtCore import Qt, QPointF
 # Basics for KDE integration
 
 ### Window ###
 
-# The first step is just using the example from TechBase
+# First we need a message box for editing the entries
+class ItemEditor(QDialog):
+    def __init__(self, parent=None):
+        QDialog.__init__(self, parent)
+        # First add a layout
+        vlay = QVBoxLayout()
+        self.setLayout(vlay)
+        # Now add widgets
+        
+        
+        
+
+    def edit(self, item):
+        """Edit an item - includes deleting it by returning None."""
+        # Be the only window which accepts input
+        self.show()
+        self.raise_()
+        self.activateWindow()
+        return_code = self.exec_()
+        
+        
+        
+    
+# We just use and extend example from TechBase
 # http://techbase.kde.org/Development/Tutorials/Plasma/Python/GettingStarted
 
 class Rad(QWidget):
 
         # And arrange them as labels in a circle
      	self.arrange_in_circle(items)
+
+        # Finally add a message_box instance for editing items
+        # self.message_box = KMessageBox()
+
+        # Also we need an editor for the items. Call it with self.editor.exec(item). 
+        self.editor = ItemEditor(self)
 	
 
     def focusOutEvent(self, event):
 		elif event.button() == Qt.RightButton: 
 		    self.editLabel(i)
 		    return None
+		else: # other buttons are ignored
+		    return None
 		# 		return self.editLabel(i)
 
                 # Otherwise we can close the pyRad
 
     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
+        self.die_on_focus_lost = False
+        # if the center gets clicked, add a new label. 
 	if label == self.circle[0]: 
-	    print "add label"
+	    print self.editor.edit((label.icon, label.action))
+        # otherwise edit the current label. 
 	else: 
 	    print "edit", label
+        self.die_on_focus_lost = True
 	
 
     def labelClicked(self, label): 
 	"""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))
+        for icon, action in items:
+            label = self.item_to_label(icon, action)
 	    circle.append(label)
 	
 	return circle
-	
+
+    def item_to_label(self, icon, action):
+        """Turn an item into a QLabel."""
+        label = QLabel(self)
+        label.icon = icon
+        label.action = action
+        label.setToolTip(str(action))
+        label.setPixmap(self.iconloader.loadIcon(icon, 0))
+        return label
     
     def load_config(self): 
 	"""Load the items from the config file.