Skip to content

Commit

Permalink
[cuegui] Replace qApp with a new cuegui.App library. (#1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcipriano committed Oct 27, 2022
1 parent 3742ff0 commit 6500fe2
Show file tree
Hide file tree
Showing 48 changed files with 328 additions and 340 deletions.
19 changes: 7 additions & 12 deletions cuegui/cuegui/AbstractTreeWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self, parent):
@type parent: QWidget
@param parent: The widget to set as the parent"""
QtWidgets.QTreeWidget.__init__(self, parent)
self.app = cuegui.app()

self._items = {}
self._lastUpdate = 0
Expand Down Expand Up @@ -104,8 +105,8 @@ def __init__(self, parent):
self.itemClicked.connect(self.__itemSingleClickedEmitToApp)
self.itemDoubleClicked.connect(self.__itemDoubleClickedEmitToApp)
self._timer.timeout.connect(self.updateRequest)
QtGui.qApp.request_update.connect(self.updateRequest)
# pylint: enable=no-member
self.app.request_update.connect(self.updateRequest)

self.updateRequest()
self.setUpdateInterval(10)
Expand Down Expand Up @@ -279,9 +280,7 @@ def __itemSingleClickedEmitToApp(item, col):
@type col: int
@param col: Column number single clicked on"""
del col
# pylint: disable=no-member
QtGui.qApp.single_click.emit(item.rpcObject)
# pylint: enable=no-member
cuegui.app().single_click.emit(item.rpcObject)

@staticmethod
def __itemDoubleClickedEmitToApp(item, col):
Expand All @@ -293,10 +292,8 @@ def __itemDoubleClickedEmitToApp(item, col):
@type col: int
@param col: Column number double clicked on"""
del col
# pylint: disable=no-member
QtGui.qApp.view_object.emit(item.rpcObject)
QtGui.qApp.double_click.emit(item.rpcObject)
# pylint: enable=no-member
cuegui.app().view_object.emit(item.rpcObject)
cuegui.app().double_click.emit(item.rpcObject)

def addObject(self, rpcObject):
"""Adds or updates an rpcObject in the list using the _createItem function
Expand Down Expand Up @@ -385,11 +382,9 @@ def _update(self):
"""Updates the items in the TreeWidget without checking when it was last
updated"""
self._lastUpdate = time.time()
if hasattr(QtGui.qApp, "threadpool"):
# pylint: disable=no-member
QtGui.qApp.threadpool.queue(
if self.app.threadpool is not None:
self.app.threadpool.queue(
self._getUpdate, self._processUpdate, "getting data for %s" % self.__class__)
# pylint: enable=no-member
else:
logger.warning("threadpool not found, doing work in gui thread")
self._processUpdate(None, self._getUpdate())
Expand Down
1 change: 1 addition & 0 deletions cuegui/cuegui/AbstractWidgetItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AbstractWidgetItem(QtWidgets.QTreeWidgetItem):

def __init__(self, itemType, rpcObject, parent, source=None):
QtWidgets.QTreeWidgetItem.__init__(self, parent, itemType)
self.app = cuegui.app()
self.column_info = self.treeWidget().getColumnInfo(itemType)
self._cache = {}
self._source = source
Expand Down
78 changes: 78 additions & 0 deletions cuegui/cuegui/App.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright Contributors to the OpenCue Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module for CueGUI's custom QApplication and associated helper functions."""

from PySide2 import QtCore
from PySide2 import QtWidgets

import cuegui.Exception

__QAPPLICATION_SINGLETON = None


class CueGuiApplication(QtWidgets.QApplication):
"""The CueGUI application."""

# Settings
settings = None

# Global signals
display_log_file_content = QtCore.Signal(object)
double_click = QtCore.Signal(object)
facility_changed = QtCore.Signal()
single_click = QtCore.Signal(object)
unmonitor = QtCore.Signal(object)
view_hosts = QtCore.Signal(object)
view_object = QtCore.Signal(object)
view_procs = QtCore.Signal(object)
request_update = QtCore.Signal()
status = QtCore.Signal()
quit = QtCore.Signal()

# Thread pool
threadpool = None
threads = []

# Shutdown signal
closingApp = False


def create_app(argv):
"""
Create an instance of the CueGUI application.
:param argv: user-provided commandline arguments
:type argv: list
:return: the application instance
:rtype: CueGuiApplication
"""
# pylint: disable=global-statement
global __QAPPLICATION_SINGLETON
if __QAPPLICATION_SINGLETON is None:
__QAPPLICATION_SINGLETON = CueGuiApplication(argv)
return __QAPPLICATION_SINGLETON


def app():
"""Returns the current application instance.
:return: the current application instance
:rtype: CueGuiApplication
:raises: opencue.exception.ApplicationNotRunningException: the application has not been
initialized yet
"""
if __QAPPLICATION_SINGLETON is None:
raise cuegui.Exception.ApplicationNotRunningException()
return __QAPPLICATION_SINGLETON
11 changes: 4 additions & 7 deletions cuegui/cuegui/Comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import pickle

from PySide2 import QtCore
from PySide2 import QtGui
from PySide2 import QtWidgets

import cuegui.Utils
Expand All @@ -50,6 +49,8 @@ def __init__(self, source, parent=None):
@type parent: QWidget
@param parent: The dialog's parent"""
QtWidgets.QDialog.__init__(self, parent)
self.app = cuegui.app()

self.__source = source

self.__labelTitle = QtWidgets.QLabel(self.__source.data.name, self)
Expand Down Expand Up @@ -208,10 +209,8 @@ def refreshComments(self):

def __macroLoad(self):
"""Loads the defined comment macros from settings"""
# pylint: disable=no-member
self.__macroList = pickle.loads(
str(QtGui.qApp.settings.value("Comments", pickle.dumps({}))))
# pylint: enable=no-member
str(self.app.settings.value("Comments", pickle.dumps({}))))
self.__macroRefresh()

