]> git.saurik.com Git - wxWidgets.git/commitdiff
handle starting out with multiple lines of text.
authorRobin Dunn <robin@alldunn.com>
Mon, 25 Sep 2006 04:58:32 +0000 (04:58 +0000)
committerRobin Dunn <robin@alldunn.com>
Mon, 25 Sep 2006 04:58:32 +0000 (04:58 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41423 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/demo/ExpandoTextCtrl.py
wxPython/wx/lib/expando.py

index 0315a39e2f22ccefe36c3a47ab4946e1b94ce22d..9c967e828747cb4affa0b27455323c9a8605de1c 100644 (file)
@@ -96,8 +96,8 @@ class TestPanel(wx.Panel):
 
 
     def OnButton(self, evt):
-        win = TestFrame(self)
-        win.Show(True)
+        self.win = TestFrame(self)
+        self.win.Show(True)
 
   
 #----------------------------------------------------------------------
index 754595687ecd1c4f13bd1a3f8780fc4ca4c2f57c..f16e5e1d52f60db1546b855a1d925b979cd4f69f 100644 (file)
@@ -64,9 +64,11 @@ class ExpandoTextCtrl(wx.TextCtrl):
                              style, validator, name)
         # save some basic metrics
         self.extraHeight = self.defaultHeight - self.GetCharHeight()
-        self.numLines = self.GetNumberOfLines()
+        self.numLines = 1
         self.maxHeight = -1
-        
+        if value:
+            wx.CallAfter(self._adjustCtrl)
+                        
         self.Bind(wx.EVT_TEXT, self.OnTextChanged)
 
 
@@ -177,7 +179,7 @@ class ExpandoTextCtrl(wx.TextCtrl):
             while idx < len(pte):
                 if line[idx] == ' ':
                     spc = idx
-                if pte[idx] - start > width - _sbw:
+                if pte[idx] - start > width:
                     # we've reached the max width, add a new line
                     count += 1
                     # did we see a space? if so restart the count at that pos
@@ -190,99 +192,3 @@ class ExpandoTextCtrl(wx.TextCtrl):
             return count
 
 #---------------------------------------------------------------------------
-
-
-if __name__ == '__main__':
-    print wx.VERSION
-    
-    class TestFrame(wx.Frame):
-        def __init__(self):
-            wx.Frame.__init__(self, None, title="Testing...")
-            self.pnl = p = wx.Panel(self)
-            self.eom = ExpandoTextCtrl(p, pos=(25,25), size=(250,-1))
-            self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.eom)
-
-            # create some buttons and sizers to use in testing some
-            # features and also the layout
-            vBtnSizer = wx.BoxSizer(wx.VERTICAL)
-
-            btn = wx.Button(p, -1, "Set MaxHeight")
-            self.Bind(wx.EVT_BUTTON, self.OnSetMaxHeight, btn)
-            vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
-
-            btn = wx.Button(p, -1, "Set Font")
-            self.Bind(wx.EVT_BUTTON, self.OnSetFont, btn)
-            vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
-
-            btn = wx.Button(p, -1, "Set Value")
-            self.Bind(wx.EVT_BUTTON, self.OnSetValue, btn)
-            vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
-
-            for x in range(5):
-                btn = wx.Button(p, -1, " ")
-                vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
-
-            hBtnSizer = wx.BoxSizer(wx.HORIZONTAL)
-            for x in range(3):
-                btn = wx.Button(p, -1, " ")
-                hBtnSizer.Add(btn, 0, wx.ALL, 5)
-
-            sizer = wx.BoxSizer(wx.HORIZONTAL)
-            col1 = wx.BoxSizer(wx.VERTICAL)
-            col1.Add(self.eom, 0, wx.ALL, 10)
-            col1.Add(hBtnSizer)
-            sizer.Add(col1)
-            sizer.Add(vBtnSizer)
-            p.SetSizer(sizer)
-
-            # Put the panel in a sizer for the frame so we can use self.Fit()
-            frameSizer = wx.BoxSizer()
-            frameSizer.Add(p, 1, wx.EXPAND)
-            self.SetSizer(frameSizer)
-            
-            self.Fit()
-
-
-        def OnRefit(self, evt):
-            # The Expando control will redo the layout of the
-            # sizer it belongs to, but sometimes this may not be
-            # enough, so it will send us this event so we can do any
-            # other layout adjustments needed.  In this case we'll
-            # just resize the frame to fit the new needs of the sizer.
-            self.Fit()
-
-        def OnSetMaxHeight(self, evt):
-            mh = self.eom.GetMaxHeight()
-            dlg = wx.NumberEntryDialog(self, "", "Enter new max height:",
-                                       "MaxHeight", mh, -1, 1000)
-            if dlg.ShowModal() == wx.ID_OK:
-                self.eom.SetMaxHeight(dlg.GetValue())
-            dlg.Destroy()
-            
-            
-        def OnSetFont(self, evt):
-            dlg = wx.FontDialog(self, wx.FontData())
-            dlg.GetFontData().SetInitialFont(self.eom.GetFont())
-            if dlg.ShowModal() == wx.ID_OK:
-                self.eom.SetFont(dlg.GetFontData().GetChosenFont())
-            dlg.Destroy()
-            
-            
-        def OnSetValue(self, evt):
-            self.eom.SetValue("This is a test...  Only a test.  If this had "
-                              "been a real emergency you would have seen the "
-                              "quick brown fox jump over the lazy dog.")
-        
-
-    app = wx.App(False)
-    frm = TestFrame()
-    frm.Show()
-    #import wx.py
-    #shell = wx.py.shell.ShellFrame(frm, size=(500,300),
-    #                               locals={'wx':wx, 'frm':frm})
-    #shell.Show()
-    frm.Raise()
-    app.MainLoop()
-
-
-