def click_in_widget( window, x=0, y=0, button=1, events=pygps.single_click_events, through_gps=True): """Simulate a click in a widget. There are various other functions adapted for specific widget types""" if os.name == 'nt' and button == 3 \ and events == pygps.single_click_events: # ??? work around # On Windows sending a BUTTON_PRESS followed by a # BUTTON_RELEASE event when opening a contextual menu does # not work. The BUTTON_RELEASE close the contextual menu. # For now we remove this event. events = events[:1] for event_type in events: if through_gps: GPS.send_button_event( button=button, x=int(x), y=int(y), window=window, type=event_type) else: event = Gdk.EventButton() event.type = event_type event.window = window event.device = pygps.default_event_device() event.x = float(x) event.y = float(y) event.button = button event.put() pygps.process_all_events()
def wait_idle(): """ This primitive allows the writer of a workflow to wait until all event have been handled, and resume execution of the workflow in an idle callback """ p = Promise() process_all_events() GLib.idle_add(lambda: p.resolve()) return p
def click_in_tree( view, path=None, column=0, button=1, events=pygps.single_click_events, process_events=True, control=False, alt=False, shift=False, ): """Simulate a click in the TreeView on the given path and column. This event is sent asynchronously, and you should check its result in an idle callback, or call process_all_events() immediately after the call to click_in_tree. If path is none, the event is sent to the first selected row. If you are using the third button to display a contextual menu, see also activate_contextual() To send a double-click, emit an event with type=gtk.gdk._2BUTTON_PRESS """ if os.name == "nt" and button == 3 and events == pygps.single_click_events: # ??? work around # On Windows sending a BUTTON_PRESS followed by a # BUTTON_RELEASE event when opening a contextual menu does # not work. The BUTTON_RELEASE close the contextual menu. # For now we remove this event. events = events[:1] if not path: path = view.get_selection().get_selected_rows()[1][0] rect = view.get_cell_area(path, view.get_column(column)) for t in events: event = gtk.gdk.Event(t) event.window = view.get_bin_window() event.button = button event.x = float(rect.x + rect.width / 2) event.y = float(rect.y + rect.height / 2) event.state = 0 if control: event.state = event.state or gtk.gdk.CONTROL_MASK if shift: event.state = event.state or gtk.gdk.SHIFT_MASK if alt: event.state = event.state or gtk.gdk.MOD1_MASK event.put() if process_events: pygps.process_all_events()
def select_in_tree(tree, column, key): """Select a row in a tree view. The row is such that the contents of the given column is key""" path = find_in_tree(tree, column, key) if path: # Expand so that path is visible, but not path itself if len(path) >= 2: tree.expand_to_path(path[:-1]) tree.get_selection().select_path(path) pygps.process_all_events()
def switch_notebook_page (notebook, label): """Switch to the page with the given label in the notebook. Returns the page number that was selected. -1 is returned if no such page exists.""" page = 0 while notebook.get_nth_page (page): p = notebook.get_nth_page (page) if get_notebook_page_label (notebook, p).get_label() == label: notebook.set_current_page (page) pygps.process_all_events() return page page = page + 1 return -1
def switch_notebook_page(notebook, label): """Switch to the page with the given label in the notebook. Returns the page number that was selected. -1 is returned if no such page exists.""" page = 0 while notebook.get_nth_page(page): p = notebook.get_nth_page(page) if get_notebook_page_label(notebook, p).get_label() == label: notebook.set_current_page(page) pygps.process_all_events() return page page = page + 1 return -1
def select_in_tree(tree, column, key): """Select a row in a tree view. The row is such that the contents of the given column is key. :return: the path of the selected row """ path = find_in_tree(tree, column, key) if path: # Expand so that path is visible, but not path itself if path.get_depth() >= 2: p = path.copy() p.up() tree.expand_to_path(p) tree.get_selection().select_path(path) pygps.process_all_events() return path return None
def process_one(timeout): global themes_to_process if len(themes_to_process) == 0: timeout.remove() GPS.exit(True) t = themes_to_process[0] themes_to_process.remove(t) name = t['name'] file_base_name = t['name'] + ".png" GPS.Console("Messages").write("generating for %s\n" % name) the_theme_switcher.apply_theme(t) pygps.process_all_events() surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 300) context = cairo.Context(surface) widget.draw(context) surface.write_to_png(os.path.join(directory, file_base_name))
def timeout_handler(): if not GPS.Task.list(): process_all_events() GLib.idle_add(lambda: p.resolve()) return False return True # will try again
def timeout_handler(): if not [x for x in GPS.Task.list() if x.name() not in filt]: process_all_events() GLib.idle_add(lambda: p.resolve()) return False return True # will try again
def click_in_tree(view, path=None, column=0, button=1, events=pygps.single_click_events, process_events=True, control=False, alt=False, shift=False, modifier=None, through_gps=True): """Simulate a click in the TreeView on the given path and column. This event is sent asynchronously, and you should check its result in an idle callback, or call process_all_events() immediately after the call to click_in_tree. If path is none, the event is sent to the first selected row. modifier is a Gdk.ModifierType, overriding control, alt or shift. If you are using the third button to display a contextual menu, see also activate_contextual() To send a double-click, emit an event with type=Gdk._2BUTTON_PRESS """ if not view.get_realized(): GPS.Logger("TESTSUITE").log("click_in_tree: view is not realized") return if (os.name == 'nt' and button == 3 and events == pygps.single_click_events): # ??? work around # On Windows sending a BUTTON_PRESS followed by a # BUTTON_RELEASE event when opening a contextual menu does # not work. The BUTTON_RELEASE close the contextual menu. # For now we remove this event. events = events[:1] if not path: path = view.get_selection().get_selected_rows()[1][0] rect = view.get_cell_area(path, view.get_column(column)) x = float(rect.x + rect.width / 2) y = float(rect.y + rect.height / 2) if modifier is not None: state = modifier else: state = Gdk.ModifierType(0) if control: if sys.platform == 'darwin': # on Mac, we need to also pass the Command key state |= Gdk.ModifierType.MOD2_MASK else: state |= Gdk.ModifierType.CONTROL_MASK if shift: state |= Gdk.ModifierType.SHIFT_MASK if alt: state |= Gdk.ModifierType.MOD1_MASK # TreeView doesn't handle single click well without # getting "enter-notify-event" first if through_gps: GPS.send_crossing_event(type=Gdk.EventType.ENTER_NOTIFY, window=view.get_bin_window(), x=int(x), y=int(y), state=0) else: event = Gdk.EventCrossing() event.type = Gdk.EventType.ENTER_NOTIFY event.window = view.get_bin_window() event.device = pygps.default_event_device() event.x = x event.y = y event.state = 0 event.put() for t in events: if through_gps: GPS.send_button_event(button=button, x=int(x), y=int(y), window=view.get_bin_window(), state=state, type=t) else: # event = Gdk.Event.new(t) event = Gdk.EventButton() event.type = t event.window = view.get_bin_window() event.device = pygps.default_event_device() event.button = button event.x = x event.y = y event.state = state event.put() if process_events: pygps.process_all_events()