Esempio n. 1
0
    def __init__(self, *args):
        QTreeView.__init__(self, *args)
        self.setStyleSheet('''
                QTreeView {
                    background-color: palette(window);
                    color: palette(window-text);
                    border: none;
                }
                QTreeView::item {
                    border: 1px solid transparent;
                    padding-top:0.5ex;
                    padding-bottom:0.5ex;
                }

                QTreeView::item:hover {
                    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
                    border: 1px solid #bfcde4;
                    border-radius: 6px;
                }
                QHeaderView::section {
                    background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                                    stop:0 #616161, stop: 0.5 #505050,
                                                    stop: 0.6 #434343, stop:1 #656565);
                    color: white;
                    padding-left: 4px;
                    padding-top: 0.5ex;
                    padding-bottom: 0.5ex;
                    border: 1px solid #6c6c6c;
                    font-weight: bold;
                }
        ''')
Esempio n. 2
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self._layout = l = QGridLayout()
     self.setLayout(self._layout)
     self.header = QLabel(
         _('Double click on any entry to change the'
           ' keyboard shortcuts associated with it'))
     l.addWidget(self.header, 0, 0, 1, 3)
     self.view = QTreeView(self)
     self.view.setAlternatingRowColors(True)
     self.view.setHeaderHidden(True)
     self.view.setAnimated(True)
     l.addWidget(self.view, 1, 0, 1, 3)
     self.delegate = Delegate()
     self.view.setItemDelegate(self.delegate)
     self.delegate.sizeHintChanged.connect(self.editor_opened,
                                           type=Qt.QueuedConnection)
     self.delegate.changed_signal.connect(self.changed_signal)
     self.search = SearchBox2(self)
     self.search.initialize('shortcuts_search_history',
                            help_text=_('Search for a shortcut by name'))
     self.search.search.connect(self.find)
     l.addWidget(self.search, 2, 0, 1, 1)
     self.nb = QPushButton(QIcon(I('arrow-down.png')), _('&Next'), self)
     self.pb = QPushButton(QIcon(I('arrow-up.png')), _('&Previous'), self)
     self.nb.clicked.connect(self.find_next)
     self.pb.clicked.connect(self.find_previous)
     l.addWidget(self.nb, 2, 1, 1, 1)
     l.addWidget(self.pb, 2, 2, 1, 1)
     l.setColumnStretch(0, 100)
Esempio n. 3
0
File: toc.py Progetto: Eksmo/calibre
    def __init__(self, *args):
        QTreeView.__init__(self, *args)
        self.setStyleSheet('''
                QTreeView {
                    background-color: palette(window);
                    color: palette(window-text);
                    border: none;
                }
                QTreeView::item {
                    border: 1px solid transparent;
                    padding-top:0.5ex;
                    padding-bottom:0.5ex;
                }

                QTreeView::item:hover {
                    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
                    border: 1px solid #bfcde4;
                    border-radius: 6px;
                }
                QHeaderView::section {
                    background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                                    stop:0 #616161, stop: 0.5 #505050,
                                                    stop: 0.6 #434343, stop:1 #656565);
                    color: white;
                    padding-left: 4px;
                    padding-top: 0.5ex;
                    padding-bottom: 0.5ex;
                    border: 1px solid #6c6c6c;
                    font-weight: bold;
                }
        ''')
 def __init__(self, name, treemodel, parent=None):
     QTreeView.__init__(self, parent)
     self.treemodel = treemodel #bruce 081216 renamed this from ne1model
     treemodel.view = self
     self.setSelectionMode(self.ExtendedSelection) #bruce 070507 MultiSelection -> ExtendedSelection
     self.qtmodel = None
     self.drag = None
     self.setAcceptDrops(True)
 def __init__(self, name, ne1model, parent=None):
     QTreeView.__init__(self, parent)
     self.ne1model = ne1model
     ne1model.view = self
     self.setSelectionMode(self.ExtendedSelection) #bruce 070507 MultiSelection -> ExtendedSelection
     self.qtmodel = None
     self.drag = None
     self.setAcceptDrops(True)
