Python gi.repository.Gtk 模块,get_major_version() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用gi.repository.Gtk.get_major_version()

项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def _headerbar(bar):
        children = [] + bar.get_children()
        pack_start = []
        pack_end = []
        for c in children:
            if child_get_property(bar, c, 'pack-type') == Gtk.PackType.END:
                bar.remove(c)
                pack_start.append(c)
            else:
                bar.remove(c)
                pack_end.append(c)
        if len(pack_end) > 1:
            c,  pack_end = pack_end[0], pack_end[1:]
            pack_end.append(c)
        if (Gtk.get_major_version(), Gtk.get_minor_version()) > (3, 10):
            # Old ubuntu has this in order, new Ubuntu has it reversed
            pack_end = reversed(pack_end)
        for c in pack_start: bar.pack_start(c)
        for c in pack_end: bar.pack_end(c)
项目:SlackBuilds    作者:montagdude    | 项目源码 | 文件源码
def backend_gtk3agg_internal_check(x):
    try:
        import gi
    except ImportError:
        return (False, "Requires pygobject to be installed.")

    try:
        gi.require_version("Gtk", "3.0")
    except ValueError:
        return (False, "Requires gtk3 development files to be installed.")
    except AttributeError:
        return (False, "pygobject version too old.")

    try:
        from gi.repository import Gtk, Gdk, GObject
    except (ImportError, RuntimeError):
        return (False, "Requires pygobject to be installed.")

    return (True, "version %s.%s.%s" % (
        Gtk.get_major_version(),
        Gtk.get_micro_version(),
        Gtk.get_minor_version()))
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def __init__(self):
        Gtk.Application.__init__(self,
                                 application_id="org.gnome.Authenticator",
                                 flags=Gio.ApplicationFlags.FLAGS_NONE)
        GLib.set_application_name(_("Gnome Authenticator"))
        GLib.set_prgname("Gnome Authenticator")

        self.observable = ApplicaitonObservable()

        self.menu = Gio.Menu()
        self.db = Database()

        result = GK.unlock_sync("org.gnome.Authenticator", None)
        if result == GK.Result.CANCELLED:
            self.quit()

        Gtk.Settings.get_default().set_property(
            "gtk-application-prefer-dark-theme", settings.get_is_night_mode())

        if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20:
            cssFileName = "org.gnome.Authenticator-post3.20.css"
        else:
            cssFileName = "org.gnome.Authenticator-pre3.20.css"
        cssProviderFile = Gio.File.new_for_uri(
            'resource:///org/gnome/Authenticator/%s' % cssFileName)
        cssProvider = Gtk.CssProvider()
        screen = Gdk.Screen.get_default()
        styleContext = Gtk.StyleContext()
        try:
            cssProvider.load_from_file(cssProviderFile)
            styleContext.add_provider_for_screen(screen, cssProvider,
                                                 Gtk.STYLE_PROVIDER_PRIORITY_USER)
            logging.debug("Loading css file ")
        except Exception as e:
            logging.error("Error message %s" % str(e))
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def shortcuts_dialog():
        if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20:
            builder = Gtk.Builder()
            builder.add_from_resource('/org/gnome/Authenticator/shortcuts.ui')
            shortcuts = builder.get_object("shortcuts")
            return shortcuts
        return None
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def _apply_css(config):
        if OSDWindow.css_provider:
            Gtk.StyleContext.remove_provider_for_screen(
                Gdk.Screen.get_default(), OSDWindow.css_provider)

        colors = {}
        for x in config['osk_colors'] : colors["osk_%s" % (x,)] = config['osk_colors'][x]
        for x in config['osd_colors'] : colors[x] = config['osd_colors'][x]
        colors = OSDCssMagic(colors)
        try:
            css_file = os.path.join(get_share_path(), "osd_styles", config["osd_style"])
            css = file(css_file, "r").read()
            if ((Gtk.get_major_version(), Gtk.get_minor_version()) > (3, 20)):
                css += OSDWindow.CSS_3_20
            OSDWindow.css_provider = Gtk.CssProvider()
            OSDWindow.css_provider.load_from_data((css % colors).encode("utf-8"))
            Gtk.StyleContext.add_provider_for_screen(
                    Gdk.Screen.get_default(),
                    OSDWindow.css_provider,
                    Gtk.STYLE_PROVIDER_PRIORITY_USER)
        except GLib.Error, e:
            log.error("Failed to apply css with user settings:")
            log.error(e)
            log.error("Retrying with default values")

            OSDWindow.css_provider = Gtk.CssProvider()
            css_file = os.path.join(get_share_path(), "osd_styles", "Classic.gtkstyle.css")
            css = file(css_file, "r").read()
            if ((Gtk.get_major_version(), Gtk.get_minor_version()) > (3, 20)):
                css += OSDWindow.CSS_3_20
            OSDWindow.css_provider.load_from_data((css % colors).encode("utf-8"))
            Gtk.StyleContext.add_provider_for_screen(
                    Gdk.Screen.get_default(),
                    OSDWindow.css_provider,
                    Gtk.STYLE_PROVIDER_PRIORITY_USER)
