Help using XRC

Hello

This is a little XRC test program I'm using to try to figure wxPython out before doing something serious. I have not been able to make it work. When running, I get a frame with a menu, but not the widgets on the panel and not the statusbar. I can do this so everything works without using XRC, but I'd really like to use the XRC approach since it makes layout so much easier. I have spent two days trying to figure this out, and no longer remember all the things I've attempted. Can someone give me a clue here?

Thanks

tst.py:

#!/usr/bin/python

import wx
from wx import xrc

class Main_Frame(wx.Frame):

     def __init__(self, parent):

         wx.Frame.__init__(self, parent)
         res = xrc.XmlResource('tst.xrc')

         frame = res.LoadFrame(self, 'frame')
         self.SetTitle("Test wxPython Program")
         menuBar = res.LoadMenuBarOnFrame(self,"menubar")

         self.statusBar = xrc.XRCCTRL(self, 'statusbar')
         self.SetStatusBar(self.statusBar)
         self.statusBar.SetStatusText("first")

         panel = xrc.XRCCTRL(self, 'mainPanel')
         mainsizer = panel.GetSizer()
         self.txtbox = xrc.XRCCTRL(panel, 'txtbox')

         mainsizer.Fit(self)
         mainsizer.SetSizeHints(self)
         self.CenterOnScreen()

class MyApp(wx.App):

     def OnInit(self):
         frame = Main_Frame(None)
         frame.Show()
         return True

if __name__ == '__main__':

     app = MyApp(False)
     app.MainLoop()

tst.xrc:

<?xml version="1.0" encoding="ascii"?>
<resource>
   <object class="wxMenuBar" name="menubar">
     <object class="wxMenu" name="menuFile">
       <label>&amp;File</label>
       <object class="wxMenuItem" name="menuFile_Open">
         <label>&amp;Open</label>
         <accel>Ctrl - O</accel>
       </object>
       <object class="wxMenuItem" name="menuFile_Close">
         <label>&amp;Close</label>
         <accel>Ctrl - C</accel>
       </object>
     </object>
   </object>
   <object class="wxFrame" name="frame">
     <title>This is my title</title>
     <object class="wxStatusBar" name="statusbar">
       <fields>1</fields>
     </object>
     <object class="wxPanel" name="mainPanel">
       <object class="wxBoxSizer">
         <orient>wxVERTICAL</orient>
         <object class="sizeritem">
           <object class="wxBoxSizer">
             <orient>wxVERTICAL</orient>
             <object class="sizeritem">
               <object class="wxButton" name="btn1">
                 <label>button 1</label>
               </object>
               <flag>wxALL|wxEXPAND</flag>
               <border>5</border>
             </object>
             <object class="sizeritem">
               <object class="wxButton" name="btn2">
                 <label>button 2</label>
               </object>
               <flag>wxALL|wxEXPAND</flag>
               <border>5</border>
             </object>
           </object>
           <flag>wxALL|wxALIGN_CENTRE</flag>
           <border>5</border>
         </object>
         <object class="sizeritem">
           <object class="wxBoxSizer">
             <orient>wxHORIZONTAL</orient>
             <object class="sizeritem">
               <object class="wxStaticText" name="label">
                 <label>Label</label>
               </object>
               <flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
               <border>5</border>
             </object>
             <object class="sizeritem">
               <object class="wxTextCtrl" name="txtbox"/>
               <flag>wxALL</flag>
               <border>5</border>
             </object>
           </object>
         </object>
       </object>
     </object>
   </object>
</resource>

Why don't you use wxGlade?
It saved me a lot of time. You design your
frames/dialogs, press a button and you have ready
code.
--- Peter van Loben Sels <ptm5851@blackfoot.net>
wrote:

···

Hello