def __macroRefresh(self):
Expand All @@ -225,9 +224,7 @@ def __macroRefresh(self):

def __macroSave(self):
"""Saves the current comment macros to settings"""
# pylint: disable=no-member
QtGui.qApp.settings.setValue("Comments", pickle.dumps(self.__macroList))
# pylint: enable=no-member
self.app.settings.setValue("Comments", pickle.dumps(self.__macroList))

def __macroHandle(self, selection):
"""Called when the comment macro combo box is selected
Expand Down
6 changes: 2 additions & 4 deletions cuegui/cuegui/CueJobMonitorTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ def __init__(self, parent):
self.__menuActions = cuegui.MenuActions.MenuActions(
self, self.updateSoon, self.selectedObjects)

self.app.facility_changed.connect(self.removeAllShows)
# pylint: disable=no-member
QtGui.qApp.facility_changed.connect(self.removeAllShows)
self.itemClicked.connect(self.__itemSingleClickedCopy)
self.itemClicked.connect(self.__itemSingleClickedComment)
# pylint: enable=no-member
Expand Down Expand Up @@ -726,9 +726,7 @@ def __init__(self, rpcObject, parent):
self.__class__.__initialized = True
self.__class__.__commentIcon = QtGui.QIcon(":comment.png")
self.__class__.__eatIcon = QtGui.QIcon(":eat.png")
# pylint: disable=no-member
self.__class__.__backgroundColor = QtGui.qApp.palette().color(QtGui.QPalette.Base)
# pylint: enable=no-member
self.__class__.__backgroundColor = cuegui.app().palette().color(QtGui.QPalette.Base)
self.__class__.__foregroundColor = cuegui.Style.ColorTheme.COLOR_JOB_FOREGROUND
self.__class__.__pausedColor = cuegui.Style.ColorTheme.COLOR_JOB_PAUSED_BACKGROUND
self.__class__.__finishedColor = cuegui.Style.ColorTheme.COLOR_JOB_FINISHED_BACKGROUND
Expand Down
5 changes: 2 additions & 3 deletions cuegui/cuegui/CueStateBarWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, sourceTree, parent=None):
@type parent: QWidget
@param parent: The parent widget"""
QtWidgets.QWidget.__init__(self, parent)
self.app = cuegui.app()

self.__background = None

Expand All @@ -55,9 +56,7 @@ def __init__(self, sourceTree, parent=None):

self.__sourceTree = weakref.proxy(sourceTree)
self.__colors = []
# pylint: disable=no-member
self.__baseColor = QtGui.qApp.palette().color(QtGui.QPalette.Base)
# pylint: enable=no-member
self.__baseColor = self.app.palette().color(QtGui.QPalette.Base)
self.__colorsLock = QtCore.QReadWriteLock()
self.__timer = QtCore.QTimer(self)
self.__lastUpdate = 0
Expand Down
11 changes: 5 additions & 6 deletions cuegui/cuegui/DarkPalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,19 @@ def init():
"""Convenience function that takes the QApplication object for the
application and configures the palette and style for the Plastique
color scheme"""
# pylint: disable=no-member
QtGui.qApp.setPalette(DarkPalette())
app = cuegui.app()
app.setPalette(DarkPalette())
if platform.system() in ['Darwin', 'Linux']:
setDarkStyleSheet()
elif platform.system() == 'Windows':
QtGui.qApp.setStyle('Fusion')
app.setStyle('Fusion')
else:
QtGui.qApp.setStyle(QtWidgets.QStyleFactory.create(cuegui.Constants.COLOR_THEME))
app.setStyle(QtWidgets.QStyleFactory.create(cuegui.Constants.COLOR_THEME))


