コード例 #1
0
    def open_document(self, path, nodes=None):
        """ Set the job.document if it is empty, otherwise close and create
        a  new Job instance.
        
        """
        if path == '-':
            log.debug("Opening document from stdin...")
        elif not os.path.exists(path):
            raise JobError("Cannot open %s, it does not exist!" % path)
        elif not os.path.isfile(path):
            raise JobError("Cannot open %s, it is not a file!" % path)

        # Close any old docs
        self.close_document()

        log.info("Opening {doc}".format(doc=path))
        try:
            self.job.document_kwargs = dict(ids=nodes)
            self.job.document = path
        except ValueError as e:
            #: Wrap in a JobError
            raise JobError(e)

        #: Copy so the ui's update
        jobs = self.jobs[:]
        jobs.append(self.job)
        self.jobs = jobs
コード例 #2
0
ファイル: plugin.py プロジェクト: yangbiaocn/inkcut
    def _refresh_preview(self, change):
        """ Redraw the preview on the screen

        """
        log.info(change)
        view_items = []

        #: Transform used by the view
        preview_plugin = self.workbench.get_plugin('inkcut.preview')
        job = self.job
        plot = preview_plugin.preview
        t = preview_plugin.transform

        #: Draw the device
        plugin = self.workbench.get_plugin('inkcut.device')
        device = plugin.device

        #: Apply the final output transforms from the device
        transform = device.transform if device else lambda p: p

        if device and device.area:
            area = device.area
            view_items.append(
                dict(path=transform(device.area.path * t),
                     pen=plot.pen_device,
                     skip_autorange=True)  #(False, [area.size[0], 0]))
            )

        #: The model is only set when a document is open and has no errors
        if job.model:
            view_items.extend([
                dict(path=transform(job.move_path), pen=plot.pen_up),
                dict(path=transform(job.cut_path), pen=plot.pen_down)
            ])
            #: TODO: This
            #if self.show_offset_path:
            #    view_items.append(PainterPathPlotItem(
            # self.job.offset_path,pen=self.pen_offset))
        if job.material:
            # Also observe any change to job.media and job.device
            view_items.extend([
                dict(path=transform(job.material.path * t),
                     pen=plot.pen_media,
                     skip_autorange=([0, job.size[0]], [0, job.size[1]])),
                dict(path=transform(job.material.padding_path * t),
                     pen=plot.pen_media_padding,
                     skip_autorange=True)
            ])

        #: Update the plot
        preview_plugin.set_preview(*view_items)

        #: Save config
        self.save()
コード例 #3
0
ファイル: plugin.py プロジェクト: yangbiaocn/inkcut
    def close_document(self):
        """ If the job currently has a "document" add this to the jobs list
        and create a new Job instance. Otherwise no job is open so do nothing.

        """
        if not self.job.document:
            return

        log.info("Closing {doc}".format(doc=self.job.document))
        # Create a new default job
        self.job = self._default_job()
コード例 #4
0
ファイル: plugin.py プロジェクト: frmdstryr/Inkcut
    def close_document(self):
        """ If the job currently has a "document" add this to the jobs list
        and create a new Job instance. Otherwise no job is open so do nothing.

        """
        if not self.job.document:
            return

        log.info("Closing {doc}".format(doc=self.job.document))
        # Create a new default job
        self.job = self._default_job()
コード例 #5
0
ファイル: plugin.py プロジェクト: frmdstryr/Inkcut
    def _refresh_preview(self, change):
        """ Redraw the preview on the screen

        """
        log.info(change)
        view_items = []

        #: Transform used by the view
        preview_plugin = self.workbench.get_plugin('inkcut.preview')
        job = self.job
        plot = preview_plugin.preview
        t = preview_plugin.transform

        #: Draw the device
        plugin = self.workbench.get_plugin('inkcut.device')
        device = plugin.device

        #: Apply the final output transforms from the device
        transform = device.transform if device else lambda p: p

        if device and device.area:
            area = device.area
            view_items.append(
                dict(path=transform(device.area.path*t),
                     pen=plot.pen_device,
                     skip_autorange=True)#(False, [area.size[0], 0]))
            )

        #: The model is only set when a document is open and has no errors
        if job.model:
            view_items.extend([
                dict(path=transform(job.move_path), pen=plot.pen_up),
                dict(path=transform(job.cut_path), pen=plot.pen_down)
            ])
            #: TODO: This
            #if self.show_offset_path:
            #    view_items.append(PainterPathPlotItem(
            # self.job.offset_path,pen=self.pen_offset))
        if job.material:
            # Also observe any change to job.media and job.device
            view_items.extend([
                dict(path=transform(job.material.path*t),
                     pen=plot.pen_media,
                     skip_autorange=([0, job.size[0]], [0, job.size[1]])),
                dict(path=transform(job.material.padding_path*t),
                     pen=plot.pen_media_padding, skip_autorange=True)
            ])

        #: Update the plot
        preview_plugin.set_preview(*view_items)

        #: Save config
        self.save()
