On Wed, Sep 03, 2014 at 01:43:39PM +0200, Jakub Wilk wrote:
> * Olly Betts <o...@survex.com>, 2014-08-24, 03:53:
> >I'm not sure why it doesn't just work (as
> >wxPython/demo/TreeCtrl.py from the wxPython 3.0 sources does and
> >the code is very similar) but adding a handler for EVT_RIGHT_CLICK
> >which calls EditLabel() makes it work as before.
> 
> Wait, _right_ click? With wxPython 2.8, if you had wx.TR_EDIT_LABELS
> in the style, you could edit stuff with _left_ click.

There's something odd here, which I can't entirely explain.

These editable labels aren't a feature I've used before, and the wx docs
seem silent on how you are meant to actually trigger an edit.  So I
experimented using demo/TreeCtrl.py in the wxPython sources.

With that, you have to *right* click on an item to edit its label, so
that's the behaviour I reproduced in my patch.

But looking more closely at the code of that demo, the rather odd thing
is that it doesn't actually enabled wx.TR_EDIT_LABELS - there's a line
for it, but it is commented out.  If you turn it on, then left click
also edits (as you say).

> >You might need to similarly fix the other wx.TreeCtrl - the djvu
> >file I had to hand for testing had no text so I couldn't check
> >that.
> 
> I use /usr/share/doc/libdjvulibre-dev/djvulibre-book-ru.djvu for
> testing.

Thanks, that's a much more useful file for testing.

The attached patch fixes edits to work in both the controls on left
click (which is the "ACTIVATED" event).

Cheers,
    Olly
