Exemplo n.º 1
0
    def start(self):
        """
        Start running the Cocos GUI.
        This method will block until the GUI has been shut down. After
        returning there might still be some processes cleaning up.
        """
        print("Starting Cocos GUI")
        print("\nUsing following settings:")
        print("\tConnection: %s:%d" % (self._hostname, self._port))
        print("\tGraphics: (%d, %d) fullscreen=%s" %
              (self._width, self._height, self._fullscreen))

        print()
        print("Loaded libraries:")
        print("\tPyglet:\t%s" % pyglet.version)
        print("\tCocos:\t%s" % cocos.version)
        import twisted
        print("\tTwisted:%s" % twisted.version.short())

        print()
        print("Opening connection to server...")
        self._connector = ClientConnector(self._hostname, self._port)
        self._connector.start()

        self._drinks = self._connector.database.get_drinks()
        random.shuffle(self._drinks)

        self._connector.database.on_drinks_updated += self._update_drinks
        self._connector.stock_exchange.on_next_round += self._next_round

        print()
        print("Initializing graphics...")
        cocos.director.director.init(width=self._width,
                                     height=self._height,
                                     fullscreen=self._fullscreen)
        cocos.director.director.set_show_FPS(debug_mode)
        self.show_gl_info()

        print()
        print("Starting the show!")
        self.show_ticker_scene()

        print()
        print("Shut down in progress...")
        print()

        self._center_display_controller.stop()
        self._connector.stop()
Exemplo n.º 2
0
 def setUpClass(cls):
     """
     Prepare a database connection
     """
     start_test_server()
     
     cls.connector = ClientConnector("localhost", test_port)
     cls.connector.start()
     cls.db = cls.connector.database
     cls.random = random.Random()
Exemplo n.º 3
0
    def start(self):
        """
        Start running the Cocos GUI.
        This method will block until the GUI has been shut down. After
        returning there might still be some processes cleaning up.
        """
        print("Starting Cocos GUI")
        print("\nUsing following settings:")
        print("\tConnection: %s:%d" % (self._hostname, self._port))
        print("\tGraphics: (%d, %d) fullscreen=%s" %(self._width, self._height, self._fullscreen))
        
        print()
        print("Loaded libraries:")
        print("\tPyglet:\t%s" % pyglet.version)
        print("\tCocos:\t%s" % cocos.version)
        import twisted
        print("\tTwisted:%s" % twisted.version.short())
        
        print()
        print("Opening connection to server...")
        self._connector = ClientConnector(self._hostname, self._port)
        self._connector.start()

        self._drinks = self._connector.database.get_drinks()
        random.shuffle(self._drinks)

        self._connector.database.on_drinks_updated += self._update_drinks
        self._connector.stock_exchange.on_next_round += self._next_round

        print()
        print("Initializing graphics...")
        cocos.director.director.init(width=self._width, height=self._height,
                                     fullscreen=self._fullscreen)
        cocos.director.director.set_show_FPS(debug_mode)
        self.show_gl_info()

        print()
        print("Starting the show!")
        self.show_ticker_scene()
        
        print()
        print("Shut down in progress...")
        print()

        self._center_display_controller.stop()
        self._connector.stop()
Exemplo n.º 4
0
import random
import time
from quartjes.connector.client import ClientConnector

debug_memory = False

if debug_memory:
    from meliae import scanner
else:
    scanner = None

__author__="rob"
__date__ ="$Jul 3, 2011 10:45:28 AM$"

if __name__ == "__main__":
    con = ClientConnector("localhost", 1234)
    con.start()
    while not con.is_connected():
        time.sleep(1)

    database = con.database
    exchange = con.stock_exchange

    current_drinks = {}
    max_position = 0
    
    mem_counter = 0

    def update_drinks(drinks):
        global current_drinks
        global max_position
