Anonymous avatar Anonymous committed 93009f1

FIX: Fell into the 'copy the list object instead of the list items' trap... - at least now the complex code is much better commented.

Comments (0)

Files changed (2)

     return Rad
 
 # 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()
+# 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
 
-def importKUniqueApplication():
-    # KApplication for basics
-    from PyKDE4.kdeui import KUniqueApplication
-    return KUniqueApplication
-KUniqueApplication = importKUniqueApplication()
+# KApplication for basics
+from PyKDE4.kdeui import KUniqueApplication
 
 # and exiting.
 from sys import exit as exit_
 	    return None # clicked cancel
 	icon, action = item
 	items = [(i.icon, i.action) for i in self.circle]
+        idx = self.circle.index(label)
 	if action is not None:
-	    items[self.circle.index(label)] = (icon, action)
+	    items[idx] = (icon, action)
 	else:
-	    idx = self.circle.index(label)
 	    items = items[:idx] + items[idx + 1:]
         self.save_config(items)
 
             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]:
+            if not label is 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.
         # We roll back the circle to the top level
         # The center can't change, so we can use the one from the previous version of the circle.
         while self.circle[0].action is not None:
-            # store items to be able to identify the folder in the lower layout
-            items_tmp = [(label.icon, label.action) for label in self.circle]
-            # but replace the first with a generic center.
-            items_tmp[0] = ( CENTER_ICON, None )
+            # store current items as item list
+            #: The current upper layout
+            items_upper = [(label.icon, label.action) for label in self.circle]
+            #: Items in the current folder, not for the circle!
+            items_folder = items_upper
+            # replace the first with a generic center.
+            items_folder[0] = ( CENTER_ICON, None )
+
+            ## Now we switch to the lower layout!
             self.labelClicked(self.circle[0])
+
             # find the folder corresponding to the upper layout.
-            items_new = [(label.icon, label.action) for label in self.circle]
-            for item in items_new:
+            #: the current *lower* layout
+            items_lower = [(label.icon, label.action) for label in self.circle]
+            found_the_folder = False
+            for item in items_lower:
                 icon, action = item
-                if action is not None and action[0] == "[" and eval(action) == items_tmp:
-                    folder_new = items
-                    folder_new[0] = ( CENTER_ICON, None )
-                    idx = items_new.index(item)
-                    item = (icon, str(folder_new))
-                    items_new = items_new[:idx] + [item] + items_new[idx + 1:]
-                    self.arrange_in_circle(items_new)
+                if action is not None and action[0] == "[" and eval(action) == items_folder:
+                    # We found the correct folder. 
+                    # the index of the folder in the lower layout
+                    idx = items_lower.index(item)
+                    # create the new folder
+                    items_folder = items[:]
+                    items_folder[0] = ( CENTER_ICON, None )
+                    # replace the old folder with the new folder.
+                    item = (icon, str(items_folder))
+                    items_lower[idx] = item
+                    self.arrange_in_circle(items_lower)
+                    found_the_folder = True
+            # make sure we save no broken configs!
+            if not found_the_folder:
+                print "Gah!"
+                return False
 
-        items_tmp = [(i.icon, i.action) for i in self.circle]
-        # Now we copy the previous circle back into the current circle.
+        items_new = [(i.icon, i.action) for i in self.circle]
+        # Now we copy the circle we wanted to save back into the current circle.
         self.arrange_in_circle(items)
         # Finally we prepare the config data
         config = "# v0.1 keep this line!\n"
-        config += str(items)
+        config += str(items_new)
         # And save it
         f = open(join(home, CONFIG_FILE_NAME), "w")
         f.write(config)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.