Esempio n. 1
0
def show_action_forms():
    # configure bands
    import bands

    class LoggingDispatcher(bands.Dispatcher):
        def __init__(self, name):
            self.name = name

        def dispatch(self, identifier, receiver, *args, **kwargs):
            print(self.name + '> Sending %s to %s' % (identifier, receiver))
            return receiver(*args, **kwargs)

    bands.get_band().dispatcher = LoggingDispatcher('bands')

    # configure construct
    construct.init()
    workspace = construct.search(tags=['workspace']).one()
    construct.set_context_from_entry(workspace)

    # configure qapp with dynamic stylesheet
    app = QtWidgets.QApplication(sys.argv)
    resources.init()
    apply_style(app, ':/styles/dark')

    # Show some forms
    form = form_for_action('file.open')
    apply_style(form, ':/styles/dark')
    form.exec_()

    form = form_for_action('file.save')
    apply_style(form, ':/styles/dark')
    form.show()

    # Wait for app loop to finish and exit
    sys.exit(app.exec_())
Esempio n. 2
0
    def create(self):
        self.layout = QtWidgets.QVBoxLayout()
        self.layout.setAlignment(QtCore.Qt.AlignTop)

        project_query = construct.search(root=self.data.root,
                                         tags=['project'],
                                         depth=1)

        self.project_list = QueryListControl(
            'Projects',
            project_query,
            formatter=lambda entry: entry.name,
            parent=self)
Esempio n. 3
0
    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))
Esempio n. 4
0
    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.'))
Esempio n. 5
0
    def create(self):

        params = self.action.parameters(self.data)

        # Make sure the form gets styled
        self.setAttribute(QtCore.Qt.WA_StyledBackground)

        # Setup project control
        def format_project(project):
            return project.name

        query = construct.search(root=self.data.root,
                                 tags=['project'],
                                 depth=1,
                                 levels=1)

        self.project_option = QueryOptionControl('project',
                                                 query=query,
                                                 formatter=format_project,
                                                 default=self.data.project,
                                                 parent=self)
        self.project_option.changed.connect(self.project_changed)

        # Setup task control
        def format_task(task):
            parents = list(task.parents())[::-1]
            if parents:
                parts = parents[1:] + [task]
                return '/'.join([p.name for p in parts])
            else:
                return task.name

        tags = ['task']

        query = construct.search(root=self.data.project.path, tags=tags)

        self.task_option = QueryOptionControl('task',
                                              query=query,
                                              formatter=format_task,
                                              default=self.data.task,
                                              parent=self)
        self.task_option.changed.connect(self.task_changed)

        # Setup save button
        self.set_workspace_button = QtWidgets.QPushButton('Set', self)
        self.set_workspace_button.clicked.connect(self.accept)

        self.grid = QtWidgets.QGridLayout()
        self.grid.setContentsMargins(20, 20, 20, 20)
        self.grid.setVerticalSpacing(20)
        self.grid.setColumnStretch(1, 1)
        self.grid.setRowStretch(2, 1)

        # Location controls
        self.grid.addWidget(RightLabel('Project'), 0, 0)
        self.grid.addWidget(self.project_option, 0, 1, 1, 3)
        self.grid.addWidget(RightLabel('Task'), 1, 0)
        self.grid.addWidget(self.task_option, 1, 1, 1, 3)

        # Buttons
        self.grid.addWidget(self.set_workspace_button, 3, 3)

        self.setLayout(self.grid)
Esempio n. 6
0
    def create(self):
        # Make sure the form gets styled
        self.setAttribute(QtCore.Qt.WA_StyledBackground)

        # Setup project control
        def format_project(project):
            return project.name

        query = construct.search(root=self.data.root,
                                 tags=['project'],
                                 depth=1,
                                 levels=1)

        self.project_option = QueryOptionControl('project',
                                                 query=query,
                                                 formatter=format_project,
                                                 default=self.data.project,
                                                 parent=self)
        self.project_option.changed.connect(self.project_changed)

        # Setup workspace control
        def format_workspace(workspace):
            parents = list(workspace.parents())[::-1]
            if parents:
                parts = parents[1:] + [workspace]
                return '/'.join([p.name for p in parts])
            else:
                return workspace.name

        if self.data.workspace:
            tags = self.data.workspace.tags
        else:
            tags = ['workspace']

        query = construct.search(root=self.data.project.path, tags=tags)

        self.workspace_option = QueryOptionControl('workspace',
                                                   query=query,
                                                   formatter=format_workspace,
                                                   default=self.data.workspace,
                                                   parent=self)
        self.workspace_option.changed.connect(self.workspace_changed)

        # Setup files view
        self.files = WorkspaceFilesView(self.workspace_option.get(),
                                        parent=self)
        self.files.doubleClicked.connect(self.accept)

        # Setup open button
        self.open_button = QtWidgets.QPushButton('Open', self)
        self.open_button.clicked.connect(self.accept)
        self.cancel_button = QtWidgets.QPushButton('Cancel', self)
        self.cancel_button.clicked.connect(self.reject)

        self.grid = QtWidgets.QGridLayout()
        self.grid.setContentsMargins(20, 20, 20, 20)
        self.grid.setVerticalSpacing(20)
        self.grid.setColumnStretch(1, 1)
        self.grid.addWidget(RightLabel('Project'), 0, 0)
        self.grid.addWidget(self.project_option, 0, 1, 1, 3)
        self.grid.addWidget(RightLabel('Workspace'), 1, 0)
        self.grid.addWidget(self.workspace_option, 1, 1, 1, 3)
        self.grid.addWidget(self.files, 2, 0, 1, 4)
        self.grid.addWidget(self.cancel_button, 3, 2)
        self.grid.addWidget(self.open_button, 3, 3)

        self.setLayout(self.grid)
