def __init__(self, form) -> None: self._form = form self._machine = machine = QStateMachine() init = self._make_initial_state(form) dev_fetched = self._make_dev_fetched_state(form) save = self._make_save_state(form) machine.addState(init) machine.addState(dev_fetched) machine.addState(save) machine.setInitialState(init) init.addTransition(form.gotDevices, dev_fetched) unselected_tr = self.CheckedTranstion( form.deviceList.itemChanged, target=dev_fetched, testFn=lambda: not self._hasSelectedItems()) save.addTransition(unselected_tr) save.addTransition(form.editBtn.clicked, init) selected_tr = self.CheckedTranstion(form.deviceList.itemChanged, target=save, testFn=self._hasSelectedItems) entered_dev_feched = self.CheckedTranstion( dev_fetched.entered, target=save, testFn=self._hasSelectedItems) dev_fetched.addTransition(selected_tr) dev_fetched.addTransition(entered_dev_feched) dev_fetched.addTransition(form.editBtn.clicked, init) machine.start()
def __init__(self, tabWidget, helper, *args): super(HTTYD, self).__init__(*args) self.setupUi(self) self._machine = QStateMachine() self._setup_states() self._event = threading.Event() self.tabName = "HTTYD" self.menuName = "HTTYD Tab" self.tabWidget = tabWidget # the above helper cf instances are only assigned to _cf_L and _cf_R after they start logging self._helper = helper self._cf = None self.last_time = 0 # assign the label to the _cf_status_ string self._cf_status = self.cfStatusLabel.text() self._status = self.statusLabel.text() # initial flight mode self.flying_enabled = False self.switch_flight_mode(FlightModeStates.DISCONNECTED) self.path_pos_threshold = 0.2 # The position and rotation of the cf and wand obtained by the # lighthouse tracking, if it cant be tracked the position becomes Nan self.cf_pos = Position(0, 0, 0) self.wand_pos = Position(0, 0, 0) # The regular cf_pos can a times due to lost tracing become Nan, # this the latest known valid cf position self.valid_cf_pos = Position(0, 0, 0) # Always wrap callbacks from Crazyflie API though QT Signal/Slots # to avoid manipulating the UI when rendering it self._connected_signal.connect(self._connected) self._disconnected_signal.connect(self._disconnected) self._log_data_signal.connect(self._log_data_received) self._param_updated_signal.connect(self._param_updated) # connect the status change signal to the update status # funciton self.statusChanged.connect(self._update_status) self.cfStatusChanged.connect(self._update_cf_status) # Connect the Crazyflie API callbacks to the signals self._helper.cf.connected.add_callback(self._connected_signal.emit) self._helper.cf.disconnected.add_callback(self._disconnected_signal.emit) # Connect the UI elements self.liftButton.clicked.connect(self.set_lift_mode) self.landButton.clicked.connect(self.set_land_mode) self.followButton.clicked.connect(self.set_follow_mode) self.emergencyButton.clicked.connect(self.set_kill_engine)
def __init__(self, stickMan, keyReceiver): self.m_stickMan = stickMan self.m_keyReceiver = keyReceiver # Create animation group to be used for all transitions. self.m_animationGroup = QParallelAnimationGroup() stickManNodeCount = self.m_stickMan.nodeCount() self._pas = [] for i in range(stickManNodeCount): pa = QPropertyAnimation(self.m_stickMan.node(i), 'pos') self._pas.append(pa) self.m_animationGroup.addAnimation(pa) # Set up intial state graph. self.m_machine = QStateMachine() self.m_machine.addDefaultAnimation(self.m_animationGroup) self.m_alive = QState(self.m_machine) self.m_alive.setObjectName('alive') # Make it blink when lightning strikes before entering dead animation. lightningBlink = QState(self.m_machine) lightningBlink.assignProperty(self.m_stickMan.scene(), 'backgroundBrush', Qt.white) lightningBlink.assignProperty(self.m_stickMan, 'penColor', Qt.black) lightningBlink.assignProperty(self.m_stickMan, 'fillColor', Qt.white) lightningBlink.assignProperty(self.m_stickMan, 'isDead', True) timer = QTimer(lightningBlink) timer.setSingleShot(True) timer.setInterval(100) lightningBlink.entered.connect(timer.start) lightningBlink.exited.connect(timer.stop) self.m_dead = QState(self.m_machine) self.m_dead.assignProperty(self.m_stickMan.scene(), 'backgroundBrush', Qt.black) self.m_dead.assignProperty(self.m_stickMan, 'penColor', Qt.white) self.m_dead.assignProperty(self.m_stickMan, 'fillColor', Qt.black) self.m_dead.setObjectName('dead') # Idle state (sets no properties). self.m_idle = QState(self.m_alive) self.m_idle.setObjectName('idle') self.m_alive.setInitialState(self.m_idle) # Lightning strikes at random. self.m_alive.addTransition(LightningStrikesTransition(lightningBlink)) lightningBlink.addTransition(timer.timeout, self.m_dead) self.m_machine.setInitialState(self.m_alive)
def my_ui(self): v_box = QVBoxLayout() config_box = QGroupBox('配置') grid = QGridLayout() label_one = QLabel('当前状态') self.choose_button = QPushButton() self.machine = QStateMachine() zoom_state = QState(self.machine) shrink_state = QState(self.machine) self.machine.setInitialState(zoom_state) zoom_state.assignProperty(self.choose_button, 'text', '放大') shrink_state.assignProperty(self.choose_button, 'text', '缩小') shrink_state.addTransition(self.choose_button.clicked, zoom_state) zoom_state.addTransition(self.choose_button.clicked, shrink_state) self.machine.start() grid.addWidget(label_one, 0, 0) grid.addWidget(self.choose_button, 0, 1) grid.addWidget(QLabel('倍数'), 1, 0) slider = QSlider(Qt.Horizontal) slider.setMaximum(5) slider.setMinimum(1) slider.setTickInterval(1) slider.setTickPosition(QSlider.TicksBothSides) slider.setSingleStep(1) slider.valueChanged.connect(self.value_deal) grid.addWidget(slider, 1, 1) kind = QComboBox() for v in self.kinds: kind.addItem(v) kind.activated.connect(self.choosed) grid.addWidget(QLabel('类别:'), 2, 0) grid.addWidget(kind, 2, 1) button_show = QPushButton('显示') button_show.clicked.connect(self.show_image) config_box.setLayout(grid) v_box.addWidget(config_box) v_box.addWidget(button_show) self.setLayout(v_box) self.resize(10, 300) self.show()
def init_ui(self): vbox = QVBoxLayout() button1 = QPushButton('fuck1') vbox.addWidget(button1) button1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) vbox.setContentsMargins(80, 80, 80, 80) self.setLayout(vbox) machine = QStateMachine(self) s1 = QState() s1.assignProperty(button1, "text", "Outside") s2 = QState() s2.assignProperty(button1, "text", "Inside") enter_transition = QEventTransition(button1, QEvent.Enter) enter_transition.setTargetState(s2) s1.addTransition(enter_transition) leave_transition = QEventTransition(button1, QEvent.Leave) leave_transition.setTargetState(s1) s2.addTransition(leave_transition) s3 = QState() s3.assignProperty(button1, 'text', 'Pressing...') press_transition = QEventTransition(button1, QEvent.MouseButtonPress) press_transition.setTargetState(s3) s2.addTransition(press_transition) release_transition = QEventTransition(button1, QEvent.MouseButtonRelease) release_transition.setTargetState(s2) s3.addTransition(release_transition) machine.addState(s1) machine.addState(s2) machine.addState(s3) machine.setInitialState(s1) machine.start()
def __init__(self): print('Стенд А3135') print('(c) ПКБ ЦТ, 2020') self.server = Server() self.form = MainForm(self.server) self.stm = QStateMachine() self.controller = Controller(server=self.server, form=self.form, stm=self.stm) self.controller.show_panel('меню') self.controller.text.setText('Hello') self.controller.show_menu('Главное меню') self.form.showMaximized() self.menu_state = MenuState(self.controller) self.stm.setInitialState(self.menu_state) self.stm.start()
def __init__(self, secret_key, access_key, server_url, external_wallet_amount): super().__init__() self.fsm = QStateMachine() self.timerRequestOrderbook = QTimer() self.timerRequestAccountInfo = QTimer() self.currentTime = datetime.datetime.now() self.init() self.createState() self.upbitIf = UpbitWrapper.UpbitWrapper(secret_key, access_key, server_url, 'KRW-XRP') self.current_price = 0 self.current_ask_price = 0 self.current_bid_price = 0 self.external_wallet_amount = external_wallet_amount self.current_account_info = 0
def init_log_sm(self): self.log_state = QStateMachine() pre_system = QState() pre_event = QState() post_event = QState() self.log_state.addState(pre_system) self.log_state.addState(pre_event) self.log_state.addState(post_event) self.log_state.setInitialState(pre_system) pre_system.assignProperty(self.events, "enabled", False) pre_system.assignProperty(self.compass, "enabled", False) pre_system.assignProperty(self.exact_angle, "enabled", False) pre_event.assignProperty(self.events, "enabled", True) pre_event.assignProperty(self.compass, "enabled", False) pre_event.assignProperty(self.exact_angle, "enabled", False) post_event.assignProperty(self.compass, "enabled", True) post_event.assignProperty(self.exact_angle, "enabled", True) pre_system.addTransition( self.systems.acted, pre_event ) pre_system.addTransition(self.timeout_timer.timeout, pre_system) pre_event.addTransition(self.timeout_timer.timeout, pre_system) post_event.addTransition(self.timeout_timer.timeout, pre_system) pre_event.addTransition( self.systems.acted, pre_event ) post_event.addTransition( self.systems.acted, pre_event ) post_event.addTransition( self.events.acted, post_event ) pre_event.addTransition( self.events.acted, post_event ) pre_system.entered.connect(self.events.switch_active) pre_system.entered.connect(self.systems.switch_active) pre_event.entered.connect(self.events.switch_active) post_event.exited.connect(self.compass.clear_state) post_event.exited.connect(lambda: self.exact_angle.log_angle(False)) self.log_state.setRunning(True)
def Home(self): self.items = [] for i in range(len(self.names['home'])): item = QPushButton(self) item.setText(self.names['home'][i]) item.setGeometry(395, 350, 120, 80) item.setStyleSheet( "QPushButton:hover{background-color:rgb(241, 90, 36);border:5px solid rgb(0, 97, 157);}\n" "QPushButton{color:white;background-color: rgb(50, 50, 50);border:5px solid rgb(255, 255, 255);}QPushButton:pressed{color:white;background-color: rgb(50, 50, 50);border:5px solid rgb(255, 255, 255);}\n" "") self.font.setPointSize(15) item.setFont(self.font) self.items.append(item) exec("""item.clicked.connect(partial(self.IND,i=%i))""" % (i)) self.rootState = QState() self.tiledState = QState(self.rootState) self.centeredState = QState(self.rootState) for i, item in enumerate(self.items): self.tiledState.assignProperty( item, 'pos', QPointF(((i % 6) * 5.3) * 30, ((i // 6) * 5.3) * 30)) self.centeredState.assignProperty(item, 'pos', QPointF()) self.states = QStateMachine() self.states.addState(self.rootState) self.states.setInitialState(self.rootState) self.rootState.setInitialState(self.centeredState) self.group = QParallelAnimationGroup() for i, item in enumerate(self.items): anim = QPropertyAnimation(item, b'pos') anim.setStartValue(QPoint(400, 300)) anim.setDuration(750 + i * 25) anim.setEasingCurve(QEasingCurve.InOutBack) self.group.addAnimation(anim) for u in self.items: trans = self.rootState.addTransition(u.clicked, self.tiledState) trans.addAnimation(self.group) self.states.start()
def twoStateButton(name,stateMachine,action,*states): st = QStateMachine() a1,a2 = states s1,s2 = QState(),QState() icon1 = QIcon(Icons + a1[1]) icon2 = QIcon(Icons + a2[1]) s1.setObjectName(a1[0]) s2.setObjectName(a2[0]) s1.assignProperty(action, "icon", icon1) s2.assignProperty(action, "icon", icon2) s1.assignProperty(action, "text", a1[0]) s2.assignProperty(action, "text", a2[0]) s1.addTransition(action.triggered, s2) s2.addTransition(action.triggered, s1) st.addState(s1) st.addState(s2) st.setInitialState(s1) stateMachine[name] = st st.start()
def gen_output_widget(self): if self._name != "__none__": # Each output is a tuple [QPushButton, QStateMachine] self.output_widget = (QPushButton(), QStateMachine()) self.output_widget[0].setStyleSheet( "background-color: #dddddd; border-style: solid; border-width: 1px; border-color: #aaaaaa; padding: 7px;" ) # Create output states output_off = QState() output_on = QState() # Attach states to output button and define state transitions output_off.assignProperty(self.output_widget[0], 'text', "%s Output On" % self._name.split()[1]) output_off.addTransition(self.output_widget[0].clicked, output_on) output_off.entered.connect(self.exec_output_off) output_on.assignProperty(self.output_widget[0], 'text', '%s Output Off' % self._name.split()[1]) output_on.addTransition(self.output_widget[0].clicked, output_off) output_on.entered.connect(self.exec_output_on) # Add states, set initial state, and start machine self.output_widget[1].addState(output_off) self.output_widget[1].addState(output_on) self.output_widget[1].setInitialState(output_off) self.output_widget[1].start() else: self.output_widget = (QPushButton(), False) self.output_widget[0].setStyleSheet( "background-color: #dddddd; border-style: solid; border-width: 1px; border-color: #aaaaaa; padding: 7px;" ) self.output_widget[0].setEnabled(False) self.output_widget[0].setText("Keithley not Initialized")
def __init__(self, parent=None): super().__init__(parent) self.setAttribute(Qt.WA_QuitOnClose) self.setAttribute(Qt.WA_DeleteOnClose) # create instance variables self._ui = uic.loadUi('mainwindow.ui', self) # create models self.measureModels = { 1: MeasureModel(self), 2: MeasureModel(self), } self._instrumentManager = InstrumentManager(self, self.measureModels) self.machine = QStateMachine() self.stateInitial = QState() self.stateReadyToCheck = QState() self.stateReadyToMeasure = QState() self.stateAfterMeasure = QState() self.initDialog()
def __init__(self): QWidget.__init__(self) style1 = "background-color: red" style2 = "background-color: black" animation = QPropertyAnimation(self, b'styleSheet') animation.setDuration(5) state1 = QState() state2 = QState() state1.assignProperty(self, 'styleSheet', style1) state2.assignProperty(self, 'styleSheet', style2) state1.addTransition(state1.propertiesAssigned, state2) state2.addTransition(state2.propertiesAssigned, state1) self.machine = QStateMachine() self.machine.addDefaultAnimation(animation) self.machine.addState(state1) self.machine.addState(state2) self.machine.setInitialState(state1) self.machine.start()
p4.setGeometry(QRectF(0.0, 236.0, 64.0, 64.0)) scene = QGraphicsScene(0, 0, 300, 300) scene.setBackgroundBrush(Qt.white) scene.addItem(p1) scene.addItem(p2) scene.addItem(p3) scene.addItem(p4) window = QGraphicsView(scene) window.setFrameStyle(0) window.setAlignment(Qt.AlignLeft | Qt.AlignTop) window.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) window.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) machine = QStateMachine() machine.setGlobalRestorePolicy(QStateMachine.RestoreProperties) group = QState(machine) selectedRect = QRect(86, 86, 128, 128) idleState = QState(group) group.setInitialState(idleState) objects = [p1, p2, p3, p4] createStates(objects, selectedRect, group) createAnimations(objects, machine) machine.setInitialState(group) machine.start()
def __init__(self): super().__init__() self.ocx = QAxWidget("KHOPENAPI.KHOpenAPICtrl.1") self.fsm = QStateMachine() self.createState()
def __init__(self, size, parent=None): super(PadNavigator, self).__init__(parent) self.form = Ui_Form() splash = SplashItem() splash.setZValue(1) pad = FlippablePad(size) flipRotation = QGraphicsRotation(pad) xRotation = QGraphicsRotation(pad) yRotation = QGraphicsRotation(pad) flipRotation.setAxis(Qt.YAxis) xRotation.setAxis(Qt.YAxis) yRotation.setAxis(Qt.XAxis) pad.setTransformations([flipRotation, xRotation, yRotation]) backItem = QGraphicsProxyWidget(pad) widget = QWidget() self.form.setupUi(widget) self.form.hostName.setFocus() backItem.setWidget(widget) backItem.setVisible(False) backItem.setFocus() backItem.setCacheMode(QGraphicsItem.ItemCoordinateCache) r = backItem.rect() backItem.setTransform(QTransform().rotate(180, Qt.YAxis).translate( -r.width() / 2, -r.height() / 2)) selectionItem = RoundRectItem(QRectF(-60, -60, 120, 120), QColor(Qt.gray), pad) selectionItem.setZValue(0.5) smoothSplashMove = QPropertyAnimation(splash) smoothSplashOpacity = QPropertyAnimation(splash) smoothSplashMove.setEasingCurve(QEasingCurve.InQuad) smoothSplashMove.setDuration(250) smoothSplashOpacity.setDuration(250) smoothXSelection = QPropertyAnimation(selectionItem) smoothYSelection = QPropertyAnimation(selectionItem) smoothXRotation = QPropertyAnimation(xRotation) smoothYRotation = QPropertyAnimation(yRotation) smoothXSelection.setDuration(125) smoothYSelection.setDuration(125) smoothXRotation.setDuration(125) smoothYRotation.setDuration(125) smoothXSelection.setEasingCurve(QEasingCurve.InOutQuad) smoothYSelection.setEasingCurve(QEasingCurve.InOutQuad) smoothXRotation.setEasingCurve(QEasingCurve.InOutQuad) smoothYRotation.setEasingCurve(QEasingCurve.InOutQuad) smoothFlipRotation = QPropertyAnimation(flipRotation) smoothFlipScale = QPropertyAnimation(pad) smoothFlipXRotation = QPropertyAnimation(xRotation) smoothFlipYRotation = QPropertyAnimation(yRotation) flipAnimation = QParallelAnimationGroup(self) smoothFlipScale.setDuration(500) smoothFlipRotation.setDuration(500) smoothFlipXRotation.setDuration(500) smoothFlipYRotation.setDuration(500) smoothFlipScale.setEasingCurve(QEasingCurve.InOutQuad) smoothFlipRotation.setEasingCurve(QEasingCurve.InOutQuad) smoothFlipXRotation.setEasingCurve(QEasingCurve.InOutQuad) smoothFlipYRotation.setEasingCurve(QEasingCurve.InOutQuad) smoothFlipScale.setKeyValueAt(0, 1.0) smoothFlipScale.setKeyValueAt(0.5, 0.7) smoothFlipScale.setKeyValueAt(1, 1.0) flipAnimation.addAnimation(smoothFlipRotation) flipAnimation.addAnimation(smoothFlipScale) flipAnimation.addAnimation(smoothFlipXRotation) flipAnimation.addAnimation(smoothFlipYRotation) setVariablesSequence = QSequentialAnimationGroup() setFillAnimation = QPropertyAnimation(pad) setBackItemVisibleAnimation = QPropertyAnimation(backItem) setSelectionItemVisibleAnimation = QPropertyAnimation(selectionItem) setFillAnimation.setDuration(0) setBackItemVisibleAnimation.setDuration(0) setSelectionItemVisibleAnimation.setDuration(0) setVariablesSequence.addPause(250) setVariablesSequence.addAnimation(setBackItemVisibleAnimation) setVariablesSequence.addAnimation(setSelectionItemVisibleAnimation) setVariablesSequence.addAnimation(setFillAnimation) flipAnimation.addAnimation(setVariablesSequence) stateMachine = QStateMachine(self) splashState = QState(stateMachine) frontState = QState(stateMachine) historyState = QHistoryState(frontState) backState = QState(stateMachine) frontState.assignProperty(pad, "fill", False) frontState.assignProperty(splash, "opacity", 0.0) frontState.assignProperty(backItem, "visible", False) frontState.assignProperty(flipRotation, "angle", 0.0) frontState.assignProperty(selectionItem, "visible", True) backState.assignProperty(pad, "fill", True) backState.assignProperty(backItem, "visible", True) backState.assignProperty(xRotation, "angle", 0.0) backState.assignProperty(yRotation, "angle", 0.0) backState.assignProperty(flipRotation, "angle", 180.0) backState.assignProperty(selectionItem, "visible", False) stateMachine.addDefaultAnimation(smoothXRotation) stateMachine.addDefaultAnimation(smoothYRotation) stateMachine.addDefaultAnimation(smoothXSelection) stateMachine.addDefaultAnimation(smoothYSelection) stateMachine.setInitialState(splashState) anyKeyTransition = QEventTransition(self, QEvent.KeyPress, splashState) anyKeyTransition.setTargetState(frontState) anyKeyTransition.addAnimation(smoothSplashMove) anyKeyTransition.addAnimation(smoothSplashOpacity) enterTransition = QKeyEventTransition(self, QEvent.KeyPress, Qt.Key_Enter, backState) returnTransition = QKeyEventTransition(self, QEvent.KeyPress, Qt.Key_Return, backState) backEnterTransition = QKeyEventTransition(self, QEvent.KeyPress, Qt.Key_Enter, frontState) backReturnTransition = QKeyEventTransition(self, QEvent.KeyPress, Qt.Key_Return, frontState) enterTransition.setTargetState(historyState) returnTransition.setTargetState(historyState) backEnterTransition.setTargetState(backState) backReturnTransition.setTargetState(backState) enterTransition.addAnimation(flipAnimation) returnTransition.addAnimation(flipAnimation) backEnterTransition.addAnimation(flipAnimation) backReturnTransition.addAnimation(flipAnimation) columns = size.width() rows = size.height() stateGrid = [] for y in range(rows): stateGrid.append([QState(frontState) for _ in range(columns)]) frontState.setInitialState(stateGrid[0][0]) selectionItem.setPos(pad.iconAt(0, 0).pos()) for y in range(rows): for x in range(columns): state = stateGrid[y][x] rightTransition = QKeyEventTransition(self, QEvent.KeyPress, Qt.Key_Right, state) leftTransition = QKeyEventTransition(self, QEvent.KeyPress, Qt.Key_Left, state) downTransition = QKeyEventTransition(self, QEvent.KeyPress, Qt.Key_Down, state) upTransition = QKeyEventTransition(self, QEvent.KeyPress, Qt.Key_Up, state) rightTransition.setTargetState(stateGrid[y][(x + 1) % columns]) leftTransition.setTargetState( stateGrid[y][((x - 1) + columns) % columns]) downTransition.setTargetState(stateGrid[(y + 1) % rows][x]) upTransition.setTargetState(stateGrid[((y - 1) + rows) % rows][x]) icon = pad.iconAt(x, y) state.assignProperty(xRotation, "angle", -icon.x() / 6.0) state.assignProperty(yRotation, "angle", icon.y() / 6.0) state.assignProperty(selectionItem, "x", icon.x()) state.assignProperty(selectionItem, "y", icon.y()) frontState.assignProperty(icon, "visible", True) backState.assignProperty(icon, "visible", False) setIconVisibleAnimation = QPropertyAnimation(icon) setIconVisibleAnimation.setDuration(0) setVariablesSequence.addAnimation(setIconVisibleAnimation) scene = QGraphicsScene(self) scene.setBackgroundBrush( QBrush(QPixmap(":/images/blue_angle_swirl.jpg"))) scene.setItemIndexMethod(QGraphicsScene.NoIndex) scene.addItem(pad) scene.setSceneRect(scene.itemsBoundingRect()) self.setScene(scene) sbr = splash.boundingRect() splash.setPos(-sbr.width() / 2, scene.sceneRect().top() - 2) frontState.assignProperty(splash, "y", splash.y() - 100.0) scene.addItem(splash) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setMinimumSize(50, 50) self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate) self.setCacheMode(QGraphicsView.CacheBackground) self.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform | QPainter.TextAntialiasing) if QGLFormat.hasOpenGL(): self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers))) stateMachine.start()
((i // 8) - 4) * kineticPix.height() + kineticPix.height() / 2)) # Centered. centeredState.assignProperty(item, 'pos', QPointF()) # Ui. view = View(scene) view.setWindowTitle("Animated Tiles") view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate) view.setBackgroundBrush(QBrush(bgPix)) view.setCacheMode(QGraphicsView.CacheBackground) view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) view.show() states = QStateMachine() states.addState(rootState) states.setInitialState(rootState) rootState.setInitialState(centeredState) group = QParallelAnimationGroup() for i, item in enumerate(items): anim = QPropertyAnimation(item, b'pos') anim.setDuration(750 + i * 25) anim.setEasingCurve(QEasingCurve.InOutBack) group.addAnimation(anim) trans = rootState.addTransition(ellipseButton.pressed, ellipseState) trans.addAnimation(group) trans = rootState.addTransition(figure8Button.pressed, figure8State)
def __init__(self, earth, desk_geo, screen_geo, *args, **kwargs): """ Please see help(MainWindow) for more info. """ super(MainWindow, self).__init__(*args, **kwargs) # Instantiate KeyboardCommands class self.commands = KeyboardCommands() # Will hold hand_recognition QtCapture class self.capture = None # Will hold camera object for OpenCV self.camera = None # Will hold thread for issuing GE commands self.command_thread = None # Make Qt gesture icon window frameless self.setWindowFlags(QtCore.Qt.FramelessWindowHint) # Get resolution, window size, and offsets for positioning self.google_earth = earth # Variables for popup windows self.popup_window = None self.popup_title = "" self.popup_text = "" # Available screen geometry self.desktop = desk_geo # Total screen geometry self.screen = screen_geo # Sets gesture icon window to be 1/4 of available screen space self.qt_window_height = int(self.desktop.height() * 1 / 4) # Set geometry of Qt gesture icon window self.setGeometry( QtWidgets.QStyle.alignedRect( QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter, QtCore.QSize(self.desktop.width(), self.qt_window_height), self.desktop)) # Create layouts for organizing Qt gesture icon window self.layout = QVBoxLayout() self.layout1 = QHBoxLayout() self.layout2 = QHBoxLayout() self.layout3 = QHBoxLayout() # Dictionary to hold labels once they are created self.label_dict = dict() # Lists hold gesture icon file names and gesture icon titles self.image_list = [ 'images/index_up.png', 'images/v_sign.png', 'images/thumb_left.png', 'images/thumb_right.png', 'images/fist.png', 'images/five_wide.png', 'images/palm.png', 'images/shaka.png' ] self.title_list = [ 'Move Up', 'Move Down', 'Move Left', 'Move Right', 'Zoom In', 'Zoom Out', 'Tilt Up', 'Tilt Down' ] # Create and add 6 labels containing hand gesture image to layout2 and 6 # labels with the gesture descriptions to layout1 for num in range(0, 8): # Each label is created to hold gesture icon image self.label = QLabel(self) # Pixmap is created with the current gesture icon image self.pixmap = QPixmap(self.image_list[num]) # Breakpoints to scale size of gesture icons for different resolutions if self.screen.width() >= 2560: self.pixmap = self.pixmap.scaledToWidth(225) elif self.screen.width() >= 1920: self.pixmap = self.pixmap.scaledToWidth(185) elif self.screen.width() > 1280 and self.screen.height() >= 1200: self.pixmap = self.pixmap.scaledToWidth(175) elif self.screen.width() > 800 and self.screen.height() >= 1024: self.pixmap = self.pixmap.scaledToWidth(125) elif self.screen.width() > 800: self.pixmap = self.pixmap.scaledToWidth(100) else: self.pixmap = self.pixmap.scaledToWidth(50) # Assigns gesture icon image to the current label self.label.setPixmap(self.pixmap) # Create gesture title label for the image self.label_title = QLabel(self.title_list[num]) # Store current icon image label in dictionary self.label_dict[num] = self.label # Place current icon image label in layout self.layout2.addWidget(self.label_dict[num], alignment=QtCore.Qt.AlignCenter) # Place current icon image title label in layout self.layout1.addWidget(self.label_title, alignment=QtCore.Qt.AlignCenter) # Create state machine to reliably handle state changes during threading self.state_machine = QStateMachine() # Create button to handle state changes when pressed self.state_button = QPushButton(self) self.state_button.setStyleSheet("background-color: silver") # Connect button released signal to check_state slot self.state_button.released.connect(self.check_state) # Create on state for state machine self.on = QState() # Create off state for state machine self.off = QState() # Add transition for on state to off state when offSignal is emitted self.on.addTransition(self.offSignal, self.off) # Add transition for on state to on state when state_button clicked signal emitted self.on.addTransition(self.state_button.clicked, self.on) # Add transition for off state to on state when onSignal is emitted self.off.addTransition(self.onSignal, self.on) # Assign text property to state_button in on state self.on.assignProperty(self.state_button, "text", "Start Gesture Navigation") # Assign text property to state_button in off state self.off.assignProperty(self.state_button, "text", "Stop Gesture Navigation") # Add off state to state machine self.state_machine.addState(self.off) # Add on state to state machine self.state_machine.addState(self.on) # Set state machine initial state to on self.state_machine.setInitialState(self.on) # State state machine self.state_machine.start() # Create gesture tips button and connect it to start_gesture_tips slot self.tips_button = QPushButton("Gesture Navigation Tips") self.tips_button.setStyleSheet("background-color: silver") self.tips_button.pressed.connect(self.start_gesture_tips) # Create exit button and connect it to exit slot self.exit_button = QPushButton("Exit Program") self.exit_button.setStyleSheet("background-color: silver") self.exit_button.pressed.connect(self.exit) # Add tips, state, and exit button to layout 3 self.layout3.addWidget(self.tips_button) self.layout3.addWidget(self.state_button) self.layout3.addWidget(self.exit_button) # Add layout 1, 2, and 3 to layout self.layout.addLayout(self.layout1) self.layout.addLayout(self.layout2) self.layout.addLayout(self.layout3) # Create widget to hold layout, add layout to widget self.widget = QWidget() self.widget.setLayout(self.layout) # Set widget with layouts as central widget self.setCentralWidget(self.widget)
def gen_mpp_ctrl(self): ################################# # mpp tracking controls # self.mpp_ctrl = QWidget() self.mpp_ctrl_layout = QVBoxLayout() # Create QStateMachine for output state self.mpp_state = QStateMachine() self.mpp_meas_button = QPushButton() self.mpp_meas_button.setStyleSheet( "background-color: #dddddd; border-style: solid; border-width: 1px; border-color: #aaaaaa; padding: 7px;" ) # Create output states self.mpp_meas_off = QState() self.mpp_meas_on = QState() # Attach states to output button and define state transitions self.mpp_meas_off.assignProperty(self.mpp_meas_button, 'text', 'MPP Monitor Off') self.mpp_meas_off.addTransition(self.mpp_meas_button.clicked, self.mpp_meas_on) self.mpp_meas_off.entered.connect(self.exec_mpp_stop) self.mpp_meas_on.assignProperty(self.mpp_meas_button, 'text', 'MPP Monitor On') self.mpp_meas_on.addTransition(self.mpp_meas_button.clicked, self.mpp_meas_off) self.mpp_meas_on.entered.connect(self.exec_mpp_run) # Add states, set initial state, and start machine self.mpp_state.addState(self.mpp_meas_off) self.mpp_state.addState(self.mpp_meas_on) self.mpp_state.setInitialState(self.mpp_meas_off) self.mpp_state.start() # Tracking mode initialization # Note this example of passing arguments to a callback self.mpp_bias_config = { "unit": "V", "min": "m", "max": "", "label": "MPP Initialization (V)", "limit": 2.0, "signed": True, "default": [0.30, ""] } self.mpp_bias = QVisaUnitSelector.QVisaUnitSelector( self.mpp_bias_config) self.mpp_bias.unit_value.valueChanged.connect( lambda arg=self.mpp_bias.value(): self.update_bias(arg)) # Compliance Spinbox self.mpp_cmpl_config = { "unit": "A", "min": "u", "max": "", "label": "Compliance (A)", "limit": 1.0, "signed": False, "default": [100, "m"] } self.mpp_cmpl = QVisaUnitSelector.QVisaUnitSelector( self.mpp_cmpl_config) # Tracking mode convergence self.mpp_ampl_config = { "unit": "V", "min": "u", "max": "m", "label": "Sense amplitude (mV)", "limit": 100, "signed": False, "default": [20.0, "m"] } self.mpp_ampl = QVisaUnitSelector.QVisaUnitSelector( self.mpp_ampl_config) # Delay self.mpp_gain_config = { "unit": "__DOUBLE__", "label": html.unescape("Proportional Gain (‰)"), "limit": 1000, "signed": False, "default": [30.0] } self.mpp_gain = QVisaUnitSelector.QVisaUnitSelector( self.mpp_gain_config) # Delay self.mpp_delay_config = { "unit": "__DOUBLE__", "label": "Measurement Interval (s)", "limit": 60.0, "signed": False, "default": [0.1] } self.mpp_delay = QVisaUnitSelector.QVisaUnitSelector( self.mpp_delay_config) # Add mpp widgets to layout self.mpp_ctrl_layout.addWidget(self.mpp_meas_button) self.mpp_ctrl_layout.addWidget(self.mpp_bias) self.mpp_ctrl_layout.addWidget(self.mpp_cmpl) self.mpp_ctrl_layout.addWidget(self.mpp_ampl) self.mpp_ctrl_layout.addWidget(self.mpp_gain) self.mpp_ctrl_layout.addWidget(self.mpp_delay) self.mpp_ctrl_layout.setContentsMargins(0, 0, 0, 0) # Set widget layout self.mpp_ctrl.setLayout(self.mpp_ctrl_layout)
def gen_iv_ctrl(self): # Sweep control layout self.iv_ctrl = QWidget() self.iv_ctrl_layout = QVBoxLayout() # Sweep measurement Button. This will be a state machine which # alternates between 'measure' and 'abort' states self.iv_meas_state = QStateMachine() self.iv_meas_button = QPushButton() self.iv_meas_button.setStyleSheet( "background-color: #dddddd; border-style: solid; border-width: 1px; border-color: #aaaaaa; padding: 7px;" ) # Create measurement states self.iv_meas_run = QState() self.iv_meas_stop = QState() # Assign state properties and transitions self.iv_meas_run.assignProperty(self.iv_meas_button, 'text', 'Abort Sweep') self.iv_meas_run.addTransition(self.iv_meas_button.clicked, self.iv_meas_stop) self.iv_meas_run.entered.connect(self.exec_iv_run) self.iv_meas_stop.assignProperty(self.iv_meas_button, 'text', 'Measure Sweep') self.iv_meas_stop.addTransition(self.iv_meas_button.clicked, self.iv_meas_run) self.iv_meas_stop.entered.connect(self.exec_iv_stop) # Add states, set initial state, and state machine self.iv_meas_state.addState(self.iv_meas_run) self.iv_meas_state.addState(self.iv_meas_stop) self.iv_meas_state.setInitialState(self.iv_meas_stop) self.iv_meas_state.start() # Sweep start self.iv_start_config = { "unit": "V", "min": "m", "max": "", "label": "Sweep Start (V)", "limit": 2.0, "signed": True, "default": [-0.5, ""] } self.iv_start = QVisaUnitSelector.QVisaUnitSelector( self.iv_start_config) # Sweep stop self.iv_stop_config = { "unit": "V", "min": "m", "max": "", "label": "Sweep Stop (V)", "limit": 2.0, "signed": True, "default": [0.5, ""] } self.iv_stop = QVisaUnitSelector.QVisaUnitSelector(self.iv_stop_config) # Compliance Spinbox self.iv_cmpl_config = { "unit": "A", "min": "u", "max": "", "label": "Compliance (A)", "limit": 1.0, "signed": False, "default": [100, "m"] } self.iv_cmpl = QVisaUnitSelector.QVisaUnitSelector(self.iv_cmpl_config) # Compliance self.iv_npts_config = { "unit": "__INT__", "label": "Number of Points", "limit": 256.0, "signed": False, "default": [51.0] } self.iv_npts = QVisaUnitSelector.QVisaUnitSelector(self.iv_npts_config) # Add sweep widgets to layout self.iv_ctrl_layout.addWidget(self.iv_meas_button) self.iv_ctrl_layout.addWidget(self.iv_start) self.iv_ctrl_layout.addWidget(self.iv_stop) self.iv_ctrl_layout.addWidget(self.iv_cmpl) self.iv_ctrl_layout.addWidget(self.iv_npts) self.iv_ctrl_layout.setContentsMargins(0, 0, 0, 0) # Set widget layout self.iv_ctrl.setLayout(self.iv_ctrl_layout)