[Chandler-dev] expanding edit fields

Reid Ellis rae at osafoundation.org
Thu Sep 14 00:04:17 PDT 2006


I was working on testing out some ideas with expanding edit fields  
and thought I would check them in, but being a prudent programmer I  
checked the functional tests first. Alas, the tests failed, and in  
fact the app crashed.

I'll look into the crashes more tomorrow, but thought I'd send this  
patch for people to take a look at. It causes the currently-being- 
edited field to switch to a 2-line-high, scrolling text field while  
it has focus. It also sets the tooltip for the field if the text is  
longer than the display width.

II'm only using for the item's title and description right now to  
test it out (e.g. the "Welcome to Chandler" and "Open Source  
Applications Foundation" text in the default item).

In case the mailing list software strips Mime attachments, it can  
also be found at http://chandler.tnir.org/rae-expano-diffs.txt

Reid

-------------- next part --------------
Index: parcels/osaf/framework/attributeEditors/AttributeEditors.py
===================================================================
--- parcels/osaf/framework/attributeEditors/AttributeEditors.py	(revision 11766)
+++ parcels/osaf/framework/attributeEditors/AttributeEditors.py	(working copy)
@@ -731,14 +731,19 @@
         del keys['staticSize']
         self.hideLoc = (-100,-100)
         self.showLoc = (0,0)
-        editControl = DragAndDropTextCtrl(self, -1, pos=position, size=size, 
-                                          style=style, *args, **keys)
+
+        # double the height of the edit contro
+        doubleSize = size;
+        doubleSize.height = doubleSize.height * 2;
+        editControl = DragAndDropTextCtrl(self, -1, pos=position, size=doubleSize, 
+                                          style=style|wx.TE_MULTILINE|wx.TE_AUTO_SCROLL, *args, **keys)
         self.editControl = editControl
         editControl.Bind(wx.EVT_KILL_FOCUS, self.OnEditLoseFocus)
         editControl.Bind(wx.EVT_SET_FOCUS, self.OnEditGainFocus)
         editControl.Bind(wx.EVT_LEFT_DOWN, self.OnEditClick)
         editControl.Bind(wx.EVT_LEFT_DCLICK, self.OnEditClick)
         editControl.Bind(wx.EVT_KEY_UP, self.OnEditKeyUp)
+
         staticControl = AEStaticText(self, -1, pos=position, 
                                                       size=staticSize, style=style, 
                                                       *args, **keys)
@@ -799,9 +804,35 @@
         self._swapControls(self.editControl)
         event.Skip()
 
+    def UpdateStaticText(self):
+        # compare the rendered text width to the width of the control
+        text = self.staticControl.GetValue()
+        tooltipText = text
+        dc = wx.PaintDC(self.staticControl)
+        (renderedStringWidth, ignoredHeight) = dc.GetTextExtent(text)
+        controlSize = self.staticControl.GetClientSize()
+        # if the rendered string does not fit inside the control, set the tooltip
+        if controlSize.width < renderedStringWidth:
+            ##rae - can't use this because the data is only stored in the controls,
+            ## so changing the control by truncating the text and adding '...' loses
+            ## the data! Should keep the string data in self.text or something.
+            ##
+            ##### end the string with an elipsis
+            ####(elipsisWidth, ignoredHeight) = dc.GetTextExtent(u'...')
+            ####while renderedStringWidth > controlSize.width + elipsisWidth:
+            ####    text = text[:-1]
+            ####    (renderedStringWidth, ignoredHeight) = dc.GetTextExtent(text)
+            ####    renderedStringWidth = renderedStringWidth + elipsisWidth
+            ####self.staticControl.SetValue(text + u'...')
+            self.staticControl.SetToolTipString(tooltipText)
+        else:
+            self.staticControl.SetToolTipString(u'')
+
+
     def OnEditLoseFocus(self, event):
         NotifyBlockToSaveValue(self)
         self._swapControls(self.staticControl)
+        self.UpdateStaticText()
         event.Skip()
 
     def OnEditKeyUp(self, event):


More information about the chandler-dev mailing list