This is a little XRC test program I'm using to try
to figure wxPython out
before doing something serious. I have not been able
to make it work. When
running, I get a frame with a menu, but not the
widgets on the panel and
not the statusbar. I can do this so everything works
without using XRC,
but I'd really like to use the XRC approach since it
makes layout so much
easier. I have spent two days trying to figure this
out, and no longer
remember all the things I've attempted. Can someone
give me a clue here?

Thanks

tst.py:

#!/usr/bin/python

import wx
from wx import xrc

class Main_Frame(wx.Frame):

     def __init__(self, parent):

         wx.Frame.__init__(self, parent)
         res = xrc.XmlResource('tst.xrc')

         frame = res.LoadFrame(self, 'frame')
         self.SetTitle("Test wxPython Program")
         menuBar =
res.LoadMenuBarOnFrame(self,"menubar")

         self.statusBar = xrc.XRCCTRL(self,
'statusbar')
         self.SetStatusBar(self.statusBar)
         self.statusBar.SetStatusText("first")

         panel = xrc.XRCCTRL(self, 'mainPanel')
         mainsizer = panel.GetSizer()
         self.txtbox = xrc.XRCCTRL(panel, 'txtbox')

         mainsizer.Fit(self)
         mainsizer.SetSizeHints(self)
         self.CenterOnScreen()

class MyApp(wx.App):

     def OnInit(self):
         frame = Main_Frame(None)
         frame.Show()
         return True

if __name__ == '__main__':

     app = MyApp(False)
     app.MainLoop()

tst.xrc:

<?xml version="1.0" encoding="ascii"?>
<resource>
   <object class="wxMenuBar" name="menubar">
     <object class="wxMenu" name="menuFile">
       <label>&amp;File</label>
       <object class="wxMenuItem"
name="menuFile_Open">
         <label>&amp;Open</label>
         <accel>Ctrl - O</accel>
       </object>
       <object class="wxMenuItem"
name="menuFile_Close">
         <label>&amp;Close</label>
         <accel>Ctrl - C</accel>
       </object>
     </object>
   </object>
   <object class="wxFrame" name="frame">
     <title>This is my title</title>
     <object class="wxStatusBar" name="statusbar">
       <fields>1</fields>
     </object>
     <object class="wxPanel" name="mainPanel">
       <object class="wxBoxSizer">
         <orient>wxVERTICAL</orient>
         <object class="sizeritem">
           <object class="wxBoxSizer">
             <orient>wxVERTICAL</orient>
             <object class="sizeritem">
               <object class="wxButton" name="btn1">
                 <label>button 1</label>
               </object>
               <flag>wxALL|wxEXPAND</flag>
               <border>5</border>
             </object>
             <object class="sizeritem">
               <object class="wxButton" name="btn2">
                 <label>button 2</label>
               </object>
               <flag>wxALL|wxEXPAND</flag>
               <border>5</border>
             </object>
           </object>
           <flag>wxALL|wxALIGN_CENTRE</flag>
           <border>5</border>
         </object>
         <object class="sizeritem">
           <object class="wxBoxSizer">
             <orient>wxHORIZONTAL</orient>
             <object class="sizeritem">
               <object class="wxStaticText"
name="label">
                 <label>Label</label>
               </object>
              
<flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
               <border>5</border>
             </object>
             <object class="sizeritem">
               <object class="wxTextCtrl"
name="txtbox"/>
               <flag>wxALL</flag>
               <border>5</border>
             </object>
           </object>
         </object>
       </object>
     </object>
   </object>
</resource>

---------------------------------------------------------------------

To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org

Peter van Loben Sels wrote:

class Main_Frame(wx.Frame):

     def __init__(self, parent):

         wx.Frame.__init__(self, parent)
         res = xrc.XmlResource('tst.xrc')

         frame = res.LoadFrame(self, 'frame')

class MyApp(wx.App):

     def OnInit(self):
         frame = Main_Frame(None)
         frame.Show()
         return True