Esempio n. 7
0
    def create(self):

        params = self.action.parameters(self.data)

        # Make sure the form gets styled
        self.setAttribute(QtCore.Qt.WA_StyledBackground)

        # Setup project control
        def format_project(project):
            return project.name

        query = construct.search(
            root=self.data.root,
            tags=['project'],
            depth=1,
            levels=1
        )

        self.project_option = QueryOptionControl(
            'project',
            query=query,
            formatter=format_project,
            default=self.data.project,
            parent=self
        )
        self.project_option.changed.connect(self.project_changed)

        # Setup workspace control
        def format_workspace(workspace):
            parents = list(workspace.parents())[::-1]
            if parents:
                parts = parents[1:] + [workspace]
                return '/'.join([p.name for p in parts])
            else:
                return workspace.name

        if self.data.workspace:
            tags = self.data.workspace.tags
        else:
            tags = ['workspace']

        query = construct.search(root=self.data.project.path, tags=tags)

        self.workspace_option = QueryOptionControl(
            'workspace',
            query=query,
            formatter=format_workspace,
            default=self.data.workspace,
            parent=self
        )
        self.workspace_option.changed.connect(self.workspace_changed)

        # Setup filenaming options

        self.name_control = StringControl(
            'name',
            default=params['name']['default'],
            parent=self
        )
        self.name_validator = QtGui.QRegExpValidator(
            QtCore.QRegExp('[A-Za-z0-9_]+')
        )
        self.name_control.setValidator(self.name_validator)
        self.name_control.changed.connect(self.update_version)
        self.version_control = IntControl(
            'name',
            range=[1, 999],
            default=params['version']['default'],
            parent=self
        )
        self.version_control.changed.connect(self.update_preview)
        self.ext_control = OptionControl(
            'ext',
            options=params['ext']['options'],
        )
        self.ext_control.changed.connect(self.update_version)

        self.name_preview = Label(self.generate_preview())

        # Setup save button
        self.save_button = QtWidgets.QPushButton('Save', self)
        self.save_button.clicked.connect(self.accept)

        self.grid = QtWidgets.QGridLayout()
        self.grid.setContentsMargins(20, 20, 20, 20)
        self.grid.setVerticalSpacing(20)
        self.grid.setRowMinimumHeight(2, 36)
        self.grid.setColumnStretch(1, 1)
        self.grid.setRowStretch(3, 1)

        # Location controls
        self.grid.addWidget(RightLabel('Project'), 0, 0)
        self.grid.addWidget(self.project_option, 0, 1, 1, 3)
        self.grid.addWidget(RightLabel('Workspace'), 1, 0)
        self.grid.addWidget(self.workspace_option, 1, 1, 1, 3)

        # File name controls
        ngrid = QtWidgets.QGridLayout()
        ngrid.setContentsMargins(0, 0, 0, 0)
        ngrid.setHorizontalSpacing(8)
        ngrid.setColumnStretch(0, 1)
        ngrid.addWidget(self.name_control, 0, 0)
        ngrid.addWidget(self.version_control, 0, 1)
        ngrid.addWidget(self.ext_control, 0, 2)
        self.grid.addWidget(RightLabel('Name'), 2, 0)
        self.grid.addLayout(ngrid, 2, 1, 1, 3)

        # Preview
        # self.grid.addWidget(RightLabel('Preview'), 3, 0)
        self.grid.addWidget(self.name_preview, 4, 1, 1, 2)

        # Buttons
        # self.grid.addWidget(self.cancel_button, 5, 2)
        self.grid.addWidget(self.save_button, 4, 3)

        self.setLayout(self.grid)