def run(self, args, *extra_args): ctx = construct.get_context() if not os.path.exists(ctx.root): os.makedirs(ctx.root) scrim = get_scrim() scrim.pushd(ctx.root)
def __init__(self, action, ctx=None, *args, **kwargs): self.action = action ctx = ctx or construct.get_context() super(ActionForm, self).__init__(ctx, *args, **kwargs) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.accepted.connect(self.on_accept) self.rejected.connect(self.on_reject) if hasattr(self, 'setWindowTitle'): self.setWindowTitle(action.label)
def format_context(): ctx = construct.get_context() ctx_data = [] for k in ctx.keys: v = ctx[k] if not v: continue if k in ctx.entry_keys: ctx_data.append((k, v.name)) else: ctx_data.append((k, v)) return format_section(CONTEXT_TITLE, ctx_data, lcolor=styled('{bright}'))
def on_request_status_change(request, last_status, status): console = stout.get_console() w = CONSOLE_WIDGETS[request.task.identifier] w.set_status(status) if status == FAILED: err = w.format_error(request.exception) console.insert(w.row, err) ctx = get_context() progress = CONSOLE_WIDGETS['progress'] i = 0 for request in ctx.requests.values(): if request._status in [FAILED, SUCCESS, SKIPPED]: i += 1 progress.set_value(i)
def run(self, args, *extra_args): import fsfs ctx = construct.get_context() if not args.tags and args.name: query = dict(selector=args.name, root=args.root, skip_root=True) entry = construct.quick_select(**query) else: query = dict(root=args.root, name=args.name, tags=args.tags, direction=args.direction, depth=args.depth or (3 if ctx.project else 2), skip_root=True) # Get a better match, not just the first hit entries = list(construct.search(**query)) if not entries: error('Could not find entry...') sys.exit(1) if len(entries) == 1: entry = entries[0] else: # The shortest entry has to be the closest to our query entry = min(entries, key=lambda e: len(e.path)) if not entry: error('Could not find entry...') sys.exit(1) path = entry.path if args.name: parts = args.name.split('/') for part in parts: highlight = styled('{bright}{fg.yellow}{}{reset}', part) path = path.replace(part, highlight) print(path) scrim = get_scrim() scrim.pushd(os.path.abspath(entry.path))
def form_for_action(action_or_identifier): if construct.action.is_action_type(action_or_identifier): action = action_or_identifier else: action = construct.actions.get(action_or_identifier) try: host = construct.get_host() parent = host.get_qt_parent() except AttributeError: host = None parent = None form_cls = construct.get_form(action.identifier) if form_cls: form = form_cls(action, construct.get_context(), parent) form.setStyleSheet(resources.style(':/styles/dark')) return form return None
def set_workspace(self, directory): import nuke from construct_ui import resources ctx = construct.get_context() fav_icon = resources.path(':/brand/construct_icon-white-on-black') favs = ['project', 'sequence', 'shot', 'asset', 'workspace'] for fav in favs: fav_name = fav.title() nuke.removeFavoriteDir(fav_name) entry = ctx[fav] if entry: directory = entry.path nuke.addFavoriteDir(fav_name, directory=directory, type=(nuke.IMAGE | nuke.SCRIPT | nuke.GEO), icon=fav_icon, tooltip=directory) os.chdir(directory) nuke.root()['project_directory'].setValue(directory)
def run(self, args, *extra_args): ctx = construct.get_context() query = dict( root=args.root, name=args.name, tags=args.tags, direction=args.direction, depth=args.depth or (3 if ctx.project else 1), ) entries = construct.search(**query) i = 0 for i, entry in enumerate(entries): path = entry.path if args.name: parts = args.name.split('/') for part in parts: highlight = styled('{bright}{fg.yellow}{}{reset}', part) path = path.replace(part, highlight) print(path) if i == 0: print(('Found 0 result.'))
def setup(): _log.debug('Configuring Construct for Maya!') construct.init() resources.init() ctx = construct.get_context() host = construct.get_host() if ctx.workspace: _log.debug('Setting workspace to ' + ctx.workspace.path) host.set_workspace(ctx.workspace.path) _log.debug('Registering callbacks...') callbacks.register() _log.debug('Creating Construct menu...') menus.ConstructMenu.setup() if ctx.workspace and not host.get_filename(): if ctx.workspace.get_work_files(): action_identifier = 'file.open' else: action_identifier = 'file.save' construct.show_form(action_identifier)
# -*- coding: utf-8 -*- from __future__ import absolute_import import logging import construct from construct_hou import callbacks, utils from construct_ui import resources _log = logging.getLogger('construct.hou.pythonrc') construct.init() resources.init() ctx = construct.get_context() host = construct.get_host() _log.debug('Setting workspace: %s' % ctx.workspace.path) host.set_workspace(ctx.workspace.path) _log.debug('Registering callbacks') callbacks.register() _log.debug('Creating Construct menu...') # TODO if utils.show_file_open_at_startup(): # TODO: Add abstraction around creating ActionForms if ctx.workspace and not host.get_filename(): action = construct.actions.get('file.open') parent = host.get_qt_parent() form_cls = construct.show_form(action.identifier)
def setup_parser(self, parser): ctx = construct.get_context() params = self.action.params(ctx) for param_name, param_options in params.items(): self.add_option(parser, param_name, param_options)
def __init__(self, *args, **kwargs): import construct self.ctx = construct.get_context() self.request = construct.get_request() super(ActionControlFlowError, self).__init__(*args, **kwargs)