Esempio n. 6
0
    def __init__(self, parent=None):
        QTreeView.__init__(self, parent=None)
        self.alter_tb = None
        self.disable_recounting = False
        self.setUniformRowHeights(True)
        self.setCursor(Qt.PointingHandCursor)
        self.setIconSize(QSize(20, 20))
        self.setTabKeyNavigation(True)
        self.setAnimated(True)
        self.setHeaderHidden(True)
        self.setItemDelegate(TagDelegate(self))
        self.made_connections = False
        self.setAcceptDrops(True)
        self.setDragEnabled(True)
        self.setDragDropMode(self.DragDrop)
        self.setDropIndicatorShown(True)
        self.in_drag_drop = False
        self.setAutoExpandDelay(500)
        self.pane_is_visible = False
        self.search_icon = QIcon(I("search.png"))
        self.user_category_icon = QIcon(I("tb_folder.png"))
        self.delete_icon = QIcon(I("list_remove.png"))
        self.rename_icon = QIcon(I("edit-undo.png"))

        self._model = TagsModel(self)
        self._model.search_item_renamed.connect(self.search_item_renamed)
        self._model.refresh_required.connect(self.refresh_required, type=Qt.QueuedConnection)
        self._model.tag_item_renamed.connect(self.tag_item_renamed)
        self._model.restriction_error.connect(self.restriction_error)
        self._model.user_categories_edited.connect(self.user_categories_edited, type=Qt.QueuedConnection)
        self._model.drag_drop_finished.connect(self.drag_drop_finished)
        stylish_tb = """
                QTreeView {
                    background-color: palette(window);
                    color: palette(window-text);
                    border: none;
                }
        """
        self.setStyleSheet(
            """
                QTreeView::item {
                    border: 1px solid transparent;
                    padding-top:0.9ex;
                    padding-bottom:0.9ex;
                }

                QTreeView::item:hover {
                    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
                    border: 1px solid #bfcde4;
                    border-radius: 6px;
                }
        """
            + ("" if gprefs["tag_browser_old_look"] else stylish_tb)
        )
        if gprefs["tag_browser_old_look"]:
            self.setAlternatingRowColors(True)
 def __init__(self, name, ne1model, parent=None):
     QTreeView.__init__(self, parent)
     self.ne1model = ne1model
     ne1model.view = self
     self.setSelectionMode(
         self.ExtendedSelection
     )  #bruce 070507 MultiSelection -> ExtendedSelection
     self.qtmodel = None
     self.drag = None
     self.setAcceptDrops(True)
Esempio n. 8
0
    def __init__(self, *args):
        QTreeView.__init__(self, *args)

        self._model = Matches()
        self.setModel(self._model)

        self.rt_delegate = RichTextDelegate(self)

        for i in self._model.HTML_COLS:
            self.setItemDelegateForColumn(i, self.rt_delegate)
Esempio n. 9
0
 def __init__(self, name, treemodel, parent=None):
     QTreeView.__init__(self, parent)
     self.treemodel = treemodel  #bruce 081216 renamed this from ne1model
     treemodel.view = self
     self.setSelectionMode(
         self.ExtendedSelection
     )  #bruce 070507 MultiSelection -> ExtendedSelection
     self.qtmodel = None
     self.drag = None
     self.setAcceptDrops(True)
Esempio n. 10
0
    def __init__(self, *args):
        QTreeView.__init__(self,*args)

        self._model = Matches()
        self.setModel(self._model)

        self.rt_delegate = RichTextDelegate(self)

        for i in self._model.HTML_COLS:
            self.setItemDelegateForColumn(i, self.rt_delegate)
Esempio n. 11
0
    def __init__(self, parent=None):
        QTreeView.__init__(self, parent=None)
        self.alter_tb = None
        self.disable_recounting = False
        self.setUniformRowHeights(True)
        self.setCursor(Qt.PointingHandCursor)
        self.setIconSize(QSize(20, 20))
        self.setTabKeyNavigation(True)
        self.setAnimated(True)
        self.setHeaderHidden(True)
        self.setItemDelegate(TagDelegate(self))
        self.made_connections = False
        self.setAcceptDrops(True)
        self.setDragEnabled(True)
        self.setDragDropMode(self.DragDrop)
        self.setDropIndicatorShown(True)
        self.in_drag_drop = False
        self.setAutoExpandDelay(500)
        self.pane_is_visible = False
        self.search_icon = QIcon(I('search.png'))
        self.user_category_icon = QIcon(I('tb_folder.png'))
        self.delete_icon = QIcon(I('list_remove.png'))
        self.rename_icon = QIcon(I('edit-undo.png'))

        self._model = TagsModel(self)
        self._model.search_item_renamed.connect(self.search_item_renamed)
        self._model.refresh_required.connect(self.refresh_required,
                                             type=Qt.QueuedConnection)
        self._model.tag_item_renamed.connect(self.tag_item_renamed)
        self._model.restriction_error.connect(self.restriction_error)
        self._model.user_categories_edited.connect(self.user_categories_edited,
                                                   type=Qt.QueuedConnection)
        self._model.drag_drop_finished.connect(self.drag_drop_finished)
        stylish_tb = '''
                QTreeView {
                    background-color: palette(window);
                    color: palette(window-text);
                    border: none;
                }
        '''
        self.setStyleSheet('''
                QTreeView::item {
                    border: 1px solid transparent;
                    padding-top:0.9ex;
                    padding-bottom:0.9ex;
                }

                QTreeView::item:hover {
                    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
                    border: 1px solid #bfcde4;
                    border-radius: 6px;
                }
        ''' + ('' if gprefs['tag_browser_old_look'] else stylish_tb))
        if gprefs['tag_browser_old_look']:
            self.setAlternatingRowColors(True)
Esempio n. 12
0
 def __init__(self, parent=None):
     QTreeView.__init__(self, parent)
     self.setHeaderHidden(True)
     self.setAnimated(True)
     self.activated.connect(self.item_activated)
     self.clicked.connect(self.item_activated)
     pi = plugins['progress_indicator'][0]
     if hasattr(pi, 'set_no_activate_on_click'):
         pi.set_no_activate_on_click(self)
     self.initialized = False
     self.setExpandsOnDoubleClick(False)
