maskedCtrl problem

Hi friends!

I have create panel from XRC and embed into it XRC subclassed widgets (masked control).

class LocalDeliveryDialog:

     def __init__(self, parent):
         self.resource = xrc.XmlResource('xrc/localdeliverydlg.xrc')

         self.dlg = self.resource.LoadDialog(parent, 'LocalDeliveryDlg')
  self.maskedBill = xrc.XRCCTRL(self.dlg, 'maskedBill')

     def ShowModal(self):
         return self.dlg.ShowModal()

     def GetBill(self):
         return self.maskedBill.maskedCtrl.GetValue()

     def SetBill(self, value):
         self.maskedBill.maskedCtrl.SetValue(value)
  
class MaskedBill(wx.Panel):

     def __init__(self):
         p = wx.PrePanel()
         # the Create step is done by XRC.
         self.PostCreate(p)
         self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

     def OnCreate(self, event):
         self.maskedCtrl = masked.TextCtrl(self, wx.ID_ANY, mask='#{15}',
                                           formatcodes='Fr<',
                                           size=(200,-1),
                                           style=wx.ALIGN_RIGHT)
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(self.maskedCtrl)
         self.SetSizerAndFit(sizer)
         self.GetParent().Layout()
         self.GetParent().Fit()

In other place of my app I'd trying following code:

dlg = LocalDeliveryDialog(self.panel)
dlg.SetBill(bill)
retVal = dlg.ShowModal()
...

and catch an error:
Traceback (most recent call last):
   File "/home/bashu/work/devel/wxExpress/gui/localdelivery.py", line 155, in OnCopy
     dlg.SetBill(bill)
   File "/home/bashu/work/devel/wxExpress/gui/localdeliverydlg.py", line 83, in SetBill
     self.maskedBill.maskedCtrl.SetValue(value)
AttributeError: 'MaskedBill' object has no attribute 'maskedCtrl'

I'm confused, what I shell do next? How to resolve this problem?

Thanks!

···

--
Basil Shubin
Freelance Software Developer

Basil Shubin wrote:

Hi friends!

I have create panel from XRC and embed into it XRC subclassed widgets (masked control).

class LocalDeliveryDialog:

    def __init__(self, parent):
        self.resource = xrc.XmlResource('xrc/localdeliverydlg.xrc')

        self.dlg = self.resource.LoadDialog(parent, 'LocalDeliveryDlg')
    self.maskedBill = xrc.XRCCTRL(self.dlg, 'maskedBill')

Is this really the indentation you have here?

    def ShowModal(self):
        return self.dlg.ShowModal()

    def GetBill(self):
        return self.maskedBill.maskedCtrl.GetValue()

    def SetBill(self, value):
        self.maskedBill.maskedCtrl.SetValue(value)
    class MaskedBill(wx.Panel):

    def __init__(self):
        p = wx.PrePanel()
        # the Create step is done by XRC.
        self.PostCreate(p)
        self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

    def OnCreate(self, event):
        self.maskedCtrl = masked.TextCtrl(self, wx.ID_ANY, mask='#{15}',
                                          formatcodes='Fr<',
                                          size=(200,-1),
                                          style=wx.ALIGN_RIGHT)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.maskedCtrl)
        self.SetSizerAndFit(sizer)
        self.GetParent().Layout()
        self.GetParent().Fit()

In other place of my app I'd trying following code:

dlg = LocalDeliveryDialog(self.panel)
dlg.SetBill(bill)
retVal = dlg.ShowModal()
...

and catch an error:
Traceback (most recent call last):
  File "/home/bashu/work/devel/wxExpress/gui/localdelivery.py", line 155, in OnCopy
    dlg.SetBill(bill)
  File "/home/bashu/work/devel/wxExpress/gui/localdeliverydlg.py", line 83, in SetBill
    self.maskedBill.maskedCtrl.SetValue(value)
AttributeError: 'MaskedBill' object has no attribute 'maskedCtrl'

At this point in time has the OnCreate method been called yet?

···

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

Robin Dunn пишет:

Basil Shubin wrote:

Hi friends!

I have create panel from XRC and embed into it XRC subclassed widgets (masked control).

