XRC beginner's question...

Somehow when I started using wxPython I passed right by XRC. I wish I’d started using it from the beginning, but oh well. I’ve decided to convert the app I’m working on to use XRC - I’m trying desperately to improve my separation of logic/presentation, and I seem to have hit the wall - but I’m stuck on what is probably a very dumb question:
How do I add widgets that aren’t in the list of things XRCed already knows about? Is this what the “unknown” widget is for, and if so what do I do with it?

In this app, I’m using the EditableListBox from gizmos, and the FileBrowseButtonWithHistory. When I’m done with this, I’ll be doing the same with a couple of apps where I use subclassed ListCtrls. In general, how do I refer to them in XRC? I’ve searched Wiki and Google, but everything I’ve found seems to assume that either 1) I’m using only standard controls or 2) I already know what the heck I’m doing.

Thanks in advance (and for not mocking my foolishment!)

···


www.fsrtechnologies.com

So could you tell why you feel you wished you had used XRC from the beginning? And if anyone else wants to chirp up on XRC?

Well, I know there are other ways to achieve good separation, but XRC looks like the best way from where I sit. From what I’ve read, the structure of the XRC file resembles the layout on-screen - one major plus - and more to the point, most of the repetitive stuff that currently clutters up my init can simply be stored as data. Here’s an example of the best I’ve been able to come up with at my current level of wxPythonicity:

