Python gtk.Notebook() Examples

The following are 14 code examples of gtk.Notebook(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gtk , or try the search function .
Example #1
Source File: terminal.py    From NINJA-PingU with GNU General Public License v3.0 6 votes vote down vote up
def ensure_visible_and_focussed(self):
        """Make sure that we're visible and focussed"""
        window = self.get_toplevel()
        topchild = window.get_child()
        maker = Factory()

        if maker.isinstance(topchild, 'Notebook'):
            prevtmp = None
            tmp = self.get_parent()
            while tmp != topchild:
                prevtmp = tmp
                tmp = tmp.get_parent() 
            page = topchild.page_num(prevtmp)
            topchild.set_current_page(page)

        self.grab_focus() 
Example #2
Source File: notebook.py    From NINJA-PingU with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, window):
        """Class initialiser"""
        if isinstance(window.get_child(), gtk.Notebook):
            err('There is already a Notebook at the top of this window')
            raise(ValueError)

        Container.__init__(self)
        gtk.Notebook.__init__(self)
        self.terminator = Terminator()
        self.window = window
        gobject.type_register(Notebook)
        self.register_signals(Notebook)
        self.configure()

        child = window.get_child()
        window.remove(child)
        window.add(self)
        self.newtab(widget=child)

        self.show_all() 
Example #3
Source File: gnome_connection_manager.py    From gnome-connection-manager with GNU General Public License v3.0 6 votes vote down vote up
def check_notebook_pages(self, widget):
        if widget.get_n_pages()==0:
            #eliminar el notebook solo si queda otro notebook y no quedan tabs en el actual            
            paned = widget.get_parent()            
            if paned==None or paned==self.hpMain:
                return
            container = paned.get_parent()
            save = paned.get_child2() if paned.get_child1()==widget else paned.get_child1()    
            container.remove(paned)
            paned.remove(save)
            container.add(save)
            if widget == self.nbConsole:                
                if isinstance(save, gtk.Notebook):
                    self.nbConsole = save
                else:
                    self.nbConsole = self.find_notebook(save) 
Example #4
Source File: notebook.py    From NINJA-PingU with GNU General Public License v3.0 5 votes vote down vote up
def remove(self, widget):
        """Remove a widget from the container"""
        page_num = self.page_num(widget)
        if page_num == -1:
            err('%s not found in Notebook. Actual parent is: %s' % 
                    (widget, widget.get_parent()))
            return(False)
        self.remove_page(page_num)
        self.disconnect_child(widget)
        return(True) 
Example #5
Source File: notebook.py    From NINJA-PingU with GNU General Public License v3.0 5 votes vote down vote up
def update_tab_label_text(self, widget, text):
        """Update the text of a tab label"""
        notebook = self.find_tab_root(widget)
        label = self.get_tab_label(notebook)
        if not label:
            err('Notebook::update_tab_label_text: %s not found' % widget)
            return
        
        label.set_label(text) 
Example #6
Source File: notebook.py    From nightmare with GNU General Public License v2.0 5 votes vote down vote up
def prepNotebook(notebook=None, group=1):
    """
    Setup a notebook for use in vwindows/vviews.
    """
    if notebook == None:
        notebook = gtk.Notebook()
    if gtk.gtk_version[0] >= 2 and gtk.gtk_version[1] >= 12:
        notebook.connect("create-window", createNotebookWindow)
    notebook.set_group_id(group)
    return notebook 
Example #7
Source File: gnome_connection_manager.py    From gnome-connection-manager with GNU General Public License v3.0 5 votes vote down vote up
def find_notebook(self, widget, exclude=None):
        if widget!=exclude and isinstance(widget, gtk.Notebook):
            return widget
        else:
            if not hasattr(widget, "get_children"):
                return None
            for w in widget.get_children():
                wid = self.find_notebook(w, exclude)
                if wid!=exclude and isinstance(wid, gtk.Notebook):
                    return wid
            return None 
Example #8
Source File: gnome_connection_manager.py    From gnome-connection-manager with GNU General Public License v3.0 5 votes vote down vote up
def on_double_click(self, widget, event, *args):
        if event.type in [gtk.gdk._2BUTTON_PRESS, gtk.gdk._3BUTTON_PRESS] and event.button == 1:
            if isinstance(widget, gtk.Notebook):
                pos = event.x + widget.get_allocation().x
                size = widget.get_tab_label(widget.get_nth_page(widget.get_n_pages()-1)).get_allocation()
                if pos <= size.x + size.width + 2 * widget.get_property("tab-vborder") + 8 or event.x >= widget.get_allocation().width - widget.style_get_property("scroll-arrow-hlength"):
                    return True
            self.addTab(widget if isinstance(widget, gtk.Notebook) else self.nbConsole, 'local')
            return True
    #-- Wmain.on_double_click }

    #-- Wmain.on_btnLocal_clicked { 