Esempio n. 13
0
 def __init__(self, parent=None):
     QTreeView.__init__(self, parent)
     self.setHeaderHidden(True)
     self.setAnimated(True)
     self.activated.connect(self.item_activated)
     self.clicked.connect(self.item_activated)
     pi = plugins['progress_indicator'][0]
     if hasattr(pi, 'set_no_activate_on_click'):
         pi.set_no_activate_on_click(self)
     self.initialized = False
     self.setExpandsOnDoubleClick(False)
Esempio n. 14
0
 def __init__(self, process, block):
     QTreeView.__init__(self)
     model = BlockModel(process, block)
     self.setModel(model)
     self.setColumnWidth(0, 160)
     self.setColumnWidth(1, 180)
     self.setColumnWidth(2, 25)
     self.resize(QSize(370, 800))
     self.setItemDelegateForColumn(1, Delegate())
     self.setEditTriggers(self.AllEditTriggers)
     self.expanded.connect(self.write_expanded)
     self.collapsed.connect(self.write_collapsed)
     self.show()
Esempio n. 15
0
 def __init__(self, process, block):
     QTreeView.__init__(self)
     model = BlockModel(process, block)
     self.setModel(model)
     self.setWindowTitle("%s: imalcolm" % model.block_path[0])
     root = os.path.join(os.path.dirname(__file__), "..", "..")
     icon_path = os.path.join(root, "docs", "malcolm-logo.svg")
     self.setWindowIcon(QIcon(icon_path))
     self.setColumnWidth(0, 160)
     self.setColumnWidth(1, 180)
     self.setColumnWidth(2, 25)
     self.resize(QSize(370, 500))
     self.setItemDelegateForColumn(1, Delegate())
     self.setEditTriggers(self.AllEditTriggers)
     self.expanded.connect(self.write_expanded)
     self.collapsed.connect(self.write_collapsed)
Esempio n. 16
0
 def resizeEvent(self, evt):
     """
     Reimplementation of resizeEvent method of QTreeView
     """
     if self.selectedItem() is not None:
         self.parent.partChanged(self.selectedItem())
     return QTreeView.resizeEvent(self, evt)                              
Esempio n. 17
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self._layout = l = QGridLayout()
     self.setLayout(self._layout)
     self.header = QLabel(_('Double click on any entry to change the'
         ' keyboard shortcuts associated with it'))
     l.addWidget(self.header, 0, 0, 1, 3)
     self.view = QTreeView(self)
     self.view.setAlternatingRowColors(True)
     self.view.setHeaderHidden(True)
     self.view.setAnimated(True)
     l.addWidget(self.view, 1, 0, 1, 3)
     self.delegate = Delegate()
     self.view.setItemDelegate(self.delegate)
     self.delegate.sizeHintChanged.connect(self.editor_opened,
             type=Qt.QueuedConnection)
     self.delegate.changed_signal.connect(self.changed_signal)
     self.search = SearchBox2(self)
     self.search.initialize('shortcuts_search_history',
             help_text=_('Search for a shortcut by name'))
     self.search.search.connect(self.find)
     l.addWidget(self.search, 2, 0, 1, 1)
     self.nb = QPushButton(QIcon(I('arrow-down.png')), _('&Next'), self)
     self.pb = QPushButton(QIcon(I('arrow-up.png')), _('&Previous'), self)
     self.nb.clicked.connect(self.find_next)
     self.pb.clicked.connect(self.find_previous)
     l.addWidget(self.nb, 2, 1, 1, 1)
     l.addWidget(self.pb, 2, 2, 1, 1)
     l.setColumnStretch(0, 100)
Esempio n. 18
0
    def __init__(self, *args):
        QTreeView.__init__(self,*args)
            
        self._model = Matches([p for p in store_plugins()])
        self.setModel(self._model)
        
        self.setIconSize(QSize(24, 24))

        self.rt_delegate = RichTextDelegate(self)

        for i in self._model.HTML_COLS:
            self.setItemDelegateForColumn(i, self.rt_delegate)

        for i in xrange(self._model.columnCount()):
            self.resizeColumnToContents(i)
            
        self.model().sort(1, Qt.AscendingOrder)
        self.header().setSortIndicator(self.model().sort_col, self.model().sort_order)
    def __init__(self, *args):
        QTreeView.__init__(self, *args)

        self._model = Matches([p for p in store_plugins()])
        self.setModel(self._model)

        self.setIconSize(QSize(24, 24))

        self.rt_delegate = RichTextDelegate(self)

        for i in self._model.HTML_COLS:
            self.setItemDelegateForColumn(i, self.rt_delegate)

        for i in xrange(self._model.columnCount()):
            self.resizeColumnToContents(i)

        self.model().sort(1, Qt.AscendingOrder)
        self.header().setSortIndicator(self.model().sort_col,
                                       self.model().sort_order)
