def __init__(self): gtk.VBox.__init__(self) self.query = RestQuery() self.query.connect('response-available', self.__on_response_available) self.urlentry = gtk.Entry() self.urlentry.set_icon_from_stock(1, gtk.STOCK_EXECUTE) self.urlentry.set_text('http://www.velib.paris.fr/service/carto') self.urlentry.connect('activate', self.__on_urlentry_activated) self.urlentry.connect('icon-press', self.__on_urlentry_icon_press) url_toolitem = gtk.ToolItem() url_toolitem.add(self.urlentry) url_toolitem.set_tooltip_text("The REST resource URL") url_toolitem.set_expand(True) self.methodcombo = gtk.combo_box_new_text() self.methodcombo.append_text("GET") self.methodcombo.append_text("POST") self.methodcombo.append_text("PUT") self.methodcombo.append_text("DELETE") self.methodcombo.append_text("HEAD") self.methodcombo.append_text("OPTIONS") self.methodcombo.append_text("TRACE") self.methodcombo.set_active(0) method_toolitem = gtk.ToolItem() method_toolitem.add(self.methodcombo) method_toolitem.set_tooltip_text("The REST resource method") toolbar = gtk.Toolbar() toolbar.insert(method_toolitem, -1) toolbar.insert(url_toolitem, -1) self.set_homogeneous(False) self.pack_start(toolbar, False) self.request_form_view = HTTPRequestFormView() self.request_form_view.set_query(self.query) self.paned = gtk.HPaned() self.paned.set_position(200) self.paned.pack1(self.request_form_view) self.responseview = HTTPResponseViewer() self.responseview.set_query(self.query) self.responseframe = gtk.Frame("Response") self.responseframe.add(self.responseview) self.responseframe.set_shadow_type(gtk.SHADOW_NONE) self.paned.pack2(self.responseframe) self.pack_start(self.paned) self.show_all()
class RestView(gtk.VBox): __gsignals__ = { 'execute-request': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()) } ''' REST Resource view ''' def __init__(self): gtk.VBox.__init__(self) self.query = RestQuery() self.query.connect('response-available', self.__on_response_available) self.urlentry = gtk.Entry() self.urlentry.set_icon_from_stock(1, gtk.STOCK_EXECUTE) self.urlentry.set_text('http://www.velib.paris.fr/service/carto') self.urlentry.connect('activate', self.__on_urlentry_activated) self.urlentry.connect('icon-press', self.__on_urlentry_icon_press) url_toolitem = gtk.ToolItem() url_toolitem.add(self.urlentry) url_toolitem.set_tooltip_text("The REST resource URL") url_toolitem.set_expand(True) self.methodcombo = gtk.combo_box_new_text() self.methodcombo.append_text("GET") self.methodcombo.append_text("POST") self.methodcombo.append_text("PUT") self.methodcombo.append_text("DELETE") self.methodcombo.append_text("HEAD") self.methodcombo.append_text("OPTIONS") self.methodcombo.append_text("TRACE") self.methodcombo.set_active(0) method_toolitem = gtk.ToolItem() method_toolitem.add(self.methodcombo) method_toolitem.set_tooltip_text("The REST resource method") toolbar = gtk.Toolbar() toolbar.insert(method_toolitem, -1) toolbar.insert(url_toolitem, -1) self.set_homogeneous(False) self.pack_start(toolbar, False) self.request_form_view = HTTPRequestFormView() self.request_form_view.set_query(self.query) self.paned = gtk.HPaned() self.paned.set_position(200) self.paned.pack1(self.request_form_view) self.responseview = HTTPResponseViewer() self.responseview.set_query(self.query) self.responseframe = gtk.Frame("Response") self.responseframe.add(self.responseview) self.responseframe.set_shadow_type(gtk.SHADOW_NONE) self.paned.pack2(self.responseframe) self.pack_start(self.paned) self.show_all() def __on_urlentry_activated(self, entry): self.execute_request() def __on_urlentry_icon_press(self, entry, icon_pos, event): self.execute_request() def __fill_query(self): url = self.urlentry.get_text() if not (url.startswith('http://') or url.startswith('https://')): url = 'http://%s' % url model = self.methodcombo.get_model() active = self.methodcombo.get_active() method = model[active][0] if active < 0: method = "GET" self.query.url = url self.query.method = method self.request_form_view.fill_query(self.query) return self.query def execute_request(self): self.emit('execute-request') self.urlentry.set_icon_from_stock(1, gtk.STOCK_STOP) self.__fill_query().request() def __on_response_available(self, query, response): self.urlentry.set_icon_from_stock(1, gtk.STOCK_EXECUTE)