def _button_press_cb(self, view, event): """Handle button presses (visibility, locked, naming)""" if self._processing_model_updates: return # Basic details about the click single_click = event.type == Gdk.EventType.BUTTON_PRESS double_click = event.type == Gdk.EventType._2BUTTON_PRESS is_menu = event.triggers_context_menu() # Determine which row & column was clicked x, y = int(event.x), int(event.y) bw_x, bw_y = view.convert_widget_to_bin_window_coords(x, y) click_info = view.get_path_at_pos(bw_x, bw_y) if click_info is None: return True treemodel = self.get_model() click_treepath, click_col, cell_x, cell_y = click_info layer = treemodel.get_layer(treepath=click_treepath) docmodel = self._docmodel rootstack = docmodel.layer_stack # Eye/visibility column toggles kinds of visibility if (click_col is self._visible_col) and not is_menu and single_click: if event.state & Gdk.ModifierType.CONTROL_MASK: current_solo = rootstack.current_layer_solo rootstack.current_layer_solo = not current_solo elif rootstack.current_layer_solo: rootstack.current_layer_solo = False else: new_visible = not layer.visible docmodel.set_layer_visibility(new_visible, layer) return True # Layer lock column elif (click_col is self._locked_col) and not is_menu and single_click: new_locked = not layer.locked docmodel.set_layer_locked(new_locked, layer) return True # Double-clicking the name column is a request to rename elif (click_col is self._name_col) and not is_menu: if double_click: self.current_layer_rename_requested() return True # Click an un-selected layer row to select it click_layerpath = tuple(click_treepath.get_indices()) if click_layerpath != rootstack.current_path: docmodel.select_layer(path=click_layerpath) self.current_layer_changed() # The type icon column acts as an extra expander. # Some themes' expander arrows are very small. if (click_col is self._type_col) and not is_menu: self.expand_to_path(click_treepath) return True # Context menu if is_menu and event.type == Gdk.EventType.BUTTON_PRESS: self.current_layer_menu_requested(event) return True # Default behaviours: allow expanders & drag-and-drop to work return False
def _button_press_cb(self, view, event): """Handle button presses (visibility, locked, naming)""" if self._processing_model_updates: return # Basic details about the click single_click = (event.type == Gdk.EventType.BUTTON_PRESS) double_click = (event.type == Gdk.EventType._2BUTTON_PRESS) is_menu = event.triggers_context_menu() # Determine which row & column was clicked x, y = int(event.x), int(event.y) bw_x, bw_y = view.convert_widget_to_bin_window_coords(x, y) click_info = view.get_path_at_pos(bw_x, bw_y) if click_info is None: return True treemodel = self.get_model() click_treepath, click_col, cell_x, cell_y = click_info layer = treemodel.get_layer(treepath=click_treepath) docmodel = self._docmodel rootstack = docmodel.layer_stack # Eye/visibility column toggles kinds of visibility if (click_col is self._visible_col) and not is_menu and single_click: if event.state & Gdk.ModifierType.CONTROL_MASK: current_solo = rootstack.current_layer_solo rootstack.current_layer_solo = not current_solo elif rootstack.current_layer_solo: rootstack.current_layer_solo = False else: new_visible = not layer.visible docmodel.set_layer_visibility(new_visible, layer) return True # Layer lock column elif (click_col is self._locked_col) and not is_menu and single_click: new_locked = not layer.locked docmodel.set_layer_locked(new_locked, layer) return True # Double-clicking the name column is a request to rename elif (click_col is self._name_col) and not is_menu: if double_click: self.current_layer_rename_requested() return True # Click an un-selected layer row to select it click_layerpath = tuple(click_treepath.get_indices()) if click_layerpath != rootstack.current_path: docmodel.select_layer(path=click_layerpath) self.current_layer_changed() # The type icon column acts as an extra expander. # Some themes' expander arrows are very small. if (click_col is self._type_col) and not is_menu: self.expand_to_path(click_treepath) return True # Context menu if is_menu and event.type == Gdk.EventType.BUTTON_PRESS: self.current_layer_menu_requested(event) return True # Default behaviours: allow expanders & drag-and-drop to work return False
def _button_press_cb(self, view, event): """Handle button presses (visibility, locked, naming)""" if self._processing_model_updates: return # Basic details about the click single_click = (event.type == Gdk.EventType.BUTTON_PRESS) double_click = (event.type == Gdk.EventType._2BUTTON_PRESS) is_menu = event.triggers_context_menu() # Determine which row & column was clicked x, y = int(event.x), int(event.y) bw_x, bw_y = view.convert_widget_to_bin_window_coords(x, y) click_info = view.get_path_at_pos(bw_x, bw_y) if click_info is None: return True treemodel = self.get_model() click_treepath, click_col, cell_x, cell_y = click_info click_layer = treemodel.get_layer(treepath=click_treepath) click_layerpath = tuple(click_treepath.get_indices()) # Defer certain kinds of click to separate handlers. These # handlers can return True to stop processing and indicate that # the current layer should not be changed. col_handlers = [ # (Column, single, double, handler) (self._visible_col, True, False, self._handle_visible_col_click), (self._locked_col, True, False, self._handle_lock_col_click), (self._name_col, False, True, self._handle_name_col_2click), (self._type_col, True, False, self._handle_type_col_click), ] if not is_menu: for col, when_single, when_double, handler in col_handlers: if when_single and not single_click: continue if when_double and not double_click: continue ca = view.get_cell_area(click_treepath, col) if not (ca.x <= bw_x < ca.x + ca.width): continue if handler(event, click_layer, click_layerpath): return True # Clicks that fall thru the above cause a layer change. if click_layerpath != self._docmodel.layer_stack.current_path: self._docmodel.select_layer(path=click_layerpath) self.current_layer_changed() # Context menu for the layer just (right) clicked. if is_menu and single_click: self.current_layer_menu_requested(event) return True # Default behaviours: allow expanders & drag-and-drop to work return False
def _button_press_cb(self, view, event): """Handle button presses (visibility, locked, naming)""" # Basic details about the click single_click = (event.type == Gdk.EventType.BUTTON_PRESS) double_click = (event.type == Gdk.EventType._2BUTTON_PRESS) is_menu = event.triggers_context_menu() # Determine which row & column was clicked x, y = int(event.x), int(event.y) bw_x, bw_y = view.convert_widget_to_bin_window_coords(x, y) click_info = view.get_path_at_pos(bw_x, bw_y) if click_info is None: return True treemodel = self.get_model() click_treepath, click_col, cell_x, cell_y = click_info click_layer = treemodel.get_layer(treepath=click_treepath) click_layerpath = tuple(click_treepath.get_indices()) # Defer certain kinds of click to separate handlers. These # handlers can return True to stop processing and indicate that # the current layer should not be changed. col_handlers = [ # (Column, CellRenderer, single, double, handler) (self._flags1_col, None, True, False, self._flags1_col_click_cb), (self._flags2_col, None, True, False, self._flags2_col_click_cb), (self._name_col, None, False, True, self._name_col_2click_cb), (self._name_col, self._preview_cell, True, False, self._preview_cell_click_cb), ] if not is_menu: for col, cell, when_single, when_double, handler in col_handlers: if when_single and not single_click: continue if when_double and not double_click: continue # Correct column? if col is not click_col: continue # Click inside the target column's entire area? ca = view.get_cell_area(click_treepath, col) if not (ca.x <= bw_x < (ca.x + ca.width)): continue # Also, inside any target CellRenderer's area? if cell: pos_info = col.cell_get_position(cell) cell_xoffs, cell_w = pos_info if None in (cell_xoffs, cell_w): continue cell_x = ca.x + cell_xoffs if not (cell_x <= bw_x < (cell_x + cell_w)): continue # Run the delegated handler if we got here. if handler(event, click_layer, click_layerpath, ca): return True # Clicks that fall thru the above cause a layer change. if click_layerpath != self._docmodel.layer_stack.current_path: self._docmodel.select_layer(path=click_layerpath) self.current_layer_changed() # Context menu for the layer just (right) clicked. if is_menu and single_click: self.current_layer_menu_requested(event) return True # Default behaviours: allow expanders & drag-and-drop to work return False