Esempio n. 20
0
        def __init__(self, mmkit, parent):
            QTreeView.__init__(self, parent)

            self.setEnabled(True)
            self.model = QtGui.QDirModel(['*.mmp', '*.MMP'], # name filters
                                         QDir.AllEntries|QDir.AllDirs|QDir.NoDotAndDotDot, # filters
                                         QDir.Name # sort order
                                         )
                # explanation of filters (from Qt 4.2 doc for QDirModel):
                # - QDir.AllEntries = list files, dirs, drives, symlinks.
                # - QDir.AllDirs = include dirs regardless of other filters [guess: needed to ignore the name filters for dirs]
                # - QDir.NoDotAndDotDot = don't include '.' and '..' dirs
                #
                # about dirnames of "CVS":
                # The docs don't mention any way to filter the dirnames using a callback,
                # or any choices besides "filter them same as filenames" or "don't filter them".
                # So there is no documented way to filter out the "CVS" subdirectories like we did in Qt3
                # (short of subclassing this and overriding some methods,
                #  but the docs don't make it obvious how to do that correctly).
                # Fortunately, autoBuild.py removes them from the partlib copy in built releases.
                #
                # Other QDirModel methods we might want to use:
                # QDirModel.refresh, to update its state from the filesystem (but see the docs --
                #  they imply we might have to pass the model's root pathname to that method,
                #  even if it hasn't changed, but they're not entirely clear on that).
                #
                # [bruce 070502 comments]

            self.path = None
            self.mmkit = mmkit
            self.setModel(self.model)
            self.setWindowTitle(self.tr("Dir View"))

            self.setItemsExpandable(True)
            self.setAlternatingRowColors(True)
            self.setColumnWidth(0, 200)
            for i in range(2,4):
                self.setColumnWidth(i, 4)

            self.show()
Esempio n. 21
0
 def dragMoveEvent(self, event):
     QTreeView.dragMoveEvent(self, event)
     self.setDropIndicatorShown(False)
     index = self.indexAt(event.pos())
     if not index.isValid():
         return
     src_is_tb = event.mimeData().hasFormat(
         'application/calibre+from_tag_browser')
     item = index.data(Qt.UserRole).toPyObject()
     if item.type == TagTreeItem.ROOT:
         return
     flags = self._model.flags(index)
     if item.type == TagTreeItem.TAG and flags & Qt.ItemIsDropEnabled:
         self.setDropIndicatorShown(not src_is_tb)
         return
     if item.type == TagTreeItem.CATEGORY and not item.is_gst:
         fm_dest = self.db.metadata_for_field(item.category_key)
         if fm_dest['kind'] == 'user':
             if src_is_tb:
                 if event.dropAction() == Qt.MoveAction:
                     data = str(event.mimeData().data(
                         'application/calibre+from_tag_browser'))
                     src = cPickle.loads(data)
                     for s in src:
                         if s[0] == TagTreeItem.TAG and \
                                 (not s[1].startswith('@') or s[2]):
                             return
                 self.setDropIndicatorShown(True)
                 return
             md = event.mimeData()
             if hasattr(md, 'column_name'):
                 fm_src = self.db.metadata_for_field(md.column_name)
                 if md.column_name in ['authors', 'publisher', 'series'] or \
                         (fm_src['is_custom'] and (
                          (fm_src['datatype'] in ['series', 'text', 'enumeration'] and
                           not fm_src['is_multiple']) or
                          (fm_src['datatype'] == 'composite' and
                           fm_src['display'].get('make_category', False)))):
                     self.setDropIndicatorShown(True)
Esempio n. 22
0
 def mouseMoveEvent(self, event):
     dex = self.indexAt(event.pos())
     if self.in_drag_drop or not dex.isValid():
         QTreeView.mouseMoveEvent(self, event)
         return
     # Must deal with odd case where the node being dragged is 'virtual',
     # created to form a hierarchy. We can't really drag this node, but in
     # addition we can't allow drag recognition to notice going over some
     # other node and grabbing that one. So we set in_drag_drop to prevent
     # this from happening, turning it off when the user lifts the button.
     self.in_drag_drop = True
     if not self._model.flags(dex) & Qt.ItemIsDragEnabled:
         QTreeView.mouseMoveEvent(self, event)
         return
     md = self._model.mimeData([dex])
     pixmap = dex.data(Qt.DecorationRole).toPyObject().pixmap(25, 25)
     drag = QDrag(self)
     drag.setPixmap(pixmap)
     drag.setMimeData(md)
     if self._model.is_in_user_category(dex):
         drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction)
     else:
         drag.exec_(Qt.CopyAction)
Esempio n. 23
0
 def mouseMoveEvent(self, event):
     dex = self.indexAt(event.pos())
     if self.in_drag_drop or not dex.isValid():
         QTreeView.mouseMoveEvent(self, event)
         return
     # Must deal with odd case where the node being dragged is 'virtual',
     # created to form a hierarchy. We can't really drag this node, but in
     # addition we can't allow drag recognition to notice going over some
     # other node and grabbing that one. So we set in_drag_drop to prevent
     # this from happening, turning it off when the user lifts the button.
     self.in_drag_drop = True
     if not self._model.flags(dex) & Qt.ItemIsDragEnabled:
         QTreeView.mouseMoveEvent(self, event)
         return
     md = self._model.mimeData([dex])
     pixmap = dex.data(Qt.DecorationRole).toPyObject().pixmap(25, 25)
     drag = QDrag(self)
     drag.setPixmap(pixmap)
     drag.setMimeData(md)
     if self._model.is_in_user_category(dex):
         drag.exec_(Qt.CopyAction|Qt.MoveAction, Qt.CopyAction)
     else:
         drag.exec_(Qt.CopyAction)