self.Options = {
“KeepInsID”: {“Label”:“Insurance IDs?”, “ToolTip”:“Do you want to keep "legacy" insurance IDs codes(Medicare, Medicaid, BX/BS, etc.?”},

        "KeepLicense":   {"Label":"Licenses?", "ToolTip":"Do you want to keep state license numbers?"},
        "KeepUxIN":      {"Label":"UPIN/USINs?", "ToolTip":"Do you want to keep UPIN and USIN codes?"}}

for opt, detail in self.Options.iteritems():
self.Options[opt][“cb”] = wx.CheckBox(pnl, -1, detail[“Label”], style=wx.ALIGN_LEFT, name=opt)
self.Options[opt][“cb”].SetToolTip(wx.ToolTip(detail[“ToolTip”]))

        self.Options[opt]["cb"].SetValue(Global.cfgFile['Current'][opt])
        self.Bind(wx.EVT_CHECKBOX, self.OnCheck, self.Options[opt]["cb"])

Which works OK, I guess, but then I have to place my controls like this:

grid3.Add(self.Options[“KeepInsID”][“cb”])
which feels ugly to me. I have an array of checkboxes, two FileBrowseButtons, a few buttons… By reducing redundancy, I’ve cut my init down to about a hundred lines, which still seems excessive (given that this is mostly layout, not logic.) I’m sure that this could be improved upon, but moving the bulk of widget definition AND layout out into a resource file seems like a much better idea. So I’m looking forward to learning XRC-fu.

···

On Sun, Apr 6, 2008 at 7:44 PM, C M cmpython@gmail.com wrote:


www.fsrtechnologies.com

Marc Tompkins wrote:

    Well, I know there are other ways to achieve good separation,

That reminds me: one other method I've seen recommended is to create a "dummy" frame - with all controls placed but only the bare minimum of methods defined - in its own class and perhaps in a separate file; then, in the "real" module, create a frame as an instance of the dummy class and flesh-out the methods. For the life of me I can't understand how this approach makes things better, unless you're really going to reuse the same layout in more than one project.

I think so too.
But I don't understand what's so easy about the XRC method, ...
... this is my way

    GUI = """
    self.Splitter_Plots ,SplitterVer
      self.Panel ,PanelVer, 010
        self.Panel_Top ,PanelHor, 11
          label1 ,wx.StaticText ,label = "Signal1"
          label2 ,wx.StaticText ,label = "Signal2"
        self.Panel_X ,wx.Panel, 11
        self.Panel_Bottom ,PanelHor
          label11 ,wx.StaticText ,label = "Signal1b"
          label12 ,wx.StaticText ,label = "Signal2b"
      Panel_B ,wx.Panel
        Button_1 ,wx.Button ,label = "Test"
        Button_2 ,wx.Button ,label = "Test2", pos = (100,0)
    """
    exec ( Create_wxGUI ( GUI ) )

(I mean, obviously the standard dialogs are a huge timesaver, but for more specialized tasks?)

Again I find them too limited, so I use this
    Names = [ 'For All Signals', 'AutoScale', 'Upper Value', 'Lower Value' ]
    Values = [ False, True, 200, 20 ]
    Types = [ bool, bool ]
    OK, Values = MultiLineDialog ( Names, Values, Types,
                                   'Set Border Values',
                                   width = 70 )

It's too bad that there are so many different (all half grown) methods of realizing the visual design :frowning:
but I guess that's the benefit of open source :wink:

cheers,
Stef

···

On Mon, Apr 7, 2008 at 12:24 AM, Marc Tompkins > <marc.tompkins@gmail.com <mailto:marc.tompkins@gmail.com>> wrote:

I use XRC as a part of skinning my application. It is suboptimal, but it works.

I have found that I need another file to add some info I can not put in the XRC.

What I would really like to see is a means to describe the behavior on buttons etc. in XRC. So I can enter it while doing the UI.

Paul

Stef Mientki wrote:

···

Marc Tompkins wrote:

On Mon, Apr 7, 2008 at 12:24 AM, Marc Tompkins >> <marc.tompkins@gmail.com <mailto:marc.tompkins@gmail.com>> wrote:

    Well, I know there are other ways to achieve good separation,

That reminds me: one other method I've seen recommended is to create a "dummy" frame - with all controls placed but only the bare minimum of methods defined - in its own class and perhaps in a separate file; then, in the "real" module, create a frame as an instance of the dummy class and flesh-out the methods. For the life of me I can't understand how this approach makes things better, unless you're really going to reuse the same layout in more than one project.

I think so too.
But I don't understand what's so easy about the XRC method, ...
... this is my way

   GUI = """
   self.Splitter_Plots ,SplitterVer
     self.Panel ,PanelVer, 010
       self.Panel_Top ,PanelHor, 11
         label1 ,wx.StaticText ,label = "Signal1"
         label2 ,wx.StaticText ,label = "Signal2"
       self.Panel_X ,wx.Panel, 11
       self.Panel_Bottom ,PanelHor
         label11 ,wx.StaticText ,label = "Signal1b"
         label12 ,wx.StaticText ,label = "Signal2b"
     Panel_B ,wx.Panel
       Button_1 ,wx.Button ,label = "Test"
       Button_2 ,wx.Button ,label = "Test2", pos = (100,0)
   """
   exec ( Create_wxGUI ( GUI ) )

(I mean, obviously the standard dialogs are a huge timesaver, but for more specialized tasks?)

Again I find them too limited, so I use this
   Names = [ 'For All Signals', 'AutoScale', 'Upper Value', 'Lower Value' ]
   Values = [ False, True, 200, 20 ]
   Types = [ bool, bool ]
   OK, Values = MultiLineDialog ( Names, Values, Types,
                                  'Set Border Values',
                                  width = 70 )

It's too bad that there are so many different (all half grown) methods of realizing the visual design :frowning:
but I guess that's the benefit of open source :wink:

cheers,
Stef

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

--
Paul Sijben tel: +31334566488
Eemvalley Technology fax: +31334557523
the Netherlands http://eemvalley.com

Thank you very much! I hate needing to have things spelled out for me, but I seem to have purchased an inferior grade of stimulant this week…must have words with Juan Valdez… :wink:

···

On Mon, Apr 7, 2008 at 6:44 PM, Robin Dunn robin@alldunn.com wrote:


(extremely useful example code)


www.fsrtechnologies.com