项目:budgie-extras    作者:UbuntuBudgie    | 项目源码 | 文件源码
def __init__(self, uuid):
        Budgie.Applet.__init__(self)
        self.box = Gtk.EventBox()
        self.lockicon = Gtk.Image.new_from_icon_name(
            "budgie-rotation-lock-button",
            Gtk.IconSize.MENU,
        )

        self.unlockicon = Gtk.Image.new_from_icon_name(
            "budgie-rotation-button",
            Gtk.IconSize.MENU,
        )

        if Gtk.get_major_version() == 3 and \
                Gtk.get_minor_version() == 18:
            # GTK+3.18
            schema = "org.gnome.settings-daemon.plugins.orientation"
            self.key = "active"
        else:
            # > GTK+3.18
            schema = "org.gnome.settings-daemon.peripherals.touchscreen"
            self.key = "orientation-lock"

        self.settings = Gio.Settings.new(schema)

        if self.settings.get_boolean(self.key):
            if self.key == "active":
                self.displayicon = self.unlockicon
            else:
                self.displayicon = self.lockicon
        else:
            if self.key == "active":
                self.displayicon = self.lockicon
            else:
                self.displayicon = self.unlockicon

        self.box.add(self.displayicon)
        self.add(self.box)
        self.box.show_all()
        self.show_all()
        self.box.connect("button-press-event", self.on_press)
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def send_bugreport(self):
        """
        Return None if successful. Return the urllib2 execption if failure.
        """
        try:
            windowsversion = str(sys.getwindowsversion())
        except AttributeError:
            windowsversion = "(not running ms windows)"
        buf = self.g_tw.get_buffer()
        description = buf.get_text(buf.get_start_iter(), buf.get_end_iter(),
                                   False)
        data = urllib.urlencode({
            'email': self.g_email.get_text(),
            'version': buildinfo.VERSION_STRING,
            'revision_id': buildinfo.REVISION_ID,
            #'pygtk_version': "pygi",
            'gtk': "(%s.%s.%s)" % (Gtk.get_major_version(),
                                         Gtk.get_minor_version(),
                                         Gtk.get_micro_version()),
            'sys.version': sys.version,
            'sys.platform': sys.platform,
            'windowsversion': windowsversion,
            'short_description': self.g_description.get_text(),
            'description': description,
            'traceback': self.m_error_text,
        })
        try:
            urllib2.urlopen("http://www.solfege.org/crashreport/", data)
        except urllib2.HTTPError, e:
            print "HTTPError:", e
        return