コード例 #6
0
    def _refresh_dock_items(self, change=None):
        """ Reload all DockItems registered by any Plugins

        Any plugin can add to this list by providing a DockItem
        extension in their PluginManifest.

        """
        workbench = self.workbench
        point = workbench.get_extension_point(extensions.DOCK_ITEM_POINT)

        #: Layout spec
        layout = {'main': [], 'left': [], 'right': [], 'bottom': [], 'top': []}

        dock_items = []
        for extension in sorted(point.extensions, key=lambda ext: ext.rank):
            for declaration in extension.get_children(extensions.DockItem):

                # Load the plugin
                plugin_id = declaration.plugin_id
                log.info("Loading plugin {}".format(plugin_id))
                plugin = workbench.get_plugin(plugin_id)

                # Check if it's known dependencies are met
                if not plugin.is_supported():
                    log.warning(
                        "Plugin {} reported unsupported".format(plugin_id))
                    continue

                # Create the item
                DockItem = declaration.factory()
                item = DockItem(plugin=plugin, closable=False)

                # Add to our layout
                layout[declaration.layout].append(item.name)

                # Save it
                dock_items.append(item)

        #: Update items
        log.debug("Updating dock items: {}".format(dock_items))
        self.dock_items = dock_items
        self._refresh_layout(layout)
コード例 #7
0
ファイル: plugin.py プロジェクト: yangbiaocn/inkcut
    def open_document(self, path, nodes=None):
        """ Set the job.document if it is empty, otherwise close and create
        a  new Job instance.

        """
        if path == '-':
            log.debug("Opening document from stdin...")
        elif not os.path.exists(path):
            raise JobError("Cannot open %s, it does not exist!" % path)
        elif not os.path.isfile(path):
            raise JobError("Cannot open %s, it is not a file!" % path)

        # Close any old docs
        self.close_document()

        log.info("Opening {doc}".format(doc=path))
        try:
            self.job.document_kwargs = dict(ids=nodes)
            self.job.document = path
        except ValueError as e:
            #: Wrap in a JobError
            raise JobError(e)

        # Update recent documents
        if path != '-':
            docs = self.recent_documents[:]
            # Remove and re-ad to make it most recent
            if path in docs:
                docs.remove(path)
            docs.append(path)

            # Keep limit to 10
            if len(docs) > 10:
                docs.pop(0)

            self.recent_documents = docs
コード例 #8
0
ファイル: plugin.py プロジェクト: frmdstryr/Inkcut
    def open_document(self, path, nodes=None):
        """ Set the job.document if it is empty, otherwise close and create
        a  new Job instance.

        """
        if path == '-':
            log.debug("Opening document from stdin...")
        elif not os.path.exists(path):
            raise JobError("Cannot open %s, it does not exist!" % path)
        elif not os.path.isfile(path):
            raise JobError("Cannot open %s, it is not a file!" % path)

        # Close any old docs
        self.close_document()

        log.info("Opening {doc}".format(doc=path))
        try:
            self.job.document_kwargs = dict(ids=nodes)
            self.job.document = path
        except ValueError as e:
            #: Wrap in a JobError
            raise JobError(e)

        # Update recent documents
        if path != '-':
            docs = self.recent_documents[:]
            # Remove and re-ad to make it most recent
            if path in docs:
                docs.remove(path)
            docs.append(path)

            # Keep limit to 10
            if len(docs) > 10:
                docs.pop(0)

            self.recent_documents = docs