def __init__(self): self.window = loader("window") self.notebook = loader("notebook1") self.menu = loader("appmenu") for a in self.apps: item = gtk.MenuItem(a[0]) self.menu.append(item) item.connect("activate", self.app_selected, a) self.back = loader("back") self.forward = loader("forward") self.reload = loader("reload") self.new = loader("new") self.location = loader("location") self.status = loader("status") self.back.connect("clicked", self.handle_back) self.forward.connect("clicked", self.handle_forward) self.reload.connect("clicked", self.handle_reload) self.new.connect("clicked", self.handle_new) self.location.connect("activate", self.handle_location) self.notebook.connect("switch-page", self.handle_switch_page) self.window.connect("destroy", gtk.main_quit) self.window.show_all() self.tabs = {} self.startup = Sync() self.startup.show() self.startup.connect("accepted", self.handle_startup)
class SilverLining(object): apps = (("new..", ("about:blank")), ("gmail", "http://mail.google.com"), ("google docs", "http://docs.google.com"), ("twitter", "http://www.twitter.com"), ("android market", "http://market.android.com/publish")) def __init__(self): self.window = loader("window") self.notebook = loader("notebook1") self.menu = loader("appmenu") for a in self.apps: item = gtk.MenuItem(a[0]) self.menu.append(item) item.connect("activate", self.app_selected, a) self.back = loader("back") self.forward = loader("forward") self.reload = loader("reload") self.new = loader("new") self.location = loader("location") self.status = loader("status") self.back.connect("clicked", self.handle_back) self.forward.connect("clicked", self.handle_forward) self.reload.connect("clicked", self.handle_reload) self.new.connect("clicked", self.handle_new) self.location.connect("activate", self.handle_location) self.notebook.connect("switch-page", self.handle_switch_page) self.window.connect("destroy", gtk.main_quit) self.window.show_all() self.tabs = {} self.startup = Sync() self.startup.show() self.startup.connect("accepted", self.handle_startup) def handle_startup(self, sync): print self.startup.username, self.startup.password, self.startup.passphrase def add_tab(self, app): tab = SessionTab(app[1], app[0]) ## this will invoke a page switch event, which depends on self.tabs, ## so order is important self.tabs[tab.child] = tab index = tab.add_to_notebook(self.notebook) tab.connect("close", self.close) tab.connect("status", self.handle_session_status) tab.connect("title", self.handle_session_title) tab.connect("location", self.handle_session_location) tab.show_all() tab.start(app[1], app[0]) self.notebook.set_current_page(index) self.update_status(tab) def current(self): return self.tabs[self.notebook.get_nth_page( self.notebook.get_current_page())] def update_status(self, tab): """ find the active tab and update the UI status widgets """ self.status.set_text(tab.status) self.window.set_title("SilverLining: " + tab.title) self.location.set_text(tab.location) print "Setting location to", tab.location ## local handlers def handle_switch_page(self, widget, page, num): child = self.notebook.get_nth_page(num) self.update_status(self.tabs[child]) def handle_back(self, widget): self.current().send("back") def handle_forward(self, widget): self.current().send("forward") def handle_reload(self, widget): self.current().send("reload") def handle_location(self, widget): url = self.location.get_text().strip() if not url: return if not (url.startswith("http:") or url.startswith("https:")): url = "http://" + url self.location.set_text(url) self.current().send("open " + url) def handle_new(self, widget): self.current().send("new about:blank") def app_selected(self, widget, app): self.add_tab(app) def close(self, tab): num = self.notebook.page_num(tab.socket) self.notebook.remove_page(num) tab.destroy() self.update_status(self.current()) ## session handlers def handle_session_status(self, tab): if tab == self.current(): self.status.set_text(tab.status) def handle_session_title(self, tab): if tab == self.current(): self.window.set_title("SilverLining: " + tab.title) def handle_session_location(self, tab): if tab == self.current(): self.location.set_text(tab.location)
class SilverLining(object): apps = (("new..", ("about:blank")), ("gmail", "http://mail.google.com"), ("google docs", "http://docs.google.com"), ("twitter", "http://www.twitter.com"), ("android market", "http://market.android.com/publish")) def __init__(self): self.window = loader("window") self.notebook = loader("notebook1") self.menu = loader("appmenu") for a in self.apps: item = gtk.MenuItem(a[0]) self.menu.append(item) item.connect("activate", self.app_selected, a) self.back = loader("back") self.forward = loader("forward") self.reload = loader("reload") self.new = loader("new") self.location = loader("location") self.status = loader("status") self.back.connect("clicked", self.handle_back) self.forward.connect("clicked", self.handle_forward) self.reload.connect("clicked", self.handle_reload) self.new.connect("clicked", self.handle_new) self.location.connect("activate", self.handle_location) self.notebook.connect("switch-page", self.handle_switch_page) self.window.connect("destroy", gtk.main_quit) self.window.show_all() self.tabs = {} self.startup = Sync() self.startup.show() self.startup.connect("accepted", self.handle_startup) def handle_startup(self, sync): print self.startup.username, self.startup.password, self.startup.passphrase def add_tab(self, app): tab = SessionTab(app[1], app[0]) ## this will invoke a page switch event, which depends on self.tabs, ## so order is important self.tabs[tab.child] = tab index = tab.add_to_notebook(self.notebook) tab.connect("close", self.close) tab.connect("status", self.handle_session_status) tab.connect("title", self.handle_session_title) tab.connect("location", self.handle_session_location) tab.show_all() tab.start(app[1], app[0]) self.notebook.set_current_page(index) self.update_status(tab) def current(self): return self.tabs[self.notebook.get_nth_page(self.notebook.get_current_page())] def update_status(self, tab): """ find the active tab and update the UI status widgets """ self.status.set_text(tab.status) self.window.set_title("SilverLining: " + tab.title) self.location.set_text(tab.location) print "Setting location to", tab.location ## local handlers def handle_switch_page(self, widget, page, num): child = self.notebook.get_nth_page(num) self.update_status(self.tabs[child]) def handle_back(self, widget): self.current().send("back") def handle_forward(self, widget): self.current().send("forward") def handle_reload(self, widget): self.current().send("reload") def handle_location(self, widget): url = self.location.get_text().strip() if not url: return if not (url.startswith("http:") or url.startswith("https:")): url = "http://" + url self.location.set_text(url) self.current().send("open " + url) def handle_new(self, widget): self.current().send("new about:blank") def app_selected(self, widget, app): self.add_tab(app) def close(self, tab): num = self.notebook.page_num(tab.socket) self.notebook.remove_page(num) tab.destroy() self.update_status(self.current()) ## session handlers def handle_session_status(self, tab): if tab == self.current(): self.status.set_text(tab.status) def handle_session_title(self, tab): if tab == self.current(): self.window.set_title("SilverLining: " + tab.title) def handle_session_location(self, tab): if tab == self.current(): self.location.set_text(tab.location)