class LocalDeliveryDialog:

    def __init__(self, parent):
        self.resource = xrc.XmlResource('xrc/localdeliverydlg.xrc')

        self.dlg = self.resource.LoadDialog(parent, 'LocalDeliveryDlg')
    self.maskedBill = xrc.XRCCTRL(self.dlg, 'maskedBill')

Is this really the indentation you have here?

No, in real application everything is correct.

    def ShowModal(self):
        return self.dlg.ShowModal()

    def GetBill(self):
        return self.maskedBill.maskedCtrl.GetValue()

    def SetBill(self, value):
        self.maskedBill.maskedCtrl.SetValue(value)
    class MaskedBill(wx.Panel):

    def __init__(self):
        p = wx.PrePanel()
        # the Create step is done by XRC.
        self.PostCreate(p)
        self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

    def OnCreate(self, event):
        self.maskedCtrl = masked.TextCtrl(self, wx.ID_ANY, mask='#{15}',
                                          formatcodes='Fr<',
                                          size=(200,-1),
                                          style=wx.ALIGN_RIGHT)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.maskedCtrl)
        self.SetSizerAndFit(sizer)
        self.GetParent().Layout()
        self.GetParent().Fit()

In other place of my app I'd trying following code:

dlg = LocalDeliveryDialog(self.panel)
dlg.SetBill(bill)
retVal = dlg.ShowModal()
...

and catch an error:
Traceback (most recent call last):
  File "/home/bashu/work/devel/wxExpress/gui/localdelivery.py", line 155, in OnCopy
    dlg.SetBill(bill)
  File "/home/bashu/work/devel/wxExpress/gui/localdeliverydlg.py", line 83, in SetBill
    self.maskedBill.maskedCtrl.SetValue(value)
AttributeError: 'MaskedBill' object has no attribute 'maskedCtrl'

At this point in time has the OnCreate method been called yet?

No, it was not called :frowning: Looks like it call OnCreate after executing ShowModal method. Let me explain, I have dialog box for acquiring data from user (GetBill is for this), after I enter data there should be way to edit it via the same dialog (SetBill is for this).

For dialogs without masked contols it's working, but I need to use masked TextCtrl for several dialog box (and it should be used with dialog drawed in XRCed, i.e. subclassed controls)

···

--
Basil Shubin
Freelance Software Developer

Robin Dunn пишет:

Basil Shubin wrote:

Hi friends!

I have create panel from XRC and embed into it XRC subclassed widgets (masked control).

class LocalDeliveryDialog:

    def __init__(self, parent):
        self.resource = xrc.XmlResource('xrc/localdeliverydlg.xrc')

        self.dlg = self.resource.LoadDialog(parent, 'LocalDeliveryDlg')
    self.maskedBill = xrc.XRCCTRL(self.dlg, 'maskedBill')

Is this really the indentation you have here?

    def ShowModal(self):
        return self.dlg.ShowModal()

    def GetBill(self):
        return self.maskedBill.maskedCtrl.GetValue()

    def SetBill(self, value):
        self.maskedBill.maskedCtrl.SetValue(value)
    class MaskedBill(wx.Panel):

    def __init__(self):
        p = wx.PrePanel()
        # the Create step is done by XRC.
        self.PostCreate(p)
        self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

    def OnCreate(self, event):
        self.maskedCtrl = masked.TextCtrl(self, wx.ID_ANY, mask='#{15}',
                                          formatcodes='Fr<',
                                          size=(200,-1),
                                          style=wx.ALIGN_RIGHT)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.maskedCtrl)
        self.SetSizerAndFit(sizer)
        self.GetParent().Layout()
        self.GetParent().Fit()

In other place of my app I'd trying following code:

dlg = LocalDeliveryDialog(self.panel)
dlg.SetBill(bill)
retVal = dlg.ShowModal()
...

and catch an error:
Traceback (most recent call last):
  File "/home/bashu/work/devel/wxExpress/gui/localdelivery.py", line 155, in OnCopy
    dlg.SetBill(bill)
  File "/home/bashu/work/devel/wxExpress/gui/localdeliverydlg.py", line 83, in SetBill
    self.maskedBill.maskedCtrl.SetValue(value)