Example #9
Source File: gnome_connection_manager.py    From gnome-connection-manager with GNU General Public License v3.0 5 votes vote down vote up
def on_btnLocal_clicked(self, widget, *args):        
        if self.current != None and self.current.get_parent()!=None and isinstance(self.current.get_parent().get_parent(), gtk.Notebook):
            ntbk = self.current.get_parent().get_parent()
        else:
            ntbk = self.nbConsole
        self.addTab(ntbk, 'local')
    #-- Wmain.on_btnLocal_clicked }

    #-- Wmain.on_btnConnect_clicked { 
Example #10
Source File: notebook.py    From NINJA-PingU with GNU General Public License v3.0 4 votes vote down vote up
def create_layout(self, layout):
        """Apply layout configuration"""
        def child_compare(a, b):
            order_a = children[a]['order']
            order_b = children[b]['order']

            if (order_a == order_b):
                return 0
            if (order_a < order_b):
                return -1
            if (order_a > order_b):
                return 1

        if not layout.has_key('children'):
            err('layout specifies no children: %s' % layout)
            return

        children = layout['children']
        if len(children) <= 1:
            #Notebooks should have two or more children
            err('incorrect number of children for Notebook: %s' % layout)
            return

        num = 0
        keys = children.keys()
        keys.sort(child_compare)

        for child_key in keys:
            child = children[child_key]
            dbg('Making a child of type: %s' % child['type'])
            if child['type'] == 'Terminal':
                pass
            elif child['type'] == 'VPaned':
                page = self.get_nth_page(num)
                self.split_axis(page, True)
            elif child['type'] == 'HPaned':
                page = self.get_nth_page(num)
                self.split_axis(page, False)
            num = num + 1

        num = 0
        for child_key in keys:
            page = self.get_nth_page(num)
            if not page:
                # This page does not yet exist, so make it
                self.newtab(children[child_key])
                page = self.get_nth_page(num)
            if layout.has_key('labels'):
                labeltext = layout['labels'][num]
                if labeltext and labeltext != "None":
                    label = self.get_tab_label(page)
                    label.set_custom_label(labeltext)
            page.create_layout(children[child_key])
            num = num + 1 
Example #11
Source File: notebook.py    From NINJA-PingU with GNU General Public License v3.0 4 votes vote down vote up
def split_axis(self, widget, vertical=True, cwd=None, sibling=None, widgetfirst=True):
        """Split the axis of a terminal inside us"""
        dbg('called for widget: %s' % widget)
        order = None
        page_num = self.page_num(widget)
        if page_num == -1:
            err('Notebook::split_axis: %s not found in Notebook' % widget)
            return

        label = self.get_tab_label(widget)
        self.remove(widget)

        maker = Factory()
        if vertical:
            container = maker.make('vpaned')
        else:
            container = maker.make('hpaned')

        if not sibling:
            sibling = maker.make('terminal')
            sibling.set_cwd(cwd)
            sibling.spawn_child()
            if widget.group and self.config['split_to_group']:
                sibling.set_group(None, widget.group)
        if self.config['always_split_with_profile']:
            sibling.force_set_profile(None, widget.get_profile())

        self.insert_page(container, None, page_num)
        self.set_tab_reorderable(container, True)
        self.set_tab_label(container, label)
        self.show_all()

        order = [widget, sibling]
        if widgetfirst is False:
            order.reverse()

        for terminal in order:
            container.add(terminal)
        self.set_current_page(page_num)

        self.show_all()
        terminal.grab_focus() 
Example #12
Source File: notebook.py    From NINJA-PingU with GNU General Public License v3.0 4 votes vote down vote up
def closetab(self, widget, label):
        """Close a tab"""
        tabnum = None
        try:
            nb = widget.notebook
        except AttributeError:
            err('TabLabel::closetab: called on non-Notebook: %s' % widget)
            return

        for i in xrange(0, nb.get_n_pages() + 1):
            if label == nb.get_tab_label(nb.get_nth_page(i)):
                tabnum = i
                break

        if tabnum is None:
            err('TabLabel::closetab: %s not in %s. Bailing.' % (label, nb))
            return

        maker = Factory()
        child = nb.get_nth_page(tabnum)

        if maker.isinstance(child, 'Terminal'):
            dbg('Notebook::closetab: child is a single Terminal')
            child.close()
            # FIXME: We only do this del and return here to avoid removing the
            # page below, which child.close() implicitly does
            del(label)
            return
        elif maker.isinstance(child, 'Container'):
            dbg('Notebook::closetab: child is a Container')
            dialog = self.construct_confirm_close(self.window, _('tab'))
            result = dialog.run()
            dialog.destroy()

            if result == gtk.RESPONSE_ACCEPT:
                containers = None
                objects = None
                containers, objects = enumerate_descendants(child)

                while len(objects) > 0:
                    descendant = objects.pop()
                    descendant.close()
                    while gtk.events_pending():
                        gtk.main_iteration()
                return
            else:
                dbg('Notebook::closetab: user cancelled request')
                return
        else:
            err('Notebook::closetab: child is unknown type %s' % child)
            return

        nb.remove_page(tabnum)
        del(label) 
