[z3-checkins] r14529 - z3/zopejam/trunk/src/zopejam

hathawsh at codespeak.net hathawsh at codespeak.net
Tue Jul 12 07:31:22 CEST 2005


Author: hathawsh
Date: Tue Jul 12 07:31:20 2005
New Revision: 14529

Modified:
   z3/zopejam/trunk/src/zopejam/main.py
Log:
Preserve the selection and focus when changing sort order.

Also auto-load the configuration file named by the environment variable 
ZOPEJAM_PROJECT.



Modified: z3/zopejam/trunk/src/zopejam/main.py
==============================================================================
--- z3/zopejam/trunk/src/zopejam/main.py	(original)
+++ z3/zopejam/trunk/src/zopejam/main.py	Tue Jul 12 07:31:20 2005
@@ -131,6 +131,10 @@
 
         self.update_commands_enabled()
 
+        proj_fn = os.environ.get('ZOPEJAM_PROJECT')
+        if proj_fn:
+            self.loadProject(proj_fn)
+
     def update_commands_enabled(self):
         p = self.project is not None
         self.commands.newfile.enable(p)
@@ -177,11 +181,14 @@
 
         if dlg.ShowModal() == wx.ID_OK:
             fn = os.path.abspath(root_zcml.GetValue())
-            self.project = Project(fn)
-            self.project.load()
-            self.frame.SetTitle('Zope Jam - %s' % self.project.root_filename)
-            self.populate()
-            self.update_commands_enabled()
+            self.loadProject(fn)
+
+    def loadProject(self, fn):
+        self.project = Project(fn)
+        self.project.load()
+        self.frame.SetTitle('Zope Jam - %s' % self.project.root_filename)
+        self.populate()
+        self.update_commands_enabled()
 
     def cmd_quit(self, event):
         self.frame.Close()
@@ -249,26 +256,27 @@
             image = images.get('zcmlfile', -1)
             child = structure.AppendItem(parent, label, image=image, data=data)
 
-            for resolver in cfg.includes:
-                data = wx.TreeItemData(resolver)
-                f = resolver.files or resolver.file
-                if resolver.abs_package:
+            for inc in cfg.includes:
+                data = wx.TreeItemData(inc)
+                f = inc.files or inc.file
+                abs_package = inc.getAbsolutePackageName()
+                if abs_package:
                     if f == 'configure.zcml':
-                        label = resolver.abs_package
+                        label = abs_package
                     else:
-                        label = '%s "%s"' % (resolver.abs_package, f)
+                        label = '%s "%s"' % (abs_package, f)
                 else:
                     label = '"%s"' % f
 
                 image_name = '%s_%s' % (
-                    resolver.override and 'includeoverride' or 'include',
-                    resolver.glob and 'glob' or 'one'
+                    inc.override and 'includeoverride' or 'include',
+                    inc.glob and 'glob' or 'one'
                     )
                 image = images.get(image_name, -1)
 
                 gchild = structure.AppendItem(
                     child, label, image=image, data=data)
-                for fn in resolver.listFiles():
+                for fn in inc.listFiles():
                     cfg = self.project.files[fn]
                     todo.append((gchild, cfg))
 
@@ -409,7 +417,6 @@
         self.gui = gui
         self.elements = []
         self.indexes = []  # list of element indexes (shuffled by sorting)
-        self.focus = -1    # element index or -1
 
         self.filter = Filter(gui, xrc.XRCCTRL(self.gui.frame, 'filter_panel'))
         self.columns = columns.create_default_columns()
@@ -423,15 +430,6 @@
 
         self.SortListItems(0, 1)
 
-        self.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.onFocusItem)
-
-    def onFocusItem(self, event):
-        item = event.GetIndex()
-        if item < 0:
-            self.focus = -1
-        else:
-            self.focus = self.indexes[item]
-
     def populate(self):
         self.itemDataMap = {}
         for c in self.columns:
@@ -488,6 +486,14 @@
         Based on code by Egor Zindy
         http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/426407
         """
+        # gather the focus and selection flags
+        flags = {}
+        mask = wx.LIST_STATE_SELECTED | wx.LIST_STATE_FOCUSED
+        for i, element_index in enumerate(self.indexes):
+            state = self.GetItemState(i, mask)
+            if state:
+                flags[element_index] = state
+        
         # _col and _colSortFlag are defined in ColumnSorterMixin.
         # col is the column which was clicked on and
         # sf, the sort flag, is False for descending (Z->A)
@@ -518,12 +524,16 @@
         # store the element indexes as self.indexes.
         self.indexes = k
 
-        # restore the focus to the element that had focus
-        if self.focus >= 0:
-            i = self.indexes.index(self.focus)
-            self.EnsureVisible(i)
-            # XXX need a way to change which item is focused (focus is
-            # independent of selection)
+        # clear state for all rows (undocumented API?)
+        self.SetItemState(-1, 0, mask)
+
+        # reapply the selection and focus flags
+        for i, element_index in enumerate(self.indexes):
+            state = flags.get(element_index)
+            if state:
+                self.SetItemState(i, state, mask)
+                if state & wx.LIST_STATE_FOCUSED:
+                    self.EnsureVisible(i)
 
         # redraw the list
         self.Refresh()


More information about the z3-checkins mailing list