I think the problem is that you are creating two different frame objects, one with the menubar (this one gets displayed by the Show() method) and one imported from the xrc file that never gets shown.

When you call

frame = Main_Frame(None)
frame.Show()

from the OnInit method, you are instantiating an instance of the frame class you've defined in your Python file. In this class you explicitly get a reference to the menubar and attach it to the frame. But that's all you do with this frame. When frame.Show() is called, this is all there is.

Within this class you are also loading the frame defined in your xrc file:

frame = res.LoadFrame(self, 'frame')

but you aren't doing anything with it. So it is floating in the ether complete with its sizers and buttons and other controls, but we can't see it. :slight_smile:

So how to fix this? Well, I'm not sure why you are creating a Main_Frame class anyway. All of this can be done in xrc. Here is a skeleton I use when I start a new file:

import wx
from wx import xrc

class MyApp(wx.App):

     def OnInit(self):
         self.res = xrc.XmlResource('gui.xrc')
         self.InitFrame()
         self.SetTopWindow(self.frame)
         self.frame.Show()
         return True

     def InitFrame(self):
         self.frame = self.res.LoadFrame(None, 'mainFrame')
         self.panel = xrc.XRCCTRL(self.frame, 'panel')

if __name__ == '__main__':
     app = MyApp(False)
     app.MainLoop()

This way, you have zero GUI code in the program. The frame gets loaded in the InitFrame method and this same frame is then what you see when self.frame.Show() is called.

In your case, you can move a lot of your code into the OnInit method and get rid of the Main_Frame class altogether.

In the xrc file, you can also define the MenuBar as a child of the frame, and it will load automatically as well, unless you have a need to do it manually as you do.

Hope that helps!

P.S. I wrote this tutorial about XRC recently: http://wiki.wxpython.org/index.cgi/XRCTutorial

It might be too basic for you since you seem to have a handle on it, but it will take you through the first steps needed to set up a Python and XRC file, so maybe it will help if you decide to convert your program into pure xrc (i.e., no Main_Frame class).

:slight_smile:
John

Thank you for your suggestion Michael. I have actually looked at wxGlade and thought it a fine program, but I like xrced better because it seems, to me, so straightforward to use. Also, using wxGlade to generate code in XRC format just (appears) to produce pretty much what xrced does. My problem, I think, is how to take my generated '.xrc' file and produce a working class in python that can be called and run the way I'm trying. But I can't figure out why the (I think trivial) program I included doesn't work! I don't know if I'm missing the boat entirely, or maybe an obscure line of code ...

Probably all the above.

Peter

···

On Thu, 26 Oct 2006, Michael S wrote:

Why don't you use wxGlade?
It saved me a lot of time. You design your
frames/dialogs, press a button and you have ready
code.
--- Peter van Loben Sels <ptm5851@blackfoot.net>
wrote:

Hello

This is a little XRC test program I'm using to try
to figure wxPython out
before doing something serious. I have not been able
to make it work. When

John Salerno wrote:

Peter van Loben Sels wrote:

class Main_Frame(wx.Frame):

     def __init__(self, parent):

         wx.Frame.__init__(self, parent)
         res = xrc.XmlResource('tst.xrc')

         frame = res.LoadFrame(self, 'frame')

class MyApp(wx.App):

     def OnInit(self):
         frame = Main_Frame(None)
         frame.Show()
         return True

I think the problem is that you are creating two different frame objects, one with the menubar (this one gets displayed by the Show() method) and one imported from the xrc file that never gets shown.

When you call

frame = Main_Frame(None)
frame.Show()

from the OnInit method, you are instantiating an instance of the frame class you've defined in your Python file. In this class you explicitly get a reference to the menubar and attach it to the frame. But that's all you do with this frame. When frame.Show() is called, this is all there is.

Within this class you are also loading the frame defined in your xrc file:

frame = res.LoadFrame(self, 'frame')

but you aren't doing anything with it. So it is floating in the ether complete with its sizers and buttons and other controls, but we can't see it. :slight_smile:

