Python

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Referencing a specific text ctrl

    11 answers - 617 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

    Hello all.
    I want to have a few text_ctrls on a screen (last name, first name,
    address, city, state, zip) all Bind <KILL_FCUSto a single routine which
    saves modifications.
    But, where I ususally will do a (), is
    there any way for me to do this with a widget's ID number as opposed to the
    specific object name? I don't see anything in GetValue() to accept an ID
    number.
    Thanks!
    Dave
    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 | | 861 bytes | |

    I usually make a hash with the IDs to map an ID to an object (maybe you
    should use the EVT_TEXT event instead of KILL_FCUS, too?)

    Lee

    "S. D. Rose" <s_david_rose (AT) hotmail (DOT) comwrote in message
    news:e0pegn$b7t$1 (AT) sea (DOT) gmane.org
    Hello all.
    I want to have a few text_ctrls on a screen (last name, first name,
    address, city, state, zip) all Bind <KILL_FCUSto a single routine which
    saves modifications.

    But, where I ususally will do a (), is
    there any way for me to do this with a widget's ID number as opposed to
    the specific object name? I don't see anything in GetValue() to accept an
    ID number.

    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.2 | | 470 bytes | |

    How do I reference a global function from within a class

    def g():
    pass

    class MyClass():
    def func():
    g()

    this construct seems to give me an error:

    UnboundLocalError: local variable 'g' referenced before assignment

    Thanks,
    Phill

    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 | | 804 bytes | |

    03/04/06, Phill Atwood <me (AT) phillatwood (DOT) namewrote:

    How do I reference a global function from within a class

    def g():
    pass

    class MyClass():
    def func():
    g()

    this construct seems to give me an error:

    UnboundLocalError: local variable 'g' referenced before assignment

    What you've written should work if g and MyClass are defined in
    the same file. If they are not, you will need to use 'import' to
    bring the name g into MyClass's namespace.

    For example:

    myglobals.py

    def g():
    return 'Hello world!'

    MyClass.py

    import myglobals

    class MyClass(object):
    def func(self):
    print myglobals.g() # call the function g in the module myglobals

    HTH!
  • No.4 | | 1069 bytes | |

    Phill,

    Class MyClass's definition does not take parenthses unless it inherits methods and properties from a parent.

    So the correct code is:

    def g():
    pass

    class MyClass:
    def func():
    g()

    Message
    From: Phill Atwood <me (AT) phillatwood (DOT) name>
    Date: Sunday, April 2, 2006 7:59 pm
    Subject: [wxPython-users] newbie object oriented question

    How do I reference a global function from within a class

    def g():
    pass

    class MyClass():
    def func():
    g()

    this construct seems to give me an error:

    UnboundLocalError: local variable 'g' referenced before assignment

    Thanks,
    Phill

    -
    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

    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 | | 2213 bytes | |

    Ira,

    This one is still a mystery to me. MyClass declaration works. What is
    below is a (too) abbreviated version from the code. It is when I added
    the g def at the top of the file that it didn't work. I'm still shakey
    on my python scope and oo too. I've resorted to a different hack. Even
    uglier that is working at the moment. But I would like to know why I
    get this error. There must be something else in the rest of my code to
    cause this (see prev. post w/ attachment)

    Phill

    irakaplan (AT) optonline (DOT) net wrote:
    Phill,

    Class MyClass's definition does not take parenthses unless it inherits methods and properties from a parent.

    So the correct code is:

    def g():
    pass

    class MyClass:
    def func():
    g()
    --
    Message
    From: Phill Atwood <me (AT) phillatwood (DOT) name>
    Date: Sunday, April 2, 2006 7:59 pm
    Subject: [wxPython-users] newbie object oriented question


    >How do I reference a global function from within a class
    >>

    >def g():
    >pass
    >>

    >class MyClass():
    >def func():
    >g()
    >>

    >this construct seems to give me an error:
    >>

    >UnboundLocalError: local variable 'g' referenced before assignment
    >>
    >>

    >Thanks,
    >Phill
    >>
    >>
    >>

    >
    >-
    >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
    >>

    >
    >


    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

    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.6 | | 1257 bytes | |

    Phill Atwood <me (AT) phillatwood (DOT) namewrote:

    Ira,

    This one is still a mystery to me. MyClass declaration works. What is
    below is a (too) abbreviated version from the code. It is when I added
    the g def at the top of the file that it didn't work. I'm still shakey
    on my python scope and oo too. I've resorted to a different hack. Even
    uglier that is working at the moment. But I would like to know why I
    get this error. There must be something else in the rest of my code to
    cause this (see prev. post w/ attachment)

    You get the same kind of thing if you do the following.

    def g():
    print "hello from g"

    class foo:
    def bar(self):
    a = g()
    g = 1

    foo().bar()
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "<stdin>", line 3, in bar
    UnboundLocalError: local variable 'g' referenced before assignment

    You are likely reusing the g name within the function bar. really
    the equivalent of both.

    - Josiah

    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 | | 3595 bytes | |

    Hi Phill,

    Noticed in your files that you mention that they are UTF-8 encoded,
    however you don't put the declaration into your files?

    You should have something like this at the top of each file, obviously
    replace the iso-8859-1 with correct code for utf-8.
    # coding: iso-8859-1

    "g" is your translation stuff, instead of reinventing the wheel you
    might want to look at the i18n support within Python and wxPython. They
    are nice tools which allow to translate things into as many languages as
    you want (including shipping the language catalogs to be translated to
    someone else with nice GUI tools (I use "poedit" for that).

    Check out the wiki pages for the i18n stuff and you might also check the
    archive of this list.

    I think your problem with "g" is this line:
    dlg = wx.MessageDialog(self, g[credit_txt][L], g["Credits"][L], \

    Wrong brackets, you are defining "g" as a list and "loose" your function g.

    Hope this helps
    Werner

    Phill Atwood wrote:

    Ira,

    This one is still a mystery to me. MyClass declaration works. What
    is below is a (too) abbreviated version from the code. It is when I
    added the g def at the top of the file that it didn't work. I'm still
    shakey on my python scope and oo too. I've resorted to a different
    hack. Even uglier that is working at the moment. But I would like to
    know why I get this error. There must be something else in the rest
    of my code to cause this (see prev. post w/ attachment)

    Phill

    irakaplan (AT) optonline (DOT) net wrote:
    >
    >Phill,
    >>

    >Class MyClass's definition does not take parenthses unless it
    >inherits methods and properties from a parent.
    >>

    >So the correct code is:
    >>

    >def g():
    >pass
    >>

    >class MyClass:
    >def func():
    >g()
    >>
    >>

    >Message
    >From: Phill Atwood <me (AT) phillatwood (DOT) name>
    >Date: Sunday, April 2, 2006 7:59 pm
    >Subject: [wxPython-users] newbie object oriented question
    >>

    >
    >>

    How do I reference a global function from within a class

    def g():
    pass

    class MyClass():
    def func():
    g()

    this construct seems to give me an error:

    UnboundLocalError: local variable 'g' referenced before assignment

    Thanks,
    Phill

    -
    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


    >>
    >>

    >
    >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
    >
    >
    >
    >
    >


    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
    >
    >
    >


    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.8 | | 2828 bytes | |

    Phill,

    Tell me which file attachment (there were a few) and which line numbers in the code are causing the error and I'll take a look.

    Ira

    Message
    From: Phill Atwood <me (AT) phillatwood (DOT) name>
    Date: Monday, April 3, 2006 11:07 am
    Subject: Re: [wxPython-users] newbie object oriented question

    Ira,

    This one is still a mystery to me. MyClass declaration works.
    What is
    below is a (too) abbreviated version from the code. It is when I
    added
    the g def at the top of the file that it didn't work. I'm still
    shakey
    on my python scope and oo too. I've resorted to a different hack.
    Even
    uglier that is working at the moment. But I would like to know why
    I
    get this error. There must be something else in the rest of my
    code to
    cause this (see prev. post w/ attachment)

    Phill

    irakaplan (AT) optonline (DOT) net wrote:
    Phill,

    Class MyClass's definition does not take parenthses unless it
    inherits methods and properties from a parent.

    So the correct code is:

    def g():
    pass

    class MyClass:
    def func():
    g()
    --
    Message
    From: Phill Atwood <me (AT) phillatwood (DOT) name>
    Date: Sunday, April 2, 2006 7:59 pm
    Subject: [wxPython-users] newbie object oriented question


    >How do I reference a global function from within a class
    >>

    >def g():
    >pass
    >>

    >class MyClass():
    >def func():
    >g()
    >>

    >this construct seems to give me an error:
    >>

    >UnboundLocalError: local variable 'g' referenced before assignment
    >>
    >>

    >Thanks,
    >Phill
    >>
    >>
    >>

    >


    >-
    >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
    >>

    >
    >


    To unsubscribe, e-mail: wxPython-users-
    unsubscribe (AT) lists (DOT) wxwidgets.orgFor additional commands, e-mail:
    wxPython-users-help (AT) lists (DOT) wxwidgets.org

    -
    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

    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.9 | | 949 bytes | |

    Sun, 2006-04-02 at 17:08 -0400, S. D. Rose wrote:
    Hello all.
    I want to have a few text_ctrls on a screen (last name, first name,
    address, city, state, zip) all Bind <KILL_FCUSto a single routine which
    saves modifications.

    But, where I ususally will do a (), is
    there any way for me to do this with a widget's ID number as opposed to the
    specific object name? I don't see anything in GetValue() to accept an ID
    number.

    Depend on what is your logic, you may not need the widget's ID.
    In you event handler you can obtain the object that generate the event
    using event.GetE().

    Something like this:

    def KillFocus(self, event):
    ctrl = event.GetE()
    value = ctrl.GetValue()

    Ricardo

    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.10 | | 2147 bytes | |

    Werner F. Bruhin wrote:

    Hi Phill,

    Noticed in your files that you mention that they are UTF-8 encoded,
    however you don't put the declaration into your files?

    You should have something like this at the top of each file, obviously
    replace the iso-8859-1 with correct code for utf-8.
    # coding: iso-8859-1

    You are probably right. However, I was having an encoding error. The
    error msg referenced the encoding PEP which I did my best to read and
    understand. From that I gleaned that putting the line that I used would
    work. And it did seem to. I no longer get the error message

    "g" is your translation stuff, instead of reinventing the wheel you
    might want to look at the i18n support within Python and wxPython.
    They are nice tools which allow to translate things into as many
    languages as you want (including shipping the language catalogs to be
    translated to someone else with nice GUI tools (I use "poedit" for that).

    Check out the wiki pages for the i18n stuff and you might also check
    the archive of this list.

    Yes, I initially did the i18n, l16n stuff the proper way with gettext.
    I had everything working nicely almost. I was trying to switch
    languages at runtime at the beginning. But I couldn't do it reliably.
    It seems it would change languages for me, but only on the next
    invocation of the program Because of time pressure I ended up
    abandoning and using my g() function, which I also had trouble with and
    abandoned and used even more of a hack to get working.

    I think your problem with "g" is this line:
    dlg = wx.MessageDialog(self, g[credit_txt][L], g["Credits"][L], \

    Wrong brackets, you are defining "g" as a list and "loose" your
    function g.

    Yes, without trying it. I think you are right. Thanks.

    Thanks very much Werner that was bugging me. I just needed to slow down
    and stop panicking!

    Phill

    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.11 | | 3927 bytes | |

    Ira,

    Don't worry about it. I think Werner found it. See earlier post.

    Thanks very much for the offer though,
    Phill

    irakaplan (AT) optonline (DOT) net wrote:

    >Phill,
    >
    >Tell me which file attachment (there were a few) and which line numbers in the code are causing the error and I'll take a look.
    >
    >Ira
    >

    Message
    >From: Phill Atwood <me (AT) phillatwood (DOT) name>
    >Date: Monday, April 3, 2006 11:07 am
    >Subject: Re: [wxPython-users] newbie object oriented question
    >


    >
    >>Ira,
    >>
    >>This one is still a mystery to me. MyClass declaration works.
    >>What is
    >>below is a (too) abbreviated version from the code. It is when I
    >>added
    >>the g def at the top of the file that it didn't work. I'm still
    >>shakey
    >>on my python scope and oo too. I've resorted to a different hack.
    >>Even
    >>uglier that is working at the moment. But I would like to know why
    >>I
    >>get this error. There must be something else in the rest of my
    >>code to
    >>cause this (see prev. post w/ attachment)
    >>
    >>Phill
    >>
    >>irakaplan (AT) optonline (DOT) net wrote:

    >
    >>

    Phill,

    Class MyClass's definition does not take parenthses unless it


    >>inherits methods and properties from a parent.

    >
    >>

    So the correct code is:

    def g():
    pass

    class MyClass:
    def func():
    g()

    Message
    From: Phill Atwood <me (AT) phillatwood (DOT) name>
    Date: Sunday, April 2, 2006 7:59 pm
    Subject: [wxPython-users] newbie object oriented question

    How do I reference a global function from within a class

    def g():
    pass

    class MyClass():
    def func():
    g()

    this construct seems to give me an error:

    UnboundLocalError: local variable 'g' referenced before assignment

    Thanks,
    Phill


    >>

    >
    >>


    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


    >>

    >
    >>

    To unsubscribe, e-mail: wxPython-users-

    >>unsubscribe (AT) lists (DOT) wxwidgets.orgFor additional commands, e-mail:
    >>wxPython-users-help (AT) lists (DOT) wxwidgets.org

    >
    >>



    >>
    >>


    >>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
    >>

    >
    >>

    >
    >
    >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


    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

Re: Referencing a specific text ctrl


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

EMSDN.COM