dynamically converting StaticText to TextCtrl

I want to convert a staticText widget to textctrl on click event

is there a way to do it width WX?

thanks!

if there is no such thing, how can I create a widget and not display it until the user ckick somewhere?
thank you

···

On Sat, Jan 10, 2009 at 8:45 PM, יהודה goldnery@gmail.com wrote:

I want to convert a staticText widget to textctrl on click event

is there a way to do it width WX?

thanks!


http://kaze.co.il
יש קצה חוט לרעיון שלך

I want to convert a staticText widget to textctrl on click event

is there a way to do it width WX?

thanks!

I think that if you create both the wx.StaticText and wx.TextCtrl controls at the same time, and put them both into their sizer with the same settings-- then call textCtrl.Show(False) during initialization, the text control will be effectively invisible and not a part of your layout.

Then in your click event on the staticText, you just do staticText.Show(False) followed by textCtrl.Show(True) and you’ll switch the visibility out. You may need to call Layout on the parent panel.

HTH, its off-the-top-of-my-head so may not work but I’ve done somewhat similar stuff this way.

–Stephen

A different solution would be to use only a wx.TextCtrl, containing the desired text. Then, with the method SetEditable() it is possible to allow or prevent the user from modifying the text, while allowing her/him to copy it with Ctrl-C in any case.

···

2009/1/10 Stephen Hansen apt.shansen@gmail.com

I want to convert a staticText widget to textctrl on click event

is there a way to do it width WX?

thanks!

I think that if you create both the wx.StaticText and wx.TextCtrl controls at the same time, and put them both into their sizer with the same settings-- then call textCtrl.Show(False) during initialization, the text control will be effectively invisible and not a part of your layout.

Then in your click event on the staticText, you just do staticText.Show(False) followed by textCtrl.Show(True) and you’ll switch the visibility out. You may need to call Layout on the parent panel.

HTH, its off-the-top-of-my-head so may not work but I’ve done somewhat similar stuff this way.

–Stephen


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Maybe you are envisioning something interesting that I don't understand,
but that doesn't sound like a conventional GUI interaction and might be
inadvisable to do from the point of view of ease of use.

···

On Sat, Jan 10, 2009 at 1:45 PM, יהודה <goldnery@gmail.com> wrote:

I want to convert a staticText widget to textctrl on click event

is there a way to do it width WX?

Hello,

I want to convert a staticText widget to textctrl on click event

is there a way to do it width WX?

You can't convert one type of control to another, but you can easily swap them out so it looks like it changed.

import wx
class TestFrame(wx.Frame):
     def __init__(self, parent):
         wx.Frame.__init__(self, parent, title="Test Frame")

         # Attributes
         self._panel = wx.Panel(self)
         self._static = wx.StaticText(self._panel, label="Hello World")
         self._txtctrl = wx.TextCtrl(self._panel, value="Hello World")

         # Layout
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.AddMany([(self._static, 0), (self._txtctrl, 0)])
         self._panel.SetSizer(sizer)
         self._txtctrl.Hide()
         msizer = wx.BoxSizer(wx.HORIZONTAL)
         msizer.Add(self._panel, 0, wx.EXPAND)
         self.SetSizer(msizer)

         # Event Handlers
         self._static.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
         self._txtctrl.Bind(wx.EVT_KEY_UP, self.OnKeyUp)

     def OnKeyUp(self, evt):
         if evt.GetKeyCode() == wx.WXK_ESCAPE:
             self._static.SetLabel(self._txtctrl.GetValue())
             self._static.Show()
             self._txtctrl.Hide()
             self._panel.Layout()
         else:
             evt.Skip()

     def OnLeftUp(self, evt):
         self._static.Hide()
         self._txtctrl.Show()
         self._txtctrl.SetFocus()
         self._panel.Layout()

if __name__ == '__main__':
     app = wx.App(False)
     frame = TestFrame(None)
     frame.Show()
     app.MainLoop()

Cody

···

On Jan 10, 2009, at 12:45 PM, יהודה wrote:

thanks!
I’m developing with javascript gui web applications for 2 years so predicted is probably not possible, but still I wonted to make sure

C M wrote:

···

On Sat, Jan 10, 2009 at 1:45 PM, יהודה <goldnery@gmail.com> wrote:

I want to convert a staticText widget to textctrl on click event

is there a way to do it width WX?

Maybe you are envisioning something interesting that I don't understand,
but that doesn't sound like a conventional GUI interaction and might be
inadvisable to do from the point of view of ease of use.

Perhaps he means sth like:

1. Click a button
2. Remove StaticText and
3. put a Textctrl on the old position of the StaticText

And: I am to new to wx. I dont know how to do that

Udo

Yes, that is probably about what he wanted to do, but again I'm not sure that
is a good idea from the point of view of typical GUI conventions, because users
generally see static text as, well, *static*, that is, unchanging,
part of the unchanging
infrastructure of the application and not the user-given parts. When
they see text
in a textbox, though, it suggests it is editable. So, my point is, if
something is intended
to be editable, shouldn't it just be in a textbox to begin with?

The exception I can think of is if the user wants to change the GUI
itself, to really
take control of how things are displayed, in order to customize the
GUI to his or her
liking. But that is kind of rare, other than maybe changing the
language it is displayed
in, but that is one all at once in some customization dropdown.

In terms of doing it the way you mention, it is easily done in the way
the responsives
above describe, if you add those approaches under the event handler
for the button.

···

On Sun, Jan 11, 2009 at 2:34 PM, Udo Müller <wxpyu-1208@mueller-udo.de> wrote:

C M wrote:

On Sat, Jan 10, 2009 at 1:45 PM, ×™×"ו×"×" <goldnery@gmail.com> wrote:

I want to convert a staticText widget to textctrl on click event

is there a way to do it width WX?

Maybe you are envisioning something interesting that I don't understand,
but that doesn't sound like a conventional GUI interaction and might be
inadvisable to do from the point of view of ease of use.

Perhaps he means sth like:

1. Click a button
2. Remove StaticText and
3. put a Textctrl on the old position of the StaticText

And: I am to new to wx. I dont know how to do that

Stephen Hansen wrote:

    I want to convert a staticText widget to textctrl on click event

    is there a way to do it width WX?

    thanks!

I think that if you create both the wx.StaticText and wx.TextCtrl controls at the same time, and put them both into their sizer with the same settings-- then call textCtrl.Show(False) during initialization, the text control will be effectively invisible and not a part of your layout.

Then in your click event on the staticText, you just do staticText.Show(False) followed by textCtrl.Show(True) and you'll switch the visibility out. You may need to call Layout on the parent panel.

HTH, its off-the-top-of-my-head so may not work but I've done somewhat similar stuff this way.

I've seen this done using your suggested approach a few times, and it does work well. It can be a very nice effect. In Chandler they also supported switching to the text ctrl when tabbing to the pair, and IIRC that needed a bit of hackery to make it work smoothly, but it is possible.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

C M wrote:

···

On Sat, Jan 10, 2009 at 1:45 PM, יהודה <goldnery@gmail.com> wrote:

I want to convert a staticText widget to textctrl on click event

is there a way to do it width WX?

Maybe you are envisioning something interesting that I don't understand,
but that doesn't sound like a conventional GUI interaction and might be
inadvisable to do from the point of view of ease of use.

There are some applications that are using similar tricks to add some coolness factor to their UI. I've already mentioned Chandler, and another one that comes to mind is Apple's iCal.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!