Esempio n. 1
0
    def __init__(self,
                 device_settings,
                 all_formats,
                 supports_subdirs,
                 must_read_metadata,
                 supports_use_author_sort,
                 extra_customization_message,
                 device,
                 extra_customization_choices=None,
                 parent=None):
        QTabWidget.__init__(self, parent)
        self._device = weakref.ref(device)

        self.device_settings = device_settings
        self.all_formats = set(all_formats)
        self.supports_subdirs = supports_subdirs
        self.must_read_metadata = must_read_metadata
        self.supports_use_author_sort = supports_use_author_sort
        self.extra_customization_message = extra_customization_message
        self.extra_customization_choices = extra_customization_choices

        try:
            self.device_name = device.get_gui_name()
        except TypeError:
            self.device_name = getattr(device, 'gui_name', None) or _('Device')

        if device.USER_CAN_ADD_NEW_FORMATS:
            self.all_formats = set(self.all_formats) | set(BOOK_EXTENSIONS)

        self.base = QWidget(self)
        #         self.insertTab(0, self.base, _('Configure %s') % self.device.current_friendly_name)
        self.insertTab(0, self.base, _("File Formats"))
        l = self.base.l = QGridLayout(self.base)
        self.base.setLayout(l)

        self.formats = FormatsConfig(self.all_formats,
                                     device_settings.format_map)
        if device.HIDE_FORMATS_CONFIG_BOX:
            self.formats.hide()

        self.opt_use_subdirs = create_checkbox(
            _("Use sub-directories"),
            _('Place files in sub-directories if the device supports them'),
            device_settings.use_subdirs)
        self.opt_read_metadata = create_checkbox(
            _("Read metadata from files on device"),
            _('Read metadata from files on device'),
            device_settings.read_metadata)

        self.template = TemplateConfig(device_settings.save_template)
        self.opt_use_author_sort = create_checkbox(
            _("Use author sort for author"), _("Use author sort for author"),
            device_settings.read_metadata)
        self.opt_use_author_sort.setObjectName("opt_use_author_sort")
        self.base.la = la = QLabel(
            _('Choose the formats to send to the %s') % self.device_name)
        la.setWordWrap(True)

        l.addWidget(la, 1, 0, 1, 1)
        l.addWidget(self.formats, 2, 0, 1, 1)
        l.addWidget(self.opt_read_metadata, 3, 0, 1, 1)
        l.addWidget(self.opt_use_subdirs, 4, 0, 1, 1)
        l.addWidget(self.opt_use_author_sort, 5, 0, 1, 1)
        l.addWidget(self.template, 6, 0, 1, 1)
        l.setRowStretch(2, 10)

        if device.HIDE_FORMATS_CONFIG_BOX:
            self.formats.hide()

        if supports_subdirs:
            self.opt_use_subdirs.setChecked(device_settings.use_subdirs)
        else:
            self.opt_use_subdirs.hide()
        if not must_read_metadata:
            self.opt_read_metadata.setChecked(device_settings.read_metadata)
        else:
            self.opt_read_metadata.hide()
        if supports_use_author_sort:
            self.opt_use_author_sort.setChecked(
                device_settings.use_author_sort)
        else:
            self.opt_use_author_sort.hide()

        self.extra_tab = ExtraCustomization(self.extra_customization_message,
                                            self.extra_customization_choices,
                                            self.device_settings)
        # Only display the extra customization tab if there are options on it.
        if self.extra_tab.has_extra_customizations:
            self.addTab(self.extra_tab, _('Extra Customization'))

        self.setCurrentIndex(0)
