def mousePressEvent(self, QMouseEvent): """ Override mousePressEvent to support mouse button actions :param QMouseEvent: :return: """ # if QMouseEvent.button() == Qt.MidButton: # self.parent.play_vid(self.video.vid_path) if QMouseEvent.button() == Qt.MidButton: self.decrease_prio() elif QMouseEvent.button( ) == Qt.LeftButton and QApplication.keyboardModifiers( ) == Qt.ControlModifier: self.decrease_prio() elif QMouseEvent.button( ) == Qt.LeftButton and QApplication.keyboardModifiers( ) == Qt.AltModifier: self.mark_discarded() elif QMouseEvent.button( ) == Qt.LeftButton and QApplication.keyboardModifiers( ) == Qt.ShiftModifier: self.config_play_video(self.video.vid_path, self.get_default_player(), mark_watched=False) elif QMouseEvent.button() == Qt.LeftButton: self.config_play_video(self.video.vid_path, self.get_default_player())
def toggleVisibility(self): button_clicked = self.sender() index = self.btnVisible.index(button_clicked) if QApplication.keyboardModifiers() == Qt.ControlModifier: self.setAllNotVisible() button_clicked.setIcon(self.icon_eyeopen) self.visibility_flags[index] = True elif QApplication.keyboardModifiers() == Qt.ShiftModifier: self.setAllVisible() button_clicked.setIcon(self.icon_eyeclosed) self.visibility_flags[index] = False else: if self.visibility_flags[index]: button_clicked.setIcon(self.icon_eyeclosed) self.visibility_flags[index] = False else: button_clicked.setIcon(self.icon_eyeopen) self.visibility_flags[index] = True self.visibilityChanged.emit()
def keyPressEvent(self, e: QtGui.QKeyEvent): if not self.m_isEditing: return if e.key() == QtCore.Qt.Key_Delete: self.deleteLater() # Moving container with arrows if QApplication.keyboardModifiers() == QtCore.Qt.ControlModifier: newPos = QPoint(self.x(), self.y()) if e.key() == QtCore.Qt.Key_Up: newPos.setY(newPos.y() - 1) if e.key() == QtCore.Qt.Key_Down: newPos.setY(newPos.y() + 1) if e.key() == QtCore.Qt.Key_Left: newPos.setX(newPos.x() - 1) if e.key() == QtCore.Qt.Key_Right: newPos.setX(newPos.x() + 1) self.move(newPos) if QApplication.keyboardModifiers() == QtCore.Qt.ShiftModifier: if e.key() == QtCore.Qt.Key_Up: self.resize(self.width(), self.height() - 1) if e.key() == QtCore.Qt.Key_Down: self.resize(self.width(), self.height() + 1) if e.key() == QtCore.Qt.Key_Left: self.resize(self.width() - 1, self.height()) if e.key() == QtCore.Qt.Key_Right: self.resize(self.width() + 1, self.height()) self.newGeometry.emit(self.geometry())
def mouseDragEvent(self, ev): if QApplication.keyboardModifiers() == Qt.ShiftModifier: if ev.button() != Qt.LeftButton: ev.ignore() return if ev.isStart(): # We are already one step into the drag. # Find the point(s) at the mouse cursor when the button was first # pressed: pos = self.parent.parent.vb.mapSceneToView(ev.pos()) self.st_pos = pos.x() pos = self.parent.parent.vb.mapSceneToView(ev.pos()) self.parent.parent.z_abs += (pos.x() - self.st_pos) / self.line.l() self.parent.parent.panel.refresh() #self.parent.parent.line_reper = self.line self.parent.parent.plot.updateVelocityAxis() self.parent.redraw() ev.accept() elif QApplication.keyboardModifiers() == Qt.AltModifier or self.info: self.showInfo() ev.accept()
def wheelEvent(self, event): if QApplication.keyboardModifiers() == Qt.ControlModifier: cursor_point = event.pos() scene_pos = self.mapToScene( QPoint(cursor_point.x(), cursor_point.y())) view_width = self.viewport().width() view_height = self.viewport().height() h_scale = cursor_point.x() / view_width v_scale = cursor_point.y() / view_height wheel_delta_value = event.angleDelta() if wheel_delta_value.y() > 0: self.zoomInSignal.emit() else: self.zoomOutSignal.emit() view_point = self.transform().map(scene_pos) self.horizontalScrollBar().setValue( int(view_point.x() - view_width * h_scale)) self.verticalScrollBar().setValue( int(view_point.y() - view_height * v_scale)) elif QApplication.keyboardModifiers() == Qt.ShiftModifier: self.horizontalScrollBar().setValue( self.horizontalScrollBar().value() - event.angleDelta().y() * self.mouse_wheel_speed) else: self.verticalScrollBar().setValue( self.verticalScrollBar().value() - event.angleDelta().y() * self.mouse_wheel_speed) event.accept()
def keyPressEvent(self, e): super(FramelessEnterSendQTextEdit, self).keyPressEvent(e) # print(e.key()) if e.key() == Qt.Key_Return: try: if QApplication.keyboardModifiers() in (Qt.ShiftModifier, Qt.ControlModifier, Qt.AltModifier): self.action() else: pass except: print('回车失败') return elif e.key() == 16777267: self.speak() elif e.key() == Qt.Key_S and QApplication.keyboardModifiers( ) == Qt.ControlModifier: print("save") self.addhistory() elif QApplication.keyboardModifiers() not in (Qt.ShiftModifier, Qt.ControlModifier, Qt.AltModifier): self.history_pos = len(self.history) elif QApplication.keyboardModifiers() == Qt.ControlModifier and e.key( ) == Qt.Key_Left: self.last_history() elif QApplication.keyboardModifiers() == Qt.ControlModifier and e.key( ) == Qt.Key_Right: self.next_history()
def __keyPressEvent(event): if (event.key() == Qt.Key_1): if QApplication.keyboardModifiers() == Qt.AltModifier: self.printCard.click() if QApplication.keyboardModifiers() == Qt.ControlModifier: if (event.key() == Qt.Key_S): self.saveCard.click() if (event.key() == Qt.Key_Q): self.buildScript.click()
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None: # 键盘快捷键事件 if event.key() == Qt.Key_R and QApplication.keyboardModifiers() == Qt.ControlModifier: self.__classify() self.listView.setFocus() if event.key() == Qt.Key_E and QApplication.keyboardModifiers() == Qt.ControlModifier: self.comboBox_level.setFocus() if event.key() == Qt.Key_W and QApplication.keyboardModifiers() == Qt.ControlModifier: self.lineEdit_works.setText("")
def keyPressEvent(self, e): if (e.key() == Qt.Key_S ) and QApplication.keyboardModifiers() and Qt.ControlModifier: print('Control S has been pressed') self.print_settings() elif (e.key() == Qt.Key_C ) and QApplication.keyboardModifiers() and Qt.ControlModifier: print('Control C has been pressed') print('The program will close down') sys.exit()
def __execute_menu_action(self, menu_item): self.__menu_selected = True global_pos = QCursor.pos() pos = self.mapFromGlobal(global_pos) point = Point(pos.x(), pos.y()) self.__drawing_area.execute_menu_action( menu_item, point, QApplication.keyboardModifiers() == Qt.ControlModifier, QApplication.keyboardModifiers() == Qt.ShiftModifier)
def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: self.close() elif event.key() == Qt.Key_S and QApplication.keyboardModifiers( ) == Qt.ControlModifier: if self.fps is not None: self.takePhotoMarking(self.change_size(self.dto.camImg[0])) elif event.key() == Qt.Key_R and QApplication.keyboardModifiers( ) == Qt.ControlModifier: if self.fps is not None: self.takePhotoAnswer(self.change_size(self.dto.camImg[0]))
def __activated(self, idx): """ Private slot to handle the activation of an entry. @param idx reference to the entry index (QModelIndex) """ if QApplication.keyboardModifiers() & Qt.ControlModifier: self.__openBookmarkInNewTab() elif QApplication.keyboardModifiers() & Qt.ShiftModifier: self.__openBookmarkInNewWindow() else: self.__openBookmarkInCurrentTab()
def mouseClickEvent(self, ev): if QApplication.keyboardModifiers() == Qt.AltModifier: self.parent.remove_line(self.parent.labels.index(self)) elif QApplication.keyboardModifiers() == Qt.ControlModifier: self.parent.remove() elif ev.double(): self.parent.set_active(not self.parent.active) self.parent.parent.doublets.update() ev.accept()
def keyPressEvent(self, event): if event.key() == Qt.Key_Delete: self.calculator_view.delete_unit() if QApplication.keyboardModifiers() == ( Qt.ShiftModifier | Qt.ControlModifier) and event.key() == Qt.Key_D: self.calculator_view.duplicate_unit(True) elif QApplication.keyboardModifiers( ) == Qt.ControlModifier and event.key() == Qt.Key_D: self.calculator_view.duplicate_unit(False) else: super().keyPressEvent(event)
def mousePressEvent(self, event): if self.hasImage(): """ Start drawing, panning with mouse, or zooming in """ scenePos = self.mapToScene(event.pos()) if event.button() == Qt.LeftButton: self._overlay_stack.append(self.mask_pixmap.copy()) if self.direct_mask_paint: self._offscreen_mask_stack.append( self._offscreen_mask.copy()) # If ALT is held, replace color repaint_was_active = False if QApplication.keyboardModifiers() & Qt.AltModifier: try: repaint_was_active = True self.viewport().setCursor(Qt.BusyCursor) self.repaintArea() except Exception as e: print("Cannot repaint region. Additional information:") print(e) self.viewport().setCursor(Qt.ArrowCursor) # If SHIFT is held, draw a line if QApplication.keyboardModifiers() & Qt.ShiftModifier: self.drawMarkerLine(event) # If CONTROL is held, erase, but only if global erase override is not enabled if not self.global_erase_override: if QApplication.keyboardModifiers() & Qt.ControlModifier: self.current_painting_mode = self.MODE_ERASE else: self.current_painting_mode = self.MODE_PAINT # If the user just clicks, add a marker (unless repainting was done) if not repaint_was_active: self.fillMarker(event) self.leftMouseButtonPressed.emit(scenePos.x(), scenePos.y()) elif event.button() == Qt.MiddleButton: if self.canPan: self.__prevMousePos = event.pos() self.viewport().setCursor(Qt.ClosedHandCursor) self._cursorHandle.hide() self.middleMouseButtonPressed.emit(scenePos.x(), scenePos.y()) elif event.button() == Qt.RightButton: if self.canZoom: self.setDragMode(QGraphicsView.RubberBandDrag) self._cursorHandle.hide() self.rightMouseButtonPressed.emit(scenePos.x(), scenePos.y()) QGraphicsView.mousePressEvent(self, event)
def mouseMoveEvent(self, event): pos = event.pos() point = Point(pos.x(), pos.y()) self.__drawing_area.mouse_move( point, QApplication.keyboardModifiers() == Qt.ControlModifier, QApplication.keyboardModifiers() == Qt.ShiftModifier) if self.__drawing_area.action_active: self.__do_update() else: self.__update_cursor()
def keyPressEvent(self, event): keyEvent = QKeyEvent(event) if keyEvent.key() == Qt.Key_S: if QApplication.keyboardModifiers() == Qt.ControlModifier: self.DataSave() elif keyEvent.key() == Qt.Key_1: if QApplication.keyboardModifiers() == Qt.AltModifier: self.Color1() elif keyEvent.key() == Qt.Key_2: if QApplication.keyboardModifiers() == Qt.AltModifier: self.Color2() elif keyEvent.key() == Qt.Key_3: if QApplication.keyboardModifiers() == Qt.AltModifier: self.Color3() elif keyEvent.key() == Qt.Key_4: if QApplication.keyboardModifiers() == Qt.AltModifier: self.Color4() elif keyEvent.key() == Qt.Key_5: if QApplication.keyboardModifiers() == Qt.AltModifier: self.Color5() elif keyEvent.key() == Qt.Key_Q: if QApplication.keyboardModifiers() == Qt.AltModifier: self.TableCombine() elif keyEvent.key() == Qt.Key_L: if QApplication.keyboardModifiers() == Qt.ControlModifier: self.login()
def keyPressEvent(self, event): key = event.key() if QApplication.keyboardModifiers( ) == Qt.ControlModifier and key == Qt.Key_F: self.ui.quicksearch_view.focus() if QApplication.keyboardModifiers( ) == Qt.ControlModifier and key == Qt.Key_S: logger.info("User data backed up") unit_storage.clean_all_units(grand=False) for r_idx in range(self.ui.unit_view.widget.count()): widget = self.ui.unit_view.widget.itemWidget( self.ui.unit_view.widget.item(r_idx)) widget.update_unit() profile_manager.cleanup()
def mousePressEvent(self, event): if event.button() == Qt.LeftButton: if (QApplication.keyboardModifiers() == Qt.ControlModifier): self.onClickedCtrl.emit(event.x(), event.y()) elif (QApplication.keyboardModifiers() == Qt.ShiftModifier): self.onClickedShift.emit(event.x(), event.y()) else: self.onClicked.emit(event.x(), event.y()) event.accept() elif event.button() == Qt.RightButton: self.onClicked[int, str].emit(event.x(), str(event.y())) event.accept() else: super(Exhibit, self).mousePressEvent(self, event)
def mouseReleaseEvent(self, event): pos = event.pos() point = Point(pos.x(), pos.y()) if self.__mouse_down: self.__drawing_area.mouse_up( point, QApplication.keyboardModifiers() == Qt.ControlModifier, QApplication.keyboardModifiers() == Qt.ShiftModifier) self.__mouse_down = False self.__do_update() else: super().mousePressEvent(event)
def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: self.close() elif event.key() == Qt.Key_S and QApplication.keyboardModifiers( ) == Qt.ControlModifier: try: thread = threading.Thread(target=self.start) thread.start() except: traceback.print_exc() elif event.key() == Qt.Key_R and QApplication.keyboardModifiers( ) == Qt.ControlModifier: if self.fps is not None: self.takePhotoAnswer(self.change_size(self.dto.camImg[0]))
def onmotion(self, event): plot_pt = np.array([event.xdata, event.ydata]) if plot_pt[0] is None: return if QApplication.keyboardModifiers() == QtCore.Qt.ShiftModifier: self.selected_x = event.xdata self.selected_range = False self.main_interface.set_scalar_value(self.selected_x, self.selected_range) elif QApplication.keyboardModifiers() == QtCore.Qt.ControlModifier: self.selected_x = event.xdata self.selected_range = True self.main_interface.set_scalar_value(self.selected_x, self.selected_range) else: self.selected_x = None self.selected_range = False self.main_interface.reset_sens_region() closest_ind = np.argmin( np.absolute(plot_pt[0] - self.genren.opacity_tf[:, 0])) mean_pt = self.genren.opacity_tf[closest_ind, 0] self.recent_mean = [mean_pt, mean_pt] if self.pt_selected is None: self.plot_update(True) self.draw() return if event.button == 1: diff_update = plot_pt - self.pressed_plot_pt self.genren.opacity_gmm[self.pt_selected, 0] += diff_update[0] self.genren.opacity_gmm[self.pt_selected, 2] += diff_update[1] elif event.button == 3: diff_bandwidth_update = (plot_pt[0] - self.pressed_plot_pt[0]) new_bandwidth = self.genren.opacity_gmm[self.pt_selected, 1] + diff_bandwidth_update new_bandwidth = min(new_bandwidth, self.genren.max_bandwidth) new_bandwidth = max(new_bandwidth, self.genren.min_bandwidth) print('old bandwidth:', self.genren.opacity_gmm[self.pt_selected, 1], 'new bandwidth:', new_bandwidth) self.genren.opacity_gmm[self.pt_selected, 1] = new_bandwidth self.genren.update_gmm_transfer_function() self.genren.encode_inputs() self.main_interface.update_image(False) self.plot_update() self.pressed_plot_pt = plot_pt
def mousePressEvent(self, QMouseEvent): pos = QMouseEvent.pos() if QApplication.keyboardModifiers() & Qt.ControlModifier: pnt = self.get_closest_waypoint(pos, 20) if pnt is not None: index = self.points.index(pnt) self.points.remove(pnt) else: pnt = self.get_closest_path_point(pos, 20) new_point = pf.Waypoint(pnt.x, pnt.y, pnt.heading) if pnt is not None: index = None for i in range(self.middle_profile.index(pnt), len(self.middle_profile)): profile_pnt = self.middle_profile[i] for j in range(len(self.points)): waypnt = self.points[j] dist = math.sqrt((waypnt.y - profile_pnt.y)**2 + (waypnt.x - profile_pnt.x)**2) if dist < 0.2: self.points.insert(j, new_point) break else: continue break self.create_profiles() self.repaint() elif QApplication.keyboardModifiers() & Qt.AltModifier: pnt = self.get_closest_arm_endpoint(pos, 20) if pnt is not None: if self.point_being_dragged is None: self.drag_mode = "angle" self.point_being_dragged = pnt self.ghost_point = pf.Waypoint(pnt.x, pnt.y, pnt.angle) arm_x, arm_y = self.get_arm_gui_point( self.point_being_dragged) self.drag_offset = [pos.x() - arm_x, pos.y() - arm_y] else: pnt = self.get_closest_waypoint(pos, 20) if pnt is not None: if self.point_being_dragged is None: self.drag_mode = "pos" self.point_being_dragged = pnt self.ghost_point = pf.Waypoint(pnt.x, pnt.y, pnt.angle) pnt_x, pnt_y = self.convert_pf_point_to_gui_point(pnt) self.drag_offset = [pos.x() - pnt_x, pos.y() - pnt_y]
def __activated(self, idx): """ Private slot to handle the activation of an entry. @param idx reference to the entry index (QModelIndex) """ self.__openBookmark(QApplication.keyboardModifiers() & Qt.ControlModifier)
def mousePressEvent(self, e): modifiers = QApplication.keyboardModifiers() if modifiers == Qt.NoModifier: for item in self.scene().selectedItems(): item.setSelected(False) self.setSelected(True) self.buildEdge(e.scenePos())
def addNewBox(self, pos: QRect) -> None: if QApplication.keyboardModifiers() == Qt.ControlModifier: return if any(isinstance(elem, ResizeHandle) for elem in self.scene.selectedItems()): return if pos.isEmpty(): return rect = CoupledRectangleElement( pos, self.connectionInput, editor=self._editor, scene=self.scene, parent=self.scene.parent() ) rect.setZValue(len(self._currentBoxesList)) rect.setColor(self.currentColor) self._currentBoxesList.append(rect) newRow = self.boxListModel.rowCount() box = BoxLabel(f"Box{newRow}", self.currentColor) box.colorChanged.connect(rect.setColor) box.lineWidthChanged.connect(rect.setLineWidth) box.fontColorChanged.connect(rect.setFontColor) box.fontSizeChanged.connect(rect.setFontSize) box.isFixedChanged.connect(self._fixedBoxesChanged) box.existenceChanged.connect(self._viewBoxesChanged) self.boxListModel.insertRow(newRow, box) box.existenceChanged.emit() rect.boxLabel = box box.isFixedChanged.connect(rect._rectItem.fixSelf) rect._updateTextWhenChanges() self.currentColor = self._getNextBoxColor()
def eventFilter(self, obj, event): # Focus emacs buffer when user click view. if event.type() in [ QEvent.MouseButtonPress, QEvent.MouseButtonRelease, QEvent.MouseMove, QEvent.MouseButtonDblClick, QEvent.Wheel ]: # Send mouse event to applicatin view. self.trigger_focus_event.emit("{0},{1}".format( event.globalX(), event.globalY())) if event.type() == QEvent.MouseButtonPress: if event.button() == MOUSE_FORWARD_BUTTON: self.forward() event.accept() return True elif event.button() == MOUSE_BACK_BUTTON: self.back() event.accept() return True if event.type() == QEvent.Wheel: modifiers = QApplication.keyboardModifiers() if modifiers == Qt.ControlModifier: if event.angleDelta().y() > 0: self.zoom_in() else: self.zoom_out() return super(QWebEngineView, self).eventFilter(obj, event)
def changeSelection(self, index): modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers & Qt.ControlModifier shift_is_active = modifiers & Qt.ShiftModifier if ctrl_is_active: item = self._objects_model.getItem(index) node = item["node"] if Selection.isSelected(node): Selection.remove(node) else: Selection.add(node) elif shift_is_active: polarity = 1 if index + 1 > self._last_selected_index else -1 for i in range(self._last_selected_index, index + polarity, polarity): item = self._objects_model.getItem(i) node = item["node"] Selection.add(node) else: # Single select item = self._objects_model.getItem(index) node = item["node"] build_plate_number = node.callDecoration("getBuildPlateNumber") if build_plate_number is not None and build_plate_number != -1: self.setActiveBuildPlate(build_plate_number) Selection.clear() Selection.add(node) self._last_selected_index = index
def grabNode(self, node_idx): self.path_edges = [] modifiers = QApplication.keyboardModifiers() if modifiers == Qt.ShiftModifier: print('Shift+MouseClick') if node_idx not in self.drag_idx: self.drag_idx.append(node_idx) else: self.drag_idx.remove(node_idx) self.cotrolPressed = True self.update() else: if self.cotrolPressed == True: if node_idx not in self.drag_idx: self.drag_idx.append(node_idx) else: self.drag_idx.remove(node_idx) self.drag_idx.append(node_idx) # making sure the pointed node is the last in the indices list self.cotrolPressed = False else: self.drag_idx = [node_idx, ] print("$"*50) print(self.drag_idx) return
def toggle(app_window): config.logger.info("controller:toggle()") config.app_window = app_window modifiers = QApplication.keyboardModifiers() if modifiers == (Qt.AltModifier | Qt.ControlModifier): # ALT+CTR-CLICK (OPTION+COMMAND on macOS) toggles the plus debug logging util.debugLogToggle() elif modifiers == Qt.AltModifier: # ALT-click (OPTION on macOS) sends the log file by email util.sendLog() else: if config.app_window.plus_account is None: # @UndefinedVariable connect() if is_connected() and is_synced( ) and config.app_window.curFile is not None: # @UndefinedVariable sync.sync() else: if config.connected: if is_synced(): # a CTR-click (COMMAND on macOS) logs out and discards the credentials disconnect( interactive=True, remove_credentials=(modifiers == Qt.ControlModifier), keepON=False) else: # we (manually) turn syncing for the current roast on if app_window.qmc.checkSaved(allow_discard=False): queue.addRoast() else: disconnect(remove_credentials=False, stop_queue=True, interactive=True, keepON=False)
def pick_event(self, event): ax = self.figure.axes[0] artist = event.artist lw = artist.get_linewidth() label = artist.get_label() if not artist.get_color() == "gray": self.color = artist.get_color() if lw == 1.5: # detect waveforms to save spiketrains artist.set_linewidth(2 * lw) self.picked_lines.append(label) elif lw > 1.5: artist.set_linewidth(lw / 2) self.picked_lines.remove(label) self.key = QApplication.keyboardModifiers() if (self.key == Qt.ShiftModifier) and (lw == 1.5): # detect waveforms to merge artist.set_color("gray") self.merged_lines.append(label) self.merged_colors.append(self.color) elif (self.key == Qt.ShiftModifier) and (lw > 1.5): index = self.merged_lines.index(label) artist.set_color(self.merged_colors[index]) self.merged_lines.remove(label) self.merged_colors.remove(self.merged_colors[index]) print("Save individual spiketrains for waveforms: ", self.picked_lines) print("Save merged spiketrains for waveforms: ", self.merged_lines) artist.figure.canvas.draw()
def query_for_schedule_scope(self): if QApplication.keyboardModifiers() & Qt.ShiftModifier: return ScheduleScope.Global if not self.app.model.show_schedule_scope_dialog: return ScheduleScope.Local dialog = ScheduleScopeDialog(self.app.mainWindow) return dialog.queryForScope()
def on_clicked(self): modifiers = QApplication.keyboardModifiers() if modifiers == Qt.AltModifier: self.bar() else: self.foo()
def addNewBox(self,pos5Dstart,pos5Dstop): modifiers=QApplication.keyboardModifiers() if modifiers == Qt.ControlModifier: #add stuff return for el in self.scene.selectedItems(): #retun if there is an handle on the scene at that position if isinstance(el, ResizeHandle): return # # print "Start = ",pos5Dstart, # print "Stop =", pos5Dstop oldstart=pos5Dstart[1:3] oldstop=pos5Dstop[1:3] start=[] stop=[] for s1,s2 in zip(oldstart,oldstop): start.append(np.minimum(s1,s2)) stop.append(np.maximum(s1,s2)) # itemsall1=self.scene.items(QPointF(*pos5Dstart[1:3])) # itemsall1 =filter(lambda el: isinstance(el, ResizeHandle), itemsall1) # itemsall2=self.scene.items(QPointF(*pos5Dstop[1:3])) # itemsall2 =filter(lambda el: isinstance(el, ResizeHandle), itemsall2) # itemsall=itemsall1+itemsall2 # print itemsall h=stop[1]-start[1] w=stop[0]-start[0] if h*w<9: return #too small rect=CoupledRectangleElement(start[0],start[1],h,w,self.connectionInput,editor = self._editor, scene=self.scene,parent=self.scene.parent()) rect.setZValue(len(self._currentBoxesList)) rect.setColor(self.currentColor) #self.counter-=1 self._currentBoxesList.append(rect) newRow=self.boxListModel.rowCount() box = BoxLabel( "Box%d"%newRow, self.currentColor) box.colorChanged.connect(rect.setColor) box.lineWidthChanged.connect(rect.setLineWidth) box.fontColorChanged.connect(rect.setFontColor) box.fontSizeChanged.connect(rect.setFontSize) box.isFixedChanged.connect(self._fixedBoxesChanged) box.existenceChanged.connect(self._viewBoxesChanged) self.boxListModel.insertRow( newRow, box ) box.existenceChanged.emit() rect.boxLabel=box box.isFixedChanged.connect(rect._rectItem.fixSelf) rect._updateTextWhenChanges() self.currentColor=self._getNextBoxColor()
def engraveRunner(self): job = self.runningJob() if job: job.abort() elif QApplication.keyboardModifiers() & Qt.SHIFT: self.engraveCustom() else: self.engravePreview()
def mousePressEvent(self, e): modifiers = QApplication.keyboardModifiers() if modifiers == Qt.ControlModifier: e.ignore() else: for item in self.scene().selectedItems(): item.setSelected(False) QGraphicsTextItem.mousePressEvent(self, e)
def startRecording(self): self.setFocus(True) # because of QTBUG 17810 self.setDown(True) self.setStyleSheet("text-align: left;") self._isrecording = True self._recseq = QKeySequence() self._modifiers = int(QApplication.keyboardModifiers() & (Qt.SHIFT | Qt.CTRL | Qt.ALT | Qt.META)) self.grabKeyboard() self.updateDisplay()
def event(self, event): modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers == Qt.ControlModifier if event.type == Event.KeyPressEvent and ctrl_is_active: if event.key == KeyEvent.UpKey: self.setLayer(self._current_layer_num + 1) return True if event.key == KeyEvent.DownKey: self.setLayer(self._current_layer_num - 1) return True
def update_current(self, current): self.current.setText(current) if self.version.text() == self.current.text(): self.version_status.setPixmap(self.check) if self.auto_launch_check.isChecked() and QApplication.keyboardModifiers() != Qt.ShiftModifier: QTimer.singleShot(1000, self.launch_dolphin) else: self.version_status.setPixmap(self.cancel) if self.auto_launch_check.isChecked() and self.dolphin_dir.text(): self.download_new()
def update_version(self, message): if message == 'finished': self.version.setText(self.version.placeholderText()) self.version.setPlaceholderText("Installation Status Unknown") self.version_status.setPixmap(self.check) self._udc.set_user_version(self.version.text()) if self.auto_launch_check.isChecked() and QApplication.keyboardModifiers() != Qt.ShiftModifier: QTimer.singleShot(1000, self.launch_dolphin) else: self.version.setPlaceholderText(message)
def enableSelectedTool(self): if (not self.mSelectedTool or not self.mMapDocument): return self.mActiveTool = self.mSelectedTool self.mActiveTool.activate(self) self.mCurrentModifiers = QApplication.keyboardModifiers() if (self.mCurrentModifiers != Qt.NoModifier): self.mActiveTool.modifiersChanged(self.mCurrentModifiers) if (self.mUnderMouse): self.mActiveTool.mouseEntered() self.mActiveTool.mouseMoved(self.mLastMousePos, Qt.KeyboardModifiers())
def eventFilter(self, obj, ev): if ev.type() != QEvent.KeyPress: return super(Completer, self).eventFilter(obj, ev) # we can't test for self.popup() as that will recursively call # eventFilter during instantiation. popupVisible = obj != self.widget() if popupVisible: # a key was pressed while the popup is visible cur = self.textCursor() modifier = QApplication.keyboardModifiers() if ev.key() in (Qt.Key_Return, Qt.Key_Enter) or ev.text() == '.': # insert the highlighted completion self.setCurrentRow(self.popup().currentIndex().row()) self.insertCompletion(self.currentIndex()) if ev.text() == '.': # deliver event and keep showing popup if necessary cur.insertText('.') self.popup().hide() return True elif ev.key() == Qt.Key_Backspace: # deliver event, hide popup if completionPrefix already none self.widget().event(ev) if self.completionPrefix(): self.showCompletionPopup() else: self.popup().hide() return True elif ev.key() == Qt.Key_Tab: if modifier == Qt.AltModifier: self.popup().hide() return True if cur.hasSelection(): self.acceptPartialCompletion() self.showCompletionPopup() self.gotoNextEntry() return True elif self.isTextEvent(ev, True): # deliver event and keep showing popup if necessary self.widget().event(ev) self.showCompletionPopup() self.insertPartialCompletion(self.currentIndex()) return True elif ev.key() not in ( Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown, Qt.Key_Shift, Qt.Key_Control, Qt.Key_Alt, Qt.Key_Meta): # hide on anything except navigation keys self.popup().hide() return super(Completer, self).eventFilter(obj, ev) # a key was pressed while the popup is not visible if self.autoComplete and self.isTextEvent(ev, False): self.widget().event(ev) self.showCompletionPopup(False) return True return False
def _post_mouse_event(self, type, button, x, y): q_button = { # TODO perhaps add right button here "left": Qt.LeftButton, "nobutton": Qt.NoButton, }.get(button) point = QPointF(x, y) buttons = QApplication.mouseButtons() modifiers = QApplication.keyboardModifiers() event = QMouseEvent(type, point, q_button, buttons, modifiers) QApplication.postEvent(self.web_page, event)
def mouseMoveEvent(self, e): modifiers = QApplication.keyboardModifiers() if modifiers == Qt.ControlModifier: mimeData = QMimeData() drag = QDrag(e.widget()) mimeData.setText("node") drag.setMimeData(mimeData) drag.exec_(Qt.MoveAction) self.ungrabMouse() if self.edgeInConstruction != None: self.edgeInConstruction.obsUpdate(e.scenePos())
def __itemActivated(self, itm, column): """ Private slot to handle the activation of an item. @param itm reference to the activated item (QTreeWidgetItem) @param column column of the activation (integer) """ if self.feedsTree.indexOfTopLevelItem(itm) != -1: return self.__openMessage( QApplication.keyboardModifiers() & Qt.ControlModifier == Qt.ControlModifier)
def event(self, event): modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers & Qt.ControlModifier shift_is_active = modifiers & Qt.ShiftModifier if event.type == Event.KeyPressEvent and ctrl_is_active: amount = 10 if shift_is_active else 1 if event.key == KeyEvent.UpKey: self.setLayer(self._current_layer_num + amount) return True if event.key == KeyEvent.DownKey: self.setLayer(self._current_layer_num - amount) return True if event.type == Event.ViewActivateEvent: # Make sure the SimulationPass is created layer_pass = self.getSimulationPass() self.getRenderer().addRenderPass(layer_pass) # Make sure the NozzleNode is add to the root nozzle = self.getNozzleNode() nozzle.setParent(self.getController().getScene().getRoot()) nozzle.setVisible(False) Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged) self._onGlobalStackChanged() if not self._simulationview_composite_shader: self._simulationview_composite_shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("SimulationView"), "simulationview_composite.shader")) theme = Application.getInstance().getTheme() self._simulationview_composite_shader.setUniformValue("u_background_color", Color(*theme.getColor("viewport_background").getRgb())) self._simulationview_composite_shader.setUniformValue("u_outline_color", Color(*theme.getColor("model_selection_outline").getRgb())) if not self._composite_pass: self._composite_pass = self.getRenderer().getRenderPass("composite") self._old_layer_bindings = self._composite_pass.getLayerBindings()[:] # make a copy so we can restore to it later self._composite_pass.getLayerBindings().append("simulationview") self._old_composite_shader = self._composite_pass.getCompositeShader() self._composite_pass.setCompositeShader(self._simulationview_composite_shader) elif event.type == Event.ViewDeactivateEvent: self._wireprint_warning_message.hide() Application.getInstance().globalContainerStackChanged.disconnect(self._onGlobalStackChanged) if self._global_container_stack: self._global_container_stack.propertyChanged.disconnect(self._onPropertyChanged) self._nozzle_node.setParent(None) self.getRenderer().removeRenderPass(self._layer_pass) self._composite_pass.setLayerBindings(self._old_layer_bindings) self._composite_pass.setCompositeShader(self._old_composite_shader)
def eventFilter(self, mainwin, ev): if ev.type() != QEvent.IconDrag: return False if not mainwin.isActiveWindow(): return False ev.accept() modifiers = QApplication.keyboardModifiers() if modifiers == Qt.NoModifier: self.startDrag(mainwin, ev) elif modifiers == Qt.ControlModifier: self.commandClick(mainwin, ev) else: ev.ignore() return True
def qt_send_text(text, target, key_type=0): """ Send text as key input event to target qt object, as if generated by `key_type`. Key type defaults to 0, meaning "the event is not a result of a known key; for example, it may be the result of a compose sequence or keyboard macro." """ modifiers = QApplication.keyboardModifiers() text = list(text) or [''] for x in text: event = QKeyEvent(QEvent.KeyPress, key_type, modifiers, x) QApplication.postEvent(target, event) # Key release does not generate any input event = QKeyEvent(QEvent.KeyRelease, key_type, modifiers, '') QApplication.postEvent(target, event)
def _doubleClicked(self, index): model = self.model() if model is None: return data = model.data(index) if isinstance(data, QColor): if QApplication.keyboardModifiers() & Qt.AltModifier: model.setData(index, QColor()) else: dialog = QColorDialog(self) dialog.setCurrentColor(data) dialog.setOption(QColorDialog.ShowAlphaChannel) ret = dialog.exec_() if ret: color = dialog.currentColor() model.setData(index, color)
def mouseReleaseEvent(self, event): if event.button() == Qt.LeftButton: clickedRect = self._optionsRects[self._clickedIndex] if QRect(*clickedRect).contains(event.pos()): self._selection = {self._clickedIndex} if self._selectionMode > 1 and QApplication.keyboardModifiers( ) & Qt.ShiftModifier: shiftSelection = self._selection ^ self._oldSelection if shiftSelection: self._selection = shiftSelection self.clicked.emit() else: self._selection = self._oldSelection self.update() del self._clickedIndex del self._oldSelection else: super().mouseReleaseEvent(event)
def mousePressEvent(self, event): if event.button() == Qt.LeftButton: for recordIndex, rect in self._optionsRects.items(): if QRect(*rect).contains(event.pos()): self._clickedIndex = recordIndex self._oldSelection = self._selection self._selection = {recordIndex} if self._selectionMode > 1 and QApplication.keyboardModifiers( ) & Qt.ShiftModifier: shiftSelection = self._selection ^ self._oldSelection if shiftSelection: self._selection = shiftSelection else: self._selection |= self._oldSelection break self.update() else: super().mousePressEvent(event)
def canvasPressEvent(self, e): self.startY = e.pos().y() self.endY = self.startY self.isEmittingPoint = True self.height = self.canvas.height() modifiers = QApplication.keyboardModifiers() self.isRotationAroundPoint = bool(modifiers & Qt.ControlModifier) self.startPoint = self.toMapCoordinates(e.pos()) self.endPoint = self.startPoint self.isLayerVisible = isLayerVisible(self.iface, self.layer) setLayerVisible(self.iface, self.layer, False) rotation = self.computeRotation() self.showRotation(rotation) self.layer.history.append({"action": "rotation", "rotation": self.layer.rotation, "center": self.layer.center}) # rotation set
def event(self, event): super().event(event) modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers & Qt.ControlModifier if event.type == Event.MousePressEvent and MouseEvent.LeftButton in event.buttons and self._controller.getToolsEnabled(): if ctrl_is_active: self._controller.setActiveTool("TranslateTool") return if self._skip_press: # The selection was previously cleared, do not add/remove an anti-support mesh but # use this click for selection and reactivating this tool only. self._skip_press = False return if self._selection_pass is None: # The selection renderpass is used to identify objects in the current view self._selection_pass = Application.getInstance().getRenderer().getRenderPass("selection") picked_node = self._controller.getScene().findObject(self._selection_pass.getIdAtPosition(event.x, event.y)) if not picked_node: # There is no slicable object at the picked location return node_stack = picked_node.callDecoration("getStack") if node_stack: if node_stack.getProperty("anti_overhang_mesh", "value"): self._removeEraserMesh(picked_node) return elif node_stack.getProperty("support_mesh", "value") or node_stack.getProperty("infill_mesh", "value") or node_stack.getProperty("cutting_mesh", "value"): # Only "normal" meshes can have anti_overhang_meshes added to them return # Create a pass for picking a world-space location from the mouse location active_camera = self._controller.getScene().getActiveCamera() picking_pass = PickingPass(active_camera.getViewportWidth(), active_camera.getViewportHeight()) picking_pass.render() picked_position = picking_pass.getPickedPosition(event.x, event.y) # Add the anti_overhang_mesh cube at the picked location self._createEraserMesh(picked_node, picked_position)
def canvasPressEvent(self, e): pressed_button = e.button() if pressed_button == 1: self.startPoint = e.pos() self.endPoint = self.startPoint self.isEmittingPoint = True self.height = float(self.canvas.height()) self.width = float(self.canvas.width()) modifiers = QApplication.keyboardModifiers() self.isKeepRelativeScale = bool(modifiers & Qt.ControlModifier) self.isLayerVisible = isLayerVisible(self.iface, self.layer) setLayerVisible(self.iface, self.layer, False) scaling = self.computeScaling() self.showScaling(*scaling) self.layer.history.append({"action": "scale", "xScale": self.layer.xScale, "yScale": self.layer.yScale})
def event(self, event): modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers == Qt.ControlModifier if event.type == Event.KeyPressEvent and ctrl_is_active: if event.key == KeyEvent.UpKey: self.setLayer(self._current_layer_num + 1) return True if event.key == KeyEvent.DownKey: self.setLayer(self._current_layer_num - 1) return True if event.type == Event.ViewActivateEvent: Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged) self._onGlobalStackChanged() elif event.type == Event.ViewDeactivateEvent: self._wireprint_warning_message.hide() Application.getInstance().globalContainerStackChanged.disconnect(self._onGlobalStackChanged) if self._global_container_stack: self._global_container_stack.propertyChanged.disconnect(self._onPropertyChanged)
def event(self, event): modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers == Qt.ControlModifier if event.type == Event.KeyPressEvent and ctrl_is_active: if event.key == KeyEvent.UpKey: self.setLayer(self._current_layer_num + 1) return True if event.key == KeyEvent.DownKey: self.setLayer(self._current_layer_num - 1) return True if event.type == Event.ViewActivateEvent: # Make sure the LayerPass is created self.getLayerPass() Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged) self._onGlobalStackChanged() if not self._layerview_composite_shader: self._layerview_composite_shader = OpenGL.getInstance().createShaderProgram( os.path.join(PluginRegistry.getInstance().getPluginPath("LayerView"), "layerview_composite.shader") ) if not self._composite_pass: self._composite_pass = self.getRenderer().getRenderPass("composite") self._old_layer_bindings = self._composite_pass.getLayerBindings()[ : ] # make a copy so we can restore to it later self._composite_pass.getLayerBindings().append("layerview") self._old_composite_shader = self._composite_pass.getCompositeShader() self._composite_pass.setCompositeShader(self._layerview_composite_shader) elif event.type == Event.ViewDeactivateEvent: self._wireprint_warning_message.hide() Application.getInstance().globalContainerStackChanged.disconnect(self._onGlobalStackChanged) if self._global_container_stack: self._global_container_stack.propertyChanged.disconnect(self._onPropertyChanged) self._composite_pass.setLayerBindings(self._old_layer_bindings) self._composite_pass.setCompositeShader(self._old_composite_shader)
def keyPressEvent(self, event): modifier = QApplication.keyboardModifiers() key = event.key() stepSize = self.stepSize stepSize *= self.stepBigMultipler if (modifier & Qt.ShiftModifier) else 1 stepSize *= self.stepMultiplier if (modifier & Qt.ControlModifier) else 1 #Resize window height and width if key == Qt.Key_Left: self.resize_window(-stepSize, 0) if key == Qt.Key_Right: self.resize_window(stepSize, 0) if key == Qt.Key_Up: self.resize_window(0, -stepSize) if key == Qt.Key_Down: self.resize_window(0, stepSize) #Move window if key == Qt.Key_A: self.move_window(-stepSize, 0) if key == Qt.Key_D: self.move_window(stepSize, 0) if key == Qt.Key_W: self.move_window(0, -stepSize) if key == Qt.Key_S: self.move_window(0, stepSize) if key == Qt.Key_Space: self.take_screenshot() if key == Qt.Key_Z: self.save_screenshot() if key == Qt.Key_C: self.clear_screenshot() if key == Qt.Key_Q: self.close() if key == Qt.Key_F: self.maximize_window()
def keyPressEvent(self, event): modifier = QApplication.keyboardModifiers() key = event.key() stepSize = self.stepSize stepSize *= self.stepBigMultipler if (modifier & Qt.ShiftModifier) else 1 stepSize *= self.stepMultiplier if (modifier & Qt.ControlModifier) else 1 #Resize end point height and width (mouseReleaseEvent) if key == Qt.Key_Left: self.resize_end_point(-stepSize, 0) if key == Qt.Key_Right: self.resize_end_point(stepSize, 0) if key == Qt.Key_Up: self.resize_end_point(0, -stepSize) if key == Qt.Key_Down: self.resize_end_point(0, stepSize) ##Resize begin point height and width (mousePressEvent) if key == Qt.Key_A: self.resize_start_point(-stepSize, 0) if key == Qt.Key_D: self.resize_start_point(stepSize, 0) if key == Qt.Key_W: self.resize_start_point(0, -stepSize) if key == Qt.Key_S: self.resize_start_point(0, stepSize) #Screenshot Functions/Miscellaneous if key == Qt.Key_Space: self.take_screenshot() if key == Qt.Key_Z: self.save_screenshot() if key == Qt.Key_C: self.change_transparent() self.clear_screenshot() if key == Qt.Key_Q: self.close()
def output(self, relativemode=False, language='nederlands'): if relativemode: pitch = self._pitch.copy() pitch.makeRelative(Note.LastPitch) Note.LastPitch.note = self._pitch.note Note.LastPitch.octave = self._pitch.octave else: pitch = self._pitch # also octavecheck if Shift is held return pitch.output(language) + (('='+ly.pitch.octaveToString(self._pitch.octave)) if QApplication.keyboardModifiers() & Qt.SHIFT else '')