Esempio n. 24
0
 def dragMoveEvent(self, event):
     QTreeView.dragMoveEvent(self, event)
     self.setDropIndicatorShown(False)
     index = self.indexAt(event.pos())
     if not index.isValid():
         return
     src_is_tb = event.mimeData().hasFormat("application/calibre+from_tag_browser")
     item = index.data(Qt.UserRole).toPyObject()
     if item.type == TagTreeItem.ROOT:
         return
     flags = self._model.flags(index)
     if item.type == TagTreeItem.TAG and flags & Qt.ItemIsDropEnabled:
         self.setDropIndicatorShown(not src_is_tb)
         return
     if item.type == TagTreeItem.CATEGORY and not item.is_gst:
         fm_dest = self.db.metadata_for_field(item.category_key)
         if fm_dest["kind"] == "user":
             if src_is_tb:
                 if event.dropAction() == Qt.MoveAction:
                     data = str(event.mimeData().data("application/calibre+from_tag_browser"))
                     src = cPickle.loads(data)
                     for s in src:
                         if s[0] == TagTreeItem.TAG and (not s[1].startswith("@") or s[2]):
                             return
                 self.setDropIndicatorShown(True)
                 return
             md = event.mimeData()
             if hasattr(md, "column_name"):
                 fm_src = self.db.metadata_for_field(md.column_name)
                 if md.column_name in ["authors", "publisher", "series"] or (
                     fm_src["is_custom"]
                     and (
                         (fm_src["datatype"] in ["series", "text", "enumeration"] and not fm_src["is_multiple"])
                         or (fm_src["datatype"] == "composite" and fm_src["display"].get("make_category", False))
                     )
                 ):
                     self.setDropIndicatorShown(True)
Esempio n. 25
0
 def dragMoveEvent(self, event):
     QTreeView.dragMoveEvent(self, event)
     self.setDropIndicatorShown(False)
     index = self.indexAt(event.pos())
     if not index.isValid():
         return
     src_is_tb = event.mimeData().hasFormat('application/calibre+from_tag_browser')
     item = index.data(Qt.UserRole).toPyObject()
     if item.type == TagTreeItem.ROOT:
         return
     flags = self._model.flags(index)
     if item.type == TagTreeItem.TAG and flags & Qt.ItemIsDropEnabled:
         self.setDropIndicatorShown(not src_is_tb)
         return
     if item.type == TagTreeItem.CATEGORY and not item.is_gst:
         fm_dest = self.db.metadata_for_field(item.category_key)
         if fm_dest['kind'] == 'user':
             if src_is_tb:
                 if event.dropAction() == Qt.MoveAction:
                     data = str(event.mimeData().data('application/calibre+from_tag_browser'))
                     src = cPickle.loads(data)
                     for s in src:
                         if s[0] == TagTreeItem.TAG and \
                                 (not s[1].startswith('@') or s[2]):
                             return
                 self.setDropIndicatorShown(True)
                 return
             md = event.mimeData()
             if hasattr(md, 'column_name'):
                 fm_src = self.db.metadata_for_field(md.column_name)
                 if md.column_name in ['authors', 'publisher', 'series'] or \
                         (fm_src['is_custom'] and (
                          (fm_src['datatype'] in ['series', 'text', 'enumeration'] and
                           not fm_src['is_multiple']) or
                          (fm_src['datatype'] == 'composite' and
                           fm_src['display'].get('make_category', False)))):
                     self.setDropIndicatorShown(True)