Exemplo n.º 5
0
                                   command=self.edit_drink,
                                   width=20,
                                   height=2,
                                   font=self.font1)
        self.b_remove_drink = Button(self.frame2,
                                     text="Remove drink",
                                     command=self.remove_drink,
                                     width=20,
                                     height=2,
                                     font=self.font1)

        self.frame1.pack(side=LEFT, fill=BOTH, expand=1)
        self.frame2.pack(side=LEFT, fill=BOTH, expand=1)

        self.b_add_drink.pack(fill=BOTH)
        self.b_add_mix.pack(fill=BOTH)
        self.b_edit_drink.pack(fill=BOTH)
        self.b_remove_drink.pack(fill=BOTH)

        self.update_listbox()


if __name__ == "__main__":
    from quartjes.connector.client import ClientConnector
    master = Tk()
    master.conn = ClientConnector()
    master.conn.start()
    app = edit_db_dialog(master)
    app.pack(fill=BOTH, expand=1)
    app.mainloop()
Exemplo n.º 6
0
class CocosGui(object):
    """
    Main object containing the Cocos2D GUI.
    Initialize and start this object to start a show.
    """

    def __init__(self, 
                 hostname=None, 
                 port=1234, 
                 width=1024, 
                 height=768,
                 fullscreen=True):
        """
        Set up all parameters and objects for the GUI.
        """
        self._width = width
        self._height = height
        self._fullscreen = fullscreen
        self._hostname = hostname
        self._port = port

        self._refresh_ticker_on_update = True

        self._ticker_layer = None
        self._center_display_controller = None
        self._title_layer = None
        self._mix_layer = None
        self._connector = None

        self._drinks = None

    def start(self):
        """
        Start running the Cocos GUI.
        This method will block until the GUI has been shut down. After
        returning there might still be some processes cleaning up.
        """
        print("Starting Cocos GUI")
        print("\nUsing following settings:")
        print("\tConnection: %s:%d" % (self._hostname, self._port))
        print("\tGraphics: (%d, %d) fullscreen=%s" %(self._width, self._height, self._fullscreen))
        
        print()
        print("Loaded libraries:")
        print("\tPyglet:\t%s" % pyglet.version)
        print("\tCocos:\t%s" % cocos.version)
        import twisted
        print("\tTwisted:%s" % twisted.version.short())
        
        print()
        print("Opening connection to server...")
        self._connector = ClientConnector(self._hostname, self._port)
        self._connector.start()

        self._drinks = self._connector.database.get_drinks()
        random.shuffle(self._drinks)

        self._connector.database.on_drinks_updated += self._update_drinks
        self._connector.stock_exchange.on_next_round += self._next_round

        print()
        print("Initializing graphics...")
        cocos.director.director.init(width=self._width, height=self._height,
                                     fullscreen=self._fullscreen)
        cocos.director.director.set_show_FPS(debug_mode)
        self.show_gl_info()

        print()
        print("Starting the show!")
        self.show_ticker_scene()
        
        print()
        print("Shut down in progress...")
        print()

        self._center_display_controller.stop()
        self._connector.stop()

    @staticmethod
    def show_gl_info():
        """
        Display some information about the GL renderer.
        """
        from pyglet.gl.gl_info import GLInfo
        info = GLInfo()
        info.set_active_context()
        
        print("GL Info:")
        print("\tVersion:\t%s" % info.get_version())
        print("\tRenderer:\t%s" % info.get_renderer())
        print("\tVendor:\t\t%s" % info.get_vendor())
        print("\tExtensions:\t%s" % info.get_extensions())
        
        from pyglet.gl.glu_info import GLUInfo
        info = GLUInfo()
        info.set_active_context()
        
        print()
        print("GLU Info:")
        print("\tVersion:\t%s" % info.get_version())
        print("\tExtensions:\t%s" % info.get_extensions())
        
    def show_ticker_scene(self, new_ticker=False):
        """
        Replace everything on screen with the scene displaying the drink ticker.
        If the engine is not yet running, this method will start a new engine
        and will block until the engine has stopped.
        """
        # Instantiate objects
        if not self._ticker_layer or new_ticker:
            self._ticker_layer = BottomTicker(screen_width=self._width)
        if not self._center_display_controller:
            self._center_display_controller = CenterDisplayController()
        if not self._title_layer:
            self._title_layer = TitleLayer()

        # Glue everything together
        self._ticker_layer.update_drinks(self._drinks)
        self._ticker_layer.on_focused_drink_changed += self._center_display_controller.drink_focused_changed

        # Show the scene
        scene = cocos.scene.Scene(self._ticker_layer, 
                                  self._center_display_controller.get_layer(), 
                                  self._title_layer)
        self._display_scene(scene)

    @staticmethod
    def _display_scene(scene):
        """
        Change the display to show the given scene.
        If no engine is running yet, an engine will be started. In that case this method
        will not return until the engine has stopped again.
        """
        if cocos.director.director.scene is None:
            cocos.director.director.run(scene)
        else:
            cocos.director.director.replace(cocos.scenes.transitions.FadeTransition(scene))

    def _update_drinks(self, drinks):
        random.shuffle(drinks)
        self._drinks = drinks
        if self._ticker_layer:
            self._ticker_layer.update_drinks(drinks)
        if self._center_display_controller:
            self._center_display_controller.update_drinks(drinks)

    def _next_round(self):
        pass