Esempio n. 2
0
    def __init__(self, device_settings, all_formats, supports_subdirs,
                    must_read_metadata, supports_use_author_sort,
                    extra_customization_message, device,
                    extra_customization_choices=None, parent=None):
        QTabWidget.__init__(self, parent)
        self._device = weakref.ref(device)

        self.device_settings = device_settings
        self.all_formats = set(all_formats)
        self.supports_subdirs = supports_subdirs
        self.must_read_metadata = must_read_metadata
        self.supports_use_author_sort = supports_use_author_sort
        self.extra_customization_message = extra_customization_message
        self.extra_customization_choices = extra_customization_choices

        try:
            self.device_name = device.get_gui_name()
        except TypeError:
            self.device_name = getattr(device, 'gui_name', None) or _('Device')

        if device.USER_CAN_ADD_NEW_FORMATS:
            self.all_formats = set(self.all_formats) | set(BOOK_EXTENSIONS)

        self.base = QWidget(self)
#         self.insertTab(0, self.base, _('Configure %s') % self.device.current_friendly_name)
        self.insertTab(0, self.base, _("File formats"))
        l = self.base.l = QGridLayout(self.base)
        self.base.setLayout(l)

        self.formats = FormatsConfig(self.all_formats, device_settings.format_map)
        if device.HIDE_FORMATS_CONFIG_BOX:
            self.formats.hide()

        self.opt_use_subdirs = create_checkbox(
                                           _("Use sub-directories"),
                                           _('Place files in sub-directories if the device supports them'),
                                           device_settings.use_subdirs
                                           )
        self.opt_read_metadata = create_checkbox(
                                             _("Read metadata from files on device"),
                                             _('Read metadata from files on device'),
                                             device_settings.read_metadata
                                             )

        self.template = TemplateConfig(device_settings.save_template)
        self.opt_use_author_sort = create_checkbox(
                                             _("Use author sort for author"),
                                             _("Use author sort for author"),
                                             device_settings.read_metadata
                                             )
        self.opt_use_author_sort.setObjectName("opt_use_author_sort")
        self.base.la = la = QLabel(_(
            'Choose the formats to send to the %s')%self.device_name)
        la.setWordWrap(True)

        l.addWidget(la,                         1, 0, 1, 1)
        l.addWidget(self.formats,               2, 0, 1, 1)
        l.addWidget(self.opt_read_metadata,     3, 0, 1, 1)
        l.addWidget(self.opt_use_subdirs,       4, 0, 1, 1)
        l.addWidget(self.opt_use_author_sort,   5, 0, 1, 1)
        l.addWidget(self.template,              6, 0, 1, 1)
        l.setRowStretch(2, 10)

        if device.HIDE_FORMATS_CONFIG_BOX:
            self.formats.hide()

        if supports_subdirs:
            self.opt_use_subdirs.setChecked(device_settings.use_subdirs)
        else:
            self.opt_use_subdirs.hide()
        if not must_read_metadata:
            self.opt_read_metadata.setChecked(device_settings.read_metadata)
        else:
            self.opt_read_metadata.hide()
        if supports_use_author_sort:
            self.opt_use_author_sort.setChecked(device_settings.use_author_sort)
        else:
            self.opt_use_author_sort.hide()

        self.extra_tab = ExtraCustomization(self.extra_customization_message,
                                            self.extra_customization_choices,
                                            self.device_settings)
        # Only display the extra customization tab if there are options on it.
        if self.extra_tab.has_extra_customizations:
            self.addTab(self.extra_tab, _('Extra customization'))

        self.setCurrentIndex(0)
