Python gobject 模块,TYPE_STRING 实例源码

我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用gobject.TYPE_STRING

项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
def __init__(self, path="gnome-connection-manager.glade",
                 root="wHost",
                 domain=domain_name, **kwargs):
        path = os.path.join(glade_dir, path)
        SimpleGladeApp.__init__(self, path, root, domain, **kwargs)

        self.treeModel = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
        self.treeTunel.set_model(self.treeModel)
        column = gtk.TreeViewColumn(_("Local"), gtk.CellRendererText(), text=0)
        self.treeTunel.append_column( column )        
        column = gtk.TreeViewColumn(_("Host"), gtk.CellRendererText(), text=1)
        self.treeTunel.append_column( column )        
        column = gtk.TreeViewColumn(_("Remoto"), gtk.CellRendererText(), text=2)
        self.treeTunel.append_column( column )        


    #-- Whost.new {
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def setup_combo_box(self, cbo, items, initial_item=None):
        """initialise a given ComboBox"""
        #create items list
        cbo.clear()
        ls = gtk.ListStore(gobject.TYPE_STRING)
        cbo.set_model(ls)
        cell = gtk.CellRendererText()
        cbo.pack_start(cell, True)
        cbo.add_attribute(cell, 'text', 0)
        #populate items
        if items:
            for item in items:
                cbo.append_text(item)
            #set initial item?
            if initial_item:
                cbo.set_active(initial_item)
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def make_pixbuf_choice(options, default=None):
    store = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
    box = gtk.ComboBox(store)

    cell = gtk.CellRendererPixbuf()
    box.pack_start(cell, True)
    box.add_attribute(cell, "pixbuf", 0)

    cell = gtk.CellRendererText()
    box.pack_start(cell, True)
    box.add_attribute(cell, "text", 1)

    _default = None
    for pic, value in options:
        iter = store.append()
        store.set(iter, 0, pic, 1, value)
        if default == value:
            _default = options.index((pic, value))

    if _default:
        box.set_active(_default)

    return box
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def __init__(self, rthread, model):
        super(MappingNameEditor, self).__init__(rthread)
        self._model = model
        self._type = common.unpluralize(model.get_name())

        types = [(gobject.TYPE_STRING, "key"),
                 (gobject.TYPE_STRING, self._type),
                 (gobject.TYPE_STRING, _("Name"))]

        self.listw = miscwidgets.KeyedListWidget(types)
        self.listw.set_editable(1, True)
        self.listw.set_sort_column(0, 1)
        self.listw.set_sort_column(1, -1)
        self.listw.show()

        self.mappings = []

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.add_with_viewport(self.listw)

        self.root = sw
        self._loaded = False