Example #13
Source File: radmin.py    From rpy2 with GNU General Public License v2.0 4 votes vote down vote up
def __init__(self):
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        window.set_title("R")
        window.connect("delete_event", self.delete_event)
        window.connect("destroy", self.destroy)
        window.set_size_request(450, 500)

        notebook = gtk.Notebook()
        notebook.set_tab_pos(gtk.POS_LEFT)
        notebook.set_show_tabs(True)
        notebook.show()
        #vbox = gtk.VBox(homogeneous=False, spacing=0)
        #vbox.show()


        consolePanel = ConsolePanel()
        #tmp = robjects.baseenv["fifo"]("")
        #robjects.baseenv["sink"](tmp)
        
        #s = r.readLines(tmp)
        #r.close(tmp)
        #s = str.join(os.linesep, s._sexp)
        consolePanel.show()
        notebook.append_page(consolePanel, gtk.Label("Console"))

        codePanel = CodePanel()
        codePanel.show()
        notebook.append_page(codePanel, gtk.Label("Code"))

        # global env
        globalEnvPanel = EnvExplorer(robjects.globalenv)
        globalEnvPanel.show()
        notebook.append_page(globalEnvPanel, gtk.Label("globalEnv"))

        # global env
        grDevPanel = GraphicalDeviceExplorer()
        grDevPanel.show()
        notebook.append_page(grDevPanel, gtk.Label("Graphics"))

        # libraries/packages
        libPanel = LibraryPanel(console=consolePanel)
        libPanel.show()
        notebook.append_page(libPanel, gtk.Label("Libraries"))

        # vignettes
        vigPanel = VignetteExplorer()
        vigPanel.show()
        notebook.append_page(vigPanel, gtk.Label("Vignettes"))

        # doc
        docPanel = HelpExplorer()
        docPanel.show()
        notebook.append_page(docPanel, gtk.Label("Documentation"))

        window.add(notebook)

        window.show() 
Example #14
Source File: gnome_connection_manager.py    From gnome-connection-manager with GNU General Public License v3.0 4 votes vote down vote up
def split_notebook(self, direction):        
        csp = self.current.get_parent() if self.current!=None else None
        cnb = csp.get_parent() if csp!=None else None
        
        #Separar solo si hay mas de 2 tabs en el notebook actual
        if csp!=None and cnb.get_n_pages()>1:
            #Crear un hpaned, en el hijo 0 dejar el notebook y en el hijo 1 el nuevo notebook
            #El nuevo hpaned dejarlo como hijo del actual parent
            hp = gtk.HPaned() if direction==HSPLIT else gtk.VPaned()
            nb = gtk.Notebook()
            nb.set_group_id(11)
            nb.connect('button_press_event', self.on_double_click, None)
            nb.connect('page_removed', self.on_page_removed)
            nb.connect("page-added", self.on_page_added)
            nb.set_property("scrollable", True)
            cp  = cnb.get_parent()

            if direction==HSPLIT:
                cnb.set_size_request(cnb.allocation.width/2, cnb.allocation.height)
            else:                
                cnb.set_size_request(cnb.allocation.width, cnb.allocation.height/2)
            #cnb.set_size_request(cnb.allocation.width/2, cnb.allocation.height/2)
            
            cp.remove(cnb)
            cp.add(hp)
            hp.add1(cnb)                        
            
            text = cnb.get_tab_label(csp).get_text()
            
            csp.reparent(nb)
            csp = nb.get_nth_page(0)
                        
            tab = NotebookTabLabel(text, nb, csp, self.popupMenuTab)
            nb.set_tab_label(csp, tab_label=tab)
            nb.set_tab_reorderable(csp, True)
            nb.set_tab_detachable(csp, True)
                        
            hp.add2(nb)
            nb.show()
            hp.show()
            hp.queue_draw()
            self.current = cnb.get_nth_page(cnb.get_current_page()).get_children()[0]