First steps to understanding Tray apps

This commit is contained in:
Jakub Trllo 2018-11-16 17:21:30 +01:00
parent b174fce9de
commit ed2c37031b
3 changed files with 69 additions and 126 deletions

View file

@ -32,6 +32,8 @@ parser.add_argument("--eventserver", action="store_true",
help="launch action server for ftrack")
parser.add_argument("--logout", action="store_true",
help="launch action server for ftrack")
parser.add_argument("--systray", action="store_true",
help="launch action server for ftrack")
kwargs, args = parser.parse_known_args()
@ -47,6 +49,15 @@ if kwargs.eventserver:
sys.executable, "-u", fname
])
elif kwargs.systray:
stud_config = os.getenv('PYPE_STUDIO_CONFIG')
items = [stud_config, "pype", "ftrack", "tray.py"]
fname = os.path.sep.join(items)
returncode = forward([
sys.executable, "-u", fname
])
else:
fname = os.path.join(os.environ["FTRACK_ACTION_SERVER"], "actionServer.py")
returncode = forward([

View file

@ -1,45 +1,38 @@
import os
import sys
import textwrap
from app import style
from app.vendor.Qt import QtCore, QtGui, QtWidgets
menu_layout_dict = {'Ftrack': {
'Avalon Core': [
'Config core',
'Create new project',
None,
'Save database',
],
'Avalon Users': [
'Config User',
'Cre&ate new user',
],
'Avalon Workfiles': [
'Config Workfiles',
],
'Pyblish': [
'Config Pyblish',
'Create new micro-plugin',
None,
'Micro-plugins manager'
],
'Pipeline': [
'Config pipeline',
'Create new template',
None,
'Templates manager'
],
'CG-wire': [
'Config CG-wire',
None,
'Pull database',
'Push database'
]
},
'Minimalize': "action",
#'Close': "action"
}
# print(menu_layout_dict)
ftrack_layout = {
'Avalon Users': {
'Config User',
'Cre&ate new user',
},
'Avalon Workfiles': {
'Config Workfiles',
},
'Pyblish': {
'Config Pyblish',
'Create new micro-plugin',
None,
'Micro-plugins manager'
},
'Pipeline': {
'Config pipeline',
'Create new template',
None,
'Templates manager'
},
'Logout': "action",
}
applications = {
'app_one':'action',
'app_two':'action'
}
menu_layout_dict = {'Ftrack':ftrack_layout, 'Apps':applications}
class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
def __init__(self, icon, parent=None):
QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)
@ -53,50 +46,38 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
# project_name_lbl = QtWidgets.QLabel('<b>Project Name</b>')
# self.main_layout.addWidget(project_name_lbl)
menu.setProperty('menu', 'on')
label = QtWidgets.QLabel('Avalon', menu)
menu.setStyleSheet(textwrap.dedent('''
QWidget {
background-color: #444444;
color: #ffffff;
}
QLineEdit {
background-color: white;
}
QLineEdit:no-text-inside-it {
background-color: red;
}
QWidget[menu=on] {
background-color: #333333;
color: #ffffff;
}
'''
)
)
menu.setStyleSheet(style.load_stylesheet())
for key, value in menu_layout_dict.items():
if value == 'action':
# menu = QtWidgets.QMenu(menu)
# menu = QtWidgets.QMenu(menu)
print(100*"*")
print(key)
print(value)
if value == 'action':
separator = menu.addSeparator()
# spacer = QtWidgets.QWidget()
menu.addAction(key)
print(key, value)
else:
else:
# menu = QtWidgets.QMenu(menu)
avalon_plugins = menu.addMenu(key)
avalon_plugins.setProperty('submenu', 'on')
self.eventFilter(avalon_plugins, QtCore.QEvent.HoverMove)
combo_box = menu.addMenu(key)
combo_box.setProperty('submenu', 'on')
self.eventFilter(combo_box, QtCore.QEvent.HoverMove)
for skey, svalue in value.items():
avalon_plugin = avalon_plugins.addMenu(skey)
avalon_plugin.setProperty('submenu', 'on')
# print(skey, svalue)
# plugins_Menu = avalon_plugin.addMenu(skey)
for action in svalue:
if action == None:
avalon_plugin.addSeparator()
else:
plugins_Action = avalon_plugin.addAction(action)
menu.addMenu(avalon_plugins)
if svalue == 'action':
combo_box.addAction(skey)
elif svalue is None:
combo_box.addSeparator()
else:
nextbox = combo_box.addMenu(skey)
nextbox.setProperty('submenu', 'on')
for action in svalue:
if action == None:
nextbox.addSeparator()
else:
nextbox.addAction(action)
menu.addMenu(combo_box)
exitAction = menu.addAction("Exit")
self.eventFilter(exitAction, QtCore.QEvent.HoverMove)
self.setContextMenu(menu)
menu.triggered.connect(self.exit)
@ -108,7 +89,6 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
# return True
# #
if event == QtCore.QEvent.HoverMove:
print("C'mon! CLick-meeee!!!")
return True
def exit(self):
QtCore.QCoreApplication.exit()
@ -116,7 +96,9 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
def _sys_tray(image):
# code source: https://stackoverflow.com/questions/893984/pyqt-show-menu-in-a-system-tray-application - add answer PyQt5
#PyQt4 to PyQt5 version: https://stackoverflow.com/questions/20749819/pyqt5-failing-import-of-qtgui
app = QtWidgets.QApplication(sys.argv)
# app = QtWidgets.QApplication(sys.argv)
app = QtWidgets.QApplication([])
app.setQuitOnLastWindowClosed(False)
w = QtWidgets.QWidget()
trayIcon = SystemTrayIcon(QtGui.QIcon(image), w)
# menu =
@ -125,5 +107,4 @@ def _sys_tray(image):
if (__name__ == ('__main__')):
avalon_core_icon = r'C:\Users\jakub.trllo\CODE\pype-setup\repos\avalon-launcher\launcher\res\icon\main.png'
print(avalon_core_icon)
_sys_tray(avalon_core_icon)

View file

@ -1,49 +0,0 @@
from app.vendor.Qt import QtGui
from app.vendor.Qt import QtWidgets
import credentials
app = QApplication([])
app.setQuitOnLastWindowClosed(False)
# Create the icon
avalon_core_icon = r'C:\Users\jakub.trllo\CODE\pype-setup\repos\avalon-launcher\launcher\res\icon\main.png'
icon = QIcon(avalon_core_icon)
clipboard = QApplication.clipboard()
dialog = QColorDialog()
def logout():
credentials.
def copy_color_hsv():
if dialog.exec_():
color = dialog.currentColor()
clipboard.setText("hsv(%d, %d, %d)" % (
color.hue(), color.saturation(), color.value()
))
def exit():
self.close()
# Create the tray
tray = QSystemTrayIcon()
tray.setIcon(icon)
tray.setVisible(True)
# Create the menu
menu = QMenu()
exit = QAction("Exit")
exit.triggered.connect(exit)
logout = QAction("Logout")
logout.triggered.connect(logout)
action3 = QAction("HSV")
action3.triggered.connect(copy_color_hsv)
menu.addAction(exit)
# menu.addAction(action2)
# menu.addAction(action3)
# Add the menu to the tray
tray.setContextMenu(menu)
app.exec_()