mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-05-08 17:59:50 +00:00
Adapted th qt part to core.gui.directory_tree.
This commit is contained in:
parent
b5dd9651c3
commit
76d351d8be
@ -21,6 +21,4 @@ http://www.hardcoded.net/licenses/hs_license
|
|||||||
#define jobScan @"job_scan"
|
#define jobScan @"job_scan"
|
||||||
#define jobCopy @"job_copy"
|
#define jobCopy @"job_copy"
|
||||||
#define jobMove @"job_move"
|
#define jobMove @"job_move"
|
||||||
#define jobDelete @"job_delete"
|
#define jobDelete @"job_delete"
|
||||||
|
|
||||||
#define DEMO_MAX_ACTION_COUNT 10
|
|
@ -23,6 +23,11 @@ class DirectoryNode(Node):
|
|||||||
self._loaded = False
|
self._loaded = False
|
||||||
self._state = STATE_ORDER.index(self._app.directories.get_state(path))
|
self._state = STATE_ORDER.index(self._app.directories.get_state(path))
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
if not self._loaded:
|
||||||
|
self._load()
|
||||||
|
return Node.__len__(self)
|
||||||
|
|
||||||
def _load(self):
|
def _load(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
subpaths = self._app.directories.get_subfolders(self._directory_path)
|
subpaths = self._app.directories.get_subfolders(self._directory_path)
|
||||||
@ -30,12 +35,6 @@ class DirectoryNode(Node):
|
|||||||
self.append(DirectoryNode(self._app, path, path[-1]))
|
self.append(DirectoryNode(self._app, path, path[-1]))
|
||||||
self._loaded = True
|
self._loaded = True
|
||||||
|
|
||||||
@property
|
|
||||||
def children_count(self):
|
|
||||||
if not self._loaded:
|
|
||||||
self._load()
|
|
||||||
return len(self)
|
|
||||||
|
|
||||||
# The state propery is an index to the combobox
|
# The state propery is an index to the combobox
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
@ -254,9 +254,7 @@ class DupeGuru(DupeGuruBase, QObject):
|
|||||||
|
|
||||||
def job_finished(self, jobid):
|
def job_finished(self, jobid):
|
||||||
self.emit(SIGNAL('resultsChanged()'))
|
self.emit(SIGNAL('resultsChanged()'))
|
||||||
if jobid == JOB_LOAD:
|
if jobid in (JOB_MOVE, JOB_COPY, JOB_DELETE) and self.last_op_error_count > 0:
|
||||||
self.emit(SIGNAL('directoriesChanged()'))
|
|
||||||
elif jobid in (JOB_MOVE, JOB_COPY, JOB_DELETE) and self.last_op_error_count > 0:
|
|
||||||
msg = "{0} files could not be processed.".format(self.results.mark_count)
|
msg = "{0} files could not be processed.".format(self.results.mark_count)
|
||||||
QMessageBox.warning(self.main_window, 'Warning', msg)
|
QMessageBox.warning(self.main_window, 'Warning', msg)
|
||||||
elif jobid == JOB_SCAN:
|
elif jobid == JOB_SCAN:
|
||||||
|
@ -26,7 +26,6 @@ class DirectoriesDialog(QDialog, Ui_DirectoriesDialog):
|
|||||||
self.connect(self.addButton, SIGNAL('clicked()'), self.addButtonClicked)
|
self.connect(self.addButton, SIGNAL('clicked()'), self.addButtonClicked)
|
||||||
self.connect(self.removeButton, SIGNAL('clicked()'), self.removeButtonClicked)
|
self.connect(self.removeButton, SIGNAL('clicked()'), self.removeButtonClicked)
|
||||||
self.connect(self.treeView.selectionModel(), SIGNAL('selectionChanged(QItemSelection,QItemSelection)'), self.selectionChanged)
|
self.connect(self.treeView.selectionModel(), SIGNAL('selectionChanged(QItemSelection,QItemSelection)'), self.selectionChanged)
|
||||||
self.connect(self.app, SIGNAL('directoriesChanged()'), self.directoriesChanged)
|
|
||||||
|
|
||||||
def _setupUi(self):
|
def _setupUi(self):
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
@ -60,10 +59,6 @@ class DirectoriesDialog(QDialog, Ui_DirectoriesDialog):
|
|||||||
return
|
return
|
||||||
self.lastAddedFolder = dirpath
|
self.lastAddedFolder = dirpath
|
||||||
self.app.add_directory(dirpath)
|
self.app.add_directory(dirpath)
|
||||||
self.directoriesModel.reset()
|
|
||||||
|
|
||||||
def directoriesChanged(self):
|
|
||||||
self.directoriesModel.reset()
|
|
||||||
|
|
||||||
def doneButtonClicked(self):
|
def doneButtonClicked(self):
|
||||||
self.hide()
|
self.hide()
|
||||||
@ -76,8 +71,7 @@ class DirectoriesDialog(QDialog, Ui_DirectoriesDialog):
|
|||||||
node = index.internalPointer()
|
node = index.internalPointer()
|
||||||
if node.parent is None:
|
if node.parent is None:
|
||||||
row = index.row()
|
row = index.row()
|
||||||
del self.app.directories[row]
|
self.app.remove_directory(row)
|
||||||
self.directoriesModel.reset()
|
|
||||||
|
|
||||||
def selectionChanged(self, selected, deselected):
|
def selectionChanged(self, selected, deselected):
|
||||||
self._updateRemoveButton()
|
self._updateRemoveButton()
|
||||||
|
@ -12,7 +12,9 @@ from PyQt4.QtCore import QModelIndex, Qt, QRect, QEvent, QPoint, QUrl
|
|||||||
from PyQt4.QtGui import (QComboBox, QStyledItemDelegate, QMouseEvent, QApplication, QBrush, QStyle,
|
from PyQt4.QtGui import (QComboBox, QStyledItemDelegate, QMouseEvent, QApplication, QBrush, QStyle,
|
||||||
QStyleOptionComboBox, QStyleOptionViewItemV4)
|
QStyleOptionComboBox, QStyleOptionViewItemV4)
|
||||||
|
|
||||||
from qtlib.tree_model import TreeNode, TreeModel
|
from qtlib.tree_model import RefNode, TreeModel
|
||||||
|
|
||||||
|
from core.gui.directory_tree import DirectoryTree
|
||||||
|
|
||||||
HEADERS = ['Name', 'State']
|
HEADERS = ['Name', 'State']
|
||||||
STATES = ['Normal', 'Reference', 'Excluded']
|
STATES = ['Normal', 'Reference', 'Excluded']
|
||||||
@ -58,36 +60,16 @@ class DirectoriesDelegate(QStyledItemDelegate):
|
|||||||
editor.setGeometry(option.rect)
|
editor.setGeometry(option.rect)
|
||||||
|
|
||||||
|
|
||||||
class DirectoryNode(TreeNode):
|
|
||||||
def __init__(self, model, parent, ref, row):
|
|
||||||
TreeNode.__init__(self, model, parent, row)
|
|
||||||
self.ref = ref
|
|
||||||
|
|
||||||
def _createNode(self, ref, row):
|
|
||||||
return DirectoryNode(self.model, self, ref, row)
|
|
||||||
|
|
||||||
def _getChildren(self):
|
|
||||||
return self.model.dirs.get_subfolders(self.ref)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
if self.parent is not None:
|
|
||||||
return self.ref[-1]
|
|
||||||
else:
|
|
||||||
return unicode(self.ref)
|
|
||||||
|
|
||||||
|
|
||||||
class DirectoriesModel(TreeModel):
|
class DirectoriesModel(TreeModel):
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
|
||||||
self.dirs = app.directories
|
|
||||||
TreeModel.__init__(self)
|
TreeModel.__init__(self)
|
||||||
|
self.model = DirectoryTree(self, app)
|
||||||
|
|
||||||
def _createNode(self, ref, row):
|
def _createNode(self, ref, row):
|
||||||
return DirectoryNode(self, None, ref, row)
|
return RefNode(self, None, ref, row)
|
||||||
|
|
||||||
def _getChildren(self):
|
def _getChildren(self):
|
||||||
return self.dirs
|
return list(self.model)
|
||||||
|
|
||||||
def columnCount(self, parent):
|
def columnCount(self, parent):
|
||||||
return 2
|
return 2
|
||||||
@ -96,15 +78,16 @@ class DirectoriesModel(TreeModel):
|
|||||||
if not index.isValid():
|
if not index.isValid():
|
||||||
return None
|
return None
|
||||||
node = index.internalPointer()
|
node = index.internalPointer()
|
||||||
|
ref = node.ref
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
if index.column() == 0:
|
if index.column() == 0:
|
||||||
return node.name
|
return ref.name
|
||||||
else:
|
else:
|
||||||
return STATES[self.dirs.get_state(node.ref)]
|
return STATES[ref.state]
|
||||||
elif role == Qt.EditRole and index.column() == 1:
|
elif role == Qt.EditRole and index.column() == 1:
|
||||||
return self.dirs.get_state(node.ref)
|
return ref.state
|
||||||
elif role == Qt.ForegroundRole:
|
elif role == Qt.ForegroundRole:
|
||||||
state = self.dirs.get_state(node.ref)
|
state = ref.state
|
||||||
if state == 1:
|
if state == 1:
|
||||||
return QBrush(Qt.blue)
|
return QBrush(Qt.blue)
|
||||||
elif state == 2:
|
elif state == 2:
|
||||||
@ -121,7 +104,7 @@ class DirectoriesModel(TreeModel):
|
|||||||
urls = unicode(unquoted, 'utf-8').split('\r\n')
|
urls = unicode(unquoted, 'utf-8').split('\r\n')
|
||||||
paths = [unicode(QUrl(url).toLocalFile()) for url in urls if url]
|
paths = [unicode(QUrl(url).toLocalFile()) for url in urls if url]
|
||||||
for path in paths:
|
for path in paths:
|
||||||
self.app.add_directory(path)
|
self.model.add_directory(path)
|
||||||
self.reset()
|
self.reset()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -146,7 +129,8 @@ class DirectoriesModel(TreeModel):
|
|||||||
if not index.isValid() or role != Qt.EditRole or index.column() != 1:
|
if not index.isValid() or role != Qt.EditRole or index.column() != 1:
|
||||||
return False
|
return False
|
||||||
node = index.internalPointer()
|
node = index.internalPointer()
|
||||||
self.dirs.set_state(node.ref, value)
|
ref = node.ref
|
||||||
|
ref.state = value
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def supportedDropActions(self):
|
def supportedDropActions(self):
|
||||||
@ -154,3 +138,7 @@ class DirectoriesModel(TreeModel):
|
|||||||
# work with ActionMove either. So screw that, and accept anything.
|
# work with ActionMove either. So screw that, and accept anything.
|
||||||
return Qt.ActionMask
|
return Qt.ActionMask
|
||||||
|
|
||||||
|
#--- model --> view
|
||||||
|
def refresh(self):
|
||||||
|
self.reset()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user