Esempio n. 3
0
class TabbedDeviceConfig(QTabWidget):
    """
    This is a generic Tabbed Device config widget. It designed for devices with more
    complex configuration. But, it is backwards compatible to the standard device
    configuration widget.

    The configuration made up of two default tabs plus extra tabs as needed for the
    device. The extra tabs are defined as part of the subclass of this widget for
    the device.

    The two default tabs are the "File Formats" and "Extra Customization". These
    tabs are the same as the two sections of the standard device configuration
    widget. The second of these tabs will only be created if the device driver has
    extra configuration options. All options on these tabs work the same way as for
    the standard device configuration widget.

    When implementing a subclass for a device driver, create tabs, subclassed from
    DeviceConfigTab, for each set of options. Within the tabs, group boxes, subclassed
    from DeviceOptionsGroupBox, are created to further group the options. The group
    boxes can be coded to support any control type and dependencies between them.
    """
    def __init__(self,
                 device_settings,
                 all_formats,
                 supports_subdirs,
                 must_read_metadata,
                 supports_use_author_sort,
                 extra_customization_message,
                 device,
                 extra_customization_choices=None,
                 parent=None):
        QTabWidget.__init__(self, parent)
        self._device = weakref.ref(device)

        self.device_settings = device_settings
        self.all_formats = set(all_formats)
        self.supports_subdirs = supports_subdirs
        self.must_read_metadata = must_read_metadata
        self.supports_use_author_sort = supports_use_author_sort
        self.extra_customization_message = extra_customization_message
        self.extra_customization_choices = extra_customization_choices

        try:
            self.device_name = device.get_gui_name()
        except TypeError:
            self.device_name = getattr(device, 'gui_name', None) or _('Device')

        if device.USER_CAN_ADD_NEW_FORMATS:
            self.all_formats = set(self.all_formats) | set(BOOK_EXTENSIONS)

        self.base = QWidget(self)
        #         self.insertTab(0, self.base, _('Configure %s') % self.device.current_friendly_name)
        self.insertTab(0, self.base, _("File Formats"))
        l = self.base.l = QGridLayout(self.base)
        self.base.setLayout(l)

        self.formats = FormatsConfig(self.all_formats,
                                     device_settings.format_map)
        if device.HIDE_FORMATS_CONFIG_BOX:
            self.formats.hide()

        self.opt_use_subdirs = create_checkbox(
            _("Use sub-directories"),
            _('Place files in sub-directories if the device supports them'),
            device_settings.use_subdirs)
        self.opt_read_metadata = create_checkbox(
            _("Read metadata from files on device"),
            _('Read metadata from files on device'),
            device_settings.read_metadata)

        self.template = TemplateConfig(device_settings.save_template)
        self.opt_use_author_sort = create_checkbox(
            _("Use author sort for author"), _("Use author sort for author"),
            device_settings.read_metadata)
        self.opt_use_author_sort.setObjectName("opt_use_author_sort")
        self.base.la = la = QLabel(
            _('Choose the formats to send to the %s') % self.device_name)
        la.setWordWrap(True)

        l.addWidget(la, 1, 0, 1, 1)
        l.addWidget(self.formats, 2, 0, 1, 1)
        l.addWidget(self.opt_read_metadata, 3, 0, 1, 1)
        l.addWidget(self.opt_use_subdirs, 4, 0, 1, 1)
        l.addWidget(self.opt_use_author_sort, 5, 0, 1, 1)
        l.addWidget(self.template, 6, 0, 1, 1)
        l.setRowStretch(2, 10)

        if device.HIDE_FORMATS_CONFIG_BOX:
            self.formats.hide()

        if supports_subdirs:
            self.opt_use_subdirs.setChecked(device_settings.use_subdirs)
        else:
            self.opt_use_subdirs.hide()
        if not must_read_metadata:
            self.opt_read_metadata.setChecked(device_settings.read_metadata)
        else:
            self.opt_read_metadata.hide()
        if supports_use_author_sort:
            self.opt_use_author_sort.setChecked(
                device_settings.use_author_sort)
        else:
            self.opt_use_author_sort.hide()

        self.extra_tab = ExtraCustomization(self.extra_customization_message,
                                            self.extra_customization_choices,
                                            self.device_settings)
        # Only display the extra customization tab if there are options on it.
        if self.extra_tab.has_extra_customizations:
            self.addTab(self.extra_tab, _('Extra Customization'))

        self.setCurrentIndex(0)

    def addDeviceTab(self, tab, label):
        '''
        This is used to add a new tab for the device config. The new tab will always be added
        as immediately before the "Extra Customization" tab.
        '''
        extra_tab_pos = self.indexOf(self.extra_tab)
        self.insertTab(extra_tab_pos, tab, label)

    def __getattr__(self, attr_name):
        "If the object doesn't have an attribute, then check each tab."
        try:
            return super(TabbedDeviceConfig, self).__getattr__(attr_name)
        except AttributeError as ae:
            for i in range(0, self.count()):
                atab = self.widget(i)
                try:
                    return getattr(atab, attr_name)
                except AttributeError:
                    pass
        raise ae

    @property
    def device(self):
        return self._device()

    def format_map(self):
        return self.formats.format_map

    def use_subdirs(self):
        return self.opt_use_subdirs.isChecked()

    def read_metadata(self):
        return self.opt_read_metadata.isChecked()

    def use_author_sort(self):
        return self.opt_use_author_sort.isChecked()

    @property
    def opt_save_template(self):
        # Really shouldn't be accessing the template this way
        return self.template.t

    def text(self):
        # Really shouldn't be accessing the template this way
        return self.template.t.text()

    @property
    def opt_extra_customization(self):
        return self.extra_tab.opt_extra_customization

    @property
    def label(self):
        return self.opt_save_template

    def validate(self):
        if hasattr(self, 'formats'):
            if not self.formats.validate():
                return False
            if not self.template.validate():
                return False
        return True

    def commit(self):
        debug_print("TabbedDeviceConfig::commit: start")
        p = self.device._configProxy()

        p['format_map'] = self.formats.format_map
        p['use_subdirs'] = self.use_subdirs()
        p['read_metadata'] = self.read_metadata()
        p['save_template'] = self.template.template
        p['extra_customization'] = self.extra_tab.extra_customization()

        return p