So how to fix this? Well, I'm not sure why you are creating a Main_Frame class anyway. All of this can be done in xrc. Here is a skeleton I use when I start a new file:

import wx
from wx import xrc

class MyApp(wx.App):

    def OnInit(self):
        self.res = xrc.XmlResource('gui.xrc')
        self.InitFrame()
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True

    def InitFrame(self):
        self.frame = self.res.LoadFrame(None, 'mainFrame')
        self.panel = xrc.XRCCTRL(self.frame, 'panel')

if __name__ == '__main__':
    app = MyApp(False)
    app.MainLoop()

This way, you have zero GUI code in the program. The frame gets loaded in the InitFrame method and this same frame is then what you see when self.frame.Show() is called.

In your case, you can move a lot of your code into the OnInit method and get rid of the Main_Frame class altogether.

In the xrc file, you can also define the MenuBar as a child of the frame, and it will load automatically as well, unless you have a need to do it manually as you do.

Hope that helps!

P.S. I wrote this tutorial about XRC recently: http://wiki.wxpython.org/index.cgi/XRCTutorial

It might be too basic for you since you seem to have a handle on it, but it will take you through the first steps needed to set up a Python and XRC file, so maybe it will help if you decide to convert your program into pure xrc (i.e., no Main_Frame class).

:slight_smile:
John

Give this a try:

#!/usr/bin/python

import wx
from wx import xrc

class MyApp(wx.App):

     def OnInit(self):
         self.res = xrc.XmlResource('tst.xrc')
         self.frame = self.res.LoadFrame(None, 'frame')
         self.menuBar = self.res.LoadMenuBarOnFrame(self.frame, 'menubar')
         self.frame.Show()
         return True

if __name__ == '__main__':

     app = MyApp(False)
     app.MainLoop()

If you haven't already, take a look at the examples in the Wiki (wiki.python.org). Enter "xrc" in the search box at the upper right, then click Titles.

Happy hunting,

···

--
Don Dwiggins
Advanced Publishing Technology

Peter van Loben Sels wrote:

Hello

This is a little XRC test program I'm using to try to figure wxPython out before doing something serious. I have not been able to make it work. When running, I get a frame with a menu, but not the widgets on the panel and not the statusbar. I can do this so everything works without using XRC, but I'd really like to use the XRC approach since it makes layout so much easier. I have spent two days trying to figure this out, and no longer remember all the things I've attempted. Can someone give me a clue here?

Thanks

tst.py:

#!/usr/bin/python

import wx
from wx import xrc

class Main_Frame(wx.Frame):

    def __init__(self, parent):

        wx.Frame.__init__(self, parent)
        res = xrc.XmlResource('tst.xrc')

        frame = res.LoadFrame(self, 'frame')

If you want this Main_Frame to be the thing that is loaded from the XRC then you need to use a little different pattern. Try this instead:

  def __init__(self, parent):
    pre = wx.PreFrame()
    res = xrc.XmlResource('tst.xrc')
    res.LoadOnFrame(pre, parent, 'frame')
    self.PostCreate(pre)

···

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

John Salerno wrote:

Peter van Loben Sels wrote:

> class Main_Frame(wx.Frame):
>

I think the problem is that you are creating two different frame objects,
one with the menubar (this one gets displayed by the Show() method) and
one imported from the xrc file that never gets shown.

I think you are correct. The light turns on ...

In fact, making the following changes:

