def loop_tests(): global test_loop def tcheck_func(): global loop_tchecks, loop_ichecks, verbose, test_loop loop_tchecks += 1 if verbose: print "%s: %u" % ('tcheck_func', loop_tchecks) if loop_tchecks >= 10 and loop_ichecks >= 100: test_loop.quit() return True # keep running def icheck_func(): global loop_ichecks, verbose loop_ichecks += 1 if verbose: print "%s: %u" % ('icheck_func', loop_ichecks) return True # keep running test_loop = Rapicorn.MainLoop() ts = test_loop.exec_timer(tcheck_func, 0, 5) src = test_loop.exec_idle(icheck_func) test_loop.run() assert loop_tchecks >= 10 and loop_ichecks >= 100
# Load and import a versioned Rapicorn module into the 'Rapicorn' namespace # Licensed CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0 import Rapicorn # Load Rapicorn language bindings for Python # Setup the application object, unsing a unique application name. app = Rapicorn.init_app ("Test Rapicorn Bindings") # Define the elements of the dialog window to be displayed. hello_window = """ <Window id="testbind-py"> <RapicornIdlTestWidget name="test-widget" string-prop="@bind somestring"/> </Window> """ app.load_string (hello_window) window = app.create_window ("testbind-py") @Rapicorn.Bindable class ObjectModel (object): def __init__ (self): self.somestring = "initial-somestring" om = ObjectModel() window.data_context (om.__aida_relay__) window.show() # sync local state with remote state, because of possible binding # notification ping-pong we have to do this in 2 phases
# check for garbage collection interleaved with this script's activity startgc = r'TestGC-Release' collected = r'GARBAGE_COLLECTED.*?purged=[1-9]' released = r'TestGC-Released' # the GC cycle executes asynchronously, so collected/released may be printed in any order gccycle = startgc + '.*?' + '(' + collected + '.*?' + released + '|' + released + '.*?' + collected + ')' gc_matches = re.findall (gccycle, output, re.S | re.M) # OK if we find the required number of GC interactions assert len (gc_matches) >= N_GC_CYCLES print ' %-6s' % 'CHECK', '%-67s' % __file__, 'OK' sys.exit (0) import Rapicorn # Load Rapicorn language bindings for Python # Setup the application object, unsing a unique application name. app = Rapicorn.init_app ("Test Rapicorn GC") # Define the elements of the dialog window to be displayed. hello_window = """ <interfaces> <Window id="testgc-py"> <Table name="container"/> </Window> <RapicornIdlTestWidget id="testwidget"/> </interfaces> """ app.load_string (hello_window) window = app.create_window ("testgc-py")
# Licensed CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0 # [HelloRapicorn-EXAMPLE] import Rapicorn # Load Rapicorn language bindings for Python # Retrieve the global Rapicorn Application object # and setup a user digestible application name. app = Rapicorn.init_app ("Hello Rapicorn") # Define the elements of the dialog window to be displayed. hello_window = """ <Window declare="hello-window"> <Alignment padding="15"> <VBox spacing="30"> <Label markup-text="Hello World!"/> <Button on-click="CLICK"> <Label markup-text="Close" /> </Button> </VBox> </Alignment> </Window> """ # Register the 'hello-window' definition for later use, for this we need # a unique domain string, it's easiest to reuse the application name. app.load_string (hello_window) # The above is all that is needed to allow us to create the window object. window = app.create_window ("hello-window") # This function is called to handle the command we use for button clicks.
# Licensed CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0 # setup Rapicorn test import Rapicorn # Load Rapicorn language bindings for Python app = Rapicorn.init_app() def show_and_display (win): # show and run main loop until the window is fully displayed # FIXME: convenience function for app assert app assert win.closed() == True def window_displayed(): window_displayed.seen_signal = True window_displayed.seen_signal = False conid = win.sig_displayed.connect (window_displayed) win.show() while not window_displayed.seen_signal: app.main_loop().iterate (True) win.sig_displayed.disconnect (conid) # = SizeGroup Tests = # create wide and a tall buttons that are resized via size groups decls = """ <Window declare="SGWindow"> <VBox> <Label markup-text="Horizontal SizeGroup:"/> <Frame> <HBox> <Button id="wide1" hsize-group="HGroupedWidgets"> <Label markup-text="Wide Button"/></Button> <Button id="tall1" hsize-group="HGroupedWidgets">
# Licensed CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0 """ PyRapicorn Loop Test """ import Rapicorn # Load Rapicorn language bindings for Python import sys # initialize application app = Rapicorn.init_app ("PyRapicorn Loop Test") verbose = 0 loop_tchecks = 0 loop_ichecks = 0 test_loop = None def loop_tests(): global test_loop def tcheck_func(): global loop_tchecks, loop_ichecks, verbose, test_loop loop_tchecks += 1 if verbose: print "%s: %u" % ('tcheck_func', loop_tchecks) if loop_tchecks >= 10 and loop_ichecks >= 100: test_loop.quit() return True # keep running def icheck_func(): global loop_ichecks, verbose loop_ichecks += 1 if verbose: print "%s: %u" % ('icheck_func', loop_ichecks) return True # keep running
""" import Rapicorn # Load Rapicorn language bindings for Python import sys # Define main window Widget Tree simple_window_widgets = """ <Window declare="simple-window"> <Button on-click="CLICK"> <Label markup-text="Hello Simple World!" /> </Button> </Window> """ # setup application app = Rapicorn.init_app("Simple PyRapicorn Test") # unique application name app.load_string(simple_window_widgets) # loads widget tree window = app.create_window("simple-window") # creates main window # signal connection testing def assert_unreachable(*args): assert "code unreachable" == True cid1 = window.sig_commands.connect(assert_unreachable) cid2 = window.sig_commands.connect(assert_unreachable) assert cid1 != 0 assert cid2 != 0 assert cid1 != cid2 disconnected = window.sig_commands.disconnect(cid2)
# Licensed CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0 # setup Rapicorn test import Rapicorn # Load Rapicorn language bindings for Python app = Rapicorn.init_app() def show_and_display( win): # show and run main loop until the window is fully displayed # FIXME: convenience function for app assert app assert win.closed() == True def window_displayed(): window_displayed.seen_signal = True window_displayed.seen_signal = False conid = win.sig_displayed.connect(window_displayed) win.show() while not window_displayed.seen_signal: app.main_loop().iterate(True) win.sig_displayed.disconnect(conid) # = SizeGroup Tests = # create wide and a tall buttons that are resized via size groups decls = """ <Window declare="SGWindow"> <VBox> <Label markup-text="Horizontal SizeGroup:"/>
def R(w, h): return Rapicorn.Requisition(width=w, height=h)
# Licensed CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0 import Rapicorn # @LINE_REWRITTEN_FOR_INSTALLCHECK@ import collections # verify that pycallable() raises Exception def assert_raises(Exception, pycallable, *args, **kwds): try: pycallable(*args, **kwds) except Exception: return raise AssertionError('%s not raised' % Exception.__name__) # test MainLoop and EventLoop object identities ml = Rapicorn.MainLoop() sl = ml.create_sub_loop() sm = sl.main_loop() m3 = Rapicorn.MainLoop() assert ml == ml and sl == sl and sm == sm and m3 == m3 assert ml != sl and sl != ml and sm != sl and sl != sm assert ml == sm and sm == ml and ml != m3 and m3 != ml assert ml.main_loop() == ml and m3.main_loop() == m3 # test exec_callback ect_counter = 5 ect_value = "" def bhandler(): global ect_counter, ect_value
# Licensed CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0 """ PyRapicorn Loop Test """ import Rapicorn # Load Rapicorn language bindings for Python import sys # initialize application app = Rapicorn.init_app("PyRapicorn Loop Test") verbose = 0 loop_tchecks = 0 loop_ichecks = 0 test_loop = None def loop_tests(): global test_loop def tcheck_func(): global loop_tchecks, loop_ichecks, verbose, test_loop loop_tchecks += 1 if verbose: print "%s: %u" % ('tcheck_func', loop_tchecks) if loop_tchecks >= 10 and loop_ichecks >= 100: test_loop.quit() return True # keep running def icheck_func(): global loop_ichecks, verbose
# Load and import a versioned Rapicorn module into the 'Rapicorn' namespace # Licensed CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0 import Rapicorn # Load Rapicorn language bindings for Python # Setup the application object, unsing a unique application name. app = Rapicorn.init_app("Test Rapicorn Bindings") # Define the elements of the dialog window to be displayed. hello_window = """ <Window declare="example-bind-py"> <Alignment padding="15"> <VBox spacing="30"> <HBox id="binding-box"> <Label markup-text="Editable Text: "/> <!-- [bind-title-EXAMPLE] --> <TextEditor markup-text="@bind title"/> <!-- [bind-title-EXAMPLE] --> </HBox> <HBox homogeneous="true" spacing="15"> <Button on-click="show" hexpand="1"> <Label markup-text="Show Model"/> </Button> <Button id="shuffler" on-click="shuffle"> <Label markup-text="Shuffle Model"/> </Button> </HBox> </VBox> </Alignment> </Window> """ app.load_string(hello_window) window = app.create_window("example-bind-py")
""" import Rapicorn # Load Rapicorn language bindings for Python import sys # Define main window Widget Tree simple_window_widgets = """ <Window declare="simple-window"> <Button on-click="CLICK"> <Label markup-text="Hello Simple World!" /> </Button> </Window> """ # setup application app = Rapicorn.init_app ("Simple PyRapicorn Test") # unique application name app.load_string (simple_window_widgets) # loads widget tree window = app.create_window ("simple-window") # creates main window # signal connection testing def assert_unreachable (*args): assert "code unreachable" == True cid1 = window.sig_commands.connect (assert_unreachable) cid2 = window.sig_commands.connect (assert_unreachable) assert cid1 != 0 assert cid2 != 0 assert cid1 != cid2 disconnected = window.sig_commands.disconnect (cid2) assert disconnected == True disconnected = window.sig_commands.disconnect (cid2) assert disconnected == False
stderr=subprocess.STDOUT) # check for garbage collection interleaved with this script's activity startgc = r'TestGC-Release' collected = r'GARBAGE_COLLECTED.*?purged=[1-9]' released = r'TestGC-Released' # the GC cycle executes asynchronously, so collected/released may be printed in any order gccycle = startgc + '.*?' + '(' + collected + '.*?' + released + '|' + released + '.*?' + collected + ')' gc_matches = re.findall(gccycle, output, re.S | re.M) # OK if we find the required number of GC interactions assert len(gc_matches) >= N_GC_CYCLES sys.exit(0) import Rapicorn # Load Rapicorn language bindings for Python # Setup the application object, unsing a unique application name. app = Rapicorn.init_app("Test Rapicorn GC") # Define the elements of the dialog window to be displayed. hello_window = """ <interfaces> <Window declare="testgc-py"> <Table id="container"/> </Window> <RapicornIdlTestWidget declare="testwidget"/> </interfaces> """ app.load_string(hello_window) window = app.create_window("testgc-py")