Using Timer to update TextCtrl

Hi,

I want to start a function periodically to update a TextCtrl.
Attached code is working fine, but when FuncStartCount() is started the update function is not called.

What am I doing wrong?

/Rob

counter.py (871 Bytes)

I have no idea what you're trying to do here, you should really send us
a sample which we can run to see the problem in action. But my best
guess would be that FuncStartCount calls time.sleep, which puts the main
thread to sleep, meaning that the timer stops updating.

···

--
James Scholes
http://twitter.com/JamesScholes

Yes, it is being called
Your problem is that you are not looking at the error messages being
produced as your app runs:
“rcount” is a local variable within FuncStartCount. Its value is
not available outside of that function. If you want it to be
visible, then you have to make it a member variable, like
“self.rcount”.
After that, there is another issue. Unless you start FuncStartCount
in a separate thread, it’s going to tie up your application. It
won’t ever get back to the message loop, so it will never be able to
process your timer message.
Finally, when you post a code sample, it’s always more helpful to
provide us code we can run. Your code refers to a module called
“gui” and one called “GPIO” that we don’t have.

···

Rob Westein wrote:

    I want to start a function periodically to update a TextCtrl.

    Attached code is working fine, but when FuncStartCount() is

started the update function is not called.

What am I doing wrong?

`

`

Traceback (most recent call last):

  `  File "counter.py", line 29, in update`

  `    print rcount`

  `NameError: global name 'rcount' is not defined`

  `Traceback (most recent call last):`

  `  File "counter.py", line 29, in update`

  `    print rcount`

  `NameError: global name 'rcount' is not defined`
-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com

I’m trying to go another way, but still some problems

What the function OnButton2Button in RW_GUI2 does is listen if there is an pulse from a machine and count the pulses…(using the GPIO module)
This is working OK, but the pulse count had to be displayed on de GUI in label staticText23 (and/or update the gauge…)
Therefore I need to call the function gaan(), and when gaan() is called I will get an error: `NameError: global name ‘gaan’ is not defined

so it cannot find the function…

All other functions works great, why does this one does’nt work?
`

GUI2.py (7.42 KB)

RW_GUI2.py (2.89 KB)

···

Op maandag 8 februari 2016 17:11:32 UTC+1 schreef Rob Westein:

Hi,

I want to start a function periodically to update a TextCtrl.
Attached code is working fine, but when FuncStartCount() is started the update function is not called.

What am I doing wrong?

/Rob

Rob Westein wrote:

I'm trying to go another way, but still some problems

What the function OnButton2Button in RW_GUI2 does is listen if there
is an pulse from a machine and count the pulses...(using the GPIO module)
This is working OK, but the pulse count had to be displayed on de GUI
in label staticText23 (and/or update the gauge...)
Therefore I need to call the function gaan(), and when gaan() is
called I will get an error: NameError: global name 'gaan' is not defined

so it cannot find the function....

All other functions works great, why does this one does'nt work?

You are trying to call "gaan" as a global function, but that's not what
it is. It is a member function. You need to do this:
        self.gaan(rcount)

Further, when you define gaan, you need to include a "self" parameter:
    def gaan(self, cvalue):
        self.statucText23.SetLabel(str(cvalue))

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Well, now the gaan() function is called but the update of the label “self.staticText23.SetLabel(str(cvalue))” does not work…
strange… (and frustrating…)

when the OnButton2Button function is called the screen seems to freeze

···

Op maandag 8 februari 2016 17:11:32 UTC+1 schreef Rob Westein:

Hi,

I want to start a function periodically to update a TextCtrl.
Attached code is working fine, but when FuncStartCount() is started the update function is not called.

What am I doing wrong?

/Rob

You likely want wx.CallAfter()

Karsten

···

Gesendet: Donnerstag, 18. Februar 2016 um 21:07 Uhr
Von: “Rob Westein” robwestein@gmail.com
An: wxPython-users wxpython-users@googlegroups.com
Betreff: [wxPython-users] Re: Using Timer to update TextCtrl

Well, now the gaan() function is called but the update of the label “self.staticText23.SetLabel(str(cvalue))” does not work…

strange… (and frustrating…)

when the OnButton2Button function is called the screen seems to freeze

Op maandag 8 februari 2016 17:11:32 UTC+1 schreef Rob Westein:

Hi,

I want to start a function periodically to update a TextCtrl.

Attached code is working fine, but when FuncStartCount() is started the update function is not called.

What am I doing wrong?

/Rob

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.