def setDarkStyleSheet():
"""Sets the stylesheet."""
# pylint: disable=no-member
QtGui.qApp.setStyleSheet(open(cuegui.Constants.DARK_STYLE_SHEET).read())
cuegui.app().setStyleSheet(open(cuegui.Constants.DARK_STYLE_SHEET).read())


def DarkPalette():
Expand Down
35 changes: 35 additions & 0 deletions cuegui/cuegui/Exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright Contributors to the OpenCue Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Custom exception classes for CueGUI application errors."""


class CueGuiException(Exception):
"""Base class for all CueGUI exceptions.
Note that this class does NOT inherit from opencue.exception.CueException, so that error
handling code can easily distinguish between API errors and CueGUI errors.
"""


class ApplicationNotRunningException(CueGuiException):
"""Raised when the CueGUI application has not been instantiated but is required to be."""

default_message = (
'attempted to access the CueGUI application before cuegui.create_app() was called')

def __init__(self, message=None):
if message is None:
message = self.default_message
super().__init__(message)
27 changes: 9 additions & 18 deletions cuegui/cuegui/FrameMonitorTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ def __itemSingleClickedViewLog(self, item, col):
except ValueError:
old_log_files = []

# pylint: disable=no-member
QtGui.qApp.display_log_file_content.emit([current_log_file] + old_log_files)
# pylint: enable=no-member
self.app.display_log_file_content.emit([current_log_file] + old_log_files)

def __itemDoubleClickedViewLog(self, item, col):
"""Called when a frame is double clicked, views the frame log in a popup
Expand Down Expand Up @@ -447,11 +445,9 @@ def _update(self):
updated"""
logger.info("_update")
self._lastUpdate = time.time()
if hasattr(QtGui.qApp, "threadpool"):
# pylint: disable=no-member
QtGui.qApp.threadpool.queue(
if self.app.threadpool is not None:
self.app.threadpool.queue(
self._getUpdate, self._processUpdate, "getting data for %s" % self.__class__)
# pylint: enable=no-member
else:
logger.warning("threadpool not found, doing work in gui thread")
self._processUpdate(None, self._getUpdate())
Expand All @@ -461,12 +457,10 @@ def _updateChanged(self):
updated"""
logger.info("_updateChanged")
self._lastUpdate = time.time()
if hasattr(QtGui.qApp, "threadpool"):
# pylint: disable=no-member
QtGui.qApp.threadpool.queue(
if self.app.threadpool is not None:
self.app.threadpool.queue(
self._getUpdateChanged, self._processUpdateChanged,
"getting data for %s" % self.__class__)
# pylint: enable=no-member
else:
logger.warning("threadpool not found, doing work in gui thread")
self._processUpdateChanged(None, self._getUpdateChanged())
Expand Down Expand Up @@ -596,9 +590,7 @@ class FrameWidgetItem(cuegui.AbstractWidgetItem.AbstractWidgetItem):
def __init__(self, rpcObject, parent, job):
if not self.__initialized:
self.__class__.__initialized = True
# pylint: disable=no-member
self.__class__.__backgroundColor = QtGui.qApp.palette().color(QtGui.QPalette.Base)
# pylint: enable=no-member
self.__class__.__backgroundColor = cuegui.app().palette().color(QtGui.QPalette.Base)
self.__class__.__foregroundColor = cuegui.Style.ColorTheme.COLOR_JOB_FOREGROUND
self.__class__.__foregroundColorBlack = QCOLOR_BLACK
self.__class__.__foregroundColorGreen = QCOLOR_GREEN
Expand Down Expand Up @@ -862,6 +854,7 @@ class FrameContextMenu(QtWidgets.QMenu):

def __init__(self, widget, filterSelectedLayersCallback):
super(FrameContextMenu, self).__init__()
self.app = cuegui.app()

self.__menuActions = cuegui.MenuActions.MenuActions(
widget, widget.updateSoon, widget.selectedObjects, widget.getJob)
Expand All @@ -880,13 +873,11 @@ def __init__(self, widget, filterSelectedLayersCallback):
elif count == 2:
self.__menuActions.frames().addAction(self, "xdiff2")

if bool(int(QtGui.qApp.settings.value("AllowDeeding", 0))):
if bool(int(self.app.settings.value("AllowDeeding", 0))):
self.__menuActions.frames().addAction(self, "useLocalCores")

# pylint: disable=no-member
if QtGui.qApp.applicationName() == "CueCommander":
if self.app.applicationName() == "CueCommander":
self.__menuActions.frames().addAction(self, "viewHost")
# pylint: enable=no-member

depend_menu = QtWidgets.QMenu("&Dependencies", self)
self.__menuActions.frames().addAction(depend_menu, "viewDepends")
Expand Down

0 comments on commit 6500fe2

Please sign in to comment.