class Main_Frame(wx.Frame):

     def __init__(self, parent):

         wx.Frame.__init__(self, parent)
         res = xrc.XmlResource('tst.xrc')

         self.frame = res.LoadFrame(self, 'frame') #####

         self.frame.SetTitle("Test wxPython Program") #####
         menuBar = res.LoadMenuBarOnFrame(self.frame,"menubar") #####

         self.statusBar = xrc.XRCCTRL(self.frame, 'statusbar') #####
         self.SetStatusBar(self.statusBar)
         self.statusBar.SetStatusText("first")

         panel = xrc.XRCCTRL(self.frame, 'mainPanel')
         mainsizer = panel.GetSizer()
         self.txtbox = xrc.XRCCTRL(panel, 'txtbox')

         mainsizer.Fit(self)
         mainsizer.SetSizeHints(self)
         self.CenterOnScreen()

class MyApp(wx.App):

     def OnInit(self):
         frame = Main_Frame(None)
         frame.frame.Show() #####
         #frame.Show() #####
         return True

if __name__ == '__main__':

     app = MyApp(False)
     app.MainLoop()

Seems to work, and displays my XRC frame, menubar, panel + widgets, and statusbar! (it segfaults on close, but ...). If I just call frame.Show(), all I now get is the frame ... Clearly I was clueless here, but it might be coming together for me. Robin Dunn has been helpful as well, and I like the way he does it using the two-stage process. I wish I understood that a little better.

So how to fix this? Well, I'm not sure why you are creating a Main_Frame class anyway.

I started experimenting with this to see how I could structure my overall project. I'd like a short main program that can call and display different activities in a modular way. Each of these would be maintained in a separate .py/.xrc file, i.e., one class per file. So I was trying to see how I could do that ...

P.S. I wrote this tutorial about XRC recently:
http://wiki.wxpython.org/index.cgi/XRCTutorial

It might be too basic for you since you seem to have a handle on it, but
it will take you through the first steps needed to set up a Python and XRC
file, so maybe it will help if you decide to convert your program into
pure xrc (i.e., no Main_Frame class).

I have read your turorial many times since starting this project, and found it very, very helpful. Not too basic at all, at least for me. In fact, I was trying to 'extend' on it a little with my tst.py/.xrc program. Your last example sort of does what I think I am looking for, but it seemed like all the python code (event processing, etc.) would be in one file doing it that way. I want to spread it out for maintainability.

It is folks like you who are willing to help with time and talent that keeps folks like me from going totally bonkers. Many thanks!

Peter

···

On Fri, 27 Oct 2006, John Salerno wrote:

Thank you! That works ... (of course)

I had looked at the material on the wiki about two-stage construction before my post, but didn't think it applied to what I was trying to do. (or maybe I just hoped it didn't ...)

Looking at the information I can find on the net about XRC and two-stage construction again, I wish I could say I had a grasp of what is happening here.

Is it correct that this two-stage construction technique is really only necessary when using XRC. That it _could_ be used, but is not a necessity, when coding without XRC? That this is true when subclassing any top-level (frame, panel, dialog, menu?) window using XRC? Actually, I don't think subclassing is the correct term here, but what I want escapes me for the moment.

Conceptually, I am thinking that the "pre = wx.PreFrame()" statement builds a 'framework' for a wxFrame, the frame details (from tst.xrc) get loaded on this 'framework' with the "res.LoadOnFrame(pre, parent, 'frame')" statement, and as part of the XRC .LoadOnFrame() process of loading the frame the frame is also _created_ which turns the frame into 'self' for the class ... and all this replaces the wxFrame.__init__(self) statement which creates a frame, but without the .xrc information. Is this about correct? What, then, does the "self.PostCreate(pre)" statement do?

Thanks for your response to my post, and your help.

Peter

···

On Fri, 27 Oct 2006, Robin Dunn wrote:

Peter van Loben Sels wrote:

Hello

This is a little XRC test program I'm using to try to figure wxPython out
before doing something serious. I have not been able to make it work. When

tst.py:

#!/usr/bin/python

import wx
from wx import xrc

class Main_Frame(wx.Frame):

     def __init__(self, parent):

         wx.Frame.__init__(self, parent)
         res = xrc.XmlResource('tst.xrc')

         frame = res.LoadFrame(self, 'frame')

