예제 #1
0
 def disconnect(self):
     log.debug("-- File | Closed '{}'".format(self.path))
     self.connected = False
     self.protocol.connection_lost()
     if self.file:
         self.file.close()
         self.file = None
예제 #2
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):
                #: Create the item
                DockItem = declaration.factory()
                item = DockItem(plugin=workbench.get_plugin(
                    declaration.plugin_id),
                                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)
예제 #3
0
    def _refresh_settings_pages(self, change=None):
        """ Reload all SettingsPages registered by any Plugins

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

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

        settings_pages = []
        typemap = {}
        for extension in sorted(point.extensions, key=lambda ext: ext.rank):
            for d in extension.get_children(extensions.SettingsPage):
                #: Save it
                settings_pages.append(d)

                #: Update the type map
                plugin = self.workbench.get_plugin(d.plugin_id)
                t = type(getattr(plugin, d.model) if d.model else plugin)
                typemap[t] = d.factory()

        #: Update items
        log.debug("Updating settings pages: {}".format(settings_pages))

        self.settings_typemap = typemap
        self.settings_pages = sorted(settings_pages, key=lambda p: p.name)
예제 #4
0
    def connect(self):
        config = self.config
        self.device_path = config.port
        try:
            #: Save a reference
            self.protocol.transport = self

            #: Make the wrapper
            self._protocol = RawFdProtocol(self, self.protocol)

            self.connection = SerialPort(self._protocol,
                                         config.port,
                                         reactor,
                                         baudrate=config.baudrate,
                                         bytesize=config.bytesize,
                                         parity=SERIAL_PARITIES[config.parity],
                                         stopbits=config.stopbits,
                                         xonxoff=config.xonxoff,
                                         rtscts=config.rtscts)

            # Twisted is missing this
            if config.dsrdtr:
                try:
                    self.connection._serial.dsrdtr = True
                except AttributeError as e:
                    log.warning("{} | dsrdtr is not supported {}".format(
                        config.port, e))

            log.debug("{} | opened".format(config.port))
        except Exception as e:
            #: Make sure to log any issues as these tracebacks can get
            #: squashed by twisted
            log.error("{} | {}".format(config.port, traceback.format_exc()))
            raise
예제 #5
0
파일: plugin.py 프로젝트: frmdstryr/Inkcut
 def disconnect(self):
     log.debug("-- File | Closed '{}'".format(self.path))
     self.connected = False
     self.protocol.connection_lost()
     if self.file:
         self.file.close()
         self.file = None
예제 #6
0
    def connect(self):
        try:
            config = self.config

            #: Save a reference
            self.protocol.transport = self

            #: Make the wrapper
            self._protocol = InkcutProtocol(self, self.protocol)

            self.connection = SerialPort(
                self._protocol,
                config.port,
                reactor,
                baudrate=config.baudrate,
                bytesize=config.bytesize,
                parity=SERIAL_PARITIES[config.parity],
                stopbits=config.stopbits,
                xonxoff=config.xonxoff,
                rtscts=config.rtscts
            )
            log.debug("{} | opened".format(self.config.port))
        except Exception as e:
            #: Make sure to log any issues as these tracebacks can get
            #: squashed by twisted
            log.error("{} | {}".format(
                self.config.port, traceback.format_exc()
            ))
            raise
예제 #7
0
 def write(self, data):
     if not self.connection:
         raise IOError("Port is not opened")
     log.debug("-> {} | {}".format(self.config.port, data))
     if hasattr(data, 'encode'):
         data = data.encode()
     self._protocol.transport.write(data)
예제 #8
0
파일: plugin.py 프로젝트: frmdstryr/Inkcut
    def connect(self):
        config = self.config
        self.device_path = config.port
        try:
            #: Save a reference
            self.protocol.transport = self

            #: Make the wrapper
            self._protocol = RawFdProtocol(self, self.protocol)

            self.connection = SerialPort(
                self._protocol,
                config.port,
                reactor,
                baudrate=config.baudrate,
                bytesize=config.bytesize,
                parity=SERIAL_PARITIES[config.parity],
                stopbits=config.stopbits,
                xonxoff=config.xonxoff,
                rtscts=config.rtscts
            )
            log.debug("{} | opened".format(config.port))
        except Exception as e:
            #: Make sure to log any issues as these tracebacks can get
            #: squashed by twisted
            log.error("{} | {}".format(config.port, traceback.format_exc()))
            raise
예제 #9
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
예제 #10
0
    def write(self, data):
        log.debug("-> File | {}".format(data))

        #: Python 3 is annoying
        if hasattr(data, 'encode'):
            data = data.encode()

        self.file.write(data)
예제 #11
0
파일: plugin.py 프로젝트: frmdstryr/Inkcut
    def write(self, data):
        log.debug("-> File | {}".format(data))

        #: Python 3 is annoying
        if hasattr(data, 'encode'):
            data = data.encode()

        self.file.write(data)
예제 #12
0
파일: plugin.py 프로젝트: vmario89/inkcut
 def write(self, data):
     if not self.connection:
         raise IOError("{} is not opened".format(self.device_path))
     log.debug("-> {} | {}".format(self.device_path, data))
     if hasattr(data, 'encode'):
         data = data.encode()
     self.last_write = data
     self.connection.write(data)
예제 #13
0
 def connect(self):
     config = self.config
     path = self.path = self._default_path()
     if not exists(config.directory):
         os.makedirs(config.directory)
     log.debug("-- File | Writing to '{}'".format(path))
     self.file = open(path, 'wb')
     self.connected = True
     #: Save a reference
     self.protocol.transport = self
     self.protocol.connection_made()
예제 #14
0
파일: plugin.py 프로젝트: frmdstryr/Inkcut
 def connect(self):
     config = self.config
     path = self.path = self._default_path()
     if not exists(config.directory):
         os.makedirs(config.directory)
     log.debug("-- File | Writing to '{}'".format(path))
     self.file = open(path, 'wb')
     self.connected = True
     #: Save a reference
     self.protocol.transport = self
     self.protocol.connection_made()
예제 #15
0
파일: plugin.py 프로젝트: raboof/inkcut
 def connect(self):
     try:
         #: Save a reference
         self.protocol.transport = self
         self.connection.transport = self
         self.connection.open()
         log.debug("{} | opened".format(self.config.printer))
     except Exception as e:
         #: Make sure to log any issues as these tracebacks can get
         #: squashed by twisted
         log.error("{} | {}".format(
             self.config.printer, traceback.format_exc()
         ))
         raise
예제 #16
0
    def start(self):
        self.init_logging()
        log.debug("Inkcut loaded.")

        #: Load the cli plugin
        w = self.workbench
        with enaml.imports():
            from inkcut.cli.manifest import CliManifest
        w.register(CliManifest())

        #: Start it
        w.get_plugin('inkcut.cli')

        #: Start the default workspace
        w.application.deferred_call(self.start_default_workspace)
예제 #17
0
파일: plugin.py 프로젝트: frmdstryr/Inkcut
    def start(self):
        self.init_logging()
        log.debug("Inkcut loaded.")

        #: Load the cli plugin
        w = self.workbench
        with enaml.imports():
            from inkcut.cli.manifest import CliManifest
        w.register(CliManifest())

        #: Start it
        w.get_plugin('inkcut.cli')

        #: Start the default workspace
        w.application.deferred_call(self.start_default_workspace)
예제 #18
0
파일: plugin.py 프로젝트: frmdstryr/Inkcut
    def connect(self):
        try:
            # Always create a new connection
            self.connection = self._default_connection()

            # Save a reference
            self.protocol.transport = self
            self.connection.transport = self
            self.connection.open()
            log.debug("{} | opened".format(self.config.printer))
        except Exception as e:
            # Make sure to log any issues as these tracebacks can get
            # squashed by twisted
            log.error("{} | {}".format(
                self.config.printer, traceback.format_exc()
            ))
            raise
예제 #19
0
    def connect(self):
        config = self.config
        #self.device_path = config.port
        device_path = self.device_path = config.port
        try:
            #: Save a reference
            self.protocol.transport = self

            self.connection = self.open_serial_port(config)
            self.connected = True
            log.debug("{} | opened".format(config.port))
            self.protocol.connection_made()

        except Exception as e:
            #: Make sure to log any issues
            log.error("{} | {}".format(config.port, traceback.format_exc()))
            raise
예제 #20
0
파일: plugin.py 프로젝트: vmario89/inkcut
    def connect(self):
        config = self.config
        device_path = self.device_path = config.device_path
        if 'win32' in sys.platform:
            # Well, technically it works, but only with stdin and stdout
            raise OSError("Raw device support cannot be used on Windows")

        try:
            self.fd = open(device_path, config.mode)
            fd = self.fd.fileno()
            log.debug("-- {} | opened".format(device_path))
            self._protocol = RawFdProtocol(self, self.protocol)
            self.connection = stdio.StandardIO(self._protocol, fd, fd)
        except Exception as e:
            #: Make sure to log any issues as these tracebacks can get
            #: squashed by twisted
            log.error("{} | {}".format(device_path, traceback.format_exc()))
            raise
예제 #21
0
파일: plugin.py 프로젝트: yangbiaocn/inkcut
def patch_pyserial_if_needed():
    """ A workaround for
    https://github.com/pyserial/pyserial/issues/286
    """
    try:
        from serial.tools.list_ports_common import ListPortInfo
    except ImportError:
        return
    try:
        dummy = ListPortInfo()
        dummy == None
        log.debug("pyserial patch not needed")
    except AttributeError:
        def __eq__(self, other):
            return isinstance(other, ListPortInfo) \
                and self.device == other.device
        ListPortInfo.__eq__ = __eq__
        log.debug("pyserial patched")
예제 #22
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)
예제 #23
0
파일: plugin.py 프로젝트: frmdstryr/Inkcut
    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):
                #: Create the item
                DockItem = declaration.factory()
                item = DockItem(
                    plugin=workbench.get_plugin(declaration.plugin_id),
                    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)
예제 #24
0
파일: plugin.py 프로젝트: vmario89/inkcut
def find_dev_name(dev):
    """ Use udevadm to lookup info on a device

    Parameters
    ----------
    dev: String
        The device path to lookup, eg /dev/usb/lp1

    Returns
    -------
    name: String
        The device name

    """
    try:
        cmd = 'udevadm info -a %s' % dev
        manufacturer = ""
        product = ""

        output = subprocess.check_output(cmd.split())
        if sys.version_info.major > 2:
            output = output.decode()
        for line in output.split('\n'):
            log.debug(line)
            m = re.search(r'ATTRS{(.+)}=="(.+)"', line)
            if m:
                k, v = m.groups()
                if k == 'manufacturer':
                    manufacturer = v.strip()
                elif k == 'product':
                    product = v.strip()
            if manufacturer and product:
                return '{} {}'.format(manufacturer, product)
        log.warning('Could not lookup device info for %s' % dev)
    except Exception as e:
        tb = traceback.format_exc()
        log.warning('Could not lookup device info for %s  %s' % (dev, tb))
    return 'usb%s' % dev.split('/')[-1]
예제 #25
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
예제 #26
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
예제 #27
0
파일: plugin.py 프로젝트: vmario89/inkcut
 def connectionLost(self, reason=connectionDone):
     self._transport.connected = False
     self._transport.fd = None
     device_path = self._transport.device_path
     log.debug("-- {} | dropped: {}".format(device_path, reason))
     self.delegate.connection_lost()
예제 #28
0
파일: plugin.py 프로젝트: vmario89/inkcut
 def disconnect(self):
     if self.connection:
         log.debug("-- {} | closed by request".format(self.device_path))
         self.connection.loseConnection()
         self.connection = None
예제 #29
0
파일: plugin.py 프로젝트: frmdstryr/Inkcut
 def disconnect(self):
     if self.connection:
         self.connection.close()
         log.debug("{} | closed".format(self.config.printer))
         self.connection = None
예제 #30
0
파일: plugin.py 프로젝트: frmdstryr/Inkcut
 def write(self, data):
     log.debug("-> {} | {}".format(self.transport.config.printer, data))
예제 #31
0
 def _observe_settings_page(self, change):
     log.debug("Settings page: {}".format(change))
예제 #32
0
파일: plugin.py 프로젝트: vmario89/inkcut
 def dataReceived(self, data):
     log.debug("<- {} | {}".format(self._transport.device_path, data))
     self._transport.last_read = data
     self.delegate.data_received(data)
예제 #33
0
 def connectionLost(self, reason=connectionDone):
     self.parent.connected = False
     log.debug("-- {} | dropped: {}".format(self.parent.config.port,
                                            reason))
     self.delegate.connection_lost()
예제 #34
0
 def dataReceived(self, data):
     log.debug("<- {} | {}".format(self.parent.config.port, data))
     self.delegate.data_received(data)
예제 #35
0
 def disconnect(self):
     if self.connection:
         log.debug("{} | closed".format(self.config.port))
         self.connection.loseConnection()
         self.connection = None
예제 #36
0
 def disconnect(self):
     if self.connection:
         self.connection.close()
         log.debug("{} | closed".format(self.config.printer))
         self.connection = None
예제 #37
0
 def write(self, data):
     log.debug("-> {} | {}".format(self.transport.config.printer, data))