Esempio n. 26
0
class ShortcutConfig(QWidget):  # {{{

    changed_signal = pyqtSignal()

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self._layout = l = QGridLayout()
        self.setLayout(self._layout)
        self.header = QLabel(_('Double click on any entry to change the'
            ' keyboard shortcuts associated with it'))
        l.addWidget(self.header, 0, 0, 1, 3)
        self.view = QTreeView(self)
        self.view.setAlternatingRowColors(True)
        self.view.setHeaderHidden(True)
        self.view.setAnimated(True)
        l.addWidget(self.view, 1, 0, 1, 3)
        self.delegate = Delegate()
        self.view.setItemDelegate(self.delegate)
        self.delegate.sizeHintChanged.connect(self.editor_opened,
                type=Qt.QueuedConnection)
        self.delegate.changed_signal.connect(self.changed_signal)
        self.search = SearchBox2(self)
        self.search.initialize('shortcuts_search_history',
                help_text=_('Search for a shortcut by name'))
        self.search.search.connect(self.find)
        l.addWidget(self.search, 2, 0, 1, 1)
        self.nb = QPushButton(QIcon(I('arrow-down.png')), _('&Next'), self)
        self.pb = QPushButton(QIcon(I('arrow-up.png')), _('&Previous'), self)
        self.nb.clicked.connect(self.find_next)
        self.pb.clicked.connect(self.find_previous)
        l.addWidget(self.nb, 2, 1, 1, 1)
        l.addWidget(self.pb, 2, 2, 1, 1)
        l.setColumnStretch(0, 100)

    def restore_defaults(self):
        self._model.restore_defaults()
        self.changed_signal.emit()

    def commit(self):
        if self.view.state() == self.view.EditingState:
            self.delegate.accept_changes()
        self._model.commit()

    def initialize(self, keyboard):
        self._model = ConfigModel(keyboard, parent=self)
        self.view.setModel(self._model)

    def editor_opened(self, index):
        self.view.scrollTo(index, self.view.EnsureVisible)

    @property
    def is_editing(self):
        return self.view.state() == self.view.EditingState

    def find(self, query):
        if not query:
            return
        try:
            idx = self._model.find(query)
        except ParseException:
            self.search.search_done(False)
            return
        self.search.search_done(True)
        if not idx.isValid():
            info_dialog(self, _('No matches'),
                    _('Could not find any shortcuts matching %s')%query,
                    show=True, show_copy_button=False)
            return
        self.highlight_index(idx)

    def highlight_index(self, idx):
        self.view.scrollTo(idx)
        self.view.selectionModel().select(idx,
                self.view.selectionModel().ClearAndSelect)
        self.view.setCurrentIndex(idx)
        self.view.setFocus(Qt.OtherFocusReason)

    def find_next(self, *args):
        idx = self.view.currentIndex()
        if not idx.isValid():
            idx = self._model.index(0, 0)
        idx = self._model.find_next(idx,
                unicode(self.search.currentText()))
        self.highlight_index(idx)

    def find_previous(self, *args):
        idx = self.view.currentIndex()
        if not idx.isValid():
            idx = self._model.index(0, 0)
        idx = self._model.find_next(idx,
            unicode(self.search.currentText()), backwards=True)
        self.highlight_index(idx)

    def highlight_group(self, group_name):
        idx = self.view.model().index_for_group(group_name)
        if idx is not None:
            self.view.expand(idx)
            self.view.scrollTo(idx, self.view.PositionAtTop)
            self.view.selectionModel().select(idx,
                    self.view.selectionModel().ClearAndSelect)
            self.view.setCurrentIndex(idx)
            self.view.setFocus(Qt.OtherFocusReason)
Esempio n. 27
0
 def mouseReleaseEvent(self, event):
     # Swallow everything except leftButton so context menus work correctly
     if event.button() == Qt.LeftButton or self.in_drag_drop:
         QTreeView.mouseReleaseEvent(self, event)
         self.in_drag_drop = False
Esempio n. 28
0
    def mouseMoveEvent(self, event):
        if self.drag is not None:
            QTreeView.mouseMoveEvent(self, event)
            return
        if ((event.globalPos() - self.mouse_press_qpoint).manhattanLength() <
                QApplication.startDragDistance()):
            return
        #
        # starting a drag
        # [logic bug, after bruce change 070507: should not do this
        #  if we already started dragging out a selection. How can we tell?
        #  Only by whether the initial press had eventInRect, I think
        #  (not yet recorded), or at least, the initial move (#e could record here).]
        #
        index = self.indexAt(event.pos())

        sellst = self.selectedList()  # bruce 070507 move earlier

        DEBUG2 = True

        if index.isValid():
            thisnode = index.internalPointer().node

            #bruce 070507 bring in some code from modelTreeGui.py
            alreadySelected = (thisnode in sellst)

            item = index.internalPointer()
            rect = self.visualRect(index)
            if DEBUG2:
                print "visualRect coords", rect.left(), rect.right(), rect.top(
                ), rect.bottom()
            qfm = QFontMetrics(QLineEdit(self).font())
            rect.setWidth(qfm.width(item.node.name) + _ICONSIZE[0] + 4)
            if DEBUG2:
                print "visualRect coords, modified:", rect.left(), rect.right(
                ), rect.top(), rect.bottom()
                # looks like icon and text, a bit taller than text (guesses)
            eventInRect = rect.contains(event.pos())
            if DEBUG2:
                print "valid index: eventInRect = %r, item = %r, index = %r, alreadySelected = %r" % \
                      (eventInRect, item, index, alreadySelected)#######
        else:
            thisnode = item = None
            alreadySelected = eventInRect = False

        if not eventInRect:
            # nothing to drag, but [bruce 070507] let super handle it (for dragging over nodes to select)
            self.drag_is_not_DND = True  ### not yet used
            QTreeView.mouseMoveEvent(self, event)
            return

        if thisnode in sellst:
            # if dragging something selected, drag along all other selected ones
            dragged_nodes = sellst
        else:
            # if dragging something unselected, ignore any selected ones
            dragged_nodes = [thisnode]
        qdrag = QDrag(self)
        drag_type = 'move'  # how do I decide between 'move' and 'copy'?
        self.drag = (dragged_nodes, drag_type, qdrag)
        mimedata = QMimeData()
        mimedata.setText("need a string here for a valid mimetype")
        qdrag.setMimeData(mimedata)
        display_prefs = {}
        pixmap = dragged_nodes[0].node_icon(display_prefs)
        qdrag.setPixmap(pixmap)
        qdrag.setHotSpot(QPoint(-8, 8))
        qdrag.start()
