我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用gi.repository.Gdk()。
def is_quartz(): """ Tests to see if Python is currently running with gtk and windowing system is Mac OS-X's "quartz". """ if mac(): try: import gi gi.require_version('Gtk', '3.0') gi.require_version('Gdk', '3.0') from gi.repository import Gtk from gi.repository import Gdk except ImportError: return False return Gdk.Display.get_default().__class__.__name__.endswith("QuartzDisplay") return False
def hide_title_bar(proc_name, when_to_hide_title_bar, continuous=CONTINUOUS): """Conditionally hide title bar of the respective process.""" result = None decoration = None if when_to_hide_title_bar == WhenToHideTitleBar.ALWAYS: decoration = Gdk.WMDecoration.BORDER result = True elif when_to_hide_title_bar == WhenToHideTitleBar.MAX_ONLY: result = False elif when_to_hide_title_bar == WhenToHideTitleBar.NEVER: decoration = Gdk.WMDecoration.ALL result = True if continuous: continuous_decoration(proc_name, decoration).join() else: decorate_windows(proc_name, decoration) return result
def __init__(self, short=False, order='NCS', xdotool=None): self.validate_order(order) self.indicator = AppIndicator3.Indicator.new( APP_NAME, ICON_LOCATION, AppIndicator3.IndicatorCategory.APPLICATION_STATUS) self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) if short: self.locks = { 'N': _('N'), 'C': _('C'), 'S': _('S') } else: self.locks = { 'N': _('Num'), 'C': _('Caps'), 'S': _('Scroll') } keymap = Gdk.Keymap.get_default() keymap.connect('state-changed', self.update_indicator, order) self.update_indicator(keymap, order) self.create_menu(xdotool, order)
def monitor_geometry(): "Return the current monitor geometry" import gi gi.require_version('Gdk', '3.0') from gi.repository import Gdk from collections import namedtuple MonitorGeometry = namedtuple( 'MonitorGeometry', ['left', 'right', 'top', 'bottom', 'width', 'height'], ) display = Gdk.Display.get_default() screen = display.get_default_screen() window = screen.get_active_window() monitor = screen.get_monitor_at_window(window) g = screen.get_monitor_geometry(monitor) right = g.x + g.width bottom = g.y + g.height return MonitorGeometry(g.x, right, g.y, bottom, g.width, g.height)
def has_display(): """ Tests to see if Python is currently running with gtk """ # FIXME: currently, Gtk.init_check() requires all strings # in argv, and we might have unicode. temp, sys.argv = sys.argv, sys.argv[:1] try: import gi gi.require_version('Gtk', '3.0') gi.require_version('Gdk', '3.0') from gi.repository import Gtk from gi.repository import Gdk except ImportError: return False try: test = Gtk.init_check(temp) and \ Gdk.Display.get_default() sys.argv = temp return bool(test) except: sys.argv = temp return False # A couple of places add menu accelerators using <alt>, which doesn't # work with Gtk-quartz. <Meta> is the usually correct replacement, but # in one case the key is a number, and <meta>number is used by Spaces # (a mac feature), so we'll use control instead.
def resolution(self): s = Gdk.Screen.get_default() return '%dx%d' % (s.get_width(), s.get_height())
def get_modifier(s): m = (('<ctrl>', Gdk.ModifierType.CONTROL_MASK), ('<shift>', Gdk.ModifierType.SHIFT_MASK), ('<alt>', Gdk.ModifierType.MOD1_MASK)) for mod, mask in m: if s.startswith(mod): return mask, s[len(mod):] return None, s
def parse_key_string(string): if not string: return None, None mod = 0 m, s = get_modifier(string) while m: mod = mod + m m, s = get_modifier(s) if len(s) == 1: return mod, ord(s) else: return mod, getattr(Gdk, 'KEY_%s' % s)
def on_scroll(self, widget, steps, direcction): if direcction == Gdk.ScrollDirection.UP: backlight = self.backlightManager.get_backlight() backlight += 10 * steps self.set_backlight(backlight) if self.show_value: self.indicator.set_label(str(int(self.backlight)), '') else: self.indicator.set_label('', '') if self.show_notifications: self.notification.update('Backlight-Indicator', _('Backlight') + ': %s' % backlight, comun.STATUS_ICON[self.theme][0]) self.notification.show() elif direcction == Gdk.ScrollDirection.DOWN: backlight = self.backlightManager.get_backlight() backlight -= 10 * steps self.set_backlight(backlight) if self.show_value: self.indicator.set_label(str(int(self.backlight)), '') else: self.indicator.set_label('', '') if self.show_notifications: self.notification.update('Backlight-Indicator', _('Backlight') + ': %s' % backlight, comun.STATUS_ICON[self.theme][0]) self.notification.show() # ################# main functions ####################
def decorate_window(window, decoration): """Decorates the respective window using Gdk.""" gdk_display = GdkX11.X11Display.get_default() Gdk.Window.process_all_updates() gdk_window = GdkX11.X11Window.foreign_new_for_display( gdk_display, window.id) Gdk.Window.set_decorations(gdk_window, decoration) Gdk.Window.process_all_updates()
def do_activate(self): self._style_provider = Gtk.CssProvider() self._current_screen = Gdk.Screen.get_default() css = b""".gedit-view { padding-bottom: 400px }""" self._style_provider.load_from_data(css) Gtk.StyleContext.add_provider_for_screen( self._current_screen, self._style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION )
def _on_row_activated(self, listbox, row): if row.model.group_id == 0: AllGroupDetail( row.model, modal=True, transient_for=self.get_toplevel(), type_hint=Gdk.WindowTypeHint.DIALOG ).present() else: GroupDetail( row.model, modal=True, transient_for=self.get_toplevel(), type_hint=Gdk.WindowTypeHint.DIALOG ).present()
def _on_row_activated(self, listbox, row): DetailWindow( row.model, modal=True, transient_for=self.get_toplevel(), type_hint=Gdk.WindowTypeHint.DIALOG ).present()
def setScreenSize(self, widthRatio, heightRatio): Screen = Gdk.Screen.get_default() self.set_default_size(Screen.get_width() * widthRatio, Screen.get_height() * heightRatio) self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) # fetching the Images/Logos from the Const File
def is_active_window_skipped(): """ Check for full-screen applications. This method must be executed by the main thread. If not, it will cause to random failure. """ logging.info('Searching for full-screen application') screen = Gdk.Screen.get_default() active_window = screen.get_active_window() if active_window: active_xid = str(active_window.get_xid()) cmdlist = ['xprop', '-root', '-notype', '-id', active_xid, 'WM_CLASS', '_NET_WM_STATE'] try: stdout = subprocess.check_output(cmdlist).decode('utf-8') except subprocess.CalledProcessError: logging.warning('Error in finding full-screen application') else: if stdout: is_fullscreen = 'FULLSCREEN' in stdout # Extract the process name process_names = re.findall('"(.+?)"', stdout) if process_names: process = process_names[1].lower() if process in skip_break_window_classes: return True elif process in take_break_window_classes: if is_fullscreen and unfullscreen_allowed: try: active_window.unfullscreen() except BaseException: logging.error('Error in unfullscreen the window ' + process) return False return is_fullscreen return False
def get_monitors(): monitors_list = [] try: x = os.environ['WAYLAND_DISPLAY'] session_type = 'wayland' except KeyError: session_type = 'x11' if session_type == 'x11': # Use GTK ## Not working with Wayland (?) display_manager = Gdk.DisplayManager.get() display = Gdk.DisplayManager.get_default_display(display_manager) n_monitors = display.get_n_monitors() for monitor_index in range(n_monitors): monitor = display.get_monitor(monitor_index) model = monitor.get_model() geometry = monitor.get_geometry() monitors_list.append(model + ' ' + str(geometry.width) + 'x' + str(geometry.height)) if monitor.is_primary(): monitor_primary = model + ' ' + str(geometry.width) + 'x' + str(geometry.height) else: # Using xrandr proc = subprocess.Popen(['xrandr'],stdout=subprocess.PIPE) for line in proc.stdout.readlines(): if re.compile(r'\b({0})\b'.format('connected'), flags=re.IGNORECASE).search(line): if 'primary' in line: monitors_list.append(line.split(' ')[0] + ' ' + line.split(' ')[3].split('+')[0]) else: monitors_list.append(line.split(' ')[0] + ' ' + line.split(' ')[2].split('+')[0]) if 'primary' in line: monitor_primary = line.split(' ')[0] + ' ' + line.split(' ')[3].split('+')[0] ## Hack for Wayland try: monitor_primary except NameError: monitor_primary = monitors_list[0] else: pass return monitors_list, monitor_primary