AttributeError: 'MaskedBill' object has no attribute 'maskedCtrl'

At this point in time has the OnCreate method been called yet?

Please, explain me how XRC subclassed widgets should works? Maybe there exist some other way for creating XRC subclassed widgets?

Thanks

···

--
Basil Shubin
Freelance Software Developer

Basil Shubin wrote:

Robin Dunn пишет:

At this point in time has the OnCreate method been called yet?

No, it was not called :frowning: Looks like it call OnCreate after executing ShowModal method.

On wxGTK the UI objects are not created immediately. In order to reduce the traffic to/from the X-Server commands are buffered until control returns to the main loop and then all pending commands are sent all at once and all the responses are received and dispatched as events if needed.

Let me explain, I have dialog box for acquiring data from user (GetBill is for this), after I enter data there should be way to edit it via the same dialog (SetBill is for this).

For dialogs without masked contols it's working, but I need to use masked TextCtrl for several dialog box (and it should be used with dialog drawed in XRCed, i.e. subclassed controls)

You can make it work by also deferring your SetValue if needed. For example, in the dialog class:

  def SetBill(self, value):
           self.maskedBill.SetValue(value)

And in the MaskedBill class:

  def SetValue(self, value):
    if hasattr(self, 'maskedCtrl'):
      self.maskedCtrl.SetValue(value)
    else:
      self._deferredValue = value

  def OnCreate(self, event):
           self.maskedCtrl = masked.TextCtrl(...)
    if hasattr(self, _deferredValue
      self.maskedCtrl.SetValue(self._deferredValue)
      del self._deferredValue
    ...

···

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

Robin Dunn пишет:

You can make it work by also deferring your SetValue if needed. For example, in the dialog class:

    def SetBill(self, value):
            self.maskedBill.SetValue(value)

And in the MaskedBill class:

    def SetValue(self, value):
        if hasattr(self, 'maskedCtrl'):
            self.maskedCtrl.SetValue(value)
        else:
            self._deferredValue = value

    def OnCreate(self, event):
            self.maskedCtrl = masked.TextCtrl(...)
        if hasattr(self, _deferredValue
            self.maskedCtrl.SetValue(self._deferredValue)
            del self._deferredValue
        ...

Thanks!!! It's working!!!

···

--
Basil Shubin
Freelance Software Developer

Robin Dunn пишет:

You can make it work by also deferring your SetValue if needed. For example, in the dialog class:

    def SetBill(self, value):
            self.maskedBill.SetValue(value)

And in the MaskedBill class:

    def SetValue(self, value):
        if hasattr(self, 'maskedCtrl'):
            self.maskedCtrl.SetValue(value)
        else:
            self._deferredValue = value

    def OnCreate(self, event):
            self.maskedCtrl = masked.TextCtrl(...)
        if hasattr(self, _deferredValue
            self.maskedCtrl.SetValue(self._deferredValue)
            del self._deferredValue
        ...

and how I can setup event handler for this control somewhere outside this class? As I understand binding the event to maskedCtrl outside this class will raise AttributeError, because maskedCtrl doesn't exist when I trying set up event handler? In main XRC dialog class I have several XRC subclassed controls for which I want setup event handlers, so how I can resolve this problem?

If I should setup event handler in the MaskedBill class, how I can than got controls from it's 'parent' which is not the same class that hold other controls, it's just loaded wxDialog drawed in XRC?

Thanks in advance!

···

--
Basil Shubin
Freelance Software Developer

Basil Shubin wrote:

Robin Dunn пишет:

You can make it work by also deferring your SetValue if needed. For example, in the dialog class:

    def SetBill(self, value):
            self.maskedBill.SetValue(value)

And in the MaskedBill class:

    def SetValue(self, value):
        if hasattr(self, 'maskedCtrl'):
            self.maskedCtrl.SetValue(value)
        else:
            self._deferredValue = value

    def OnCreate(self, event):
            self.maskedCtrl = masked.TextCtrl(...)
        if hasattr(self, _deferredValue
            self.maskedCtrl.SetValue(self._deferredValue)
            del self._deferredValue
        ...

and how I can setup event handler for this control somewhere outside this class? As I understand binding the event to maskedCtrl outside this class will raise AttributeError, because maskedCtrl doesn't exist when I trying set up event handler?

The maskedCtrl belongs to MaskedBill, so I would do the binding there in the OnCreate method. If you need to have the handlers call methods in the parent window, or to send a message in some other way, that can easily be done.

If I should setup event handler in the MaskedBill class, how I can than got controls from it's 'parent' which is not the same class that hold other controls, it's just loaded wxDialog drawed in XRC?

Not exactly sure what you mean by this, but GetParent() should help.

···

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

Hi friends!

And how I can access other contols from XRC subclassed conrol?

class LocalDeliveryDialog:

     def __init__(self, parent):
         self.resource = xrc.XmlResource('xrc/localdeliverydlg.xrc')

         self.dlg = self.resource.LoadDialog(parent, 'LocalDeliveryDlg')

         self.maskedBill1 = xrc.XRCCTRL(self.dlg, 'maskedBill1')
         self.maskedBill2 = xrc.XRCCTRL(self.dlg, 'maskedBill2')

class MaskedBill1(wx.Panel):

     def __init__(self):
         p = wx.PrePanel()
         # the Create step is done by XRC.
         self.PostCreate(p)
         self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

     def SetValue(self, value):
         if hasattr(self, 'maskedCtrl'):
             self.maskedCtrl.SetValue(value)
         else:
             self._deferredValue = value

     def OnCreate(self, event):
         self.maskedCtrl = masked.TextCtrl(self, wx.ID_ANY, mask='#{15}',
                                           formatcodes='Fr<', size=(200,-1),
                                           style=wx.ALIGN_RIGHT)
         if hasattr(self, '_deferredValue'):
             self.maskedCtrl.SetValue(self._deferredValue)
             del self._deferredValue
         self.Bind(wx.EVT_TEXT, self.OnText, self.maskedCtrl)
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(self.maskedCtrl)
         self.SetSizerAndFit(sizer)
         self.GetParent().Layout()
         self.GetParent().Fit()

     def OnText(self, event):
         self.GetParent().maskedBill2.SetValue('112233')

I just got this error:

Traceback (most recent call last):
   File "/home/bashu/work/devel/wxExpress/gui/localdeliverydlg.py", line 336, in OnText
     self.GetParent().maskedBill1.SetValue('1')
AttributeError: 'Dialog' object has no attribute 'maskedBill1'

···

--
Basil Shubin
Freelance Software Developer

Hi friends!

And how I can access other contols from XRC subclassed conrol?

class LocalDeliveryDialog:

     def __init__(self, parent):
         self.resource = xrc.XmlResource('xrc/localdeliverydlg.xrc')

         self.dlg = self.resource.LoadDialog(parent, 'LocalDeliveryDlg')

         self.maskedBill1 = xrc.XRCCTRL(self.dlg, 'maskedBill1')
         self.maskedBill2 = xrc.XRCCTRL(self.dlg, 'maskedBill2')

class MaskedBill1(wx.Panel):

     def __init__(self):
         p = wx.PrePanel()
         # the Create step is done by XRC.
         self.PostCreate(p)
         self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

     def SetValue(self, value):
         if hasattr(self, 'maskedCtrl'):
             self.maskedCtrl.SetValue(value)
         else:
             self._deferredValue = value

     def OnCreate(self, event):
         self.maskedCtrl = masked.TextCtrl(self, wx.ID_ANY, mask='#{15}',
                                           formatcodes='Fr<', size=(200,-1),
                                           style=wx.ALIGN_RIGHT)
         if hasattr(self, '_deferredValue'):
             self.maskedCtrl.SetValue(self._deferredValue)
             del self._deferredValue
         self.Bind(wx.EVT_TEXT, self.OnText, self.maskedCtrl)
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(self.maskedCtrl)
         self.SetSizerAndFit(sizer)
         self.GetParent().Layout()
         self.GetParent().Fit()

     def OnText(self, event):
         self.GetParent().maskedBill2.SetValue('112233')

I just got this error:

Traceback (most recent call last):
   File "/home/bashu/work/devel/wxExpress/gui/localdeliverydlg.py", line 336, in OnText
     self.GetParent().maskedBill2.SetValue('1')
AttributeError: 'Dialog' object has no attribute 'maskedBill2'

···

--
Basil Shubin
Freelance Software Developer

Hi friends!

And how I can access other contols from XRC subclassed conrol?

class LocalDeliveryDialog:

     def __init__(self, parent):
         self.resource = xrc.XmlResource('xrc/localdeliverydlg.xrc')

         self.dlg = self.resource.LoadDialog(parent, 'LocalDeliveryDlg')

         self.maskedBill1 = xrc.XRCCTRL(self.dlg, 'maskedBill1')
         self.maskedBill2 = xrc.XRCCTRL(self.dlg, 'maskedBill2')

class MaskedBill1(wx.Panel):

     def __init__(self):
         p = wx.PrePanel()
         # the Create step is done by XRC.
         self.PostCreate(p)
         self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

     def SetValue(self, value):
         if hasattr(self, 'maskedCtrl'):
             self.maskedCtrl.SetValue(value)
         else:
             self._deferredValue = value

     def OnCreate(self, event):
         self.maskedCtrl = masked.TextCtrl(self, wx.ID_ANY, mask='#{15}',
                                           formatcodes='Fr<', size=(200,-1),
                                           style=wx.ALIGN_RIGHT)
         if hasattr(self, '_deferredValue'):
             self.maskedCtrl.SetValue(self._deferredValue)
             del self._deferredValue
         self.Bind(wx.EVT_TEXT, self.OnText, self.maskedCtrl)
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(self.maskedCtrl)
         self.SetSizerAndFit(sizer)
         self.GetParent().Layout()
         self.GetParent().Fit()

     def OnText(self, event):
         self.GetParent().maskedBill2.SetValue('112233')

I just got this error:

Traceback (most recent call last):
   File "/home/bashu/work/devel/wxExpress/gui/localdeliverydlg.py", line 336, in OnText
     self.GetParent().maskedBill2.SetValue('112233')
AttributeError: 'Dialog' object has no attribute 'maskedBill2'

···

--
Basil Shubin
Freelance Software Developer

Basil Shubin wrote:

Hi friends!

And how I can access other contols from XRC subclassed conrol?

class LocalDeliveryDialog:

    def __init__(self, parent):
        self.resource = xrc.XmlResource('xrc/localdeliverydlg.xrc')

        self.dlg = self.resource.LoadDialog(parent, 'LocalDeliveryDlg')

        self.maskedBill1 = xrc.XRCCTRL(self.dlg, 'maskedBill1')
        self.maskedBill2 = xrc.XRCCTRL(self.dlg, 'maskedBill2')

class MaskedBill1(wx.Panel):

    def __init__(self):
        p = wx.PrePanel()
        # the Create step is done by XRC.
        self.PostCreate(p)
        self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

    def SetValue(self, value):
        if hasattr(self, 'maskedCtrl'):
            self.maskedCtrl.SetValue(value)
        else:
            self._deferredValue = value

    def OnCreate(self, event):
        self.maskedCtrl = masked.TextCtrl(self, wx.ID_ANY, mask='#{15}',
                                          formatcodes='Fr<', size=(200,-1),
                                          style=wx.ALIGN_RIGHT)
        if hasattr(self, '_deferredValue'):
            self.maskedCtrl.SetValue(self._deferredValue)
            del self._deferredValue
        self.Bind(wx.EVT_TEXT, self.OnText, self.maskedCtrl)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.maskedCtrl)
        self.SetSizerAndFit(sizer)
        self.GetParent().Layout()
        self.GetParent().Fit()

    def OnText(self, event):
        self.GetParent().maskedBill2.SetValue('112233')

I just got this error:

Traceback (most recent call last):
  File "/home/bashu/work/devel/wxExpress/gui/localdeliverydlg.py", line 336, in OnText
    self.GetParent().maskedBill2.SetValue('112233')
AttributeError: 'Dialog' object has no attribute 'maskedBill2'

GetParent returns the parent window, but you are not assigning the maskedBill1 and maskedBill2 attributes to that object. You are assigning them to the LocalDeliveryDialog, which is not the parent of the panels. It just has a reference to the parent (self.dlg.)

···

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