Esempio n. 4
0
class TabbedDeviceConfig(QTabWidget):
    """
    This is a generic Tabbed Device config widget. It designed for devices with more
    complex configuration. But, it is backwards compatible to the standard device
    configuration widget.

    The configuration made up of two default tabs plus extra tabs as needed for the
    device. The extra tabs are defined as part of the subclass of this widget for
    the device.

    The two default tabs are the "File Formats" and "Extra Customization". These
    tabs are the same as the two sections of the standard device configuration
    widget. The second of these tabs will only be created if the device driver has
    extra configuration options. All options on these tabs work the same way as for
    the standard device configuration widget.

    When implementing a subclass for a device driver, create tabs, subclassed from
    DeviceConfigTab, for each set of options. Within the tabs, group boxes, subclassed
    from DeviceOptionsGroupBox, are created to further group the options. The group
    boxes can be coded to support any control type and dependencies between them.
    """

    def __init__(self, device_settings, all_formats, supports_subdirs,
                    must_read_metadata, supports_use_author_sort,
                    extra_customization_message, device,
                    extra_customization_choices=None, parent=None):
        QTabWidget.__init__(self, parent)
        self._device = weakref.ref(device)

        self.device_settings = device_settings
        self.all_formats = set(all_formats)
        self.supports_subdirs = supports_subdirs
        self.must_read_metadata = must_read_metadata
        self.supports_use_author_sort = supports_use_author_sort
        self.extra_customization_message = extra_customization_message
        self.extra_customization_choices = extra_customization_choices

        try:
            self.device_name = device.get_gui_name()
        except TypeError:
            self.device_name = getattr(device, 'gui_name', None) or _('Device')

        if device.USER_CAN_ADD_NEW_FORMATS:
            self.all_formats = set(self.all_formats) | set(BOOK_EXTENSIONS)

        self.base = QWidget(self)
