Python gi.repository.GObject 模块,TYPE_STRING 实例源码

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

项目:pycam    作者:SebKuzminsky    | 项目源码 | 文件源码
def __init__(self, choices, change_handler=None):
        self.model = gtk.ListStore(GObject.TYPE_STRING)
        self._values = []
        for label, value in choices:
            self.model.append((label,))
            self._values.append(value)
        renderer = gtk.CellRendererText()
        self.control = gtk.ScrolledWindow()
        self.control.show()
        self._treeview = gtk.TreeView(self.model)
        self._treeview.show()
        self.control.add(self._treeview)
        self.control.set_shadow_type(gtk.ShadowType.ETCHED_OUT)
        self.control.set_policy(gtk.PolicyType.AUTOMATIC, gtk.PolicyType.AUTOMATIC)
        # Sadly there seems to be no way to adjust the size of the ScrolledWindow to its content.
        # The default size of the ScrolledWindow is too small (making it hard to select the model).
        self.control.set_size_request(200, -1)
        column = gtk.TreeViewColumn()
        column.pack_start(renderer, expand=False)
        column.set_attributes(renderer, text=0)
        self._treeview.append_column(column)
        self._treeview.set_headers_visible(False)
        self._selection = self._treeview.get_selection()
        self._selection.set_mode(gtk.SelectionMode.MULTIPLE)
        self.connect("changed", change_handler, self._selection)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, icons):
        super(OneConfViews, self).__init__()
        model = Gtk.ListStore(GdkPixbuf.Pixbuf, GObject.TYPE_STRING,
            GObject.TYPE_STRING)
        model.set_sort_column_id(self.COL_HOSTNAME, Gtk.SortType.ASCENDING)
        model.set_sort_func(self.COL_HOSTNAME, self._sort_hosts)
        self.set_model(model)
        self.set_headers_visible(False)
        self.col = Gtk.TreeViewColumn('hostname')

        hosticon_renderer = Gtk.CellRendererPixbuf()
        hostname_renderer = Gtk.CellRendererText()
        self.col.pack_start(hosticon_renderer, False)
        self.col.add_attribute(hosticon_renderer, 'pixbuf', self.COL_ICON)
        self.col.pack_start(hostname_renderer, True)
        self.col.add_attribute(hostname_renderer, 'text', self.COL_HOSTNAME)
        self.append_column(self.col)
        self.current_hostid = None
        self.hostids = []

        # TODO: load the dynamic one (if present), later
        self.default_computer_icon = icons.load_icon("computer", 22, 0)

        self.connect("cursor-changed", self.on_cursor_changed)
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def __init__(self, icons):
        super(OneConfViews, self).__init__()
        model = Gtk.ListStore(GdkPixbuf.Pixbuf, GObject.TYPE_STRING,
            GObject.TYPE_STRING)
        model.set_sort_column_id(self.COL_HOSTNAME, Gtk.SortType.ASCENDING)
        model.set_sort_func(self.COL_HOSTNAME, self._sort_hosts)
        self.set_model(model)
        self.set_headers_visible(False)
        self.col = Gtk.TreeViewColumn('hostname')

        hosticon_renderer = Gtk.CellRendererPixbuf()
        hostname_renderer = Gtk.CellRendererText()
        self.col.pack_start(hosticon_renderer, False)
        self.col.add_attribute(hosticon_renderer, 'pixbuf', self.COL_ICON)
        self.col.pack_start(hostname_renderer, True)
        self.col.add_attribute(hostname_renderer, 'text', self.COL_HOSTNAME)
        self.append_column(self.col)
        self.current_hostid = None
        self.hostids = []

        # TODO: load the dynamic one (if present), later
        self.default_computer_icon = icons.load_icon("computer", 22, 0)

        self.connect("cursor-changed", self.on_cursor_changed)