Exemplo n.º 7
0
 def __init__(self, root):
     root.title('Sales client')
     Frame.__init__(self, root)
     self.pack(fill=BOTH, expand=1)
     self.createWidgets()
     self.conn = ClientConnector()
Exemplo n.º 8
0
class Sales_client(Frame):
    f1 = ("Arial", 12, "bold")

    def __init__(self, root):
        root.title('Sales client')
        Frame.__init__(self, root)
        self.pack(fill=BOTH, expand=1)
        self.createWidgets()
        self.conn = ClientConnector()

    def connect_to_server(self):
        if self.conn.is_connected():
            self.conn.stop()
            self.b_connect_to_server.config(text="Not connected to server",
                                            bg="#ff0000",
                                            activebackground="#ff5555")
            self.ed.destroy()
            self.sd.destroy()
        else:
            try:
                self.conn.host = str(self.e_server_hostname.get())
                self.conn.port = int(self.e_server_port.get())
            except:
                import traceback
                traceback.print_exc()
                pass

            self.conn.start()
            self.b_connect_to_server.config(text="Connected",
                                            bg="#00ff00",
                                            activebackground="#55ff55")
            self.ed = edit_db_dialog(self)
            self.sd = sell_dialog(self)
            self.sd.pack(side=BOTTOM, fill=BOTH, expand=1)

    def edit_db(self):
        if self.conn.is_connected():
            self.sd.forget()
            self.ed.pack(side=BOTTOM, fill=BOTH, expand=1)
        else:
            tkMessageBox.showwarning("Not connected to server",
                                     "Please connected to a server first.")

    def sell(self):
        if self.conn.is_connected():
            self.ed.forget()
            self.sd.pack(side=BOTTOM, fill=BOTH, expand=1)
        else:
            tkMessageBox.showwarning("Not connected to server",
                                     "Please connected to a server first.")

    def createWidgets(self):
        # frame 1
        self.frame1 = Frame(self)

        Label(self.frame1, text="Server hostname/IP:",
              font=self.f1).pack(side=LEFT, fill=X, expand=1)
        self.e_server_hostname = Entry(self.frame1, font=self.f1)
        self.e_server_hostname.pack(side=LEFT, fill=X, expand=1)
        Label(self.frame1, text="Port:", font=self.f1).pack(side=LEFT,
                                                            fill=X,
                                                            expand=1)
        self.e_server_port = Entry(self.frame1, font=self.f1)
        self.e_server_port.pack(side=LEFT, fill=X, expand=1)

        self.b_connect_to_server = Button(self.frame1,
                                          text="Connect to server",
                                          bg="#ff0000",
                                          activebackground="#ff5555",
                                          command=self.connect_to_server,
                                          font=self.f1)
        self.b_connect_to_server.pack(side=LEFT, fill=X, expand=1, padx=10)

        self.b_edit_dialog = Button(self.frame1,
                                    text="Edit database",
                                    command=self.edit_db,
                                    font=self.f1)
        self.b_sell_dialog = Button(self.frame1,
                                    text="Sell dialog",
                                    command=self.sell,
                                    font=self.f1)

        self.frame1.pack(fill=X)
        self.b_edit_dialog.pack(side=LEFT, fill=X, expand=1, padx=10)
        self.b_sell_dialog.pack(side=LEFT, fill=X, expand=1, padx=10)
