def __init__(self, parent): super(Gyrometer, self).__init__() self.setLayout(QHBoxLayout(self)) self.parent = parent self.xData = [] self.yData = [] self.rotationX = 0 self.rotationY = 0 self.calibrationX = 0 self.calibrationY = 0 self.comm = None self.serial = None # Add serial monitor comPorts = list_ports.comports() for port in comPorts: if port.product == "Arduino Uno": self.comm = port.device break if self.comm is not None: self.serial = SerialMonitor(port=self.comm, baud=115200) self.serial.open() # Add serial read timer self.serialTimer = QTimer() self.serialTimer.timeout.connect(self.__readSerial) # Add graphic update timers self.sideViewTimer = QTimer() self.sideViewTimer.timeout.connect(self.rotateSideView) self.frontViewTimer = QTimer() self.frontViewTimer.timeout.connect(self.rotateFrontView) # Side view icon self._sideImage = GyroImage(Config.icons['gyro']['side']['path'], self, 'y', scaleWidth=150, compassRotation=90, fixedSize=300) self.layout().addWidget(self._sideImage) # Front view icon self._frontImage = GyroImage(Config.icons['gyro']['rear']['path'], self, 'x', scaleHeight=100, fixedSize=300) self.layout().addWidget(self._frontImage) # Load cal values file = open(Config.cal, 'rb') cal = pickle.load(file) self.calibrationX = cal['x'] self.calibrationY = cal['y'] file.close()
def test_dock_standalone(self): widget = QWidget() layout = QHBoxLayout() widget.setLayout(layout) layout.addStretch(1) widget.show() dock = CollapsibleDockWidget() layout.addWidget(dock) list_view = QListView() list_view.setModel(QStringListModel(["a", "b"], list_view)) label = QLabel("A label. ") label.setWordWrap(True) dock.setExpandedWidget(label) dock.setCollapsedWidget(list_view) dock.setExpanded(True) dock.setExpanded(False) timer = QTimer(dock, interval=50) timer.timeout.connect(lambda: dock.setExpanded(not dock.expanded())) timer.start() self.qWait() timer.stop()
def test_outputview(self): output = OutputView() output.show() line1 = "A line \n" line2 = "A different line\n" output.write(line1) self.assertEqual(six.text_type(output.toPlainText()), line1) output.write(line2) self.assertEqual(six.text_type(output.toPlainText()), line1 + line2) output.clear() self.assertEqual(six.text_type(output.toPlainText()), "") output.writelines([line1, line2]) self.assertEqual(six.text_type(output.toPlainText()), line1 + line2) output.setMaximumLines(5) def advance(): now = datetime.now().strftime("%c\n") output.write(now) text = six.text_type(output.toPlainText()) self.assertLessEqual(len(text.splitlines()), 5) timer = QTimer(output, interval=500) timer.timeout.connect(advance) timer.start() self.app.exec_()
def __init__(self, *args): super().__init__(*args) self.setAlignment(Qt.AlignTop | Qt.AlignLeft) self.__backgroundIcon = QIcon() self.__autoScroll = False self.__autoScrollMargin = 16 self.__autoScrollTimer = QTimer(self) self.__autoScrollTimer.timeout.connect(self.__autoScrollAdvance) # scale factor accumulating partial increments from wheel events self.__zoomLevel = 100 # effective scale level(rounded to whole integers) self.__effectiveZoomLevel = 100 self.__zoomInAction = QAction( self.tr("Zoom in"), self, objectName="action-zoom-in", shortcut=QKeySequence.ZoomIn, triggered=self.zoomIn, ) self.__zoomOutAction = QAction(self.tr("Zoom out"), self, objectName="action-zoom-out", shortcut=QKeySequence.ZoomOut, triggered=self.zoomOut) self.__zoomResetAction = QAction( self.tr("Reset Zoom"), self, objectName="action-zoom-reset", triggered=self.zoomReset, shortcut=QKeySequence(Qt.ControlModifier | Qt.Key_0))
def __init__(self, parent=None, **kwargs): # type: (Optional[QWidget], Any) -> None super().__init__(parent, **kwargs) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setLayout(layout) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) self.__tabs = [] # type: List[_Tab] self.__currentIndex = -1 self.__changeOnHover = False self.__iconSize = QSize(26, 26) self.__group = QButtonGroup(self, exclusive=True) self.__group.buttonPressed[QAbstractButton].connect( self.__onButtonPressed) self.setMouseTracking(True) self.__sloppyButton = None # type: Optional[QAbstractButton] self.__sloppyRegion = QRegion() self.__sloppyTimer = QTimer(self, singleShot=True) self.__sloppyTimer.timeout.connect(self.__onSloppyTimeout)
def __init__(self, session: Session): BaseWidget.__init__(self, session.name) self.set_margin(5) self.session = session self._reload = ControlButton('Reload') self._graph = ControlMatplotlib('Value') self._timer = QTimer() self._timer.timeout.connect(self.update) self._read = 0 self._deltas = None self._last_trial_end = None self._states_dict = {} self._trials_list = [] self.formset = ['_graph'] self.colors = list(mcolors.CSS4_COLORS.values()) self._graph.on_draw = self.__on_draw_evt self._reload.value = self.__reload_evt
def __init__(self): super().__init__() #: Input dissimilarity matrix self.matrix = None # type: Optional[DistMatrix] #: Data table from the `self.matrix.row_items` (if present) self.matrix_data = None # type: Optional[Table] #: Input data table self.signal_data = None self.__invalidated = True self.embedding = None self.effective_matrix = None self.__update_loop = None # timer for scheduling updates self.__timer = QTimer(self, singleShot=True, interval=0) self.__timer.timeout.connect(self.__next_step) self.__state = OWMDS.Waiting self.__in_next_step = False self.graph.pause_drawing_pairs() self.size_model = self.gui.points_models[2] self.size_model.order = \ self.gui.points_models[2].order[:1] \ + ("Stress", ) + \ self.gui.points_models[2].order[1:]
def test_splashscreen(self): splash = pkg_resources.resource_filename( config.__package__, "icons/orange-canvas-core-splash.svg" ) w = SplashScreen() w.setPixmap(QPixmap(splash)) w.setTextRect(QRect(100, 100, 400, 50)) w.show() def advance_time(): now = datetime.now() time = now.strftime("%c : %f") i = now.second % 3 if i == 2: w.setTextFormat(Qt.RichText) time = "<i>" + time + "</i>" else: w.setTextFormat(Qt.PlainText) w.showMessage(time, alignment=Qt.AlignCenter) rect = QRect(100, 100 + i * 20, 400, 50) w.setTextRect(rect) self.assertEqual(w.textRect(), rect) timer = QTimer(w, interval=1) timer.timeout.connect(advance_time) timer.start() self.app.exec_()
def __init__(self, parent, plot): super().__init__(parent, plot) self.__timer = QTimer(self, interval=50) self.__timer.timeout.connect(self.__timeout) self._radius = 20.0 self._density = 4.0 self._pos = None
def __init__(self): super().__init__() self.cap = None self.snapshot_flash = 0 self.IMAGE_DIR = tempfile.mkdtemp(prefix='Orange-WebcamCapture-') self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) box = self.controlArea image = self.imageLabel = QLabel(margin=0, alignment=Qt.AlignCenter, sizePolicy=QSizePolicy( QSizePolicy.Ignored, QSizePolicy.Ignored)) box.layout().addWidget(image, 100) self.name_edit = line_edit = gui.lineEdit(box, self, 'image_title', 'Title:', orientation=Qt.Horizontal) line_edit.setPlaceholderText(self.DEFAULT_TITLE) hbox = gui.hBox(box) gui.checkBox(hbox, self, 'avatar_filter', 'Avatar filter') button = self.capture_button = QPushButton('Capture', self, clicked=self.capture_image) hbox.layout().addWidget(button, 1000) box.layout().addWidget(hbox) timer = QTimer(self, interval=40) timer.timeout.connect(self.update_webcam_image) timer.start()
def test_arrowannotation(self): item = ArrowItem() self.scene.addItem(item) item.setLine(QLineF(100, 100, 100, 200)) item.setLineWidth(5) item = ArrowItem() item.setLine(QLineF(150, 100, 150, 200)) item.setLineWidth(10) item.setArrowStyle(ArrowItem.Concave) self.scene.addItem(item) item = ArrowAnnotation() item.setPos(10, 10) item.setLine(QLineF(10, 10, 200, 200)) self.scene.addItem(item) item.setLineWidth(5) def advance(): clock = time.clock() * 10 item.setLineWidth(5 + math.sin(clock) * 5) item.setColor(QColor(Qt.red).lighter(100 + 30 * math.cos(clock))) timer = QTimer(item, interval=10) timer.timeout.connect(advance) timer.start() self.app.exec_()
def __init__(self, parent=None, items=None): QStandardItemModel.__init__(self, parent) if items is not None: self.insertColumn(0, items) self.__timer = QTimer(self)
def __init__(self): # These are already needed in super().__init__() self.number_of_nodes = 0 self.number_of_edges = 0 self.nHighlighted = 0 self.nSelected = 0 self.nodes_per_edge = 0 self.edges_per_node = 0 self.mark_mode = 0 self.mark_text = "" super().__init__() self.network = None self.node_data = None self.distance_matrix = None self.edges = None self.positions = None self._optimizer = None self._animation_thread = None self._stop_optimization = False self.marked_nodes = None self.searchStringTimer = QTimer(self) self.searchStringTimer.timeout.connect(self.update_marks) self.set_mark_mode() self.setMinimumWidth(600)
def test_dynamic_link(self): link = LinkItem() anchor1 = AnchorPoint() anchor2 = AnchorPoint() self.scene.addItem(link) self.scene.addItem(anchor1) self.scene.addItem(anchor2) link.setSourceItem(None, anchor1) link.setSinkItem(None, anchor2) anchor2.setPos(100, 100) link.setSourceName("1") link.setSinkName("2") link.setDynamic(True) self.assertTrue(link.isDynamic()) link.setDynamicEnabled(True) self.assertTrue(link.isDynamicEnabled()) def advance(): clock = time.process_time() link.setDynamic(clock > 1) link.setDynamicEnabled(int(clock) % 2 == 0) timer = QTimer(link, interval=0) timer.timeout.connect(advance) timer.start() self.qWait() timer.stop()
def __init__(self, *args, **kwargs): minimum = kwargs.get('minimum', 0) maximum = kwargs.get('maximum', 0) self.__min_value = self._min_position = kwargs.pop('minimumValue', minimum) self.__max_value = self._max_position = kwargs.pop('maximumValue', maximum) playback_interval = kwargs.pop('playbackInterval', 1000) self._min_position = kwargs.pop('minimumPosition', self._min_position) self._max_position = kwargs.pop('maximumPosition', self._max_position) kwargs.setdefault('orientation', Qt.Horizontal) kwargs.setdefault('tickPosition', self.TicksBelow) super().__init__(*args, **kwargs) self.tracking_timer = QTimer(self, interval=playback_interval, timeout=self.__send_tracked_selection) self.__tracked_selection = None self.__pressed_control = QStyle.SC_None self.__hovered_control = QStyle.SC_None self.__active_slider = -1 self.__click_offset = 0 self.__new_selection_drawing_origin = None # type: (int, int) self._showControlTooltip = False
def __init__(self, parent=None): QObject.__init__(self, parent) self.__scheme = None self.__signal_manager = None self.__widgets = [] self.__initstate_for_node = {} self.__creation_policy = WidgetManager.Normal #: a queue of all nodes whose widgets are scheduled for #: creation/initialization self.__init_queue = deque() # type: Deque[SchemeNode] #: Timer for scheduling widget initialization self.__init_timer = QTimer(self, interval=0, singleShot=True) self.__init_timer.timeout.connect(self.__create_delayed) #: A mapping of SchemeNode -> OWWidget (note: a mapping is only added #: after the widget is actually created) self.__widget_for_node = {} #: a mapping of OWWidget -> SchemeNode self.__node_for_widget = {} # Widgets that were 'removed' from the scheme but were at # the time in an input update loop and could not be deleted # immediately self.__delay_delete = set() #: Deleted/removed during creation/initialization. self.__delete_after_create = [] #: processing state flags for all widgets (including the ones #: in __delay_delete). #: Note: widgets which have not yet been created do not have an entry self.__widget_processing_state = {} # Tracks the widget in the update loop by the SignalManager self.__updating_widget = None
def __init__(self, parent=None, items=None): super().__init__(parent) self.__preview_index = -1 if items is not None: self.insertColumn(0, items) self.__timer = QTimer(self) self.__timer.timeout.connect(self.__process_next)
def __init__(self, parent, plot): super().__init__(parent, plot) self.__timer = QTimer(self, interval=50) self.__timer.timeout.connect(self._do) self._pos = None self._radius = 20.0 self._intensity = 5.0 self.__count = itertools.count()
def __init__(self, gui): log.info("Creating timer thread") QThread.__init__(self) self.gui = gui self.timer = QTimer() self.current_task = None self.current_duration = None self.secs = 0
def update_sizes(self): """ Trigger an update of point sizes The method calls `self.get_sizes`, which in turn calls the widget's `get_size_data`. The result are properly scaled and then passed back to widget for imputing (`master.impute_sizes`). """ if self.scatterplot_item: size_data = self.get_sizes() size_imputer = getattr( self.master, "impute_sizes", self.default_impute_sizes) size_imputer(size_data) if self.timer is not None and self.timer.isActive(): self.timer.stop() self.timer = None current_size_data = self.scatterplot_item.data["size"].copy() diff = size_data - current_size_data widget = self class Timeout: # 0.5 - np.cos(np.arange(0.17, 1, 0.17) * np.pi) / 2 factors = [0.07, 0.26, 0.52, 0.77, 0.95, 1] def __init__(self): self._counter = 0 def __call__(self): factor = self.factors[self._counter] self._counter += 1 size = current_size_data + diff * factor if len(self.factors) == self._counter: widget.timer.stop() widget.timer = None size = size_data widget.scatterplot_item.setSize(size) widget.scatterplot_item_sel.setSize(size + SELECTION_WIDTH) if widget.timer is None: widget.end_resizing.emit() else: widget.step_resizing.emit() if self.n_valid <= MAX_N_VALID_SIZE_ANIMATE and \ np.all(current_size_data > 0) and np.any(diff != 0): # If encountered any strange behaviour when updating sizes, # implement it with threads self.begin_resizing.emit() self.timer = QTimer(self.scatterplot_item, interval=50) self.timer.timeout.connect(Timeout()) self.timer.start() else: self.begin_resizing.emit() self.scatterplot_item.setSize(size_data) self.scatterplot_item_sel.setSize(size_data + SELECTION_WIDTH) self.end_resizing.emit()
def __init__(self, boundsig, **kwargs): super(QSignalSpy, self).__init__(**kwargs) from AnyQt.QtCore import QEventLoop, QTimer self.__boundsig = boundsig self.__boundsig.connect(lambda *args: self.__record(*args)) self.__recorded = [] # type: List[List[Any]] self.__loop = QEventLoop() self.__timer = QTimer(self, singleShot=True) self.__timer.timeout.connect(self.__loop.quit)
def __init__(self, master): """Initialize the attributes and set up the interface""" QDialog.__init__(self, master, windowTitle=self.captionTitle) WidgetMessagesMixin.__init__(self) self.setLayout(QVBoxLayout()) self.insert_message_bar() self.layout().insertWidget(0, self.message_bar) self.master = master self.keep_running = False self.scheduled_call = None self.saved_state = None self.saved_progress = 0 self.scores = [] self.add_to_model = queue.Queue() self.update_timer = QTimer(self) self.update_timer.timeout.connect(self._update) self.update_timer.setInterval(200) self._thread = None self._worker = None self.filter = QLineEdit() self.filter.setPlaceholderText("Filter ...") self.filter.textChanged.connect(self.filter_changed) self.layout().addWidget(self.filter) # Remove focus from line edit self.setFocus(Qt.ActiveWindowFocusReason) self.rank_model = QStandardItemModel(self) self.model_proxy = QSortFilterProxyModel(self, filterCaseSensitivity=False) self.model_proxy.setSourceModel(self.rank_model) self.rank_table = view = QTableView( selectionBehavior=QTableView.SelectRows, selectionMode=QTableView.SingleSelection, showGrid=False, editTriggers=gui.TableView.NoEditTriggers) if self._has_bars: view.setItemDelegate(TableBarItem()) else: view.setItemDelegate(HorizontalGridDelegate()) view.setModel(self.model_proxy) view.selectionModel().selectionChanged.connect( self.on_selection_changed) view.horizontalHeader().setStretchLastSection(True) view.horizontalHeader().hide() self.layout().addWidget(view) self.button = gui.button(self, self, "Start", callback=self.toggle, default=True)
def __init__(self, *args): QGraphicsView.__init__(self, *args) self.setAlignment(Qt.AlignTop | Qt.AlignLeft) self.__backgroundIcon = QIcon() self.__autoScroll = False self.__autoScrollMargin = 16 self.__autoScrollTimer = QTimer(self) self.__autoScrollTimer.timeout.connect(self.__autoScrollAdvance)
def __init__(self, *args, **kwargs): QTextBrowser.__init__(self, *args, **kwargs) self.setOpenExternalLinks(False) self.setOpenLinks(False) self.__text = "" self.__permanentText = "" self.__timer = QTimer(self, timeout=self.__on_timeout, singleShot=True) self.anchorClicked.connect(self.__on_anchorClicked)
def test_framelesswindow(self): window = FramelessWindow() window.show() def cycle(): window.setRadius((window.radius() + 3) % 30) timer = QTimer(window, interval=250) timer.timeout.connect(cycle) timer.start() self.app.exec_()
def __init__(self): super().__init__() self.pca_data = None self.projection = None self.tsne_runner = None self.tsne_iterator = None self.__update_loop = None # timer for scheduling updates self.__timer = QTimer(self, singleShot=True, interval=1, timeout=self.__next_step) self.__state = OWtSNE.Waiting self.__in_next_step = False self.__draw_similar_pairs = False def reset_needs_to_draw(): self.needs_to_draw = True self.needs_to_draw = True self.__timer_draw = QTimer(self, interval=2000, timeout=reset_needs_to_draw)
def __init__(self): self.sql_data = None # Orange.data.sql.table.SqlTable self.attribute_selection_list = None # list of Orange.data.Variable self.__timer = QTimer(self, interval=1200) self.__timer.timeout.connect(self.add_data) super().__init__() # manually register Matplotlib file writers self.graph_writers = self.graph_writers.copy() for w in [MatplotlibFormat, MatplotlibPDFFormat]: self.graph_writers.append(w)
def test_delay_by_change(self): dn = gui.DelayedNotification(timeout=500) call = Mock() dn.notification.connect(call) timer = QTimer() timer.timeout.connect(dn.changed) timer.start(100) dn.changed() # notification should never be emitted as the input changes too fast with self.assertRaises(TimeoutError): self.process_events(lambda: call.call_args is not None, timeout=1000)
def __init__(self): super().__init__() self.pca_data = None self.projection = None self.__update_loop = None # timer for scheduling updates self.__timer = QTimer(self, singleShot=True, interval=1, timeout=self.__next_step) self.__state = OWtSNE.Waiting self.__in_next_step = False self.__draw_similar_pairs = False
def __init__(self, *args, **kwargs): self._strobe = kwargs.get('strobe', False) self._strobeState = False self._strobeTimer = QTimer() self._strobeTimer.timeout.connect(self.__strobeEffect) self._parent = kwargs.get('parent', None) super(LightControl, self).__init__(*args) self.clicked.connect(self.__callback) self.setCheckable(True) self.setIconSize(QSize(Config.iconSize, Config.iconSize)) self.setFixedSize(Config.controlWidth, Config.controlHeight) self._lastPress = 0