Esempio n. 29
0
 def resizeEvent(self, evt):
     """ Reimplementation of resizeEvent method of QTreeView"""
     if self.selectedItem() is not None:
             self.mmkit._libPageView()
     return QTreeView.resizeEvent(self, evt)
    def mouseMoveEvent(self, event):
        if self.drag is not None:
            QTreeView.mouseMoveEvent(self, event)
            return
        if ((event.globalPos() - self.mouse_press_qpoint).manhattanLength()
            < QApplication.startDragDistance()):
            return
        #
        # starting a drag
        # [logic bug, after bruce change 070507: should not do this
        #  if we already started dragging out a selection. How can we tell?
        #  Only by whether the initial press had eventInRect, I think
        #  (not yet recorded), or at least, the initial move (#e could record here).]
        #
        index = self.indexAt(event.pos())

        sellst = self.selectedList() # bruce 070507 move earlier

        DEBUG2 = True

        if index.isValid():
            thisnode = index.internalPointer().node

            #bruce 070507 bring in some code from modelTreeGui.py
            alreadySelected = (thisnode in sellst)

            item = index.internalPointer()
            rect = self.visualRect(index)
            if DEBUG2:
                print "visualRect coords",rect.left(), rect.right(), rect.top(), rect.bottom()
            qfm = QFontMetrics(QLineEdit(self).font())
            rect.setWidth(qfm.width(item.node.name) + _ICONSIZE[0] + 4)
            if DEBUG2:
                print "visualRect coords, modified:",rect.left(), rect.right(), rect.top(), rect.bottom()
                # looks like icon and text, a bit taller than text (guesses)
            eventInRect = rect.contains(event.pos())
            if DEBUG2:
                print "valid index: eventInRect = %r, item = %r, index = %r, alreadySelected = %r" % \
                      (eventInRect, item, index, alreadySelected)#######
        else:
            thisnode = item = None
            alreadySelected = eventInRect = False

        if not eventInRect:
            # nothing to drag, but [bruce 070507] let super handle it (for dragging over nodes to select)
            self.drag_is_not_DND = True ### not yet used
            QTreeView.mouseMoveEvent(self, event)
            return

        if thisnode in sellst:
            # if dragging something selected, drag along all other selected ones
            dragged_nodes = sellst
        else:
            # if dragging something unselected, ignore any selected ones
            dragged_nodes = [ thisnode ]
        qdrag = QDrag(self)
        drag_type = 'move'  # how do I decide between 'move' and 'copy'?
        self.drag = (dragged_nodes, drag_type, qdrag)
        mimedata = QMimeData()
        mimedata.setText("need a string here for a valid mimetype")
        qdrag.setMimeData(mimedata)
        display_prefs = { }
        pixmap = dragged_nodes[0].node_icon(display_prefs)
        qdrag.setPixmap(pixmap)
        qdrag.setHotSpot(QPoint(-8, 8))
        qdrag.start()
Esempio n. 31
0
 def mouseReleaseEvent(self, event):
     # Swallow everything except leftButton so context menus work correctly
     if event.button() == Qt.LeftButton or self.in_drag_drop:
         QTreeView.mouseReleaseEvent(self, event)
         self.in_drag_drop = False
Esempio n. 32
0
 def mouseReleaseEvent(self, event):
     self.drag_is_not_DND = False
     if self.drag is None:
         QTreeView.mousePressEvent(self, self.mouse_press_event)
     self.drag = None
     QTreeView.mouseReleaseEvent(self, event)