Exemplo n.º 9
0
class CocosGui(object):
    """
    Main object containing the Cocos2D GUI.
    Initialize and start this object to start a show.
    """
    def __init__(self,
                 hostname=None,
                 port=1234,
                 width=1024,
                 height=768,
                 fullscreen=True):
        """
        Set up all parameters and objects for the GUI.
        """
        self._width = width
        self._height = height
        self._fullscreen = fullscreen
        self._hostname = hostname
        self._port = port

        self._refresh_ticker_on_update = True

        self._ticker_layer = None
        self._center_display_controller = None
        self._title_layer = None
        self._mix_layer = None
        self._connector = None

        self._drinks = None

    def start(self):
        """
        Start running the Cocos GUI.
        This method will block until the GUI has been shut down. After
        returning there might still be some processes cleaning up.
        """
        print("Starting Cocos GUI")
        print("\nUsing following settings:")
        print("\tConnection: %s:%d" % (self._hostname, self._port))
        print("\tGraphics: (%d, %d) fullscreen=%s" %
              (self._width, self._height, self._fullscreen))

        print()
        print("Loaded libraries:")
        print("\tPyglet:\t%s" % pyglet.version)
        print("\tCocos:\t%s" % cocos.version)
        import twisted
        print("\tTwisted:%s" % twisted.version.short())

        print()
        print("Opening connection to server...")
        self._connector = ClientConnector(self._hostname, self._port)
        self._connector.start()

        self._drinks = self._connector.database.get_drinks()
        random.shuffle(self._drinks)

        self._connector.database.on_drinks_updated += self._update_drinks
        self._connector.stock_exchange.on_next_round += self._next_round

        print()
        print("Initializing graphics...")
        cocos.director.director.init(width=self._width,
                                     height=self._height,
                                     fullscreen=self._fullscreen)
        cocos.director.director.set_show_FPS(debug_mode)
        self.show_gl_info()

        print()
        print("Starting the show!")
        self.show_ticker_scene()

        print()
        print("Shut down in progress...")
        print()

        self._center_display_controller.stop()
        self._connector.stop()

    @staticmethod
    def show_gl_info():
        """
        Display some information about the GL renderer.
        """
        from pyglet.gl.gl_info import GLInfo
        info = GLInfo()
        info.set_active_context()

        print("GL Info:")
        print("\tVersion:\t%s" % info.get_version())
        print("\tRenderer:\t%s" % info.get_renderer())
        print("\tVendor:\t\t%s" % info.get_vendor())
        print("\tExtensions:\t%s" % info.get_extensions())

        from pyglet.gl.glu_info import GLUInfo
        info = GLUInfo()
        info.set_active_context()

        print()
        print("GLU Info:")
        print("\tVersion:\t%s" % info.get_version())
        print("\tExtensions:\t%s" % info.get_extensions())

    def show_ticker_scene(self, new_ticker=False):
        """
        Replace everything on screen with the scene displaying the drink ticker.
        If the engine is not yet running, this method will start a new engine
        and will block until the engine has stopped.
        """
        # Instantiate objects
        if not self._ticker_layer or new_ticker:
            self._ticker_layer = BottomTicker(screen_width=self._width)
        if not self._center_display_controller:
            self._center_display_controller = CenterDisplayController()
        if not self._title_layer:
            self._title_layer = TitleLayer()

        # Glue everything together
        self._ticker_layer.update_drinks(self._drinks)
        self._ticker_layer.on_focused_drink_changed += self._center_display_controller.drink_focused_changed

        # Show the scene
        scene = cocos.scene.Scene(self._ticker_layer,
                                  self._center_display_controller.get_layer(),
                                  self._title_layer)
        self._display_scene(scene)

    @staticmethod
    def _display_scene(scene):
        """
        Change the display to show the given scene.
        If no engine is running yet, an engine will be started. In that case this method
        will not return until the engine has stopped again.
        """
        if cocos.director.director.scene is None:
            cocos.director.director.run(scene)
        else:
            cocos.director.director.replace(
                cocos.scenes.transitions.FadeTransition(scene))

    def _update_drinks(self, drinks):
        random.shuffle(drinks)
        self._drinks = drinks
        if self._ticker_layer:
            self._ticker_layer.update_drinks(drinks)
        if self._center_display_controller:
            self._center_display_controller.update_drinks(drinks)

    def _next_round(self):
        pass
