Exemplo n.º 1
0
    def __init__(self, window, msg, formats):
        '''
        formats is a list of tuples: [(format, exists, convertible)].
            format: Lower case format identifier. E.G. mobi
            exists: String representing the number of books that
                    exist in the format.
            convertible: True if the format is a convertible format.
        formats should be ordered in the device's preferred format ordering.
        '''
        QDialog.__init__(self, window)
        Ui_ChooseFormatDeviceDialog.__init__(self)
        self.setupUi(self)
        self.formats.activated[QModelIndex].connect(self.activated_slot)

        self.msg.setText(msg)
        for i, (format, exists, convertible) in enumerate(formats):
            t_item = QTreeWidgetItem()
            t_item.setIcon(0,
                           file_icon_provider().icon_from_ext(format.lower()))
            t_item.setText(0, format.upper())
            t_item.setText(1, exists)
            if convertible:
                t_item.setIcon(2, QIcon(I('ok.png')))
            self.formats.addTopLevelItem(t_item)
            if i == 0:
                self.formats.setCurrentItem(t_item)
                t_item.setSelected(True)
        self.formats.resizeColumnToContents(2)
        self.formats.resizeColumnToContents(1)
        self.formats.resizeColumnToContents(0)
        self.formats.header().resizeSection(
            0,
            self.formats.header().sectionSize(0) * 2)
        self._format = None
Exemplo n.º 2
0
    def __init__(self, window, msg, formats):
        '''
        formats is a list of tuples: [(format, exists, convertible)].
            format: Lower case format identifier. E.G. mobi
            exists: String representing the number of books that
                    exist in the format.
            convertible: True if the format is a convertible format.
        formats should be ordered in the device's preferred format ordering.
        '''
        QDialog.__init__(self, window)
        Ui_ChooseFormatDeviceDialog.__init__(self)
        self.setupUi(self)
        self.formats.activated[QModelIndex].connect(self.activated_slot)

        self.msg.setText(msg)
        for i, (format, exists, convertible) in enumerate(formats):
            t_item = QTreeWidgetItem()
            t_item.setIcon(0, file_icon_provider().icon_from_ext(format.lower()))
            t_item.setText(0, format.upper())
            t_item.setText(1, exists)
            if convertible:
                t_item.setIcon(2, QIcon(I('ok.png')))
            self.formats.addTopLevelItem(t_item)
            if i == 0:
                self.formats.setCurrentItem(t_item)
                t_item.setSelected(True)
        self.formats.resizeColumnToContents(2)
        self.formats.resizeColumnToContents(1)
        self.formats.resizeColumnToContents(0)
        self.formats.header().resizeSection(0, self.formats.header().sectionSize(0) * 2)
        self._format = None
Exemplo n.º 3
0
 def create_folder(self, item):
     text, ok = QInputDialog.getText(self, _('Folder name'), _('Enter a name for the new folder'))
     if ok and unicode_type(text):
         c = QTreeWidgetItem(item, (unicode_type(text),))
         c.setIcon(0, QIcon(I('mimetypes/dir.png')))
         for item in self.folders.selectedItems():
             item.setSelected(False)
         c.setSelected(True)
         self.folders.setCurrentItem(c)
Exemplo n.º 4
0
 def unserialize_node(dict_node, parent):
     n = QTreeWidgetItem(parent)
     n.setData(0, Qt.DisplayRole, dict_node['title'])
     n.setData(0, Qt.UserRole, dict_node['toc_node'])
     n.setFlags(NODE_FLAGS)
     n.setData(0, Qt.DecorationRole, dict_node['icon'])
     n.setData(0, Qt.ToolTipRole, dict_node['tooltip'])
     self.update_status_tip(n)
     n.setExpanded(dict_node['is_expanded'])
     n.setSelected(dict_node['is_selected'])
     for c in dict_node['children']:
         unserialize_node(c, n)
Exemplo n.º 5
0
 def unserialize_node(dict_node, parent):
     n = QTreeWidgetItem(parent)
     n.setData(0, Qt.DisplayRole, dict_node['title'])
     n.setData(0, Qt.UserRole, dict_node['toc_node'])
     n.setFlags(NODE_FLAGS)
     n.setData(0, Qt.DecorationRole, dict_node['icon'])
     n.setData(0, Qt.ToolTipRole, dict_node['tooltip'])
     self.update_status_tip(n)
     n.setExpanded(dict_node['is_expanded'])
     n.setSelected(dict_node['is_selected'])
     for c in dict_node['children']:
         unserialize_node(c, n)
Exemplo n.º 6
0
class ChooseFolder(Dialog):  # {{{

    def __init__(self, msg=None, parent=None):
        self.msg = msg
        Dialog.__init__(self, _('Choose folder'), 'choose-folder', parent=parent)

    def setup_ui(self):
        self.l = l = QVBoxLayout(self)
        self.setLayout(l)

        self.msg = m = QLabel(self.msg or _(
        'Choose the folder into which the files will be placed'))
        l.addWidget(m)
        m.setWordWrap(True)

        self.folders = f = QTreeWidget(self)
        f.setHeaderHidden(True)
        f.itemDoubleClicked.connect(self.accept)
        l.addWidget(f)
        f.setContextMenuPolicy(Qt.CustomContextMenu)
        f.customContextMenuRequested.connect(self.show_context_menu)
        self.root = QTreeWidgetItem(f, ('/',))

        def process(node, parent):
            parent.setIcon(0, QIcon(I('mimetypes/dir.png')))
            for child in sorted(node, key=numeric_sort_key):
                c = QTreeWidgetItem(parent, (child,))
                process(node[child], c)
        process(create_folder_tree(current_container()), self.root)
        self.root.setSelected(True)
        f.expandAll()

        l.addWidget(self.bb)

    def show_context_menu(self, point):
        item = self.folders.itemAt(point)
        if item is None:
            return
        m = QMenu(self)
        m.addAction(QIcon(I('mimetypes/dir.png')), _('Create new folder'), partial(self.create_folder, item))
        m.popup(self.folders.mapToGlobal(point))

    def create_folder(self, item):
        text, ok = QInputDialog.getText(self, _('Folder name'), _('Enter a name for the new folder'))
        if ok and unicode_type(text):
            c = QTreeWidgetItem(item, (unicode_type(text),))
            c.setIcon(0, QIcon(I('mimetypes/dir.png')))
            for item in self.folders.selectedItems():
                item.setSelected(False)
            c.setSelected(True)
            self.folders.setCurrentItem(c)

    def folder_path(self, item):
        ans = []
        while item is not self.root:
            ans.append(unicode_type(item.text(0)))
            item = item.parent()
        return tuple(reversed(ans))

    @property
    def chosen_folder(self):
        try:
            return '/'.join(self.folder_path(self.folders.selectedItems()[0]))
        except IndexError:
            return ''