def set_session_state(self, states): while self.get_n_pages(): self.remove_page(self.get_n_pages() - 1) for state in states: if state['type'] == TAB_PDF: tab_page = PDFTabPage(state=state['state']) tab_page.browser.connect('new-tab', self.__new_tab_cb) tab_page.browser.connect('tab-close', self.__tab_close_cb) label = TabLabel(tab_page.browser) label.connect('tab-close', self.__tab_close_cb, tab_page) self.append_page(tab_page, label) tab_page.show() label.show() elif state['type'] == TAB_BROWSER: browser = Browser(self._activity, state=state['state']) browser.connect('new-tab', self.__new_tab_cb) browser.connect('enter-fullscreen', self.__enter_fullscreen_cb) browser.connect('leave-fullscreen', self.__leave_fullscreen_cb) browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb) browser.connect('ready-to-show', self.__web_view_ready_cb) browser.connect('create', self.__create_web_view_cb) browser.connect('web-process-crashed', self.__crashed_cb) self._append_tab(browser) else: logging.error('Encountered unknown tab state %r', state)
def set_history(self, tab_histories): if tab_histories and isinstance(tab_histories[0], dict): # Old format, no tabs tab_histories = [tab_histories] while self.get_n_pages(): self.remove_page(self.get_n_pages() - 1) def is_pdf_history(tab_history): return (len(tab_history) == 1 and tab_history[0]['url'].lower().endswith('pdf')) for tab_history in tab_histories: if is_pdf_history(tab_history): url = tab_history[0]['url'] tab_page = PDFTabPage() tab_page.browser.connect('new-tab', self.__new_tab_cb) tab_page.browser.connect('tab-close', self.__tab_close_cb) label = TabLabel(tab_page.browser) label.connect('tab-close', self.__tab_close_cb, tab_page) self.append_page(tab_page, label) tab_page.show() label.show() tab_page.setup(url, title=tab_history[0]['title']) else: browser = Browser() browser.connect('new-tab', self.__new_tab_cb) browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb) self._append_tab(browser) browser.set_history(tab_history)
def __open_pdf_in_new_tab_cb(self, browser, url): tab_page = PDFTabPage() tab_page.browser.connect('new-tab', self.__new_tab_cb) tab_page.browser.connect('tab-close', self.__tab_close_cb) label = TabLabel(tab_page.browser) label.connect('tab-close', self.__tab_close_cb, tab_page) next_index = self.get_current_page() + 1 self.insert_page(tab_page, label, next_index) tab_page.show() label.show() self.set_current_page(next_index) tab_page.setup(url)
def set_history(self, tab_histories): if tab_histories and isinstance(tab_histories[0], dict): # Old format, no tabs tab_histories = [tab_histories] while self.get_n_pages(): self.remove_page(self.get_n_pages() - 1) def is_pdf_history(tab_history): return (len(tab_history) == 1 and tab_history[0]['url'].lower().endswith('pdf')) for tab_history in tab_histories: if is_pdf_history(tab_history): url = tab_history[0]['url'] tab_page = PDFTabPage() tab_page.browser.connect('new-tab', self.__new_tab_cb) tab_page.browser.connect('tab-close', self.__tab_close_cb) label = TabLabel(tab_page.browser) label.connect('tab-close', self.__tab_close_cb, tab_page) self.append_page(tab_page, label) tab_page.show() label.show() tab_page.setup(url, title=tab_history[0]['title']) else: browser = Browser() browser.connect('new-tab', self.__new_tab_cb) browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb) browser.connect('web-view-ready', self.__web_view_ready_cb) browser.connect('create-web-view', self.__create_web_view_cb) self._append_tab(browser) browser.set_history(tab_history)
def set_legacy_history(self, tab_histories, currents): if tab_histories and isinstance(tab_histories[0], dict): # Old format, no tabs tab_histories = [tab_histories] currents = [currents] while self.get_n_pages(): self.remove_page(self.get_n_pages() - 1) def is_pdf_history(tab_history): return (len(tab_history) == 1 and tab_history[0]['url'].lower().endswith('pdf')) for tab_history, current in zip(tab_histories, currents): if is_pdf_history(tab_history): url = tab_history[0]['url'] tab_page = PDFTabPage() tab_page.browser.connect('new-tab', self.__new_tab_cb) tab_page.browser.connect('tab-close', self.__tab_close_cb) label = TabLabel(tab_page.browser) label.connect('tab-close', self.__tab_close_cb, tab_page) self.append_page(tab_page, label) tab_page.show() label.show() tab_page.setup(url, title=tab_history[0]['title']) else: browser = Browser(self._activity) browser.connect('new-tab', self.__new_tab_cb) browser.connect('enter-fullscreen', self.__enter_fullscreen_cb) browser.connect('leave-fullscreen', self.__leave_fullscreen_cb) browser.connect('open-pdf', self.__open_pdf_in_new_tab_cb) browser.connect('ready-to-show', self.__web_view_ready_cb) browser.connect('create', self.__create_web_view_cb) self._append_tab(browser) browser.set_legacy_history(tab_history, current)