我们从Python开源项目中,提取了以下47个代码示例,用于说明如何使用PyQt5.QtCore.QObject()。
def start_playing(self, filename): class QtPlaybin(Playbin, QtCore.QObject): eos = QtCore.pyqtSignal() def end_of_stream(self): self.eos.emit() def create_video_sink(self, name): if platform.system() == 'Darwin': # default (gl) sink does not play well with GstOverlay, at least not when using Qt return Gst.ElementFactory.make('osxvideosink', name) elif platform.system() == 'Linux': # Same for the default on Linux... return Gst.ElementFactory.make('xvimagesink', name) return super().create_video_sink(name) self.playbin = QtPlaybin(win_id=self.winId()) self.playbin.eos.connect(self.close) yield from self.playbin.play(filename)
def show_settings(self): """Shows a dialog containing settings for DSW""" self.dialog = QDialog(self) self.dialog.ui = uic.loadUi(SETTINGS_UI_FILE, self.dialog) self.dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.dialog.findChild(QtCore.QObject, BUTTONBOX) \ .accepted.connect(self.generate_conf) if cfg[CONFIG_BUFFER_STREAM]: self.dialog.findChild(QtCore.QObject, RECORD_SETTINGS).setChecked(True) if cfg[CONFIG_MUTE]: self.dialog.findChild(QtCore.QObject, MUTE_SETTINGS).setChecked(True) self.dialog.findChild(QtCore.QObject, QUALITY_SETTINGS) \ .setText(CONFIG_QUALITY_DELIMITER_JOIN.join(cfg[CONFIG_QUALITY])) self.dialog.findChild(QtCore.QObject, BUFFER_SIZE).setValue(cfg[CONFIG_BUFFER_SIZE]) self.dialog.show()
def _createAdditionalComponentsView(self): Logger.log("d", "Creating additional ui components for UM3.") path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting"), "UM3InfoComponents.qml")) self.__additional_component = QQmlComponent(Application.getInstance()._engine, path) # We need access to engine (although technically we can't) self.__additional_components_context = QQmlContext(Application.getInstance()._engine.rootContext()) self.__additional_components_context.setContextProperty("manager", self) self.__additional_components_view = self.__additional_component.create(self.__additional_components_context) if not self.__additional_components_view: Logger.log("w", "Could not create ui components for UM3.") return Application.getInstance().addAdditionalComponent("monitorButtons", self.__additional_components_view.findChild(QObject, "networkPrinterConnectButton")) Application.getInstance().addAdditionalComponent("machinesDetailPane", self.__additional_components_view.findChild(QObject, "networkPrinterConnectionInfo"))
def _createAdditionalComponentsView(self): Logger.log("d", "Creating additional ui components for Pause Backend plugin.") path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("PauseBackendPlugin"), "PauseBackend.qml")) self._additional_component = QQmlComponent(Application.getInstance()._engine, path) # We need access to engine (although technically we can't) self._additional_components_context = QQmlContext(Application.getInstance()._engine.rootContext()) self._additional_components_context.setContextProperty("manager", self) self._additional_components_view = self._additional_component.create(self._additional_components_context) if not self._additional_components_view: Logger.log("w", "Could not create additional components for Pause Backend plugin.") return Application.getInstance().addAdditionalComponent("saveButton", self._additional_components_view.findChild(QObject, "pauseResumeButton"))
def test_selection_calculation_of_wlc_returns_correct_results(self): from PyQt5.QtCore import pyqtSignal from PyQt5.QtCore import QObject class PM(QObject): def callwithmyid(self, id): pass heres_a_curve_signal = pyqtSignal(object) pm=PM() class testData: id = "P2" requestingcurve="boo" years=100 cons=200000*.32 r=3 A=.022 lunits=c.METERS N0=0.081 length=300 age=20 cost=1.0*1.e6*length/1000. pd=testData() wlcthread=WLCThread(pm, pd) wlcthread.do_the_job() self.assertAlmostEqual(wlcthread.result.damagecost[50],102579,delta=10000) self.assertAlmostEqual(wlcthread.result.renewalcost[50],68000,delta=1000)
def __init__(self, host, port=7772): QtCore.QObject.__init__(self) self.context = zmq.Context() self.socket = self.context.socket(zmq.SUB) self.socket.connect("tcp://{}:{}".format(host, port)) self.socket.setsockopt_string(zmq.SUBSCRIBE, "data") self.socket.setsockopt_string(zmq.SUBSCRIBE, "done") self.poller = zmq.Poller() self.poller.register(self.socket, zmq.POLLIN) self.running = True
def stop(self): """ Stop all running widgets, it's threads and any I/O tasks. """ for child in self.findChildren(QObject): if hasattr(child, "stop_running"): child.stop_running()
def __init__(self, trigger): QtCore.QObject.__init__(self) ActivityBase.__init__(self) self.trigger_obj = trigger self.trigger_obj.add_activity(self) self.handles = {} self.signal.connect(self.signal_handler)
def __init__(self, queue, *args, **kwargs): """A QObject (to be run in a QThread) which sits waiting for data to come through a Queue.Queue(). It blocks until data is available, and one it has got something from the _logging_update_queue, it sends it to the "MainThread" by emitting a Qt Signal. Attributes: is_running (boolean): set to False to stop the receiver. """ super(MessageReceiver, self).__init__(*args, **kwargs) self.queue = queue self.is_running = True
def eventFilter(self, obj: QObject, event: QEvent) -> bool: if event.type() == QEvent.ToolTip: return True elif event.type() == QEvent.Enter and obj.isEnabled(): qApp.setOverrideCursor(Qt.PointingHandCursor) elif event.type() == QEvent.Leave: qApp.restoreOverrideCursor() elif event.type() == QEvent.StatusTip and not obj.isEnabled(): return True return super(VideoToolBar, self).eventFilter(obj, event)
def initThumbs(self) -> None: framesize = self.parent.videoService.framesize() thumbsize = QSize(VideoService.ThumbSize.TIMELINE.value.height() * (framesize.width() / framesize.height()), VideoService.ThumbSize.TIMELINE.value.height()) positions, frametimes = [], [] thumbs = int(math.ceil((self.rect().width() - (self.offset * 2)) / thumbsize.width())) for pos in range(thumbs): val = QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), (thumbsize.width() * pos) - self.offset, self.rect().width() - (self.offset * 2)) positions.append(val) positions[0] = 1000 [frametimes.append(self.parent.delta2QTime(msec).toString(self.parent.timeformat)) for msec in positions] class ThumbWorker(QObject): completed = pyqtSignal(list) def __init__(self, media: str, times: list, size: QSize): super(ThumbWorker, self).__init__() self.media = media self.times = times self.size = size @pyqtSlot() def generate(self): frames = list() [frames.append(VideoService.captureFrame(self.media, frame, self.size)) for frame in self.times] self.completed.emit(frames) self.thumbsThread = QThread(self) self.thumbsWorker = ThumbWorker(self.parent.currentMedia, frametimes, thumbsize) self.thumbsWorker.moveToThread(self.thumbsThread) self.thumbsThread.started.connect(self.parent.sliderWidget.setLoader) self.thumbsThread.started.connect(self.thumbsWorker.generate) self.thumbsThread.finished.connect(self.thumbsThread.deleteLater, Qt.DirectConnection) self.thumbsWorker.completed.connect(self.buildTimeline) self.thumbsWorker.completed.connect(self.thumbsWorker.deleteLater, Qt.DirectConnection) self.thumbsWorker.completed.connect(self.thumbsThread.quit, Qt.DirectConnection) self.thumbsThread.start()
def eventFilter(self, obj: QObject, event: QMouseEvent) -> bool: if event.type() == QEvent.MouseButtonRelease and event.button() == Qt.LeftButton: if self.parent.mediaAvailable and self.isEnabled(): newpos = QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x() - self.offset, self.width() - (self.offset * 2)) self.setValue(newpos) self.parent.setPosition(newpos) self.parent.parent.mousePressEvent(event) return super(VideoSlider, self).eventFilter(obj, event)
def eventFilter(self, obj: QObject, event: QEvent) -> bool: if event.type() == QEvent.Enter: qApp.setOverrideCursor(Qt.PointingHandCursor) elif event.type() == QEvent.Leave: qApp.restoreOverrideCursor() return super(ClipErrorsDialog.VCToolBox, self).eventFilter(obj, event)
def __init__(self): QtCore.QObject.__init__(self) self.new_signal.connect(goto_ui_jump) self.stop_signal.connect(stop_torrent_from_client) self.control_signal.connect(start_player_remotely) self.nav_remote.connect(navigate_player_remotely) self.delete_torrent_signal.connect(delete_torrent_history) self.update_signal.connect(update_databse_signal) self.total_navigation.connect(total_ui_navigation)
def __init__(self): QtCore.QObject.__init__(self) self.new_signal.connect(goto_ui_jump)
def set_env_variable(self, env_id: str, var_name: str, var_value: str, cause: QObject=None): """ Sets a new value for the given environment variable :param env_id: :param var_name: :param var_value: :param cause: :return: """ self.current_configuration.envs[env_id].env_variables_dct[var_name] = var_value # print('[' + env_id + '] Set \'' + var_name + '\' to \'' + var_value + '\'') # emit the 'data changed' message # noinspection PyUnresolvedReferences self.signals.current_config_changed_or_saved.emit(cause)
def setup_file_aware(self, file_type_short: str, file_extensions: List[str], enable_when_dirty: List[QObject], open_signals: List, save_signals: List, save_as_signals: List, cancel_signals: List, quit_signals: List): """ This function needs to be called once in order to configure the object :param enable_when_dirty: :return: """ self.file_type_short = file_type_short self.file_extensions = file_extensions self.enable_when_dirty = enable_when_dirty for signal in open_signals: signal.connect(self.lslot_open) for signal in save_signals: signal.connect(self.lslot_save) for signal in save_as_signals: signal.connect(self.lslot_save_as) for signal in cancel_signals: signal.connect(self.lslot_cancel_modifications) for signal in quit_signals: signal.connect(self.lslot_quit)
def __init__(self, filename=None): QtCore.QObject.__init__(self) # Setting up logger # logger = g.logger.logger str_ = self.Read_File(filename) g.config.metric = self.Get_Unit(str_) self.update_tool_values() # Load the contour and store the values in the classes self.line_pairs = self.Get_Line_Pairs(str_) # Debug Informationen # logger.info(("\n\nFile has %0.0f Lines" % len(str_)), 1) # logger.info(("\nFile has %0.0f Linepairs" % self.line_pairs.nrs), 1) logger.info(self.tr("Reading DXF Structure")) sections_pos = self.Get_Sections_pos() self.layers = self.Read_Layers(sections_pos) blocks_pos = self.Get_Blocks_pos(sections_pos) self.blocks = self.Read_Blocks(blocks_pos) self.entities = self.Read_Entities(sections_pos) # Aufruf der Klasse um die Konturen zur suchen # Schleife fr die Anzahl der Blcke und den Layern # Call the class to define the contours of search # Loop for the number of blocks and the layer for i in range(len(self.blocks.Entities)): # '\n' # print self.blocks.Entities[i] logger.info(self.tr("Creating Contours of Block Nr: %i") %i) self.blocks.Entities[i].cont = self.Get_Contour(self.blocks.Entities[i]) logger.info(self.tr("Creating Contours of Entities")) self.entities.cont = self.Get_Contour(self.entities)
def __init__(self): QtCore.QObject.__init__(self) self.pool = QtCore.QThreadPool() self.pool.setMaxThreadCount(5) self.cards = [] self.result = {} self.tmpdir = tempfile.mkdtemp()
def setup_ui(self, ui_file): uic.loadUi(ui_file, self) # Find the draw area self.draw_area = self.findChild(QtCore.QObject, "drawArea") # Bind the player # Get the current operating system os = platform.system().lower() if os == OS.LINUX: self.player.set_xwindow(self.draw_area.winId()) elif os == OS.WINDOWS: self.player.set_hwnd(self.draw_area.winId()) elif os == OS.MAC_OS: self.player.set_nsobject(int(self.draw_area.winId())) else: sys.exit("Platform unsupported")
def setup_ui(self): super(LiveVideoFrame, self).setup_ui("ui/frame.ui") self.findChild(QtCore.QObject, "delete_button").clicked.connect(self.delete_stream) self.findChild(QtCore.QObject, "pause_button").clicked.connect(self.toggle_playback) self.findChild(QtCore.QObject, "volume_slider").valueChanged.connect(self.set_volume) # Store stream_end_label self.stream_end_label = self.findChild(QtWidgets.QLabel, "end_label")
def setup_ui(self): super(RewoundVideoFrame, self).setup_ui("ui/rewoundframe.ui") self.findChild(QtCore.QObject, "pause_button").clicked.connect(self.toggle_playback) self.findChild(QtCore.QObject, "forward_button").clicked.connect(self.scrub_forward) self.findChild(QtCore.QObject, "backward_button").clicked.connect(self.scrub_backward) self.findChild(QtCore.QObject, "volume_slider").valueChanged.connect(self.set_volume)
def setup_ui(self): """Loads the main.ui file and sets up the window and grid.""" self.ui = uic.loadUi("ui/main.ui", self) with open("ui/styles.qss", "r") as f: self.setStyleSheet(f.read()) self.grid = VideoFrameGrid(self) self.container = self.ui.findChild(QtCore.QObject, "container") self.container.addLayout(self.grid) self.menubar = self.ui.findChild(QtCore.QObject, "MenuBar") # Connect up all actions. self.actions = {} self.actions[MUTE_CHECKBOX] = self.ui.findChild(QtCore.QObject, MUTE_ALL_STREAMS) self.__bind_view_to_action(MUTE_ALL_STREAMS, self.mute_all_streams, toggled=True) self.__bind_view_to_action(EXPORT_STREAMS_TO_CLIPBOARD, self.export_streams_to_clipboard) self.__bind_view_to_action(ADD_NEW_STREAM, self.add_new_stream) self.__bind_view_to_action(ADD_NEW_SCHEDULED_STREAM, self.add_new_scheduled_stream) self.__bind_view_to_action(IMPORT_STREAMS_FROM_CLIPBOARD, self.import_streams_from_clipboard) self.__bind_view_to_action(SETTINGS_MENU, self.show_settings) self.__bind_view_to_action(LOAD_STREAM_HISTORY, self.stream_history) self.recent_menu = self.ui.findChild(QtCore.QObject, "menuRecent") # Create the loading gear but dont add it to anywhere, just save it self.setup_loading_gif() self.ui.show()
def __bind_view_to_action(self, view, action, toggled=False): return self.ui.findChild(QtCore.QObject, view).toggled.connect(action) if toggled else self.ui.findChild( QtCore.QObject, view).triggered.connect(action)
def notify_wheel_event(app: QtWidgets.QApplication, obj: QtCore.QObject, event: QtCore.QEvent): """Notify obj or obj.parent() based on orientation lock state""" update_lock_orientation(event) if (event.orientation() == locked_orientation and (type(obj) is not QtGui.QScrollBar or obj.orientation() == locked_orientation)): return super(type(app), app).notify(obj, event) else: return super(type(app), app).notify(obj.parent(), event)
def mui_to_qt(self, mui_name): if hostMode != "maya": return ptr = mui.MQtUtil.findControl(mui_name) if ptr is None: ptr = mui.MQtUtil.findLayout(mui_name) if ptr is None: ptr = mui.MQtUtil.findMenuItem(mui_name) if ptr is not None: if qtMode in (0,2): # ==== for pyside ==== return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget) elif qtMode in (1,3): # ==== for PyQt==== return sip.wrapinstance(long(ptr), QtCore.QObject)
def import_signals(): try: from PyQt5.QtCore import QObject, pyqtSignal return QObject, pyqtSignal except ImportError: return object, None
def __init__(self): QtCore.QObject.__init__(self) self._settings = QtCore.QSettings() self.model = FiltersModel(self) self.showCompleted = False self.showFuture = True self.showHidden = False self.searchText = "" # self.currentFilters = self._settings.value("current_filters", ["All"]) # move to QML self.currentFilters = []
def __init__(self, text): QtCore.QObject.__init__(self) self._settings = QtCore.QSettings() self._highest_priority = 'A' # all other class attributes are defined in _reset method # which is called in _parse self._parse(text)
def __init__(self): QtCore.QObject.__init__(self) self.newline = '\n' self.tasks = [] self.filename = '' self._fileObserver = FileObserver() self._fileObserver.fileChangetSig.connect(self.fileExternallyModified) self.modified = False
def __init__(self): QtCore.QObject.__init__(self) self.new_signal.connect(goToUi_jump) self.stop_signal.connect(stop_torrent_from_client)
def __init__(self, parent = None): QtCore.QObject.__init__(self, parent) self.filters = []
def __init__(self, func): QtCore.QObject.__init__(self) self.widget_func = func self.widget = None self.injected = False self.tc_count = 0
def _createAdditionalComponentsView(self): Logger.log("d", "Creating additional ui components for OctoPrint-connected printers.") path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "OctoPrintComponents.qml") self._additional_components = Application.getInstance().createQmlComponent(path, {"manager": self}) if not self._additional_components: Logger.log("w", "Could not create additional components for OctoPrint-connected printers.") return Application.getInstance().addAdditionalComponent("monitorButtons", self._additional_components.findChild(QObject, "openOctoPrintButton")) ## Handler for all requests that have finished.
def main(mode=0): # get parent window in Maya parentWin = None if hostMode == "maya": if qtMode in (0,2): # pyside parentWin = shiboken.wrapInstance(long(mui.MQtUtil.mainWindow()), QtWidgets.QWidget) elif qtMode in (1,3): # PyQt parentWin = sip.wrapinstance(long(mui.MQtUtil.mainWindow()), QtCore.QObject) # create app object for certain host app = None if hostMode in ("desktop", "blender"): app = QtWidgets.QApplication(sys.argv) #-------------------------- # ui instance #-------------------------- # template 1 - Keep only one copy of windows ui in Maya global single_UITranslator if single_UITranslator is None: if hostMode == "maya": single_UITranslator = UITranslator(parentWin, mode) else: single_UITranslator = UITranslator() # extra note: in Maya () for no parent; (parentWin,0) for extra mode input single_UITranslator.show() ui = single_UITranslator # template 2 - allow loading multiple windows of same UI in Maya ''' if hostMode == "maya": ui = UITranslator(parentWin) ui.show() else: # extra note: in Maya () for no parent; (parentWin,0) for extra mode input ''' # loop app object for certain host if hostMode in ("desktop"): sys.exit(app.exec_()) return ui
def main(mode=0): # get parent window in Maya parentWin = None if hostMode == "maya": if qtMode in (0,2): # pyside parentWin = shiboken.wrapInstance(long(mui.MQtUtil.mainWindow()), QtWidgets.QWidget) elif qtMode in (1,3): # PyQt parentWin = sip.wrapinstance(long(mui.MQtUtil.mainWindow()), QtCore.QObject) # create app object for certain host app = None if hostMode in ("desktop", "blender"): app = QtWidgets.QApplication(sys.argv) #-------------------------- # ui instance #-------------------------- # template 1 - Keep only one copy of windows ui in Maya global single_UniversalToolUI if single_UniversalToolUI is None: if hostMode == "maya": single_UniversalToolUI = UniversalToolUI(parentWin, mode) else: single_UniversalToolUI = UniversalToolUI() # extra note: in Maya () for no parent; (parentWin,0) for extra mode input single_UniversalToolUI.show() ui = single_UniversalToolUI # template 2 - allow loading multiple windows of same UI in Maya ''' if hostMode == "maya": ui = UniversalToolUI(parentWin) ui.show() else: # extra note: in Maya () for no parent; (parentWin,0) for extra mode input ''' # loop app object for certain host if hostMode in ("desktop"): sys.exit(app.exec_()) return ui
def main(mode=0): # get parent window in Maya parentWin = None if hostMode == "maya": if qtMode in (0,2): # pyside parentWin = shiboken.wrapInstance(long(mui.MQtUtil.mainWindow()), QtWidgets.QWidget) elif qtMode in (1,3): # PyQt parentWin = sip.wrapinstance(long(mui.MQtUtil.mainWindow()), QtCore.QObject) # create app object for certain host app = None if hostMode in ("desktop", "blender"): app = QtWidgets.QApplication(sys.argv) #-------------------------- # ui instance #-------------------------- # template 1 - Keep only one copy of windows ui in Maya global single_UserClassUI if single_UserClassUI is None: if hostMode == "maya": single_UserClassUI = UserClassUI(parentWin, mode) else: single_UserClassUI = UserClassUI() # extra note: in Maya () for no parent; (parentWin,0) for extra mode input single_UserClassUI.show() ui = single_UserClassUI # template 2 - allow loading multiple windows of same UI in Maya ''' if hostMode == "maya": ui = UserClassUI(parentWin) ui.show() else: # extra note: in Maya () for no parent; (parentWin,0) for extra mode input ''' # loop app object for certain host if hostMode in ("desktop"): sys.exit(app.exec_()) return ui
def epnShowHide(self): global fullscrT,idwMain,idw,name,curR if fullscrT == 0: self.list2.show() self.tab_5.setFocus() self.btn1.close() self.btn1 = Btn1(self.dockWidgetContents_3) self.btn1.setGeometry(QtCore.QRect(20, 55, 130, 31)) self.btn1.setObjectName(_fromUtf8("btn1")) self.btn1.addItem(_fromUtf8("")) self.btn1.addItem(_fromUtf8("")) self.btn1.addItem(_fromUtf8("")) self.btn1.addItem(_fromUtf8("")) self.btn1.addItem(_fromUtf8("")) self.btn1.addItem(_fromUtf8("")) self.btn1.addItem(_fromUtf8("")) self.btn1.addItem(_fromUtf8("")) self.btn1.addItem(_fromUtf8("")) self.btn1.setItemText(0, _translate("MainWindow", "Select", None)) self.btn1.setItemText(1, _translate("MainWindow", "Animejoy", None)) self.btn1.setItemText(2, _translate("MainWindow", "Animebam", None)) self.btn1.setItemText(3, _translate("MainWindow", "AnimePlace", None)) self.btn1.setItemText(4, _translate("MainWindow", "SubbedAnime", None)) self.btn1.setItemText(5, _translate("MainWindow", "DubbedAnime", None)) self.btn1.setItemText(6, _translate("MainWindow", "AnimeHi10", None)) self.btn1.setItemText(7, _translate("MainWindow", "KissAnime", None)) self.btn1.setItemText(8, _translate("MainWindow", "KissDrama", None)) self.btnOpt.hide() self.go_opt.hide() self.dockWidget_3.show() QtCore.QObject.connect( self.btn1,QtCore.SIGNAL(_fromUtf8("currentIndexChanged(int)")), self.ka ) self.btn1.setFocus() self.gridLayout.addWidget(self.list2,0,2,1,1) self.btn1.setStyleSheet("font: bold 12px;color:white;background:rgba(0,0,0,30%);border:rgba(0,0,0,30%)") self.buttonStyle() else: self.dockWidget_3.hide() self.goto_epn.hide() self.horizontalLayout_7.insertWidget(1,self.btn1,0) self.verticalLayout_40.insertWidget(2,self.list2,0) self.btnOpt.show() self.go_opt.show() self.listfound() self.list2.setCurrentRow(0) self.buttonStyle() self.btn1.setFocus()