def __init__(self, tray_widget, main_window): self.tray_widget = tray_widget self.main_window = main_window self.log = Logger().get_logger(self.__class__.__name__) self.modules = {} self.services = {} self.services_submenu = None self.errors = [] CURRENT_DIR = os.path.dirname(__file__) self.modules_imports = config.load_json( os.path.join(CURRENT_DIR, "modules_imports.json")) presets = config.get_presets(first_run=True) menu_items = presets["tray"]["menu_items"] try: self.modules_usage = menu_items["item_usage"] except Exception: self.modules_usage = {} self.log.critical("Couldn't find modules usage data.") self.module_attributes = menu_items.get("attributes") or {} self.icon_run = QtGui.QIcon( resources.get_resource("icons", "circle_green.png")) self.icon_stay = QtGui.QIcon( resources.get_resource("icons", "circle_orange.png")) self.icon_failed = QtGui.QIcon( resources.get_resource("icons", "circle_red.png"))
def get_action_icon(action): icon_name = action.icon if not icon_name: return None global ICON_CACHE icon = ICON_CACHE.get(icon_name) if icon is NOT_FOUND: return None elif icon: return icon icon_path = resources.get_resource(icon_name) if os.path.exists(icon_path): icon = QtGui.QIcon(icon_path) ICON_CACHE[icon_name] = icon return icon try: icon_color = getattr(action, "color", None) or "white" icon = qtawesome.icon( "fa.{}".format(icon_name), color=icon_color ) except Exception: ICON_CACHE[icon_name] = NOT_FOUND print("Can't load icon \"{}\"".format(icon_name)) return icon
def __init__(self, module): self.module = module self.thread_action_server = None self.thread_socket_server = None self.thread_timer = None self.bool_logged = False self.bool_action_server_running = False self.bool_action_thread_running = False self.bool_timer_event = False self.widget_login = login_dialog.CredentialsDialog() self.widget_login.login_changed.connect(self.on_login_change) self.widget_login.logout_signal.connect(self.on_logout) self.action_credentials = None self.tray_server_menu = None self.icon_logged = QtGui.QIcon( resources.get_resource("icons", "circle_green.png")) self.icon_not_logged = QtGui.QIcon( resources.get_resource("icons", "circle_orange.png"))
def set_context_favorites(favorites={}): """ Addig favorite folders to nuke's browser Argumets: favorites (dict): couples of {name:path} """ icon_path = resources.get_resource("icons", "folder-favorite3.png") for name, path in favorites.items(): nuke.addFavoriteDir( name, path, nuke.IMAGE | nuke.SCRIPT | nuke.GEO, icon=icon_path)
def set_working_widget(self): image_file = resources.get_resource("icons", "working.svg") img_pix = QtGui.QPixmap(image_file) if image_file.endswith('.svg'): widget = QtSvg.QSvgWidget(image_file) else: widget = QtWidgets.QLabel() widget.setPixmap(img_pix) # Set widget properties widget.setGeometry(img_pix.rect()) widget.setMask(img_pix.mask()) widget.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.FramelessWindowHint) widget.setAttribute(QtCore.Qt.WA_TranslucentBackground, True) self.center_widget(widget) self._working_widget = widget self.helper = DragAndDropHelper(self._working_widget)
class LoginServerHandler(BaseHTTPRequestHandler): '''Login server handler.''' message_filepath = resources.get_resource("ftrack", "sign_in_message.html") def __init__(self, login_callback, *args, **kw): '''Initialise handler.''' self.login_callback = login_callback BaseHTTPRequestHandler.__init__(self, *args, **kw) def do_GET(self): '''Override to handle requests ourselves.''' parsed_path = parse.urlparse(self.path) query = parsed_path.query api_user = None api_key = None login_credentials = None if 'api_user' and 'api_key' in query: login_credentials = parse.parse_qs(query) api_user = login_credentials['api_user'][0] api_key = login_credentials['api_key'][0] with open(self.message_filepath, "r") as message_file: sign_in_message = message_file.read() # formatting html code for python replacements = (("{", "{{"), ("}", "}}"), ("{{}}", "{}")) for replacement in (replacements): sign_in_message = sign_in_message.replace(*replacement) message = sign_in_message.format(api_user) else: message = "<h1>Failed to sign in</h1>" self.send_response(200) self.end_headers() self.wfile.write(message.encode()) if login_credentials: self.login_callback(api_user, api_key)
def override_toolbox_ui(): """Add custom buttons in Toolbox as replacement for Maya web help icon.""" inventory = None loader = None launch_workfiles_app = None mayalookassigner = None try: import avalon.tools.sceneinventory as inventory except Exception: log.warning("Could not import SceneInventory tool") try: import avalon.tools.loader as loader except Exception: log.warning("Could not import Loader tool") try: from avalon.maya.pipeline import launch_workfiles_app except Exception: log.warning("Could not import Workfiles tool") try: from pype.tools import mayalookassigner except Exception: log.warning("Could not import Maya Look assigner tool") from pype.api import resources icons = resources.get_resource("icons") if not any((mayalookassigner, launch_workfiles_app, loader, inventory)): return # Ensure the maya web icon on toolbox exists web_button = "ToolBox|MainToolboxLayout|mayaWebButton" if not mc.iconTextButton(web_button, query=True, exists=True): return mc.iconTextButton(web_button, edit=True, visible=False) # real = 32, but 36 with padding - according to toolbox mel script icon_size = 36 parent = web_button.rsplit("|", 1)[0] # Ensure the parent is a formLayout if not mc.objectTypeUI(parent) == "formLayout": return # Create our controls background_color = (0.267, 0.267, 0.267) controls = [] if mayalookassigner: controls.append( mc.iconTextButton("pype_toolbox_lookmanager", annotation="Look Manager", label="Look Manager", image=os.path.join(icons, "lookmanager.png"), command=lambda: mayalookassigner.show(), bgc=background_color, width=icon_size, height=icon_size, parent=parent)) if launch_workfiles_app: controls.append( mc.iconTextButton("pype_toolbox_workfiles", annotation="Work Files", label="Work Files", image=os.path.join(icons, "workfiles.png"), command=lambda: launch_workfiles_app(), bgc=background_color, width=icon_size, height=icon_size, parent=parent)) if loader: controls.append( mc.iconTextButton("pype_toolbox_loader", annotation="Loader", label="Loader", image=os.path.join(icons, "loader.png"), command=lambda: loader.show(use_context=True), bgc=background_color, width=icon_size, height=icon_size, parent=parent)) if inventory: controls.append( mc.iconTextButton("pype_toolbox_manager", annotation="Inventory", label="Inventory", image=os.path.join(icons, "inventory.png"), command=lambda: inventory.show(), bgc=background_color, width=icon_size, height=icon_size, parent=parent)) # Add the buttons on the bottom and stack # them above each other with side padding controls.reverse() for i, control in enumerate(controls): previous = controls[i - 1] if i > 0 else web_button mc.formLayout(parent, edit=True, attachControl=[control, "bottom", 0, previous], attachForm=([control, "left", 1], [control, "right", 1]))