| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
''' |
| 25 |
Hi all, |
| 26 |
I'm new to this mailing list, but we've been using Fltk for about 15 years at my work and pyFltk to a lesser extent and more recently (for 5+ years). We started using pyFltk for some more serious development very recently and have found a few small bugs. Today, I'm sending over a patch for the remove_timeout behavior, to make it more compliant with standard Fltk behavior. Hopefully we've got this right here, but please let me know if we did something wrong. |
| 27 |
|
| 28 |
We've also attached a test program (test_timeout.py) that demonstrates the bugs this patch attempts to fix. |
| 29 |
|
| 30 |
This program tests pyFltk for compliance with Fltk remove_timeout behavior. |
| 31 |
pyFltk 1.3.3 and previous have bugs in remove_timeout when: |
| 32 |
timeout callback is a member function of a class |
| 33 |
FIX: function comparison must not be a C-pointer comparison but rather a python comparison |
| 34 |
data pointer in C ("argp") is ignored for pyFltk remove_timeout |
| 35 |
FIX: do Python comparison to check that passed data matches |
| 36 |
remove_timeout in Fltk 1.3.3 docs says that it removes all matching timeouts, not just the last one |
| 37 |
FIX: keep looping after finding first match |
| 38 |
ALSO FIXED: DECREF is in wrong place |
| 39 |
|
| 40 |
This program sets up 4 different timeouts with 3 different data values passed to a member function timeout callback. Data = (1,30) is used twice. |
| 41 |
remove_timeout is called on data=(1,30) and both timeouts should be removed according to the Fltk docs. |
| 42 |
Running with pyFltk 1.3.3, none of the timeouts is removed. With the supplied patch, the two (1,30) timeouts are removed. |
| 43 |
''' |
| 44 |
|
| 45 |
import time |
| 46 |
|
| 47 |
import fltk |
| 48 |
print('fltk.__file__ = {!r}'.format( fltk.__file__ )) |
| 49 |
|
| 50 |
win = fltk.Fl_Window( 640, 480, 'Timeout test' ) |
| 51 |
win.show() |
| 52 |
|
| 53 |
class TestClass( object ): |
| 54 |
def __init__( self ): |
| 55 |
self.x = 5 |
| 56 |
self.y = 1 |
| 57 |
|
| 58 |
def timeout_cb( self, data ): |
| 59 |
print('timeout called: x={}, y={}, data = {!r}'.format( self.x, self.y, data )) |
| 60 |
fltk.Fl.repeat_timeout( 1, self.timeout_cb, data ) |
| 61 |
|
| 62 |
tc = TestClass() |
| 63 |
fltk.Fl.add_timeout( 1, tc.timeout_cb, ( 1, 31 ) ) |
| 64 |
fltk.Fl.add_timeout( 1, tc.timeout_cb, ( 1, 30 ) ) |
| 65 |
fltk.Fl.add_timeout( 1, tc.timeout_cb, ( 1, 30 ) ) |
| 66 |
fltk.Fl.add_timeout( 1, tc.timeout_cb, ( 1, 29 ) ) |
| 67 |
|
| 68 |
print('waiting....') |
| 69 |
|
| 70 |
startTime = time.time() |
| 71 |
while time.time() < startTime+5: |
| 72 |
fltk.Fl.wait( 5 - ( time.time() - startTime ) ) |
| 73 |
|
| 74 |
print('removing timeout... (1, 30)') |
| 75 |
fltk.Fl.remove_timeout( tc.timeout_cb, ( 1, 30 ) ) |
| 76 |
fltk.Fl.run() |