If you want this Main_Frame to be the thing that is loaded from the XRC then you need to use a little different pattern. Try this instead:

   def __init__(self, parent):
     pre = wx.PreFrame()
     res = xrc.XmlResource('tst.xrc')
     res.LoadOnFrame(pre, parent, 'frame')
     self.PostCreate(pre)

Thank you Don. I've actually done a _lot_ of searching. I think the information is out there; I'm just not putting it together well.

Peter

···

On Fri, 27 Oct 2006, Don Dwiggins wrote:

If you haven't already, take a look at the examples in the Wiki (wiki.python.org). Enter "xrc" in the search box at the upper right, then click Titles.

Happy hunting,

--
Don Dwiggins
Advanced Publishing Technology

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Peter van Loben Sels wrote:

Peter van Loben Sels wrote:

Hello

This is a little XRC test program I'm using to try to figure wxPython out
before doing something serious. I have not been able to make it work. When

tst.py:

#!/usr/bin/python

import wx
from wx import xrc

class Main_Frame(wx.Frame):

     def __init__(self, parent):

         wx.Frame.__init__(self, parent)
         res = xrc.XmlResource('tst.xrc')

         frame = res.LoadFrame(self, 'frame')

If you want this Main_Frame to be the thing that is loaded from the XRC then you need to use a little different pattern. Try this instead:

     def __init__(self, parent):
         pre = wx.PreFrame()
         res = xrc.XmlResource('tst.xrc')
         res.LoadOnFrame(pre, parent, 'frame')
         self.PostCreate(pre)

Thank you! That works ... (of course)

I had looked at the material on the wiki about two-stage construction before my post, but didn't think it applied to what I was trying to do. (or maybe I just hoped it didn't ...)

Looking at the information I can find on the net about XRC and two-stage construction again, I wish I could say I had a grasp of what is happening here.

Is it correct that this two-stage construction technique is really only necessary when using XRC. That it _could_ be used, but is not a necessity, when coding without XRC? That this is true when subclassing any top-level (frame, panel, dialog, menu?) window using XRC? Actually, I don't think subclassing is the correct term here, but what I want escapes me for the moment.

[ WARNING! WARNING! C++-phobic readers should skip this section! :wink: ]

It's typically something that is used more often from C++. Since C++ supports function overloading most of the UI classes have at least two constructors, one that takes no parameters, and one that takes all the parameters that we are used to using from wxPython. This is useful from C++ because the no-parameter version is what C++ calls the default constructor and will be used automatically in several language constructs unless explicit parameters are specified, for example when a derived class is instantiated and it needs to initialize its base classes. So it basically allows the all the C++ parts of a class (including the base classes) to get initialized, but delay the creation of the actual UI object until later. This also means that the UI creation code only runs once, not for each base class.

The Create function of the class is normally executed from within the non-default constructor (the one that takes parameters) but because of the 2-phase create there is no special dance needed to only do the UI object creation one time, and C++ itself does most of the work. For example the order of function calls when a wxBitmapButton is created goes something like this:

call wxBitmapButton(parent, id, bmp)
  call wxButton default ctor
    call wxControl default ctor
      call wxWindow default ctor
        and so on...
  call wxBitmapButton::Create(parent, id, bmp)

The creator of XRC found it convenient to build upon this model and allow the instance that is created be separated from the call to create the UI object, especially when XRC is used to create instances of classes that XRC doesn't already know about, but where it does know about the base class. It uses it essentially as a way to be dynamic from a very non-dynamic language.

Conceptually, I am thinking that the "pre = wx.PreFrame()" statement builds a 'framework' for a wxFrame,

It creates a C++ instance of the wxFrame class without calling the code that creates the actual UI object, and pre is a proxy for that C++ object.

the frame details (from tst.xrc) get loaded on this 'framework' with the "res.LoadOnFrame(pre, parent, 'frame')" statement, and as part of the XRC .LoadOnFrame() process of loading the frame the frame is also _created_

