Python

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • XML subclassing and wx.lib.masked.TimeCtrl

    7 answers - 1274 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi folks,
    Let's suppose I have XML subclassed widgets of wx.Panel:
    class WorkoutTime(wx.Panel):
    """Masked control for workout start/finish time"""
    def __init__(self):
    p = wx.PrePanel()
    # the Create step is done by XRC.
    self.PostCreate(p)
    self.Bind(wx.EVT_WINDW_CREATE, Create)
    def Create(self, event):
    """Create masked control for time control"""
    self.timeCtrl = wx.lib.masked.TimeCtrl(self, fmt24hr=True,
    display_seconds=False)
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(self.timeCtrl)
    self.SetSizerAndFit(sizer)
    self.GetParent().Layout()
    That I got it from XRC resource file:
    # get masked controls start/finish time
    self.startTime = xrc.XRCCTRL(self.parent, 'startTime')
    self.finishTime = xrc.XRCCTRL(self.parent, 'finishTime')
    Questions is: which event I should catch when the text in a control
    updated and how I can get access to self.timeCtrl? How to set event
    handler for self.timeCtrl that is inside the other class?
    Thanks for any help!
    To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
    For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
  • No.1 | | 626 bytes | |

    Basil Shubin wrote:

    # get masked controls start/finish time
    self.startTime = xrc.XRCCTRL(self.parent, 'startTime')
    self.finishTime = xrc.XRCCTRL(self.parent, 'finishTime')

    Questions is: which event I should catch when the text in a control
    updated

    AS shown in the demo, use EVT_TIMEUPDATE

    and how I can get access to self.timeCtrl?

    Just like you showed above with XRCCTRL

    How to set event
    handler for self.timeCtrl that is inside the other class?

    The same as you would for any control. Get a reference to the control
    and call its Bind method.
  • No.2 | | 1324 bytes | |

    Robin Dunn wrote:
    Basil Shubin wrote:

    >>

    ># get masked controls start/finish time
    >self.startTime = xrc.XRCCTRL(self.parent, 'startTime')
    >self.finishTime = xrc.XRCCTRL(self.parent, 'finishTime')
    >>

    >Questions is: which event I should catch when the text in a control
    >updated


    AS shown in the demo, use EVT_TIMEUPDATE


    >and how I can get access to self.timeCtrl?


    Just like you showed above with XRCCTRL

    >How to set event handler for self.timeCtrl that is inside the other
    >class?


    The same as you would for any control. Get a reference to the control
    and call its Bind method.

    For the above example I make following changes:

    self.parent.Bind(wx.lib.masked.EVT_TIMEUPDATE,
    TimeUpdate,
    self.startTime.timeCtrl)

    and I recive an error:

    AttributeError: 'WorkoutTime' object has no attribute 'timeCtrl'

    What is my fault?

    To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
    For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
  • No.3 | | 799 bytes | |

    Basil Shubin wrote:
    Robin Dunn wrote:
    >Basil Shubin wrote:
    >>


    # get masked controls start/finish time
    self.startTime = xrc.XRCCTRL(self.parent, 'startTime')
    self.finishTime = xrc.XRCCTRL(self.parent, 'finishTime')

    For the above example I make following changes:

    self.parent.Bind(wx.lib.masked.EVT_TIMEUPDATE,
    TimeUpdate,
    self.startTime.timeCtrl)

    and I recive an error:

    AttributeError: 'WorkoutTime' object has no attribute 'timeCtrl'

    What is my fault?

    You probably want to use just self.startTime, don't you? Are you
    expecting self.startTime to have a timeCtrl attribute? Do you give it
    one in your code anyplace?
  • No.4 | | 1634 bytes | |

    Robin Dunn wrote:
    Basil Shubin wrote:
    >Robin Dunn wrote:

    Basil Shubin wrote:

    # get masked controls start/finish time
    self.startTime = xrc.XRCCTRL(self.parent, 'startTime')
    self.finishTime = xrc.XRCCTRL(self.parent, 'finishTime')


    >For the above example I make following changes:
    >>

    >self.parent.Bind(wx.lib.masked.EVT_TIMEUPDATE,
    >TimeUpdate,
    >self.startTime.timeCtrl)
    >>

    >and I recive an error:
    >>

    >AttributeError: 'WorkoutTime' object has no attribute 'timeCtrl'
    >>

    >What is my fault?
    >>


    You probably want to use just self.startTime, don't you? Are you
    expecting self.startTime to have a timeCtrl attribute? Do you give it
    one in your code anyplace?

    I am puzzled totally! Yes, I want to use just self.startTime. timeCtrl
    is created in the Create method of WorkoutTime subclass, is it
    timeCtrl its attribute or what? self.startTime itself is not wxTimeCtrl,
    right? so it cannot recive EVT_TIMEUPDATE event, right? Uhh, I am
    totally puzzled! :-(
    Sorry for my english understanding and writting too :-)

    Thanks you Robin for you help and great patient!

    To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
    For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
  • No.5 | | 1869 bytes | |

    Basil Shubin wrote:
    Robin Dunn wrote:
    >Basil Shubin wrote:

    Robin Dunn wrote:
    Basil Shubin wrote:

    # get masked controls start/finish time
    self.startTime = xrc.XRCCTRL(self.parent, 'startTime')
    self.finishTime = xrc.XRCCTRL(self.parent, 'finishTime')

    >>

    For the above example I make following changes:

    self.parent.Bind(wx.lib.masked.EVT_TIMEUPDATE,
    TimeUpdate,
    self.startTime.timeCtrl)

    and I recive an error:

    AttributeError: 'WorkoutTime' object has no attribute 'timeCtrl'

    What is my fault?

    >>

    >You probably want to use just self.startTime, don't you? Are you
    >expecting self.startTime to have a timeCtrl attribute? Do you give it
    >one in your code anyplace?


    I am puzzled totally! Yes, I want to use just self.startTime. timeCtrl
    is created in the Create method of WorkoutTime subclass, is it
    timeCtrl its attribute or what? self.startTime itself is not wxTimeCtrl,
    right? so it cannot recive EVT_TIMEUPDATE event, right? Uhh, I am
    totally puzzled! :-(

    I think I am confused now too.

    What type is self.startTime? I assume that is the object you are
    creating with your XRC subclass?

    If it is not a TimeCtrl, but contains one, then yes, you'll need to do
    something like self.startTime.timeCtrl to get to it, but if
    self.startTime.timeCtrl is not created until the Create then it may
    not exist yet. approach you can take is to move the event handler
    to the WorkoutTime class and do the binding in Create. Then the
    handler can call a method in the parent if needed, or perhaps just send
    a message, or whatever.
  • No.6 | | 2350 bytes | |

    Robin Dunn wrote:
    Basil Shubin wrote:
    >Robin Dunn wrote:

    Basil Shubin wrote:
    Robin Dunn wrote:
    Basil Shubin wrote:

    # get masked controls start/finish time
    self.startTime = xrc.XRCCTRL(self.parent, 'startTime')
    self.finishTime = xrc.XRCCTRL(self.parent, 'finishTime')

    For the above example I make following changes:

    self.parent.Bind(wx.lib.masked.EVT_TIMEUPDATE,
    TimeUpdate,
    self.startTime.timeCtrl)

    and I recive an error:

    AttributeError: 'WorkoutTime' object has no attribute 'timeCtrl'

    What is my fault?

    You probably want to use just self.startTime, don't you? Are you
    expecting self.startTime to have a timeCtrl attribute? Do you give
    it one in your code anyplace?
    >>

    >I am puzzled totally! Yes, I want to use just self.startTime. timeCtrl
    >is created in the Create method of WorkoutTime subclass, is it
    >timeCtrl its attribute or what? self.startTime itself is not
    >wxTimeCtrl, right? so it cannot recive EVT_TIMEUPDATE event, right?
    >Uhh, I am totally puzzled! :-(


    I think I am confused now too.

    What type is self.startTime? I assume that is the object you are
    creating with your XRC subclass?

    If it is not a TimeCtrl, but contains one, then yes, you'll need to do
    something like self.startTime.timeCtrl to get to it, but if
    self.startTime.timeCtrl is not created until the Create then it may
    not exist yet. approach you can take is to move the event handler
    to the WorkoutTime class and do the binding in Create. Then the
    handler can call a method in the parent if needed, or perhaps just send
    a message, or whatever.

    Doh! I am still confused!

    Can somebody give me explanation how I can get value from self.time.Ctrl
    that from WorkoutTime in other class - WorkoutsTab. Please, give me
    explanation on a example code I provide. Is it what I do is right? Maybe
    I should done this task in other way?

    Thanks for any help!

    To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
    For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
  • No.7 | | 3552 bytes | |

    Basil Shubin wrote:
    Robin Dunn wrote:
    >Basil Shubin wrote:

    Robin Dunn wrote:
    Basil Shubin wrote:
    Robin Dunn wrote:
    Basil Shubin wrote:

    # get masked controls start/finish time
    self.startTime = xrc.XRCCTRL(self.parent, 'startTime')
    self.finishTime = xrc.XRCCTRL(self.parent, 'finishTime')

    For the above example I make following changes:

    self.parent.Bind(wx.lib.masked.EVT_TIMEUPDATE,
    TimeUpdate,
    self.startTime.timeCtrl)

    and I recive an error:

    AttributeError: 'WorkoutTime' object has no attribute 'timeCtrl'

    What is my fault?

    You probably want to use just self.startTime, don't you? Are you
    expecting self.startTime to have a timeCtrl attribute? Do you give
    it one in your code anyplace?

    I am puzzled totally! Yes, I want to use just self.startTime.
    timeCtrl is created in the Create method of WorkoutTime subclass,
    is it timeCtrl its attribute or what? self.startTime itself is not
    wxTimeCtrl, right? so it cannot recive EVT_TIMEUPDATE event, right?
    Uhh, I am totally puzzled! :-(
    >>

    >I think I am confused now too.
    >>

    >What type is self.startTime? I assume that is the object you are
    >creating with your XRC subclass?
    >>

    >If it is not a TimeCtrl, but contains one, then yes, you'll need to do
    >something like self.startTime.timeCtrl to get to it, but if
    >self.startTime.timeCtrl is not created until the Create then it may
    >not exist yet. approach you can take is to move the event handler
    >to the WorkoutTime class and do the binding in Create. Then the
    >handler can call a method in the parent if needed, or perhaps just
    >send a message, or whatever.


    Doh! I am still confused!

    Can somebody give me explanation how I can get value from self.time.Ctrl
    that from WorkoutTime in other class - WorkoutsTab. Please, give me
    explanation on a example code I provide. Is it what I do is right? Maybe
    I should done this task in other way?

    class WorkoutTime(wx.Panel):
    """Masked control for workout start/finish time"""

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

    def Create(self, event):
    """Create masked control for time control"""
    self.timeCtrl = wx.lib.masked.TimeCtrl(self, fmt24hr=True,
    display_seconds=False)
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(self.timeCtrl)
    self.SetSizerAndFit(sizer)
    self.GetParent().Layout()

    self.Bind(wx.lib.masked.EVT_TIMEUPDATE,
    TimeUpdate,
    self.timeCtrl)

    def TimeUpdate(self, event):
    return self.timeCtrl.GetValue()

    The return value (if any) of an event handler is ignored. In most cases
    there is no place to put the value since the calling of the handler is
    not coming from your code. What you probably want is something like this:

    def GetValue(self):
    return self.timeCtrl.GetValue()

    If you are running into problems with the timeCtrl not being created yet
    (because the widget has not yet been realized on the display) then you
    can protect yourself something like this:

    def GetValue(self):
    if hasattr(self, 'timeCtrl'):
    return self.timeCtrl.GetValue()
    else:
    return ""

Re: XML subclassing and wx.lib.masked.TimeCtrl


max 4000 letters.
Your nickname that display:
In order to stop the spam: 5 + 4 =
QUESTION ON "Python"

EMSDN.COM