Esempio n. 33
0
class ShortcutConfig(QWidget):  # {{{

    changed_signal = pyqtSignal()

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self._layout = l = QGridLayout()
        self.setLayout(self._layout)
        self.header = QLabel(
            _('Double click on any entry to change the'
              ' keyboard shortcuts associated with it'))
        l.addWidget(self.header, 0, 0, 1, 3)
        self.view = QTreeView(self)
        self.view.setAlternatingRowColors(True)
        self.view.setHeaderHidden(True)
        self.view.setAnimated(True)
        l.addWidget(self.view, 1, 0, 1, 3)
        self.delegate = Delegate()
        self.view.setItemDelegate(self.delegate)
        self.delegate.sizeHintChanged.connect(self.editor_opened,
                                              type=Qt.QueuedConnection)
        self.delegate.changed_signal.connect(self.changed_signal)
        self.search = SearchBox2(self)
        self.search.initialize('shortcuts_search_history',
                               help_text=_('Search for a shortcut by name'))
        self.search.search.connect(self.find)
        l.addWidget(self.search, 2, 0, 1, 1)
        self.nb = QPushButton(QIcon(I('arrow-down.png')), _('&Next'), self)
        self.pb = QPushButton(QIcon(I('arrow-up.png')), _('&Previous'), self)
        self.nb.clicked.connect(self.find_next)
        self.pb.clicked.connect(self.find_previous)
        l.addWidget(self.nb, 2, 1, 1, 1)
        l.addWidget(self.pb, 2, 2, 1, 1)
        l.setColumnStretch(0, 100)

    def restore_defaults(self):
        self._model.restore_defaults()
        self.changed_signal.emit()

    def commit(self):
        if self.view.state() == self.view.EditingState:
            self.delegate.accept_changes()
        self._model.commit()

    def initialize(self, keyboard):
        self._model = ConfigModel(keyboard, parent=self)
        self.view.setModel(self._model)

    def editor_opened(self, index):
        self.view.scrollTo(index, self.view.EnsureVisible)

    @property
    def is_editing(self):
        return self.view.state() == self.view.EditingState

    def find(self, query):
        if not query:
            return
        try:
            idx = self._model.find(query)
        except ParseException:
            self.search.search_done(False)
            return
        self.search.search_done(True)
        if not idx.isValid():
            info_dialog(self,
                        _('No matches'),
                        _('Could not find any shortcuts matching %s') % query,
                        show=True,
                        show_copy_button=False)
            return
        self.highlight_index(idx)

    def highlight_index(self, idx):
        self.view.scrollTo(idx)
        self.view.selectionModel().select(
            idx,
            self.view.selectionModel().ClearAndSelect)
        self.view.setCurrentIndex(idx)
        self.view.setFocus(Qt.OtherFocusReason)

    def find_next(self, *args):
        idx = self.view.currentIndex()
        if not idx.isValid():
            idx = self._model.index(0, 0)
        idx = self._model.find_next(idx, unicode(self.search.currentText()))
        self.highlight_index(idx)

    def find_previous(self, *args):
        idx = self.view.currentIndex()
        if not idx.isValid():
            idx = self._model.index(0, 0)
        idx = self._model.find_next(idx,
                                    unicode(self.search.currentText()),
                                    backwards=True)
        self.highlight_index(idx)

    def highlight_group(self, group_name):
        idx = self.view.model().index_for_group(group_name)
        if idx is not None:
            self.view.expand(idx)
            self.view.scrollTo(idx, self.view.PositionAtTop)
            self.view.selectionModel().select(
                idx,
                self.view.selectionModel().ClearAndSelect)
            self.view.setCurrentIndex(idx)
            self.view.setFocus(Qt.OtherFocusReason)
Esempio n. 34
0
    def __init__(self, parent):        
        """
        The constructor of PM_TreeView class that provides provides a partlib 
        object (as a 'treeview' of any user specified directory) to the 
        client code. The parts from the partlib can be pasted in the 3D  
        Workspace.
        """
        QTreeView.__init__(self, parent)            
        self.parent = parent
        self.setEnabled(True)
        
        self.model = QDirModel(
            ['*.mmp', '*.MMP'], # name filters
            QDir.AllEntries|QDir.AllDirs|QDir.NoDotAndDotDot, # filters
            QDir.Name # sort order
            )
        
        # explanation of filters (from Qt 4.2 doc for QDirModel):
        # - QDir.AllEntries = list files, dirs, drives, symlinks.
        # - QDir.AllDirs = include dirs regardless of other filters 
        #   [guess: needed to ignore the name filters for dirs]
        # - QDir.NoDotAndDotDot = don't include '.' and '..' dirs
        #
        # about dirnames of "CVS":
        # The docs don't mention any way to filter the dirnames using a 
        # callback, or any choices besides "filter them same as filenames" or 
        # "don't filter them". So there is no documented way to filter out the 
        # "CVS" subdirectories like we did in Qt3
        # (short of subclassing this and overriding some methods,
        #  but the docs don't make it obvious how to do that correctly).
        # Fortunately, autoBuild.py removes them from the partlib copy in built 
        # releases.
        #
        # Other QDirModel methods we might want to use:
        # QDirModel.refresh, to update its state from the filesystem 
        # (but see the docs --
        #  they imply we might have to pass the model's root pathname to that 
        #  method,
        #  even if it hasn't changed, but they're not entirely clear on that).
        #
        # [bruce 070502 comments]
            
        self.path = None
        self.setModel(self.model)    
        self.setWindowTitle(self.tr("Tree View"))
        
        self.setItemsExpandable(True)
        self.setAlternatingRowColors(True)        
        self.setColumnWidth(0, 150) 
        self.setSortingEnabled(True)
        self.sortByColumn(0, Qt.AscendingOrder)
        self.setMinimumHeight(300)
        
        for i in range(2, 4):
            self.setColumnWidth(i, 4)    
        
        filePath = os.path.dirname(os.path.abspath(sys.argv[0]))
        libDir = os.path.normpath(filePath + '/../partlib')
        
        self.libPathKey = '/nanorex/nE-1/libraryPath'
        libDir = env.prefs.get(self.libPathKey, libDir)

        if os.path.isdir(libDir):
            self.rootDir = libDir
            self.setRootPath(libDir)
        else:
            self.rootDir = None
            env.history.message(redmsg("The part library directory: %s doesn't"\
                                       " exist." %libDir))
            
        self.show()
 def mouseReleaseEvent(self, event):
     self.drag_is_not_DND = False
     if self.drag is None:
         QTreeView.mousePressEvent(self, self.mouse_press_event)
     self.drag = None
     QTreeView.mouseReleaseEvent(self, event)