项目:pycam    作者:SebKuzminsky    | 项目源码 | 文件源码
def __init__(self, choices, start=None, change_handler=None):
        self.model = gtk.ListStore(GObject.TYPE_STRING)
        self._values = []
        for label, value in choices:
            self.model.append((label, ))
            self._values.append(value)
        renderer = gtk.CellRendererText()
        self.control = gtk.ComboBox.new_with_model(self.model)
        self.control.pack_start(renderer, expand=False)
        self.control.add_attribute(renderer, 'text', 0)
        if start is None:
            self.control.set_active(0)
        else:
            self.set_value(start)
        self.connect("changed", change_handler)
项目:isar    作者:ilbers    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title("Dependency Explorer")
        self.set_default_size(500, 500)
        self.connect("delete-event", Gtk.main_quit)

        # Create the data models
        self.pkg_model = Gtk.ListStore(GObject.TYPE_STRING)
        self.pkg_model.set_sort_column_id(COL_PKG_NAME, Gtk.SortType.ASCENDING)
        self.depends_model = Gtk.ListStore(GObject.TYPE_INT, GObject.TYPE_STRING, GObject.TYPE_STRING)
        self.depends_model.set_sort_column_id(COL_DEP_PACKAGE, Gtk.SortType.ASCENDING)

        pane = Gtk.HPaned()
        pane.set_position(250)
        self.add(pane)

        # The master list of packages
        scrolled = Gtk.ScrolledWindow()
        scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scrolled.set_shadow_type(Gtk.ShadowType.IN)

        self.pkg_treeview = Gtk.TreeView(self.pkg_model)
        self.pkg_treeview.get_selection().connect("changed", self.on_cursor_changed)
        column = Gtk.TreeViewColumn("Package", Gtk.CellRendererText(), text=COL_PKG_NAME)
        self.pkg_treeview.append_column(column)
        pane.add1(scrolled)
        scrolled.add(self.pkg_treeview)

        box = Gtk.VBox(homogeneous=True, spacing=4)

        # Runtime Depends
        scrolled = Gtk.ScrolledWindow()
        scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scrolled.set_shadow_type(Gtk.ShadowType.IN)
        self.rdep_treeview = PackageDepView(self.depends_model, TYPE_RDEP, "Runtime Depends")
        self.rdep_treeview.connect("row-activated", self.on_package_activated, COL_DEP_PACKAGE)
        scrolled.add(self.rdep_treeview)
        box.add(scrolled)

        # Build Depends
        scrolled = Gtk.ScrolledWindow()
        scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scrolled.set_shadow_type(Gtk.ShadowType.IN)
        self.dep_treeview = PackageDepView(self.depends_model, TYPE_DEP, "Build Depends")
        self.dep_treeview.connect("row-activated", self.on_package_activated, COL_DEP_PACKAGE)
        scrolled.add(self.dep_treeview)
        box.add(scrolled)
        pane.add2(box)

        # Reverse Depends
        scrolled = Gtk.ScrolledWindow()
        scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scrolled.set_shadow_type(Gtk.ShadowType.IN)
        self.revdep_treeview = PackageReverseDepView(self.depends_model, "Reverse Depends")
        self.revdep_treeview.connect("row-activated", self.on_package_activated, COL_DEP_PARENT)
        scrolled.add(self.revdep_treeview)
        box.add(scrolled)
        pane.add2(box)

        self.show_all()
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def create_idtone_accels_config(self, parent):
        it, page_vbox = self.new_page_box(parent, _("Identify tone keyboard accelerators"))
        self.g_idtone_accels = Gtk.ListStore(GObject.TYPE_STRING,
            GObject.TYPE_STRING)
        notenames = ('c', 'cis', 'd', 'dis', 'e', 'f', 'fis',
                     'g', 'gis', 'a', 'ais', 'b')
        for notename in notenames:
            self.g_idtone_accels.append((
                solfege.mpd.MusicalPitch.new_from_notename(notename).get_user_notename(),
                cfg.get_string('idtone/tone_%s_ak' % notename)))
        self.g_treeview = Gtk.TreeView(self.g_idtone_accels)
        renderer = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn(_("Note name"), renderer, text=0)
        self.g_treeview.append_column(column)
        renderer = Gtk.CellRendererAccel()
        renderer.set_property('editable', True)

        def acc_ff(renderer, path, accel_key, accel_mods, hw_key):
            is_unique = True
            for notename in notenames:
                if (notename != notenames[int(path)]
                    and cfg.get_string('idtone/tone_%s_ak' % notename) == unichr(accel_key)):
                    is_unique = False
                    break

            if not is_unique:
                gu.dialog_ok(_(u"The accelerator in use for the tone “%s”. You have to choose another key.") % solfege.mpd.MusicalPitch.new_from_notename(notename).get_user_notename(), parent=self, msgtype=Gtk.MessageType.ERROR)
                return
            it = self.g_idtone_accels.get_iter(path)
            cfg.set_string('idtone/tone_%s_ak' % notenames[int(path)], unichr(accel_key))
            self.g_idtone_accels.set(it, 1, unichr(accel_key))
            return True
        renderer.connect('accel-edited', acc_ff)
        column = Gtk.TreeViewColumn(_i("keyboard|Key"), renderer, text=1)
        self.g_treeview.append_column(column)
        page_vbox.pack_start(self.g_treeview, True, True, 0)
        layouts = {'ascii': (_('ASCII'), u'awsedfujikol'),
                   'dvorak': (_('Dvorak'), u'a,o.eughctrn'),
        }
        hbox = Gtk.HBox()
        page_vbox.pack_start(hbox, False, False, 0)

        def set_buttons(widget, layout):
            v = layouts[layout][1]
            idx = 0
            it = self.g_idtone_accels.get_iter_first()
            while True:
                self.g_idtone_accels.set_value(it, 1, v[idx])
                cfg.set_string('idtone/tone_%s_ak' % notenames[idx], v[idx])
                it = self.g_idtone_accels.iter_next(it)
                idx += 1
                if not it:
                    break
        for key in layouts:
            btn = Gtk.Button(layouts[key][0])
            btn.connect('clicked', set_buttons, key)
            hbox.pack_start(btn, True, True, 0)
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def create_interval_accels_config(self, parent):
        it, page_vbox = self.new_page_box(parent, _("Interval keyboard accelerators"))
        self.g_interval_accels = Gtk.ListStore(GObject.TYPE_STRING,
            GObject.TYPE_STRING)
        intervals = ['minor2', 'major2', 'minor3', 'major3',
                     'perfect4', 'diminished5', 'perfect5', 'minor6',
                     'major6', 'minor7', 'major7', 'perfect8',
                     'minor9', 'major9', 'minor10', 'major10']
        for interval in intervals:
            self.g_interval_accels.append((
                mpd.Interval.new_from_int(intervals.index(interval)).get_name(),
                cfg.get_string('interval_input/%s' % interval)))
        self.g_intervals_treeview = Gtk.TreeView(self.g_interval_accels)
        renderer = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn(_("Interval"), renderer, text=0)
        self.g_intervals_treeview.append_column(column)
        renderer = Gtk.CellRendererAccel()
        renderer.set_property('editable', True)

        def acc_ff(renderer, path, accel_key, accel_mods, hw_key):
            is_unique = True
            for interval in intervals:
                if (interval != intervals[int(path)]
                    and cfg.get_string('interval_input/%s' % interval) == unichr(accel_key)):
                    is_unique = False
                    break

            if not is_unique:
                gu.dialog_ok(_(u"The accelerator in use for “%s”. You have to choose another key.") % mpd.Interval.new_from_int(intervals.index(interval)).get_name(), parent=self, msgtype=Gtk.MessageType.ERROR)
                return
            it = self.g_interval_accels.get_iter(path)
            cfg.set_string('interval_input/%s' % intervals[int(path)], unichr(accel_key))
            self.g_interval_accels.set(it, 1, unichr(accel_key))
            return True
        renderer.connect('accel-edited', acc_ff)
        column = Gtk.TreeViewColumn(_i("keyboard|Key"), renderer, text=1)
        self.g_intervals_treeview.append_column(column)
        page_vbox.pack_start(self.g_intervals_treeview, True, True, 0)
        hbox = Gtk.HBox()
        page_vbox.pack_start(hbox, False, False, 0)
        layouts = {'ascii': (_('ASCII'), u'1qaz2wsx3edc4rfv'),
                   'dvorak': (_('Dvorak'), u"1'a;2,oq3.ej4puk"),
        }

        def set_buttons(widget, layout):
            v = layouts[layout][1]
            idx = 0
            it = self.g_interval_accels.get_iter_first()
            while True:
                self.g_interval_accels.set_value(it, 1, v[idx])
                cfg.set_string('interval_input/%s' % intervals[idx], v[idx])
                it = self.g_interval_accels.iter_next(it)
                idx += 1

                if not it:
                    break
        for key in layouts:
            btn = Gtk.Button(layouts[key][0])
            btn.connect('clicked', set_buttons, key)
            hbox.pack_start(btn, True, True, 0)
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def __init__(self, default_profile):
        Gtk.Dialog.__init__(self, _("GNU Solfege - Choose User Profile"))
        # We save the initially selected profile, because we need to keep
        # track of it if the user renames it and then presses cancel.
        self.m_default_profile = default_profile
        vbox = gu.hig_dlg_vbox()
        self.vbox.pack_start(vbox, False, False, 0)
        l = Gtk.Label(_("Solfege will save your statistics and test results in the user profile. By adding additional user profiles to Solfege, multiple users can share a user account on the operating system."))
        l.set_alignment(0.0, 0.5)
        l.set_line_wrap(True)
        vbox.pack_start(l, True, True, 0)

        hbox = Gtk.HBox()
        hbox.set_spacing(gu.hig.SPACE_MEDIUM)
        vbox.pack_start(hbox, True, True, 0)
        button_box = Gtk.VBox()

        self.g_create_profile = Gtk.Button.new_with_mnemonic(_(u"_Create profile\u2026"))
        self.g_create_profile.connect('clicked', self.on_create_profile)
        button_box.pack_start(self.g_create_profile, False, False, 0)

        self.g_rename_profile = Gtk.Button.new_with_mnemonic(_(u"_Rename profile\u2026"))
        self.g_rename_profile.connect('clicked', self.on_rename_profile)
        button_box.pack_start(self.g_rename_profile, False, False, 0)

        self.g_delete_profile = Gtk.Button.new_with_mnemonic(_(u"_Delete profile\u2026"))
        self.g_delete_profile.connect('clicked', self.on_delete_profile)
        button_box.pack_start(self.g_delete_profile, False, False, 0)

        hbox.pack_start(button_box, False, False, 0)
        self.g_liststore = liststore = Gtk.ListStore(GObject.TYPE_STRING)
        liststore.append((_("Standard profile"),))
        if os.path.exists(os.path.join(filesystem.app_data(), 'profiles')):
            for subdir in os.listdir(os.path.join(filesystem.app_data(),
                'profiles')):
                liststore.append((subdir,))
        #
        self.g_tw = tw = Gtk.TreeView(liststore)
        tw.connect('row-activated', lambda a, b, c: self.response(Gtk.ResponseType.ACCEPT))
        tw.set_headers_visible(False)
        renderer = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn(None, renderer, text=0)
        tw.append_column(column)
        hbox.pack_start(tw, False, False, 0)
        tw.show()
        tw.connect('cursor-changed', self.on_cursor_changed)
        tw.set_cursor((0,))
        for idx, s in enumerate(self.g_liststore):

            if s[0].decode("utf-8") == default_profile:
                tw.set_cursor((idx, ))
        #
        chk = gu.nCheckButton("app", "noprofilemanager", _("D_on't ask at startup"))
        vbox.pack_start(chk, False, False, 0)
        self.show_all()