项目:mgr.p2p.proxy    作者:tomusdrw    | 项目源码 | 文件源码
def createListStore(self, data):
        lstore = gtk.ListStore(gobject.TYPE_STRING)
        for item in data:
            iter = lstore.append()
            lstore.set(iter, 0, item)
        return lstore
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def people_treeview(self, create=True):
    row = None
    self.p_treemodel = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
    self.widgets['preferences']['treeview'].set_model(self.p_treemodel)
    self.widgets['preferences']['treeview'].set_headers_visible(True)

    if create is True:
        # name column
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_('Name'), renderer, text=0)
        column.set_resizable(True)
        column.set_sort_column_id(0)
        self.widgets['preferences']['treeview'].append_column(column)
        # email column
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_('E-mail'), renderer, text=1)
        column.set_resizable(True)
        column.set_sort_column_id(1)
        self.widgets['preferences']['treeview'].append_column(column)
    # add data to treeview
    self.p_treemodel.clear()
    for i in self.db.session.query(db.Person.name, db.Person.email).order_by(db.Person.name.asc()):
        myiter = self.p_treemodel.insert_before(None, None)
        self.p_treemodel.set_value(myiter, 0, i.name)
        self.p_treemodel.set_value(myiter, 1, i.email)
    self.widgets['preferences']['treeview'].show()
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
def initLeftPane(self):
        global groups       

        self.treeModel = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gtk.gdk.Pixbuf)
        self.treeServers.set_model(self.treeModel)

        self.treeServers.set_level_indentation(5)
        #Force the alternating row colors, by default it's off with one column
        self.treeServers.set_property('rules-hint', True)
        gtk.rc_parse_string( """
                style "custom-treestyle"{
                    GtkTreeView::allow-rules = 1
                }
                widget "*treeServers*" style "custom-treestyle"
            """)
        column = gtk.TreeViewColumn()
        column.set_title('Servers')
        self.treeServers.append_column( column )

        renderer = gtk.CellRendererPixbuf()
        column.pack_start(renderer, expand=False)
        column.add_attribute(renderer, 'pixbuf', 2)

        renderer = gtk.CellRendererText()
        column.pack_start(renderer, expand=True)
        column.add_attribute(renderer, 'text', 0)

        self.treeServers.set_has_tooltip(True)
        self.treeServers.connect('query-tooltip', self.on_treeServers_tooltip)
        self.loadConfig()
        self.updateTree()
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
def new(self):        
        self.treeHosts = self.get_widget('treeHosts')
        self.treeStore = gtk.TreeStore( gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_OBJECT )
        for x in self.terms:
            self.treeStore.append( None, (False, x[0], x[1]) )
        self.treeHosts.set_model( self.treeStore )               

        crt = gtk.CellRendererToggle()
        crt.set_property('activatable', True)
        crt.connect('toggled', self.on_active_toggled)        
        col = gtk.TreeViewColumn(_("Activar"), crt, active=0)               
        self.treeHosts.append_column( col )
        self.treeHosts.append_column(gtk.TreeViewColumn(_("Host"), gtk.CellRendererText(), text=1 ))
        self.get_widget("txtCommands").history = []
    #-- Wcluster.new }

    #-- Wcluster custom methods {
    #   Write your own methods here
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def setup_combo_box_entry(self, cboe, initial_text=None):
        """initialise a given ComboBoxEntry"""
        #create items list
        ls = gtk.ListStore(gobject.TYPE_STRING)
        cboe.set_model(ls)
        cboe.set_text_column(0)
        #populate with text?
        if initial_text:
            ls.append((initial_text, ))
            cboe.child.set_text(initial_text)