Exemplo n.º 10
0
import random
import time
from quartjes.connector.client import ClientConnector

debug_memory = False

if debug_memory:
    from meliae import scanner
else:
    scanner = None

__author__ = "rob"
__date__ = "$Jul 3, 2011 10:45:28 AM$"

if __name__ == "__main__":
    con = ClientConnector("localhost", 1234)
    con.start()
    while not con.is_connected():
        time.sleep(1)

    database = con.database
    exchange = con.stock_exchange

    current_drinks = {}
    max_position = 0

    mem_counter = 0

    def update_drinks(drinks):
        global current_drinks
        global max_position
Exemplo n.º 11
0
    def testClientServer(self):
        """
        Do some client server tests.
        """
        import time

        def callback(text):
            callback.count += 1
            callback.last_result = text

        def testfunc():
            pass

        callback.count = 0

        cl = ClientConnector("localhost", test_port)
        cl.start()
        self.assertTrue(cl.is_connected(), "Connection failed.")

        testService = cl.get_service_interface("test")

        result = testService.test(text="Spam")
        self.assertEqual(result, "Spam", "Expecting same message back.")
        result = testService.test("Spam")
        self.assertEqual(result, "Spam", "Expecting same message back.")

        with self.assertRaises(TypeError):
            result = testService.test(testfunc)

        testService.on_trigger += callback

        testService.trigger(text="Eggs")
        self.assertEqual(callback.count, 1, "No callback received")
        self.assertEqual(callback.last_result, "Callback: Eggs",
                         "Received incorrect result text.")

        testService.trigger2("Ham")
        self.assertEqual(callback.count, 2, "No callback received")
        self.assertEqual(callback.last_result, "Callback2: Ham",
                         "Received incorrect result text.")

        from quartjes.connector.protocol import default_timeout
        with self.assertRaises(TimeoutError):
            testService.test_timeout(default_timeout + 10)

        time.sleep(10)
        cl.stop()
        time.sleep(10)
        cl.start()

        result = testService.test(text="Spam")
        self.assertEqual(result, "Spam", "Expecting same message back.")

        cl.stop()
Exemplo n.º 12
0
 def __init__(self, root):        
     root.title('Sales client')
     Frame.__init__(self, root)
     self.pack(fill=BOTH,expand=1)
     self.createWidgets()
     self.conn = ClientConnector() 
