我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用gi.repository.Gtk.get_minor_version()。
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)
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()))
def __init_css(self): """ Initialize the main css files and providers. Add css classes to the default screen style context. """ if Gtk.get_minor_version() > 18: log.debug("Fanciest design possible") cssProviderFile = Gio.File.new_for_uri( "resource:///de/geigi/cozy/application.css") else: log.debug("Using legacy css file") cssProviderFile = Gio.File.new_for_uri( "resource:///de/geigi/cozy/application_legacy.css") cssProvider = Gtk.CssProvider() cssProvider.load_from_file(cssProviderFile) # add the bordered css class to the default screen for the borders around album art screen = Gdk.Screen.get_default() styleContext = Gtk.StyleContext() styleContext.add_provider_for_screen( screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER) styleContext.add_class("bordered")
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))
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
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)
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)
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
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()))
def __close_search_popover(self, object=None): """ Close the search popover specific to the used gtk version. """ if Gtk.get_minor_version() < 22: self.search_popover.hide() else: self.search_popover.popdown()
def __create_popover(self): self.popover = Gtk.Popover.new(self) self.popover.set_position(Gtk.PositionType.BOTTOM) # We need to scroll when there are many tracks in a Book scroller = Gtk.ScrolledWindow() scroller.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) # This box contains all content self.track_box = Gtk.Box() self.track_box.set_orientation(Gtk.Orientation.VERTICAL) self.track_box.set_halign(Gtk.Align.CENTER) self.track_box.set_valign(Gtk.Align.START) self.track_box.props.margin = 8 count = 0 for track in tracks(self.book): self.track_box.add(TrackElement(track, self.ui)) count += 1 if Gtk.get_minor_version() > 20: scroller.set_propagate_natural_height(True) scroller.set_max_content_height(500) else: padding = 17 height = 24 scroller_height = count * height + padding if scroller_height > 500: scroller_height = 500 scroller.set_size_request(-1, scroller_height) self.popover.connect("closed", self.__on_popover_close) self.popover.add(scroller) scroller.add_with_viewport(self.track_box) scroller.show_all() self._mark_current_track()
def __on_button_press(self, eventbox, event): self.art.selected = True if Gtk.get_minor_version() > 20: self.popover.popup() else: self.popover.show_all() pass
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")
def __init__(self, config, on_save_settings): self.config = config self.on_save_settings = on_save_settings self.plugin_switches = {} self.plugin_map = {} self.last_short_break_interval = config.get('break_interval') self.initializing = True self.infobar_long_break_shown = False builder = Utility.create_gtk_builder(SETTINGS_DIALOG_GLADE) builder.connect_signals(self) self.window = builder.get_object('window_settings') self.box_short_breaks = builder.get_object('box_short_breaks') self.box_long_breaks = builder.get_object('box_long_breaks') box_plugins = builder.get_object('box_plugins') for short_break in config.get('short_breaks'): self.__create_break_item(short_break, True) for long_break in config.get('long_breaks'): self.__create_break_item(long_break, False) for plugin_config in Utility.load_plugins_config(config): box_plugins.pack_start(self.__create_plugin_item(plugin_config), False, False, 0) self.spin_short_break_duration = builder.get_object('spin_short_break_duration') self.spin_long_break_duration = builder.get_object('spin_long_break_duration') self.spin_short_break_interval = builder.get_object('spin_short_break_interval') self.spin_long_break_interval = builder.get_object('spin_long_break_interval') self.spin_time_to_prepare = builder.get_object('spin_time_to_prepare') self.spin_postpone_duration = builder.get_object('spin_postpone_duration') self.spin_disable_keyboard_shortcut = builder.get_object('spin_disable_keyboard_shortcut') self.switch_strict_break = builder.get_object('switch_strict_break') self.switch_postpone = builder.get_object('switch_postpone') self.switch_persist = builder.get_object('switch_persist') self.info_bar_long_break = builder.get_object("info_bar_long_break") self.info_bar_long_break.hide() # Set the current values of input fields self.spin_short_break_duration.set_value(config.get('short_break_duration')) self.spin_long_break_duration.set_value(config.get('long_break_duration')) self.spin_short_break_interval.set_value(config.get('break_interval')) self.spin_long_break_interval.set_value(config.get('no_of_short_breaks_per_long_break') * config.get('break_interval')) self.spin_time_to_prepare.set_value(config.get('pre_break_warning_time')) self.spin_postpone_duration.set_value(config.get('postpone_duration')) self.spin_disable_keyboard_shortcut.set_value(config.get('shortcut_disable_time')) self.switch_strict_break.set_active(config.get('strict_break')) self.switch_postpone.set_active(config.get('allow_postpone') and not config.get('strict_break')) self.switch_persist.set_active(config.get('persist_state')) # Update relative states # GtkSwitch state-set signal is available only from 3.14 if Gtk.get_minor_version() >= 14: self.switch_strict_break.connect('state-set', self.on_switch_strict_break_activate) self.switch_postpone.connect('state-set', self.on_switch_postpone_activate) self.on_switch_strict_break_activate(self.switch_strict_break, self.switch_strict_break.get_active()) self.on_switch_postpone_activate(self.switch_postpone, self.switch_postpone.get_active()) self.initializing = False