Пример #1
0
class SampleGTKServer(object):

    def __init__(self):
        self.setup_gtk()
        self.setup_epc()

    def setup_gtk(self):
        gtk.threads_init()

        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        # Quit when window is closed
        self.window.connect("destroy", self.destroy)

        # Creates a new button
        self.button = gtk.Button("Push me!")
        self.button.connect("clicked", self.clicked, None)

        # Show widgets and window
        self.window.add(self.button)
        self.button.show()
        self.window.show()

    def setup_epc(self):
        self.server = ThreadingEPCServer(('localhost', 0), log_traceback=True)

        # Setup logger
        self.server.logger.setLevel(logging.DEBUG)
        ch = logging.FileHandler(filename='python-epc.log', mode='w')
        ch.setLevel(logging.DEBUG)
        self.server.logger.addHandler(ch)

        # Setup server thread
        self.server_thread = threading.Thread(target=self.server.serve_forever)
        self.server_thread.allow_reuse_address = True

        # Define and register RPC functions
        def destroy():
            gobject.idle_add(gtk.Widget.destroy, self.window)

        def set_button_label(label):
            gobject.idle_add(self.button.set_label, label)

        self.server.register_function(destroy)
        self.server.register_function(set_button_label)

    def clicked(self, widget, data=None):
        handler = self.server.clients[0]
        message = "Button '{0}' is clicked!".format(self.button.get_label())
        handler.call('message', [message])

    def destroy(self, widget, data=None):
        self.server.shutdown()
        gtk.main_quit()

    def main(self):
        self.server_thread.start()
        self.server.print_port()
        gtk.main()
Пример #2
0
    def toggle_console_info():
        global print_console_info
        
        print_console_info = not print_console_info
        
    def update_buffer():
        while True:
            for buffer in buffer_dict.values():
                buffer.redraw()

            time.sleep(0.05)

    server_thread.start()
    server.print_port()

    server.register_function(init)
    server.register_function(create_buffer)
    server.register_function(remove_buffer)
    server.register_function(adjust_size)
    server.register_function(update_views)
    server.register_function(focus_view)
    server.register_function(toggle_console_info)

    threading.Thread(target=update_buffer).start()

    active_window_watcher = ActiveWindowWatcher()
    active_window_watcher.activeWindowChanged.connect(handle_active_window)
    active_window_watcher.start()

    signal.signal(signal.SIGINT, signal.SIG_DFL)
    sys.exit(app.exec_())
Пример #3
0
        
    @postGui(False)    
    def hide():
        tray_view.hide()
        
    @postGui(False)    
    def set_minibuffer_allocation(x, y, w, h):
        tray_view.set_minibuffer_allocation(x, y, w, h)
        tray_view.update_allocation(tray_view.get_string_width())
        
    @postGui(False)    
    def update_pos(row, column, line_number):
        tray_view.update_pos(row, column, line_number)
        
    server_thread.start()
    server.print_port()
    
    server.register_function(init)
    server.register_function(hide)
    server.register_function(show)
    server.register_function(set_minibuffer_allocation)
    server.register_function(update_pos)
    
    # tray_view = TrayView(0, 24)
    # show()
    # tray_view.move(300, 300)
    # tray_view.resize(200, 30)
    
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    sys.exit(app.exec_())
Пример #4
0
         if buffer.view_dict.has_key(view_id):
             view = buffer.view_dict[view_id]
             view_xwindow_id = view.winId().__int__()
             grab_focus(view_xwindow_id)
             
 def update_buffer():
     while True:
         for buffer in buffer_dict.values():
             buffer.redraw()
         
         time.sleep(0.05)
         
 server_thread.start()
 server.print_port()
 
 server.register_function(init)
 server.register_function(create_buffer)
 server.register_function(remove_buffer)
 server.register_function(adjust_size)
 server.register_function(update_views)
 server.register_function(focus_view)
 
 threading.Thread(target=update_buffer).start()            
 
 active_window_watcher = ActiveWindowWatcher()
 active_window_watcher.activeWindowChanged.connect(handle_active_window)
 active_window_watcher.start()        
 
 # This function just for test python module.
 def test():
     emacs_xid = "106954839"
Пример #5
0
    @postGui(False)
    def hide():
        tray_view.hide()

    @postGui(False)
    def set_minibuffer_allocation(x, y, w, h):
        tray_view.set_minibuffer_allocation(x, y, w, h)
        tray_view.update_allocation(tray_view.get_string_width())

    @postGui(False)
    def update_pos(row, column, line_number):
        tray_view.update_pos(row, column, line_number)

    server_thread.start()
    server.print_port()

    server.register_function(init)
    server.register_function(hide)
    server.register_function(show)
    server.register_function(set_minibuffer_allocation)
    server.register_function(update_pos)

    # tray_view = TrayView(0, 24)
    # show()
    # tray_view.move(300, 300)
    # tray_view.resize(200, 30)

    signal.signal(signal.SIGINT, signal.SIG_DFL)
    sys.exit(app.exec_())
Пример #6
0
        return result


global browser
browser = EpcBrowser()
browser.setup()


def js_ex(string):
    print "js_ex "
    result = browser.js_ex(string)
    print result
    return result


server.register_function(js_ex)


def string_to_selected_cell(codeStr):
    jsCode = """
    return (function(codeStr) {
    var nb = IPython.notebook;
    var selCell = nb.get_selected_cell();
    selCell.set_text(codeStr);
    })(arguments[0]);
    """
    browser.js_ex(jsCode, codeStr)


server.register_function(string_to_selected_cell)
Пример #7
0
            if buffer.view_dict.has_key(view_id):
                view = buffer.view_dict[view_id]
                view_xwindow_id = view.winId().__int__()
                grab_focus(view_xwindow_id)

    def update_buffer():
        while True:
            for buffer in buffer_dict.values():
                buffer.redraw()

            time.sleep(0.05)

    server_thread.start()
    server.print_port()

    server.register_function(init)
    server.register_function(create_buffer)
    server.register_function(remove_buffer)
    server.register_function(adjust_size)
    server.register_function(update_views)
    server.register_function(focus_view)

    threading.Thread(target=update_buffer).start()

    active_window_watcher = ActiveWindowWatcher()
    active_window_watcher.activeWindowChanged.connect(handle_active_window)
    active_window_watcher.start()

    # This function just for test python module.
    def test():
        emacs_xid = "106954839"