mirror of
https://github.com/arsenetar/dupeguru.git
synced 2026-01-22 06:37:17 +00:00
Implement dialog and base classes for model/view
This commit is contained in:
64
core/gui/exclude_list_dialog.py
Normal file
64
core/gui/exclude_list_dialog.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# Created On: 2012/03/13
|
||||
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
||||
#
|
||||
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
||||
# which should be included with this package. The terms are also available at
|
||||
# http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
# from hscommon.trans import tr
|
||||
from .exclude_list_table import ExcludeListTable
|
||||
|
||||
default_regexes = [".*thumbs", "\.DS.Store", "\.Trash", "Trash-Bin"]
|
||||
|
||||
|
||||
class ExcludeListDialogCore:
|
||||
# --- View interface
|
||||
# show()
|
||||
#
|
||||
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.exclude_list = self.app.exclude_list # Markable from exclude.py
|
||||
self.exclude_list_table = ExcludeListTable(self, app) # GUITable, this is the "model"
|
||||
|
||||
def restore_defaults(self):
|
||||
for _, regex in self.exclude_list:
|
||||
if regex not in default_regexes:
|
||||
self.exclude_list.unmark(regex)
|
||||
for default_regex in default_regexes:
|
||||
if not self.exclude_list.isExcluded(default_regex):
|
||||
self.exclude_list.add(default_regex)
|
||||
self.exclude_list.mark(default_regex)
|
||||
self.refresh()
|
||||
|
||||
def refresh(self):
|
||||
self.exclude_list_table.refresh()
|
||||
|
||||
def remove_selected(self):
|
||||
for row in self.exclude_list_table.selected_rows:
|
||||
self.exclude_list_table.remove(row)
|
||||
self.exclude_list.remove(row.regex)
|
||||
self.refresh()
|
||||
|
||||
def rename_selected(self, newregex):
|
||||
"""Renames the selected regex to ``newregex``.
|
||||
If there's more than one selected row, the first one is used.
|
||||
:param str newregex: The regex to rename the row's regex to.
|
||||
"""
|
||||
try:
|
||||
r = self.exclude_list_table.selected_rows[0]
|
||||
self.exclude_list.rename(r.regex, newregex)
|
||||
self.refresh()
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"dupeGuru Warning: {e}")
|
||||
return False
|
||||
|
||||
def add(self, regex):
|
||||
self.exclude_list.add(regex)
|
||||
self.exclude_list.mark(regex)
|
||||
# TODO make checks here before adding to GUI
|
||||
self.exclude_list_table.add(regex)
|
||||
|
||||
def show(self):
|
||||
self.view.show()
|
||||
117
core/gui/exclude_list_table.py
Normal file
117
core/gui/exclude_list_table.py
Normal file
@@ -0,0 +1,117 @@
|
||||
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
||||
# which should be included with this package. The terms are also available at
|
||||
# http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
from .base import DupeGuruGUIObject
|
||||
from hscommon.gui.table import GUITable, Row
|
||||
from hscommon.gui.column import Column, Columns
|
||||
from hscommon.trans import trget
|
||||
tr = trget("ui")
|
||||
|
||||
|
||||
class ExcludeListTable(GUITable, DupeGuruGUIObject):
|
||||
COLUMNS = [
|
||||
Column("marked", ""),
|
||||
Column("regex", tr("Regex"))
|
||||
]
|
||||
|
||||
def __init__(self, exclude_list_dialog, app):
|
||||
GUITable.__init__(self)
|
||||
DupeGuruGUIObject.__init__(self, app)
|
||||
# self.columns = Columns(self, prefaccess=app, savename="ExcludeTable")
|
||||
self.columns = Columns(self)
|
||||
self.dialog = exclude_list_dialog
|
||||
|
||||
def rename_selected(self, newname):
|
||||
row = self.selected_row
|
||||
if row is None:
|
||||
# There's all kinds of way the current row can be swept off during rename. When it
|
||||
# happens, selected_row will be None.
|
||||
return False
|
||||
row._data = None
|
||||
return self.dialog.rename_selected(newname)
|
||||
|
||||
# --- Virtual
|
||||
def _do_add(self, regex):
|
||||
"""(Virtual) Creates a new row, adds it in the table.
|
||||
Returns ``(row, insert_index)``.
|
||||
"""
|
||||
# Return index 0 to insert at the top
|
||||
return ExcludeListRow(self, self.dialog.exclude_list.is_marked(regex), regex), 0
|
||||
|
||||
def _do_delete(self):
|
||||
self.dalog.exclude_list.remove(self.selected_row.regex)
|
||||
|
||||
# --- Override
|
||||
def add(self, regex):
|
||||
row, insert_index = self._do_add(regex)
|
||||
self.insert(insert_index, row)
|
||||
# self.select([insert_index])
|
||||
self.view.refresh()
|
||||
|
||||
def _fill(self):
|
||||
for enabled, regex in self.dialog.exclude_list:
|
||||
self.append(ExcludeListRow(self, enabled, regex))
|
||||
|
||||
# def remove(self):
|
||||
# super().remove(super().selected_rows)
|
||||
|
||||
# def _update_selection(self):
|
||||
# # rows = self.selected_rows
|
||||
# # self.dialog._select_rows(list(map(attrgetter("_dupe"), rows)))
|
||||
# self.dialog.remove_selected()
|
||||
|
||||
def refresh(self, refresh_view=True):
|
||||
"""Override to avoid keeping previous selection in case of multiple rows
|
||||
selected previously."""
|
||||
self.cancel_edits()
|
||||
del self[:]
|
||||
self._fill()
|
||||
# sd = self._sort_descriptor
|
||||
# if sd is not None:
|
||||
# super().sort_by(self, column_name=sd.column, desc=sd.desc)
|
||||
if refresh_view:
|
||||
self.view.refresh()
|
||||
|
||||
|
||||
class ExcludeListRow(Row):
|
||||
def __init__(self, table, enabled, regex):
|
||||
Row.__init__(self, table)
|
||||
self._app = table.app
|
||||
self._data = None
|
||||
self.enabled_original = enabled
|
||||
self.regex_original = regex
|
||||
self.enabled = str(enabled)
|
||||
self.regex = str(regex)
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
def get_display_info(row):
|
||||
return {"marked": row.enabled, "regex": row.regex}
|
||||
|
||||
if self._data is None:
|
||||
self._data = get_display_info(self)
|
||||
return self._data
|
||||
|
||||
@property
|
||||
def markable(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def marked(self):
|
||||
return self._app.exclude_list.is_marked(self.regex)
|
||||
|
||||
@marked.setter
|
||||
def marked(self, value):
|
||||
if value:
|
||||
self._app.exclude_list.mark(self.regex)
|
||||
else:
|
||||
self._app.exclude_list.unmark(self.regex)
|
||||
|
||||
# @property
|
||||
# def regex(self):
|
||||
# return self.regex
|
||||
|
||||
# @regex.setter
|
||||
# def regex(self, value):
|
||||
# self._app.exclude_list.add(self._regex, value)
|
||||
@@ -17,7 +17,7 @@ class IgnoreListDialog:
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.ignore_list = self.app.ignore_list
|
||||
self.ignore_list_table = IgnoreListTable(self)
|
||||
self.ignore_list_table = IgnoreListTable(self) # GUITable
|
||||
|
||||
def clear(self):
|
||||
if not self.ignore_list:
|
||||
|
||||
Reference in New Issue
Block a user