项目:Automation-Framework-for-devices    作者:tok-gogogo    | 项目源码 | 文件源码
def __init__(self):
        self.model = gtk.ListStore(gobject.TYPE_STRING)
        self.nameEntry = gtk.Entry()
        self.buttons = []
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def _build_ui(self):
        self._display = gtk.Table(20, 2)

        self._store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
        self._tree = gtk.TreeView(self._store)

        rend = gtk.CellRendererText()
        tvc = gtk.TreeViewColumn('Element', rend, text=0)
        self._tree.append_column(tvc)
        self._tree.connect('button_press_event', self._tree_click)
        self._tree.set_size_request(200, -1)

        self.root = gtk.HBox(False, 3)
        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.add(self._tree)
        sw.show()
        self.root.pack_start(sw, 0, 0, 0)
        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.add_with_viewport(self._display)
        sw.show()
        self.root.pack_start(sw, 1, 1, 1)
        self._tree.show()
        self._display.show()
        self.root.show()
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def _make_view(self):
        colnum = -1

        for typ, cap in self.columns:
            colnum += 1
            if colnum == 0:
                continue  # Key column

            if typ in [gobject.TYPE_STRING, gobject.TYPE_INT,
                       gobject.TYPE_FLOAT]:
                rend = gtk.CellRendererText()
                rend.set_property("ellipsize", pango.ELLIPSIZE_END)
                column = gtk.TreeViewColumn(cap, rend, text=colnum)
            elif typ in [gobject.TYPE_BOOLEAN]:
                rend = gtk.CellRendererToggle()
                rend.connect("toggled", self._toggle, colnum)
                column = gtk.TreeViewColumn(cap, rend, active=colnum)
            else:
                raise Exception("Unsupported type %s" % typ)

            column.set_sort_column_id(colnum)
            self.__view.append_column(column)

        self.__view.connect("button_press_event", self._mouse)
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def make_view(self, columns):
        self._view = gtk.TreeView(self._store)

        for _type, _col in columns:
            if _col.startswith("__"):
                continue

            index = columns.index((_type, _col))
            if _type == gobject.TYPE_STRING or \
                    _type == gobject.TYPE_INT or \
                    _type == gobject.TYPE_FLOAT:
                rend = gtk.CellRendererText()
                column = gtk.TreeViewColumn(_col, rend, text=index)
                column.set_resizable(True)
                rend.set_property("ellipsize", pango.ELLIPSIZE_END)
            elif _type == gobject.TYPE_BOOLEAN:
                rend = gtk.CellRendererToggle()
                rend.connect("toggled", self._toggle, index)
                column = gtk.TreeViewColumn(_col, rend, active=index)
            else:
                raise Exception("Unknown column type (%i)" % index)

            column.set_sort_column_id(index)
            self._view.append_column(column)

        self._view.connect("button_press_event", self.mouse_cb)
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def __init__(self, rthread):
        super(SettingsEditor, self).__init__(rthread)

        # The main box
        self.root = gtk.HBox(False, 0)

        # The pane
        paned = gtk.HPaned()
        paned.show()
        self.root.pack_start(paned, 1, 1, 0)

        # The selection tree
        self._store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_INT)
        self._view = gtk.TreeView(self._store)
        self._view.get_selection().connect("changed", self._view_changed_cb)
        self._view.append_column(
            gtk.TreeViewColumn("", gtk.CellRendererText(), text=0))
        self._view.show()
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scrolled_window.add_with_viewport(self._view)
        scrolled_window.set_size_request(200, -1)
        scrolled_window.show()
        paned.pack1(scrolled_window)

        # The settings notebook
        self._notebook = gtk.Notebook()
        self._notebook.set_show_tabs(False)
        self._notebook.set_show_border(False)
        self._notebook.show()
        paned.pack2(self._notebook)

        self._changed = False
        self._settings = None

        job = common.RadioJob(self._get_settings_cb, "get_settings")
        job.set_desc("Getting radio settings")
        self.rthread.submit(job)
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def setup_iconview(self, columns, column_types, container, changed_cb=None, activate_cb=None, text_style='text'):
        """ Create a ready-to-use (list based) iconview widget (GTK+2.6 and baove)
        Parameters:
            columns      : List of column names (should only be two - one for icon & one for description)
            column_types : List of variable types for each column
                           (eg. [gobject.TYPE_STRING, gobject.TYPE_LONG])
            container    : reference to widget that is to contain list,
                           almost always a scrolled window - gtk.ScrolledWindow()
            changed_cb   : the callback function for the "changed" TreeViewSelection signal
            activate_cb  : the callback function for the "changed" TreeViewSelection signal
            text_style   : 'text' for normail plain text,
                           'markup' for pango marked-up text
        Returns:
            Reference to IconView and ListStore widgets

        e.g. to create a four column (first two displayed, rest hidden) icon view...
            self.tvwProjects, self.lsProjects, self.tvwsProjects = self.setup_treeview(
                ['Picture', 'Desc'],
                [gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_LONG, gobject.TYPE_STRING],
                self.scwPictures,
                self.on_tvwsPictures_changed,
                None
                'text')
        """
        #create the ListStore and IconView objects
        ls = gtk.ListStore(*column_types)
        ivw = gtk.IconView(ls)
        #set columns
        for i in range(len(columns)):
            if column_types[i] != gtk.gdk.Pixbuf:
                #create text renderer
                tvwRendererText = gtk.CellRendererText()
                tvwRendererText.set_property('yalign', 0.0)
                if text_style == 'markup':
                    #markup text rendering
                    column = gtk.TreeViewColumn(columns[i], tvwRendererText, markup=i)
                    ivw.set_markup_column(i)
                else:
                    #default text rendering
                    column = gtk.TreeViewColumn(columns[i], tvwRendererText, text=i)
                    ivw.set_text_column(i)
            else:
                #create pixbuf renderer
                tvwRendererPixbuf = gtk.CellRendererPixbuf()
                column = gtk.TreeViewColumn(columns[i], tvwRendererPixbuf, pixbuf=i)
                ivw.set_pixbuf_column(i)
        #display it (add iconview to given widget)
        container.add(ivw)
        ivw.show()
        #connect callbacks
        if changed_cb:
            ivw.connect('selection_changed', changed_cb)
        if activate_cb:
            ivw.connect('item_activated', activate_cb)
        #done
        return ivw, ls
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def test():
    win = gtk.Window(gtk.WINDOW_TOPLEVEL)
    lst = ListWidget([(gobject.TYPE_STRING, "Foo"),
                      (gobject.TYPE_BOOLEAN, "Bar")])

    lst.add_item("Test1", True)
    lst.set_values([("Test2", True), ("Test3", False)])

    lst.show()
    win.add(lst)
    win.show()

    win1 = ProgressDialog("foo")
    win1.show()

    win2 = gtk.Window(gtk.WINDOW_TOPLEVEL)
    lle = LatLonEntry()
    lle.show()
    win2.add(lle)
    win2.show()

    win3 = gtk.Window(gtk.WINDOW_TOPLEVEL)
    lst = TreeWidget([(gobject.TYPE_STRING, "Id"),
                      (gobject.TYPE_STRING, "Value")],
                     1)
    lst.set_values({"Fruit": [("Apple", "Red"), ("Orange", "Orange")],
                    "Pizza": [("Cheese", "Simple"), ("Pepperoni", "Yummy")]})
    lst.add_item("Fruit", "Bananna", "Yellow")
    lst.show()
    win3.add(lst)
    win3.show()

    def print_val(entry):
        if entry.validate():
            print "Valid: %s" % entry.value()
        else:
            print "Invalid"
    lle.connect("activate", print_val)

    lle.set_text("45 13 12")

    try:
        gtk.main()
    except KeyboardInterrupt:
        pass

    print lst.get_values()
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def make_view(self):
        editable = [self.col_nloc, self.col_name, self.col_comm]

        self.__store = gtk.ListStore(gobject.TYPE_BOOLEAN,  # Import
                                     gobject.TYPE_INT,      # Source loc
                                     gobject.TYPE_INT,      # Destination loc
                                     gobject.TYPE_STRING,   # Name
                                     gobject.TYPE_STRING,   # Frequency
                                     gobject.TYPE_STRING,   # Comment
                                     gobject.TYPE_BOOLEAN,
                                     gobject.TYPE_STRING)
        self.__view = gtk.TreeView(self.__store)
        self.__view.show()

        tips = gtk.Tooltips()

        for k in self.caps.keys():
            t = self.types[k]

            if t == gobject.TYPE_BOOLEAN:
                rend = gtk.CellRendererToggle()
                rend.connect("toggled", self._toggle, k)
                column = gtk.TreeViewColumn(self.caps[k], rend,
                                            active=k,
                                            sensitive=self.col_okay,
                                            activatable=self.col_okay)
            else:
                rend = gtk.CellRendererText()
                if k in editable:
                    rend.set_property("editable", True)
                    rend.connect("edited", self._edited, k)
                column = gtk.TreeViewColumn(self.caps[k], rend,
                                            text=k,
                                            sensitive=self.col_okay)

            if k == self.col_nloc:
                column.set_cell_data_func(rend, self._render, k)

            if k in self.tips.keys():
                LOG.debug("Doing %s" % k)
                lab = gtk.Label(self.caps[k])
                column.set_widget(lab)
                tips.set_tip(lab, self.tips[k])
                lab.show()
            column.set_sort_column_id(k)
            self.__view.append_column(column)

        self.__view.set_tooltip_column(self.col_tmsg)

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.add(self.__view)
        sw.show()

        return sw
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def __init__(self, src_radio, dst_radio, parent=None):
        gtk.Dialog.__init__(self,
                            buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
                                     gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL),
                            title=self.TITLE,
                            parent=parent)

        self.col_import = 0
        self.col_nloc = 1
        self.col_oloc = 2
        self.col_name = 3
        self.col_freq = 4
        self.col_comm = 5
        self.col_okay = 6
        self.col_tmsg = 7

        self.caps = {
            self.col_import:  self.ACTION,
            self.col_nloc:    _("To"),
            self.col_oloc:    _("From"),
            self.col_name:    _("Name"),
            self.col_freq:    _("Frequency"),
            self.col_comm:    _("Comment"),
            }

        self.tips = {
            self.col_nloc:  _("Location memory will be imported into"),
            self.col_oloc:  _("Location of memory in the file being imported"),
            }

        self.types = {
            self.col_import:  gobject.TYPE_BOOLEAN,
            self.col_oloc:    gobject.TYPE_INT,
            self.col_nloc:    gobject.TYPE_INT,
            self.col_name:    gobject.TYPE_STRING,
            self.col_freq:    gobject.TYPE_STRING,
            self.col_comm:    gobject.TYPE_STRING,
            self.col_okay:    gobject.TYPE_BOOLEAN,
            self.col_tmsg:    gobject.TYPE_STRING,
            }

        self.src_radio = src_radio
        self.dst_radio = dst_radio

        self.used_list = []
        self.not_used_list = []

        self.build_ui()
        self.set_default_size(600, 400)

        self.ww = WaitWindow(_("Preparing memory list..."), parent=parent)
        self.ww.show()
        self.ww.grind()

        self.populate_list()

        self.ww.hide()