Exemplo n.º 13
0
class Sales_client(Frame):  
    f1 = ("Arial", 12, "bold")  
    def __init__(self, root):        
        root.title('Sales client')
        Frame.__init__(self, root)
        self.pack(fill=BOTH,expand=1)
        self.createWidgets()
        self.conn = ClientConnector() 

    def connect_to_server(self):        
        if self.conn.is_connected():
            self.conn.stop()
            self.b_connect_to_server.config(text = "Not connected to server", bg="#ff0000",activebackground="#ff5555")
            self.ed.destroy()
            self.sd.destroy()
        else:                        
            try:
                self.conn.host = str(self.e_server_hostname.get())
                self.conn.port = int(self.e_server_port.get())
            except:
                import traceback
                traceback.print_exc()
                pass                
            
            self.conn.start()
            self.b_connect_to_server.config(text = "Connected", bg="#00ff00",activebackground="#55ff55")
            self.ed = edit_db_dialog(self)
            self.sd = sell_dialog(self)
            self.sd.pack(side=BOTTOM,fill=BOTH,expand=1)

    def edit_db(self):
        if self.conn.is_connected():
            self.sd.forget()
            self.ed.pack(side=BOTTOM,fill=BOTH,expand=1)
        else:
            tkMessageBox.showwarning("Not connected to server","Please connected to a server first.")

    def sell(self):
        if self.conn.is_connected():
            self.ed.forget()
            self.sd.pack(side=BOTTOM,fill=BOTH,expand=1)
        else:
            tkMessageBox.showwarning("Not connected to server","Please connected to a server first.")

    def createWidgets(self):                
        # frame 1
        self.frame1 = Frame(self)
        
        Label(self.frame1, text="Server hostname/IP:",font = self.f1).pack(side=LEFT,fill=X,expand=1)        
        self.e_server_hostname = Entry(self.frame1,font = self.f1)
        self.e_server_hostname.pack(side=LEFT,fill=X,expand=1)
        Label(self.frame1, text="Port:",font = self.f1).pack(side=LEFT,fill=X,expand=1)
        self.e_server_port = Entry(self.frame1, font = self.f1)
        self.e_server_port.pack(side=LEFT,fill=X,expand=1)
         
        self.b_connect_to_server = Button(self.frame1, text = "Connect to server", bg="#ff0000", activebackground="#ff5555", command =  self.connect_to_server, font = self.f1)
        self.b_connect_to_server.pack(side=LEFT,fill=X,expand=1,padx=10)

        self.b_edit_dialog = Button(self.frame1, text = "Edit database",command = self.edit_db, font = self.f1)
        self.b_sell_dialog = Button(self.frame1, text = "Sell dialog", command = self.sell, font = self.f1)

        self.frame1.pack(fill=X)
        self.b_edit_dialog.pack(side=LEFT,fill=X,expand=1,padx=10)
        self.b_sell_dialog.pack(side=LEFT,fill=X,expand=1,padx=10)
Exemplo n.º 14
0
    def testClientServer(self):
        """
        Do some client server tests.
        """
        import time

        def callback(text):
            callback.count += 1
            callback.last_result = text

        def testfunc():
            pass

        callback.count = 0

        cl = ClientConnector("localhost", test_port)
        cl.start()
        self.assertTrue(cl.is_connected(), "Connection failed.")

        testService = cl.get_service_interface("test")

        result = testService.test(text="Spam")
        self.assertEqual(result, "Spam", "Expecting same message back.")
        result = testService.test("Spam")
        self.assertEqual(result, "Spam", "Expecting same message back.")

        with self.assertRaises(TypeError):
            result = testService.test(testfunc)

        testService.on_trigger += callback

        testService.trigger(text="Eggs")
        self.assertEqual(callback.count, 1, "No callback received")
        self.assertEqual(callback.last_result, "Callback: Eggs", "Received incorrect result text.")

        testService.trigger2("Ham")
        self.assertEqual(callback.count, 2, "No callback received")
        self.assertEqual(callback.last_result, "Callback2: Ham", "Received incorrect result text.")

        from quartjes.connector.protocol import default_timeout

        with self.assertRaises(TimeoutError):
            testService.test_timeout(default_timeout + 10)

        time.sleep(10)
        cl.stop()
        time.sleep(10)
        cl.start()

        result = testService.test(text="Spam")
        self.assertEqual(result, "Spam", "Expecting same message back.")

        cl.stop()