#         self.insertTab(0, self.base, _('Configure %s') % self.device.current_friendly_name)
        self.insertTab(0, self.base, _("File formats"))
        l = self.base.l = QGridLayout(self.base)
        self.base.setLayout(l)

        self.formats = FormatsConfig(self.all_formats, device_settings.format_map)
        if device.HIDE_FORMATS_CONFIG_BOX:
            self.formats.hide()

        self.opt_use_subdirs = create_checkbox(
                                           _("Use sub-directories"),
                                           _('Place files in sub-directories if the device supports them'),
                                           device_settings.use_subdirs
                                           )
        self.opt_read_metadata = create_checkbox(
                                             _("Read metadata from files on device"),
                                             _('Read metadata from files on device'),
                                             device_settings.read_metadata
                                             )

        self.template = TemplateConfig(device_settings.save_template)
        self.opt_use_author_sort = create_checkbox(
                                             _("Use author sort for author"),
                                             _("Use author sort for author"),
                                             device_settings.read_metadata
                                             )
        self.opt_use_author_sort.setObjectName("opt_use_author_sort")
        self.base.la = la = QLabel(_(
            'Choose the formats to send to the %s')%self.device_name)
        la.setWordWrap(True)

        l.addWidget(la,                         1, 0, 1, 1)
        l.addWidget(self.formats,               2, 0, 1, 1)
        l.addWidget(self.opt_read_metadata,     3, 0, 1, 1)
        l.addWidget(self.opt_use_subdirs,       4, 0, 1, 1)
        l.addWidget(self.opt_use_author_sort,   5, 0, 1, 1)
        l.addWidget(self.template,              6, 0, 1, 1)
        l.setRowStretch(2, 10)

        if device.HIDE_FORMATS_CONFIG_BOX:
            self.formats.hide()

        if supports_subdirs:
            self.opt_use_subdirs.setChecked(device_settings.use_subdirs)
        else:
            self.opt_use_subdirs.hide()
        if not must_read_metadata:
            self.opt_read_metadata.setChecked(device_settings.read_metadata)
        else:
            self.opt_read_metadata.hide()
        if supports_use_author_sort:
            self.opt_use_author_sort.setChecked(device_settings.use_author_sort)
        else:
            self.opt_use_author_sort.hide()

        self.extra_tab = ExtraCustomization(self.extra_customization_message,
                                            self.extra_customization_choices,
                                            self.device_settings)
        # Only display the extra customization tab if there are options on it.
        if self.extra_tab.has_extra_customizations:
            self.addTab(self.extra_tab, _('Extra customization'))

        self.setCurrentIndex(0)

    def addDeviceTab(self, tab, label):
        '''
        This is used to add a new tab for the device config. The new tab will always be added
        as immediately before the "Extra Customization" tab.
        '''
        extra_tab_pos = self.indexOf(self.extra_tab)
        self.insertTab(extra_tab_pos, tab, label)

    def __getattr__(self, attr_name):
        "If the object doesn't have an attribute, then check each tab."
        try:
            return super(TabbedDeviceConfig, self).__getattr__(attr_name)
        except AttributeError as ae:
            for i in range(0, self.count()):
                atab = self.widget(i)
                try:
                    return getattr(atab, attr_name)
                except AttributeError:
                    pass
            raise ae

    @property
    def device(self):
        return self._device()

    def format_map(self):
        return self.formats.format_map

    def use_subdirs(self):
        return self.opt_use_subdirs.isChecked()

    def read_metadata(self):
        return self.opt_read_metadata.isChecked()

    def use_author_sort(self):
        return self.opt_use_author_sort.isChecked()

    @property
    def opt_save_template(self):
        # Really shouldn't be accessing the template this way
        return self.template.t

    def text(self):
        # Really shouldn't be accessing the template this way
        return self.template.t.text()

    @property
    def opt_extra_customization(self):
        return self.extra_tab.opt_extra_customization

    @property
    def label(self):
        return self.opt_save_template

    def validate(self):
        if hasattr(self, 'formats'):
            if not self.formats.validate():
                return False
            if not self.template.validate():
                return False
        return True

    def commit(self):
        debug_print("TabbedDeviceConfig::commit: start")
        p = self.device._configProxy()

        p['format_map'] = self.formats.format_map
        p['use_subdirs'] = self.use_subdirs()
        p['read_metadata'] = self.read_metadata()
        p['save_template'] = self.template.template
        p['extra_customization'] = self.extra_tab.extra_customization()

        return p