项目:SlackBuilds    作者:montagdude    | 项目源码 | 文件源码
def backend_gtk3cairo_internal_check(x):
    try:
        import cairocffi
    except ImportError:
        try:
            import cairo
        except ImportError:
            return (False, "Requires cairocffi or pycairo to be installed.")

    try:
        import gi
    except ImportError:
        return (False, "Requires pygobject to be installed.")

    try:
        gi.require_version("Gtk", "3.0")
    except ValueError:
        return (False, "Requires gtk3 development files to be installed.")
    except AttributeError:
        return (False, "pygobject version too old.")

    try:
        from gi.repository import Gtk, Gdk, GObject
    except (RuntimeError, ImportError):
        return (False, "Requires pygobject to be installed.")

    return (True, "version %s.%s.%s" % (
        Gtk.get_major_version(),
        Gtk.get_micro_version(),
        Gtk.get_minor_version()))
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def generate_menu(self):
        # Settings section
        settings_content = Gio.Menu.new()
        settings_content.append_item(
            Gio.MenuItem.new(_("Settings"), "app.settings"))
        settings_section = Gio.MenuItem.new_section(None, settings_content)
        self.menu.append_item(settings_section)

        # Help section
        help_content = Gio.Menu.new()
        help_content.append_item(Gio.MenuItem.new(_("Night Mode"), "app.night_mode"))
        if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20:
            help_content.append_item(Gio.MenuItem.new(
                _("Shortcuts"), "app.shortcuts"))

        help_content.append_item(Gio.MenuItem.new(_("About"), "app.about"))
        help_content.append_item(Gio.MenuItem.new(_("Quit"), "app.quit"))
        help_section = Gio.MenuItem.new_section(None, help_content)
        self.menu.append_item(help_section)

        self.settings_action = Gio.SimpleAction.new("settings", None)
        self.settings_action.connect("activate", self.on_settings)
        self.settings_action.set_enabled(not settings.get_is_locked())
        settings.bind('locked', self.settings_action, 'enabled', Gio.SettingsBindFlags.INVERT_BOOLEAN)
        self.add_action(self.settings_action)


        action = Gio.SimpleAction.new_stateful("night_mode", None, GLib.Variant.new_boolean(settings.get_is_night_mode()))
        action.connect("change-state", self.on_night_mode)
        self.add_action(action)

        if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20:
            action = Gio.SimpleAction.new("shortcuts", None)
            action.connect("activate", self.on_shortcuts)
            self.add_action(action)

        action = Gio.SimpleAction.new("about", None)
        action.connect("activate", self.on_about)
        self.add_action(action)

        action = Gio.SimpleAction.new("quit", None)
        action.connect("activate", self.on_quit)
        self.add_action(action)
        if not show_app_menu():
            self.set_app_menu(self.menu)
            logging.debug("Adding gnome shell menu")
项目:bokken    作者:thestr4ng3r    | 项目源码 | 文件源码
def gtkui_dependency_check():
    '''
    This function verifies that the dependencies that are needed by the GTK user interface are met.
    '''

    print('\tGTK UI dependencies...', end='')

    # Check Gtk
    try:
        import gi
        gi.require_version('Gtk', '3.0')
        from gi.repository import Gtk
        from gi.repository import GObject
        assert Gtk.get_major_version() >= 3
        print(common.console_color('\tOK', 'green'))
    except:
        print(common.console_color("\tD'oh!", 'red'))
        print('You have to install GTK+3 and PyGObject version >= 3.0 to be able to '
                'run the GTK user interface.\n'
                '    - On Debian-based distributions: apt-get install python-gi\n'
                '    - On Mac: brew install pygobject3')
        sys.exit(1)

    # Check GtkSourceView
    try:
        print('\tGtkSourceView3...', end='')
        gi.require_version('GtkSource', '3.0')
        from gi.repository import GtkSource
        print(common.console_color('\tOK', 'green'))
    except:
        print(common.console_color("\tD'oh!", 'red'))
        print('GtkSourceView3 not installed! Install it for your platform:\n'
                '    - On Debian-based distributions: apt-get install gir1.2-gtksource-3.0')
        sys.exit(1)

    # Check PyCairo for GTK+.
    try:
        print('\tPython Cairo bindings...', end='')
        gi.require_version('PangoCairo', '1.0')
        from gi.repository import PangoCairo
        print(common.console_color('\tOK', 'green'))
    except:
        print(common.console_color("\tD'oh!", 'red'))
        print('Python Cairo bindings for GObject not installed! Install them for your platform:\n'
                '    - On Debian-based distributions: apt-get install python-gi-cairo')
        sys.exit(1)