def __init__(self, parent=None): """ Constructor """ QtGui.QWidget.__init__(self, parent) self._bundle = sgtk.platform.current_bundle() # hook up a listener to the parent window so we # can resize the overlay at the same time as the parent window # is being resized. filter = ResizeEventFilter(parent) filter.resized.connect(self._on_parent_resized) parent.installEventFilter(filter) # make it transparent self.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents) # turn off the widget self.setVisible(False) self._mode = self.MODE_OFF # setup spinner timer self._timer = QtCore.QTimer(self) self._timer.timeout.connect(self._on_animation) self._spin_angle = 0
def __init__(self): """ Constructor """ # first, call the base class and let it do its thing. QtGui.QWidget.__init__(self) # now load in the UI that was created in the UI designer self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.pushButton_start.clicked.connect(self.start_timer) self.ui.pushButton_stop.clicked.connect(self.stop_and_log) self.ui.pushButton_pause.clicked.connect(self.pause_timer) # timer stuff self._update_timer = QtCore.QTimer(self) self._update_timer.timeout.connect(self.update_ticker) # most of the useful accessors are available through the Application class instance # it is often handy to keep a reference to this. You can get it via the following method: self._app = sgtk.platform.current_bundle() self.sg = self._app.shotgun self.context = self._app.context print self.sg # via the self._app handle we can for example access: # - The engine, via self._app.engine # - A Shotgun API instance, via self._app.shotgun # - A tk API instance, via self._app.tk # lastly, set up our very basic UI self.ui.context.setText("Current Context: %s" % self._app.context)
def __init__(self, parent=None): BasePage.__init__(self, parent) self._thread_success = False self._original_next_css = None self._original_next_text = None self._new_logs = [] self._chapter = None self._progress = None self._log_timer = QtCore.QTimer(parent=self) self._log_timer.timeout.connect(self._process_new_logged_info) self._log_timer.start(LOG_TIMER_INTERVAL) self.execute_thread = None
def __init__(self, parent): """ :param parent: Qt parent object :type parent: :class:`~PySide.QtGui.QWidget` """ # first, call the base class and let it do its thing. super(ShotgunSearchWidget, self).__init__(parent) # trigger the completer to popup as text changes self.textEdited.connect(self._search_edited) # Taken from https://wiki.qt.io/Delay_action_to_wait_for_user_interaction self._delay_timer = QtCore.QTimer(self) self._delay_timer.timeout.connect(self._typing_timeout) self._delay_timer.setSingleShot(True) # FIXME: The following was stolen from SearchWidget. We can't refactor easily that # part of the code since the base classes for ShotgunSearchWidget and SearchWidget # are not the same, but at least the ShotgunSearchWidget has feature parity. self.set_placeholder_text("Search") # dynamically create the clear button so that we can place it over the # edit widget: self._clear_btn = QtGui.QPushButton(self) self._clear_btn.setFocusPolicy(QtCore.Qt.StrongFocus) self._clear_btn.setFlat(True) self._clear_btn.setCursor(QtCore.Qt.ArrowCursor) # Loads the style sheet for the search button. qss_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "search_style.qss") with open(qss_file, "rt") as f: # apply to widget (and all its children) self._clear_btn.setStyleSheet(f.read()) self._clear_btn.hide() h_layout = QtGui.QHBoxLayout(self) h_layout.addStretch() h_layout.addWidget(self._clear_btn) h_layout.setContentsMargins(3, 0, 3, 0) h_layout.setSpacing(0) self.setLayout(h_layout) self._clear_btn.clicked.connect(self._on_clear_clicked)
def __init__(self, parent=None): """ :param parent: The parent widget :type parent: :class:`~PySide.QtGui.QWidget` """ QtGui.QWidget.__init__(self, parent) # public properties: self.fps = 20 self.border = 2 self.line_width = 2 self.arc_length = 300 self.seconds_per_spin = 3 # timer used to force a repaint: self._timer = QtCore.QTimer(self) self._timer.timeout.connect(self._on_timer_timeout) # keep track of the current start angle to avoid # unnecessary repaints self._start_angle = 0
def ensure_file_change_timer_running(): """ Ensures a timer is running to periodically check for current file change. """ # do nothing if it is already running global g_file_change_timer if g_file_change_timer: return import hou import sgtk from sgtk.platform.qt import QtCore global g_current_file g_current_file = hou.hipFile.path() # start up a timer to execute a callback to check for current file changes g_file_change_timer = QtCore.QTimer() g_file_change_timer.timeout.connect(_on_file_change_timeout) g_file_change_timer.start(1000)
def __init__(self, parent): """ :param parent: QT parent object :type parent: :class:`PySide.QtGui.QWidget` """ # first, call the base class and let it do its thing. QtCore.QObject.__init__(self, parent) # set up some handy references self._bundle = sgtk.platform.current_bundle() # default not found/loading thumb self._default_icon = QtGui.QPixmap( ":/tk_framework_qtwidgets.global_search_widget/rect_512x400.png" ) # cache path on disk self._cache_path = os.path.join( self._bundle.cache_location, "activity_stream_v%s.sqlite" % self.DATBASE_FORMAT_VERSION, ) # set up a data retriever self._sg_data_retriever = None # Offered as an option to rescan(), and if True will trigger # a forced requery of activity stream data during rescan. self._force_activity_stream_update = False # This is a timer that can be started to trigger a cache dump and # rescan after a given interval (20 seconds as of this writing). self._rescan_timer = QtCore.QTimer(self) self._rescan_timer.setSingleShot(True) self._rescan_timer.setInterval(self.RESCAN_TIMER_INTERVAL) self._rescan_timer.timeout.connect(self.__hard_refresh) # set up defaults self.__reset()
def __init__(self, parent=None): """ Initialize the menu. :param parent: The menu's parent. :type parent: :class:`~PySide.QtGui.QWidget` """ super(ShotgunMenu, self).__init__(parent) self._typed_text = "" # create a single shot timer to clear any typed text string after a # second. this allows the user to search for something in the menu but # clears the text so they can start over if need be. self._type_timer = QtCore.QTimer(self) self._type_timer.setSingleShot(True) self._type_timer.setInterval(1000) self._type_timer.timeout.connect(self._on_type_timer_timeout) # styling to resemble SG web menus self.setStyleSheet( """ QMenu { /* * Ensure the menu only takes up one column and scrolls rather * than expanding horizontally (the default) */ menu-scrollable: 1; background: palette(window); padding: 0px 1px 1px 0px; margin: 0px; } QMenu::scroller { height: 16px; } QMenu::item { padding: 2px 22px 2px 22px; } QMenu::item:selected { border-color: none; background: palette(midlight); } QMenu::separator { height: 1px; background: palette(base); margin-left: 0px; margin-right: 0px; margin-top: 4px; margin-bottom: 0px; } QMenu::indicator { left: 5px; top: 1px; } QMenu::indicator:unchecked { image: none; } QMenu::indicator:checked { image: url(:tk_framework_qtwidgets.shotgun_menus/check.png); } """ )
def hide(self): self.hide_timer = QtCore.QTimer() self.hide_timer.timeout.connect(super(ProgressDialog, self).hide) self.hide_timer.setSingleShot(2000) self.hide_timer.start()
def __init__(self): """ Constructor """ # first, call the base class and let it do its thing. QtGui.QWidget.__init__(self) # On Linux, in Nuke 11, we have a crash on close problem. This # should be safe across the board, though, so no need to limit # it to a specific version of Nuke. We just want to make sure # that panel apps, specifically shotgunpanel, have the opportunity # to shut down gracefully prior to application close. QtGui.QApplication.instance().aboutToQuit.connect( self._on_parent_closed) # pick up the rest of the construction parameters # these are set via the class emthod set_init_parameters() # because we cannot control the constructor args PanelClass = self._init_widget_class panel_id = self._init_panel_id args = self._init_args kwargs = self._init_kwargs bundle = self._init_bundle self.nuke_panel = self._nuke_panel # and now clear the init parameters self.set_init_parameters(None, None, None, None, None, None) bundle.logger.debug("Creating panel '%s' to host %s", panel_id, PanelClass) # set up this object and create a layout self.setObjectName("%s.wrapper" % panel_id) self.layout = QtGui.QHBoxLayout(self) self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setObjectName("%s.wrapper.layout" % panel_id) # now loop over all widgets and look for our panel widget # if we find it, take it out of the layout and then # destroy the current container. # this will keep the widget around but destroy the nuke tab # that it was sitting in. self.toolkit_widget = None widget_name = "%s.widget" % panel_id for widget in QtGui.QApplication.allWidgets(): # if the widget has got the unique widget name, # it's our previously created object! if widget.objectName() == widget_name: # found an existing panel widget! self.toolkit_widget = widget bundle.logger.debug("Found existing panel widget: %s", self.toolkit_widget) # now find the tab widget by going up the hierarchy tab_widget = self._find_panel_tab(self.toolkit_widget) if tab_widget: # find the stacked widget that the tab is parented to stacked_widget = tab_widget.parent() if stacked_widget: # and remove the tab widget completely! # our widget will now be hidden stacked_widget.removeWidget(tab_widget) bundle.logger.debug("Removed previous panel tab %s", tab_widget) break # now check if a widget was found. If not, # we need to create one. if self.toolkit_widget is None: # create a new dialog # keep a python side reference # and also parent it to this widget self.toolkit_widget = PanelClass(*args, **kwargs) # give our main widget a name so that we can identify it later self.toolkit_widget.setObjectName(widget_name) bundle.logger.debug("Created new toolkit panel widget %s", self.toolkit_widget) # now let the core apply any external stylesheets # # NOTE: To be honest, we're not entirely sure why this is required. In Nuke 12 # we started experiencing a crash when the shotgunpanel app was being launched # in panel mode. On OSX that was cured with a tiny tweak to the qss itself, but # the problem persisted on Windows and Linux. In those cases, it does not appear # that anything in the qss itself was the problem, it was simply that there was # qss being applied AT ALL right here. # # The solution here is to defer the application of the stylesheet by 1ms, which # gives Qt time process other events before getting to this call. With that in # mind, we did attempt to just make a call to processEvents here to try to get # the same result without a timer, but that did not stop the crash problem. def _set_qss(): bundle.engine._apply_external_styleshet( bundle, self.toolkit_widget) self._timer = QtCore.QTimer(self.toolkit_widget) self._timer.setSingleShot(True) self._timer.timeout.connect(_set_qss) self._timer.start(0) else: # there is already a dialog. Re-parent it to this # object and move it across into this layout self.toolkit_widget.setParent(self) bundle.logger.debug("Reparented existing toolkit widget.") # Add the widget to our current layout self.layout.addWidget(self.toolkit_widget) bundle.logger.debug("Added toolkit widget to panel hierarchy") # now, the close widget logic does not propagate correctly # down to the child widgets. When someone closes a tab or pane, # QStackedWidget::removeWidget is being called, which merely takes # our widget out of the layout and hides it. So it will stay resident # in memory which is not what we want. Instead, it should close properly # if someone decides to close its tab. # # We can accomplish this by installing a close event listener on the # tab itself and have that call our widget so that we can close ourselves. # note that we search for the tab widget by unique id rather than going # up in the widget hierarchy, because the hierarchy has not been properly # established at this point yet. for widget in QtGui.QApplication.allWidgets(): if widget.objectName() == panel_id: filter = CloseEventFilter(widget) filter.parent_closed.connect(self._on_parent_closed) widget.installEventFilter(filter) bundle.logger.debug( "Installed close-event filter watcher on tab %s", widget) break # We should have a parent panel object. If we do, we can alert it to the # concrete sgtk panel widget we're wrapping. This will allow is to provide # the wrapped widget's interface to higher-level callers. if self.nuke_panel: self.nuke_panel.toolkit_widget = self.toolkit_widget
def create_timer(self): """ Create a timer that check for new notifications when it runs out """ self._timer = QtCore.QTimer() self._timer.setSingleShot(True) self._timer.timeout.connect(self.check_for_notifications)