Exemplo n.º 1
0
    def __init__(self):
        ## Make a gtk builder
        b = gtk.Builder()
        b.add_from_file('janus-0.6.glade')
        
        ## auto connect signals
        b.connect_signals(self)
        
        ## Get Windows
        self.window = b.get_object("main_window")
        self.test_window = b.get_object("test_window")
        self.about_window = b.get_object("about_window")
                
        ## Get Widgets
        self.info_bar = InfoBar()
        b.get_object("info_bar").add(self.info_bar)

        ## input
        self.entry = FancyInput() 
        b.get_object("main_input_frame").add(self.entry)

        ## Map
        self.map = Map()
        b.get_object('map_box').add(self.map)

        ## Contents
        self.contents = RoomContents()
        b.get_object('contents').add(self.contents.treeview)
        self.contents.idle()

        ## Spellbar
        b.get_object('spellbar').add(SpellBar())

        ## Textview
        self.textview = AutoScrolledTextView()        
        b.get_object("scrolled_window").add(self.textview)       

        ## Connect up events
        self.window.connect("delete_event", delete_event)        
        self.entry.connect("entry-send", self.send)
        
        ## Show Windows that need it.
        self.window.show_all()

        ## Focus the entry box
        self.entry.grab_focus()

        ## Setup socket
        self.sock = Connection()
        gobject.timeout_add(10, self.poll)
Exemplo n.º 2
0
class Client:
    def __init__(self):
        ## Make a gtk builder
        b = gtk.Builder()
        b.add_from_file('janus-0.6.glade')
        
        ## auto connect signals
        b.connect_signals(self)
        
        ## Get Windows
        self.window = b.get_object("main_window")
        self.test_window = b.get_object("test_window")
        self.about_window = b.get_object("about_window")
                
        ## Get Widgets
        self.info_bar = InfoBar()
        b.get_object("info_bar").add(self.info_bar)

        ## input
        self.entry = FancyInput() 
        b.get_object("main_input_frame").add(self.entry)

        ## Map
        self.map = Map()
        b.get_object('map_box').add(self.map)

        ## Contents
        self.contents = RoomContents()
        b.get_object('contents').add(self.contents.treeview)
        self.contents.idle()

        ## Spellbar
        b.get_object('spellbar').add(SpellBar())

        ## Textview
        self.textview = AutoScrolledTextView()        
        b.get_object("scrolled_window").add(self.textview)       

        ## Connect up events
        self.window.connect("delete_event", delete_event)        
        self.entry.connect("entry-send", self.send)
        
        ## Show Windows that need it.
        self.window.show_all()

        ## Focus the entry box
        self.entry.grab_focus()

        ## Setup socket
        self.sock = Connection()
        gobject.timeout_add(10, self.poll)
        
    
    def ping(self):
        if self.ping_timeout:
            try:
                self.sock.send('ping')
                return True
            except:
                return False
        else:
            return False
            
    def handle_connect(self, widget):
        """ 
            handle a click on Session->Connect 
        """
        self.ping_timeout = 0
        self.sock.close()
        self.sock = Connection()
        self.sock.connect()
        self.textview.insert("Connected.", 'green')
                
    def handle_disconnect(self, widget):
        """ 
            handle a click on Session-Disconnect 
        """
        self.sock.close()
        self.textview.insert("You have been disconnected.", 'yellow')
        self.ping_timeout = 0
        
    def handle_close(self, widget):
        """
            handle a click on Session-Close
        """ 
        gtk.main_quit()
        return False
            
    def send(self, widget, text):
        """ 
            a callback for events wanting to write to the socket
        """
        #report to textview
        try:
            self.sock.send(text)
        except socket.error:
            self.textview.insert("You are not connected.", 'yellow')
    def handle_about(self, widget):
        self.about_window.show_all()
           
    
    def poll(self):
        """
            poll the socket and see if there is any data to be processed.
            if so, loop through the packets and process all of it before 
            the next loop.
        """
        if self.sock.read():
            messages = []
            while self.sock.read():
                messages.append(self.sock.get_packet())
            for m in messages:
                parse_packet(self, m)
            self.sock.buf = ''
        return True

    def start_pings(self):
        pass#self.ping_timeout = gobject.timeout_add(6000, self.ping)