diff -Nru djvusmooth-0.2.14/debian/changelog djvusmooth-0.2.14/debian/changelog
--- djvusmooth-0.2.14/debian/changelog	2014-08-25 05:08:06.000000000 -0300
+++ djvusmooth-0.2.14/debian/changelog	2014-09-03 22:16:02.000000000 -0300
@@ -1,3 +1,10 @@
+djvusmooth (0.2.14-3.1) unstable; urgency=medium
+
+  * Non-maintainer upload.
+  * Fix label editing in tree controls.
+
+ -- Olly Betts <o...@survex.com>  Thu, 04 Sep 2014 01:15:34 +0000
+
 djvusmooth (0.2.14-3) unstable; urgency=low
 
   * wxpython3.0 transition (Closes: #758950):
diff -Nru djvusmooth-0.2.14/debian/patches/wxpython3.0-transition.patch djvusmooth-0.2.14/debian/patches/wxpython3.0-transition.patch
--- djvusmooth-0.2.14/debian/patches/wxpython3.0-transition.patch	2014-08-25 04:59:44.000000000 -0300
+++ djvusmooth-0.2.14/debian/patches/wxpython3.0-transition.patch	2014-09-03 22:31:14.000000000 -0300
@@ -3,10 +3,12 @@
 Bug: https://bugs.debian.org/758950
 Forwarded: yes
 Reviewed-by: Olly Betts <o...@survex.com>
-Last-Update: 2014-08-25
+Last-Update: 2014-09-03
 
---- a/lib/dependencies.py
-+++ b/lib/dependencies.py
+Index: djvusmooth-0.2.14/lib/dependencies.py
+===================================================================
+--- djvusmooth-0.2.14.orig/lib/dependencies.py
++++ djvusmooth-0.2.14/lib/dependencies.py
 @@ -14,7 +14,10 @@
  Checks for djvusmooth dependencies.
  '''
@@ -19,7 +21,7 @@
  DDJVU_API_MIN_VERSION = 26
  PYTHON_DJVULIBRE_MIN_VERSION = (0, 1, 4)
  
-@@ -55,7 +58,7 @@
+@@ -55,7 +58,7 @@ def _check_wx():
      except ImportError, ex:
          raise ImportError('%s; perhaps wxPython is not installed' % (ex,))
      if not wxversion.checkInstalled(WX_VERSIONS):
@@ -28,9 +30,11 @@
      wxversion.select(WX_VERSIONS)
  
  _check_signals()
---- a/lib/gui/main.py
-+++ b/lib/gui/main.py
-@@ -62,10 +62,6 @@
+Index: djvusmooth-0.2.14/lib/gui/main.py
+===================================================================
+--- djvusmooth-0.2.14.orig/lib/gui/main.py
++++ djvusmooth-0.2.14/lib/gui/main.py
+@@ -62,10 +62,6 @@ WxDjVuMessage, wx.EVT_DJVU_MESSAGE = wx.
  
  system_encoding = locale.getpreferredencoding()
  
@@ -41,7 +45,7 @@
  class OpenDialog(wx.FileDialog):
  
      __wildcard = _(
-@@ -75,7 +71,7 @@
+@@ -75,7 +71,7 @@ class OpenDialog(wx.FileDialog):
  
      def __init__(self, parent):
          wx.FileDialog.__init__(self, parent,
@@ -50,7 +54,7 @@
              wildcard=self.__wildcard,
              message=_('Open a DjVu document')
          )
-@@ -355,7 +351,7 @@
+@@ -355,7 +351,7 @@ class MainWindow(wx.Frame):
          self.status_bar = self.CreateStatusBar(2, style = wx.ST_SIZEGRIP)
          self.splitter = wx.SplitterWindow(self, style = wx.SP_LIVE_UPDATE)
          self.splitter.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.on_splitter_sash_changed)
@@ -59,7 +63,7 @@
          self.text_browser = TextBrowser(self.sidebar)
          self.outline_browser = OutlineBrowser(self.sidebar)
          self.maparea_browser = MapAreaBrowser(self.sidebar)
-@@ -363,7 +359,7 @@
+@@ -363,7 +359,7 @@ class MainWindow(wx.Frame):
          self.sidebar.AddPage(self.maparea_browser, _('Hyperlinks'))
          self.sidebar.AddPage(self.text_browser, _('Text'))
          self.sidebar.Bind(
@@ -68,9 +72,11 @@
              self._on_sidebar_page_changed(
                  self.on_display_no_nonraster,
                  self.on_display_maparea,
---- a/lib/gui/page.py
-+++ b/lib/gui/page.py
-@@ -327,7 +327,7 @@
+Index: djvusmooth-0.2.14/lib/gui/page.py
+===================================================================
+--- djvusmooth-0.2.14.orig/lib/gui/page.py
++++ djvusmooth-0.2.14/lib/gui/page.py
+@@ -327,7 +327,7 @@ class TextShape(NodeShape):
      }
  
      def _get_frame_color(self):
@@ -79,7 +85,7 @@
  
      def _get_text(self):
          if self._node.is_inner():
-@@ -626,7 +626,7 @@
+@@ -626,7 +626,7 @@ class PageWidget(wx.lib.ogl.ShapeCanvas)
          if self.GetSize() == size:
              return
          self.SetSize(size)
@@ -88,13 +94,15 @@
          self.GetParent().Layout()
          self.GetParent().SetupScrolling()
  
---- a/lib/gui/outline_browser.py
-+++ b/lib/gui/outline_browser.py
-@@ -45,9 +45,11 @@
+Index: djvusmooth-0.2.14/lib/gui/outline_browser.py
+===================================================================
+--- djvusmooth-0.2.14.orig/lib/gui/outline_browser.py
++++ djvusmooth-0.2.14/lib/gui/outline_browser.py
+@@ -45,9 +45,11 @@ class OutlineBrowser(wx.TreeCtrl):
          self._items = {}
          self._root_item = None
          self._document = None
-+        self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.on_right_click)
++        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.on_activated)
          self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.on_begin_edit, self)
          self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.on_end_edit, self)
          self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_selection_changed, self)
@@ -102,7 +110,7 @@
          self.Bind(wx.EVT_CHAR, self.on_char)
          self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.on_begin_drag)
          self.Bind(wx.EVT_TREE_END_DRAG, self.on_end_drag)
-@@ -108,6 +110,21 @@
+@@ -108,6 +110,21 @@ class OutlineBrowser(wx.TreeCtrl):
          except NotImplementedError:
              return
  
@@ -124,11 +132,34 @@
      _WXK_TO_METHOD = {
          wx.WXK_RETURN: do_goto_node,
          wx.WXK_DELETE: do_delete_node
-@@ -179,6 +196,10 @@
+@@ -179,6 +196,10 @@ class OutlineBrowser(wx.TreeCtrl):
              return
          node.notify_select()
  
-+    def on_right_click(self, event):
++    def on_activated(self, event):
++        item = event.GetItem()
++        self.EditLabel(item)
++
+     def on_begin_edit(self, event):
+         item = event.GetItem()
+         if not self.do_begin_edit(item):
+Index: djvusmooth-0.2.14/lib/gui/text_browser.py
+===================================================================
+--- djvusmooth-0.2.14.orig/lib/gui/text_browser.py
++++ djvusmooth-0.2.14/lib/gui/text_browser.py
+@@ -51,6 +51,7 @@ class TextBrowser(wx.TreeCtrl):
+         wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
+         self._have_root = False
+         self.page = None
++        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.on_activated)
+         self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.on_begin_edit, self)
+         self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.on_end_edit, self)
+         self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_selection_changed, self)
+@@ -98,6 +99,10 @@ class TextBrowser(wx.TreeCtrl):
+             return
+         node.notify_select()
+ 
++    def on_activated(self, event):
 +        item = event.GetItem()
 +        self.EditLabel(item)
 +

Reply via email to