def get_icon_size(self, icon_size): if icon_size == 'default' or icon_size == 'mini': return icon_size elif icon_size.isdigit(): icon_size = int(icon_size) Wnck.set_default_icon_size(icon_size) return 'default'
def _activate_window_(self): """This function uses Wnck to set a window as the active/focused window on the user's screen. It is especially useful when combined with Gdk to get active window pixels. Note: Gdk has no direct way of accessing a window by title. Returns: bool: True if window found and activated, else False """ screen = Wnck.Screen.get_default() screen.force_update() # recommended per Wnck documentation found_win = False for window in screen.get_windows(): name = window.get_name() if (name == self.window_title): found_win = True window.activate(0) time.sleep(self.activation_delay) ##should be the proper solution but Wnck/Pygi is kinda trash; ##the active boolean never returns true and proper activate times fail. # window.activate(int(time.time())) # while(not window.is_active()): # time.sleep(self.activation_delay) break # clean up Wnck (saves resources, check documentation) window = None screen = None Wnck.shutdown() return found_win
def handler_manager(self, src=None): # Activate window of running instance, if any try: screen = Wnck.Screen.get_default() screen.force_update() for window in screen.get_windows(): if window.get_class_instance_name() == "boincmgr": window.activate(time.time()) return finally: window = None screen = None Wnck.shutdown() # Launch via desktop for desktop in xdg.load_data_paths(osp.join("applications", "boinc-manager.desktop")): Gio.DesktopAppInfo.new_from_filename(desktop).launch([], None) return # Launch via executable try: subprocess.Popen(["boincmgr"], cwd="/var/lib/boinc-client") return except OSError: pass
def getAllWindowsPid(self): try: screen = Wnck.Screen.get_default() screen.force_update() return [win.get_pid() for win in screen.get_windows()] finally: screen = None Wnck.shutdown()
def on_event(self, event, extension): for window in list_windows(): if window.get_xid() == event.get_data(): previous_selection = extension.selection extension.previous_selection = previous_selection extension.selection = window.get_xid() activate(window) Wnck.shutdown()
def initGameCapture(self, gameWindow, monitorIndex, captureFullscreen): self.winCapture = mss() # find default monitor resolution if captureFullscreen: window = Gtk.Window() screen = window.get_screen() self.width = screen.get_monitor_geometry(monitorIndex).width self.height = screen.get_monitor_geometry(monitorIndex).height self.winGame = { 'top': screen.get_monitor_geometry(monitorIndex).y, 'left': screen.get_monitor_geometry(monitorIndex).x, 'width': self.width, 'height': self.height } self.reducedSizeSsim = (int(self.width * self.ratioSsim), int(self.height * self.ratioSsim)) self.reducedSizeTemplate = (int(self.width * self.ratioTemplate), int(self.height * self.ratioTemplate)) # try to find a window names after settings.gameWindow else: Gtk.init([]) screen = Wnck.Screen.get(monitorIndex) screen.force_update() winGeometry = 0 for window in screen.get_windows(): if window.get_name() == gameWindow: winGeometry = window.get_geometry() break window = None screen = None Wnck.shutdown() assert winGeometry != 0, gameWindow + ' not found; exiting...' self.width = winGeometry.widthp self.height = winGeometry.heightp self.winGame = { 'top': winGeometry.yp, 'left': winGeometry.xp, 'width': self.width, 'height': self.height } self.reducedSizeSsim = (int(winGeometry.widthp * self.ratioSsim), int(winGeometry.heightp * self.ratioSsim)) self.reducedSizeTemplate = (int(winGeometry.widthp * self.ratioTemplate), int(winGeometry.heightp * self.ratioTemplate))
def main(argv): # No arg list, pass out help if len(argv) == 0: printHelp() sys.exit(2) buff = 20 try: opts, args = getopt.getopt(argv,"hudlrb:v") except getopt.GetoptError as err: printHelp() sys.exit(2) direction = "" verbose = False for opt, arg in opts: if opt == "-h": printHelp() sys.exit() elif opt == "-u": direction = "UP" elif opt == "-d": direction = "DOWN" elif opt == "-l": direction = "LEFT" elif opt == "-r": direction = "RIGHT" elif opt == "-b": buff = int(arg) elif opt == "-v": verbose = True # Grab window list and geo Gtk.init([]) # necessary if not using a Gtk.main() loop screen = Wnck.Screen.get_default() screen.force_update() # recommended per Wnck documentation window_list = screen.get_windows() active_window = screen.get_active_window() workspace_id = screen.get_active_workspace().get_number() if len(window_list) > 0: window = findWindow( direction, window_list, workspace_id, active_window, buff, verbose ) else: print( "Empty window list!" ) sys.exit(2) if window != None: now = GdkX11.x11_get_server_time(Gdk.get_default_root_window()) window.activate(now) window = None screen = None Wnck.shutdown()
def close(self): print('close window: %s' % self.pid) screen = Wnck.Screen.get_default() screen.force_update() for win in screen.get_windows(): if self.pid == win.get_pid(): win.close(1) screen = None Wnck.shutdown()
def __init__(self, list_workspaces=False): self.list_workspaces = list_workspaces self.active = Active(windows=self) self.focus = Focus(windows=self) Wnck.set_client_type(Wnck.ClientType.PAGER) self.staging = False self.visible = [] self.visible_map = {} self.buffers = [] self.screen = None self.line = self.column = None
def getWindowName(): sleep(5) try: screen = Wnck.Screen.get_default() screen.force_update() window = screen.get_active_window() return window.get_name() finally: window = None screen = None Wnck.shutdown()
def getAllWindows(): try: wins = [] screen = Wnck.Screen.get_default() screen.force_update() for win in screen.get_windows(): wins.append(win) return wins finally: win = None screen = None Wnck.shutdown()
def getAllWindowNames(): sleep(5) try: winNames = [] screen = Wnck.Screen.get_default() screen.force_update() for win in screen.get_windows(): winNames.append(win.get_name()) return winNames finally: win = None screen = None Wnck.shutdown()
def xgeo_wnck(): gi.require_version('Wnck', '3.0') from gi.repository import Wnck screen = Wnck.Screen.get_default() screen.force_update() #for window in screen.get_windows(): # if window.is_active(): # print(window.get_geometry()) # window_name = window.get_name() # print(window_name) screen = None Wnck.shutdown()
def findWindow(windowname): screen = Wnck.Screen.get_default() screen.force_update() for win in screen.get_windows(): if windowname == win.get_name(): screen = None Wnck.shutdown() return win screen = None win = None Wnck.shutdown() return None
def poll(self): while gtk.events_pending(): gtk.main_iteration() if not gtk3: screen = wnck.screen_get_default() else: screen = wnck.Screen.get_default() screen.force_update() window_list = screen.get_windows() for w in window_list: if self._frame_name: current_window = w.get_name() if re.search( \ fnmatch.translate(self._frame_name), current_window, re.U | re.M | re.L) \ or re.search(fnmatch.translate(re.sub("(^frm)|(^dlg)", "", self._frame_name)), re.sub(" *(\t*)|(\n*)", "", current_window), re.U | re.M | re.L): # If window name specified, then activate just that window w.activate(int(time.time())) self.success = True break else: break
def poll(self): while gtk.events_pending(): gtk.main_iteration() if not gtk3: screen = wnck.screen_get_default() else: screen = wnck.Screen.get_default() # Added screen.force_update() based on # http://stackoverflow.com/questions/5794309/how-can-i-get-a-list-of-windows-with-wnck-using-pygi screen.force_update() window_list = screen.get_windows() for w in window_list: if self._frame_name: current_window = w.get_name() if re.search( \ fnmatch.translate(self._frame_name), current_window, re.U | re.M | re.L) \ or re.search(fnmatch.translate(re.sub("(^frm)|(^dlg)", "", self._frame_name)), re.sub(" *(\t*)|(\n*)", "", current_window), re.U | re.M | re.L): # If window name specified, then close just that window w.close(int(time.time())) self.success = True break else: # Close all window w.close(int(time.time())) self.success = True
def find_active_win_dbg(screen_no): wl = wnck.screen_get(screen_no).get_windows_stacked() for w in range(len(wl) - 1, 0, -1): if (wl[w].is_active()): print("%s - Active" % (wl[w].get_name())) else: print(wl[w].get_name())
def setPagerWidget(self): pager = Wnck.Pager() if self.orientation == 0: self.builder.get_object('taskBarWorkspacesHor').add(pager) else: self.builder.get_object('taskBarWorkspacesVer').add(pager) pager.show()
def main(): while Gtk.events_pending(): Gtk.main_iteration() screen = Wnck.Screen.get_default() screen.force_update() screen.connect("window-opened", on_new_window) screen.change_workspace_count(1) screen.force_update() config_file = open(sys.argv[1], 'r') for line in config_file: glib.timeout_add(1000, execute, line) Gtk.main() Wnck.shutdown() screen.force_update()
def selectCharacterWindow(window_to_select): """Select the characters window.""" Gtk.init([]) # necessary only if not using a Gtk.main() loop screen = Wnck.Screen.get_default() screen.force_update() # recommended per Wnck documentation # loop all windows for window in screen.get_windows(): if window.get_name() == window_to_select: print ' - Getting window %s info' % window_to_select window.get(window.get_xid()) print ' - Activating window %s' % window_to_select window.activate(int(time.time())) print ' - Setting window %s fullscreen' % window_to_select window.set_fullscreen(True) # clean up Wnck (saves resources, check documentation) window = None screen = None Wnck.shutdown()
def get_active_windows(): Gtk.init([]) # necessary only if not using a Gtk.main() loop screen = Wnck.Screen.get_default() screen.force_update() # recommended per Wnck documentation windows = screen.get_windows_stacked() for i, window in enumerate(windows): try: window.workspace_id = window.get_workspace().get_number() + 1 except AttributeError: logger.debug("A window ({}) is not attached to any workspace".format(window.get_name())) # remove the window from the list to avoid NoneType on workspace_id del(windows[i]) # clean up Wnck (saves resources, check documentation) screen = None Wnck.shutdown() return windows
def findWindowList(windowname, comparetype="equal"): screen = Wnck.Screen.get_default() screen.force_update() winlist = [] for win in screen.get_windows(): if "equal" == comparetype: if windowname == win.get_name(): winlist.append(win) else: if windowname in win.get_name(): winlist.append(win) screen = None Wnck.shutdown() if len(winlist) > 0: return winlist return None
def _kill_window(self, window_path): from gi.repository import Wnck as wnck from gi.repository import Gtk as gtk window_names = self._get_window_names(window_path) screen = wnck.screen_get_default() while gtk.events_pending(): gtk.main_iteration() windows = screen.get_windows() for window_name in window_names: for w in windows: if w.get_name() == window_name: self._do_kill(w.get_pid()) return
def setTasklistWidget(self): tasklist = Wnck.Tasklist() tasklist.set_scroll_enabled(False) tasklist.set_button_relief(2) # 0 = normal relief, 2 = no relief tasklist.set_grouping( 1) # 0 = mever group, 1 auto group, 2 = always group tasklist.set_orientation(self.orientation) if self.orientation == 0: self.builder.get_object('taskBarButtonsHor').add(tasklist) else: self.builder.get_object('taskBarButtonsVer').add(tasklist) tasklist.show()
def getWnckWindow(self): # pragma: no cover """ Get the wnck.Window instance for this window, or None """ # FIXME: this probably needs rewriting: screen = Wnck.screen_get_default() # You have to force an update before any of the wnck methods # do anything: screen.force_update() for wnckWindow in screen.get_windows(): # FIXME: a dubious hack: search by window title: if wnckWindow.get_name() == self.name: return wnckWindow
def find_global_active(): """ return: current screen catch: each screen might have one active window. so if there's 2, use default screen. """ count = 0 s = None screen = wnck.Screen.get_default() screen.force_update() active_win = screen.get_active_window() if active_win is not None: s = screen count += 1 if count == 1: return s elif count > 1: return wnck.screen_get_default() return None
def _findWindow(windowname, comparetype): screen = Wnck.Screen.get_default() screen.force_update() for win in screen.get_windows(): if "equal" == comparetype: if windowname == win.get_name(): screen = None Wnck.shutdown() return win else: if windowname in win.get_name(): screen = None Wnck.shutdown() return win screen = None win = None Wnck.shutdown() return None
def _findWindowByAppName(applicationName, comparetype): screen = Wnck.Screen.get_default() screen.force_update() for win in screen.get_windows(): #if "equal" == comparetype: if applicationName == (win.get_application()).get_name(): print((win.get_application()).get_name()) print(len((win.get_application()).get_name())) print(len(applicationName)) screen = None Wnck.shutdown() return win #else: if applicationName in (win.get_application()).get_name(): screen = None Wnck.shutdown() return win screen = None win = None Wnck.shutdown() return None
def exit(self, *args): # I don't know if this is actually necessary... self.screen = None Wnck.shutdown() Gtk.main_quit()
def _do_reload_menu(self): if not self.active: return this_items = {} if self._mode == "applications": if self.bamf_matcher != None: for window in self.bamf_matcher.RunningApplications(): try: item = self._get_item_for_bamf_application(window) this_items[item.id] = item except Exception as e: logger.debug("Could not get info from BAMF", exc_info=e) pass else: from gi.repository import Wnck as wnck screen = wnck.screen_get_default() for window in screen.get_windows(): pid = window.get_pid() if pid > 0: item = self._get_menu_item(pid) item.process_name = window.get_name() this_items[item.id] = item pixbuf = window.get_icon() if pixbuf: item.icon = g15cairo.pixbuf_to_surface(pixbuf) else: for process_id in gtop.proclist(): process_id = "%d" % process_id try: pid = int(process_id) proc_state = gtop.proc_state(pid) proc_args = gtop.proc_args(pid) if self._mode == "all" or (self._mode != "all" and proc_state.uid == os.getuid()): item = self._get_menu_item(pid) item.icon = None item.process_name = self._get_process_name( proc_args, proc_state.cmd) this_items[item.id] = item except Exception as e: logger.debug("Process may have disappeared", exc_info=e) # In case the process disappears pass # Remove any missing items for item in self.menu.get_children(): if not item.id in this_items: self.menu.remove_child(item) # Make sure selected still exists if self.menu.selected != None and self.menu.get_child_by_id( self.menu.selected.id) is None: if len(self.menu.get_child_count()) > 0: self.menu.selected = self.menu.get_children()[0] else: self.menu.selected = None self.page.mark_dirty() self.screen.redraw(self.page)
from gi.repository import Gtk, Wnck Gtk.init([]) # necessary only if not using a Gtk.main() loop screen = Wnck.Screen.get_default() screen.force_update() # recommended per Wnck documentation # loop all windows for window in screen.get_windows(): name = window.get_name() print(name) if name == "Rad Racer (U)": print("Right window founded") window.set_geometry(0,Wnck.WindowMoveResizeMask.X | \ Wnck.WindowMoveResizeMask.Y | \ Wnck.WindowMoveResizeMask.WIDTH | \ Wnck.WindowMoveResizeMask.HEIGHT,100,100,800,600) # ... do whatever you want with this window # clean up Wnck (saves resources, check documentation) window = None screen = None Wnck.shutdown()
def _configure_process(): Wnck.set_client_type(Wnck.ClientType.PAGER) setproctitle.setproctitle("pocoy") unix_signal_add = _signal_function() for sig in (SIGINT, SIGTERM, SIGHUP): unix_signal_add(GLib.PRIORITY_HIGH, sig, _unix_signal_handler, sig)
) self.ind.set_icon(self.icon_pause_gpu) else: # TODO: Must test if there *IS* a GPU (CcState.have_gpu()) # Set UI for 'gpu active' self.check_set_active("suspend_resume_gpu", False) self.menu["status_gpu"].set_label(_("GPU computing is enabled")) self.ind.set_icon(self.icon_normal) # (re-)show menus for 'cpu active' self.menu["status_gpu"].show() # (re-)show menus for 'connected' as last action, # to avoid any visual glitches self.menu["status_net"].show() self.menu["status_cpu"].show() return True # returning False would deactivate update timer if __name__ == "__main__": GLib.set_application_name(__appname__) GLib.set_prgname(__apptag__) Wnck.set_client_type(Wnck.ClientType.PAGER) # TODO: add command-line arguments (via argparse), specially --refresh # Which could move from __init__() to main() ind = BoincIndicator() sys.exit(ind.main())
} } # type: Dict[str, CfgDict] #: Used for resolving certain keysyms #: #: .. todo:: Figure out how to replace :data:`KEYLOOKUP` with a fallback that #: uses something in `Gtk <http://lazka.github.io/pgi-docs/Gtk-3.0/>`_ or #: ``python-xlib`` to look up the keysym from the character it types. KEYLOOKUP = { ',': 'comma', '.': 'period', '+': 'plus', '-': 'minus', } Wnck.set_client_type(Wnck.ClientType.PAGER) class QuickTileApp(object): """The basic Glib application itself. :param commands: The command registry to use to resolve command names. :param keys: A dict mapping :func:`Gtk.accelerator_parse` strings to command names. :param modmask: A modifier mask to prepend to all ``keys``. :param winman: The window manager to invoke commands with so they can act. """ def __init__( self, winman: WindowManager, commands: commands.CommandRegistry,
def __exit__(self, exc_type, exc_value, traceback): screen = None Wnck.shutdown()
print("found index window") time.sleep(2) i = GPIO.input(13) old_value = i print ("start detection") while True: print ("i value: ",i) time.sleep(0.1) i = GPIO.input(13) if old_value != i: if i == 0: print ("No detection",i) empty_window.activate(int(time.time())) GPIO.output(11,0) time.sleep(0.1) old_value = 0 elif i == 1: index_window.activate(int(time.time())) print ("Something detected",i) GPIO.output(11,1) time.sleep(0.1) old_value = 1 Wnck.ShutDown()
from gi.repository import Gtk, Wnck Gtk.init([]) # necessary only if not using a Gtk.main() loop screen = Wnck.Screen.get_default() screen.force_update() # recommended per Wnck documentation visibility = False # loop all windows for window in screen.get_windows(): if window.get_name() == 'Guake!': visibility = True # clean up Wnck (saves resources, check documentation) window = None screen = None Wnck.shutdown() print visibility