Exemplo n.º 1
0
    def __init__(self, win, url=None):
        super(Tab, self).__init__()
        self.icon = None
        self.loading = False
        self.win = win
        to_end = False
        # create the tab
        self.label = TabLabel(url or 'about:blank')
        self.label.connect("close", self.close_tab)
        self.label.show_all()
        if isinstance(url, basestring) or url is None:
            if url is None:
                to_end = True
                if win.app.conf.new_tab_show_home:
                    url = None
                else:
                    url = 'about:blank'
            self.browser = BrowserPage(self, win.browser_actions)
            self.browser.home = url is None#url == win.app.conf.home_url
            if url is None:
                self.browser.load_string(open(path.join(path.dirname(__file__),'speeddial.html')).read(), "text/html", "iso-8859-15", 'about:speeddial')
            else:
                self.browser.open(url)
        else:
            self.set_label_text(url.title)
            self.browser = url
            self.browser.tab = self
        self.inspector = Inspector(self.browser.get_web_inspector())

        self.scrolled_window = gtk.ScrolledWindow()
        self.scrolled_window.props.hscrollbar_policy = gtk.POLICY_AUTOMATIC
        self.scrolled_window.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC
        self.scrolled_window.add(self.browser)
        self.scrolled_window.show_all()
        self.pack_end(self.scrolled_window)

        self.label.child = self.scrolled_window

        new_tab_number = to_end and -1 or win.notebook.get_current_page()+1
        win.notebook.insert_page(self, self.label, new_tab_number)
        win.notebook.set_tab_reorderable(self, True)
        win.notebook.set_tab_detachable(self, True)
        win.notebook.set_tab_label_packing(self, False, False, gtk.PACK_START)
        win.notebook.set_tab_label(self, self.label)

        # hide the tab if there's only one
        win.notebook.set_show_tabs(win.notebook.get_n_pages() > 1)

        win.notebook.show_all()
        if to_end:
            win.notebook.set_current_page(new_tab_number)
            win.location.grab_focus()
Exemplo n.º 2
0
class Tab(gtk.VBox):
    def __init__(self, win, url=None):
        super(Tab, self).__init__()
        self.icon = None
        self.loading = False
        self.win = win
        to_end = False
        # create the tab
        self.label = TabLabel(url or 'about:blank')
        self.label.connect("close", self.close_tab)
        self.label.show_all()
        if isinstance(url, basestring) or url is None:
            if url is None:
                to_end = True
                if win.app.conf.new_tab_show_home:
                    url = None
                else:
                    url = 'about:blank'
            self.browser = BrowserPage(self, win.browser_actions)
            self.browser.home = url is None#url == win.app.conf.home_url
            if url is None:
                self.browser.load_string(open(path.join(path.dirname(__file__),'speeddial.html')).read(), "text/html", "iso-8859-15", 'about:speeddial')
            else:
                self.browser.open(url)
        else:
            self.set_label_text(url.title)
            self.browser = url
            self.browser.tab = self
        self.inspector = Inspector(self.browser.get_web_inspector())

        self.scrolled_window = gtk.ScrolledWindow()
        self.scrolled_window.props.hscrollbar_policy = gtk.POLICY_AUTOMATIC
        self.scrolled_window.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC
        self.scrolled_window.add(self.browser)
        self.scrolled_window.show_all()
        self.pack_end(self.scrolled_window)

        self.label.child = self.scrolled_window

        new_tab_number = to_end and -1 or win.notebook.get_current_page()+1
        win.notebook.insert_page(self, self.label, new_tab_number)
        win.notebook.set_tab_reorderable(self, True)
        win.notebook.set_tab_detachable(self, True)
        win.notebook.set_tab_label_packing(self, False, False, gtk.PACK_START)
        win.notebook.set_tab_label(self, self.label)

        # hide the tab if there's only one
        win.notebook.set_show_tabs(win.notebook.get_n_pages() > 1)

        win.notebook.show_all()
        if to_end:
            win.notebook.set_current_page(new_tab_number)
            win.location.grab_focus()

    def set_label_text(self, text):
        self.title = text or ''
        self.label.set_label_text(self.title)
        self.win.notebook.set_menu_label_text(self, self.title)

    def close_tab (self, label, child):
        page_num = self.win.notebook.page_num(self)
        if page_num != -1:
            self.browser.destroy()
            self.win.notebook.remove_page(page_num)
        if not self.win.notebook.get_n_pages():
            self.win.destroy()
        if not self.win.app.conf.always_show_tabs:# and self.win.app.conf.decorated:
            self.win.notebook.set_show_tabs(self.win.notebook.get_n_pages() > 1)

    def update_toolbar(self):
        if self.browser and self.win.active_tab == self:
            self.win.back.set_visible(self.browser.can_go_back())
            if self.browser.can_go_back():
                self.win.toolbar_back.show()
            else:
                self.win.toolbar_back.hide()
            if self.loading:
                self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
                self.browser.set_cursor('wait')
                self.win.toolbar_stop.show()
                self.win.toolbar_reload.hide()
            else:
                self.window.set_cursor(None)
                self.browser.set_cursor(None)
                self.win.location.set_progress_fraction(0.0)
                self.win.toolbar_stop.hide()
                self.win.toolbar_reload.show()
            if self.browser.url in self.win.app.bookmarks:
                icon = path.join(path.dirname(__file__),'favorite1.png')
            else:
                icon = path.join(path.dirname(__file__),'favorite0.png')
            pb = gtk.gdk.pixbuf_new_from_file(icon)
            self.win.location.set_icon_from_pixbuf(gtk.ENTRY_ICON_PRIMARY,gtk.gdk.pixbuf_new_from_file(icon))