Beispiel #1
0
def game_main():
    # Instantiate a canvas using the SoftwareX11 rendering engine. This
    # does all the work of creating the canvas, assigning it to the
    # rendering engine and integrating it with the `ecore' loop.
    #
    # From there onwards, the only thing left is add objects to the
    # Canvas, and manipulate these objects. The `ecore' loop will call
    # render automatically on `idle'.
    w, h   = SCREEN_SIZE
    ee     = SoftwareX11(w=w, h=h)
    canvas = ee.evas

    # Setups the game window and field by creating objects and adding
    # them to the canvas.
    setup_field(ee)

    # Sets the framerate of the game to 60FPS
    animator_frametime_set(1.0 / 60.0)

    # Finally, shows all this stuff to the user and enters the main
    # loop. From there ownards the only say we have is on the callbacks
    # from the events we've set to watch.
    ee.title = "Pong"
    ee.size_max_set(*SCREEN_SIZE)
    ee.size_min_set(*SCREEN_SIZE)

    ee.show()
    main_loop_begin()

    # Stops stuff when the game ends
    fire_hooks('the:end')
Beispiel #2
0
    def run(self):
        """start the main loop

        This method only return after we call `quit`.
        """

        ecore.main_loop_begin()
        ecore.x.on_window_delete_request_add(self.test)
Beispiel #3
0
 def main(self):
     """ Enters the RUNNING state by running the main loop until
     main_quit() is called.
     """
     self._main_call_before_start_funcs()
     self.state = REACTOR_STATE_RUNNING
     ecore.main_loop_begin()
     self.state = REACTOR_STATE_STOPPED
     self._main_call_after_stop_funcs()
Beispiel #4
0
 def main(self):
     """ Enters the RUNNING state by running the main loop until
     main_quit() is called.
     """
     self._main_call_before_start_funcs()
     self.state = REACTOR_STATE_RUNNING
     ecore.main_loop_begin()
     self.state = REACTOR_STATE_STOPPED
     self._main_call_after_stop_funcs()
	def run( self ):
		# Inititalize the Accelerometer
		self.accel.init()

		# Load the groups
		self.addGroup( "background" )
		self.addGroup( "eightball" )
		self.getGroup( "eightball" ).signal_callback_add( 
			"display_random_answer",
			"*",
			self.onDisplayRandomAnswer
		)

		self.ee.show()
		ecore.main_loop_begin()
Beispiel #6
0
    def run(self):
        self.stopped = False
        self.elapsedTime = 0.0
        self.timeStart = time.time()
        ecore.timer_add(UPDATE_TIME, self.update)
        ecore.main_loop_begin()

        # DMR old way of doing it.
        """
        while self.running == True:
        timeStart = time.time()
            self.do_work()
        self.elapsedTime = time.time() - timeStart
        """
        self.stopped = True
Beispiel #7
0
    def run(self):
        mainloop = gobject.MainLoop(is_running=True)
        context = mainloop.get_context()

        def glib_context_iterate():
            iters = 0
            while iters < 10 and context.pending():
                context.iteration()
            return True

        # Every 100ms, call an iteration of the glib main context loop
        # to allow the protocol context loop to work
        ecore.timer_add(0.1, glib_context_iterate)

        ecore.main_loop_begin()
Beispiel #8
0
    def run(self):
        #ecore.main_loop_glib_integrate()
        mainloop = gobject.MainLoop(is_running=True)
        context = mainloop.get_context()

        def glib_context_iterate():
            iters = 0
            while iters < 10 and context.pending():
                context.iteration()
                iters += 1
            return True

        # Every 100ms, call an iteration of the glib main context loop
        # to allow the protocol context loop to work
        ecore.timer_add(0.1, glib_context_iterate)

        #equals elementary.run()
        ecore.main_loop_begin()
Beispiel #9
0
    obj = ee.data["obj"]
    canvas = ee.evas
    bg.size = canvas.size
    obj.center = canvas.rect.center


if __name__ == "__main__":
    ee = ecore.evas.SoftwareX11(w=800, h=600)

    canvas = ee.evas
    bg = canvas.Rectangle(color=(255, 255, 255, 255))
    bg.size = canvas.size
    bg.show()

    obj = canvas.Image(file="icon.png")
    w, h = obj.image_size
    obj.size = (w, h)
    obj.fill = (0, 0, w, h)
    obj.center = canvas.rect.center
    obj.show()

    ee.data["bg"] = bg
    ee.data["obj"] = obj
    ee.callback_resize = resize_cb

    ecore.animator_add(animate_obj, ee, obj)

    ee.show()
    ecore.animator_frametime_set(1.0 / 60.0)
    ecore.main_loop_begin()
Beispiel #10
0
def print_every_300ms():
    global counter2
    counter2 += 1
    print "every 300ms, run:", counter2
    return True  # keep running, stop_print_every_300ms will stop me


def stop_print_every_300ms(my_timer):
    print "stopping 'print_every_300ms' timer"
    my_timer.delete()


if __name__ == "__main__":
    # Use C-like API
    ecore.timer_add(0.5, print_every_500ms, "arg1", 1234, q=890, p=567)
    ecore.timer_add(0.6, print_every_600ms_twice)
    ecore.timer_add(0.7, print_once_after_700ms)

    # Use pythonic API, ecore.Timer() is a class
    ecore.Timer(1.0, print_every_1s, "arg1.1", 1234.1, p=567.1)

    # keep timer object so we can stop it from the other timer
    my_timer = ecore.timer_add(0.3, print_every_300ms)
    ecore.timer_add(1.5, stop_print_every_300ms, my_timer)

    # regular timer using C-like API, will trigger ecore.main_loop_quit()
    ecore.timer_add(3.0, quit_after_3s)

    # without a main loop, timers will not work
    ecore.main_loop_begin()
Beispiel #11
0
 def start(self):
     ecore.main_loop_begin()
Beispiel #12
0
 def run(self):
     ecore.main_loop_begin()