Exemple #1
0
 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
Exemple #2
0
 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
Exemple #3
0
 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
Exemple #4
0
 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
Exemple #5
0
 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
Exemple #6
0
    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
Exemple #7
0
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
Exemple #8
0
    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)