The order is the other way around. XRC calls the frame's Create method, and then the contents defined in the xrc file are recursivly created with the frame as the parent, following a similar pattern, (create the instance, and then call Create.) When it is done, the pre frame is now a fully constructed wx.Frame object, which takes us to the next step...

which turns the frame into 'self' for the class ...

That is actually done in the PostCreate method call. Since pre is its own instance of a wx.Frame, but you are working with separate instance of the Main_Frame class, it would be nice to be able to combine them. Originally I recommended using delegation and forwarding everything to the instance created by XRC, but that became real awkward real fast. So since this is Python and if you can think it you can probably do it, I realized that we could easily transfer everything that makes pre be a wx.Frame and put it in self so self will be that frame, and also be an instance of the Main_Frame class. That magic is done on PostCreate, (and is surprisingly simple.)

···

On Fri, 27 Oct 2006, Robin Dunn wrote:

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

Peter van Loben Sels wrote:

I have read your turorial many times since starting this project, and found it very, very helpful. Not too basic at all, at least for me. In fact, I was trying to 'extend' on it a little with my tst.py/.xrc program. Your last example sort of does what I think I am looking for, but it seemed like all the python code (event processing, etc.) would be in one file doing it that way. I want to spread it out for maintainability.

It is folks like you who are willing to help with time and talent that keeps folks like me from going totally bonkers. Many thanks!

Wow, you have no idea how happy that makes me to know I can actually help someone with this stuff! I'm glad the tutorial was decent enough to guide you along, at least at first. It's true that the two-step process that Robin showed you might be helpful in your case, but that has always gone over my head since I've never needed it yet. :slight_smile:

(Robin is like the spade in a game of cards, he trumps everything we all say) :wink:

Robin Dunn wrote:

[ WARNING! WARNING! C++-phobic readers should skip this section! :wink: ]

  ... section omitted ...

Robin, I think this section is useful enough to find a home in the wiki. I've been reasonably successful using two-stage create, pretty much "by the book", but reading this gave me a clearer insight.

Thanks yet again for all you do,

···

--
Don Dwiggins
Advanced Publishing Technology

Don Dwiggins wrote:

Robin Dunn wrote:

[ WARNING! WARNING! C++-phobic readers should skip this section! :wink: ]

... section omitted ...

Robin, I think this section is useful enough to find a home in the wiki.

Feel free to add it wherever it makes sense to do so.

···

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

Hi

I've been experimenting with stattext from wx.lib. The default appears to be to draw the text aligned left but aligned up from centered vertically. This seems to be different from wx.StaticText or wx.TextControl, where normally the text is centered vertically in its window.

This seems to be the same whether I use wx.SUNKEN_BORDER or wx.NO_BORDER.

The relevant parts of the program I'm playing with are:

from wx.lib.stattext import GenStaticText as StaticText
.....
self.creditField = StaticText(panel, -1, "0.00", size=self.Number_Field_Size, style = wx.SUNKEN_BORDER|wx.ALIGN_RIGHT)
...
gbs = wx.GridBagSizer(10, 10)
...
gbs.Add(self.creditField, (5,0), border=10, flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER)

The above aligns the text "0.00" on the right border, but up from vertical. It is a small thing, but it looks funny when mixing stattext widgets with TextControls, for example. Am I doing something wrong, is this a bug, or what? Thanks for any help!

Peter

python 2.4.3
wx-2.6-gtk2

Peter van Loben Sels wrote:

The above aligns the text "0.00" on the right border, but up from vertical. It is a small thing, but it looks funny when mixing stattext widgets with TextControls, for example. Am I doing something wrong, is this a bug, or what? Thanks for any help!

Please provide a sample that clearly shows the difference between wx.StaticText and GenStaticText, and if you feel up to it, a patch to bring GenStaticText into conformity.

···

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