Skip to content

Commit 1a5d933

Browse files
committed
PR Notes
- Uniform font / gui font keyboard modifiers - Remove QRegExp (deprecated, QRegularExpression not supported byQt.py) - Identifier classes now subclass py3 enums - update attr check name - Add copy filename context menu item - Better linked file comparisons by with `pathlib.Path` instances (ie remove `as_posix()` - Cleanup doc strings
1 parent d9a44da commit 1a5d933

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

preditor/gui/drag_tab_bar.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import
22

3+
from enum import IntEnum
34
from functools import partial
45
from pathlib import Path
56

@@ -22,7 +23,7 @@
2223
from . import QtPropertyInit
2324

2425

25-
class TabStates:
26+
class TabStates(IntEnum):
2627
"""Nice names for the Tab states for coloring"""
2728

2829
Normal = 0
@@ -366,6 +367,9 @@ def tab_menu(self, pos, popup=True):
366367

367368
act = menu.addAction('Save As')
368369
act.triggered.connect(partial(self.save_and_link_file, workbox))
370+
371+
act = menu.addAction('Copy Filename')
372+
act.triggered.connect(partial(self.copyFilename, workbox))
369373
else:
370374
act = menu.addAction('Explore File')
371375
act.triggered.connect(partial(self.explore_file, workbox))
@@ -465,6 +469,15 @@ def unlink_file(self, workbox):
465469
name = self.parent().default_title
466470
self.setTabText(self._context_menu_tab, name)
467471

472+
def copyFilename(self, workbox):
473+
"""Copy the given workbox's filename to the clipboard
474+
475+
Args:
476+
workbox (WorkboxMixin): The workbox for which to provide the filename
477+
"""
478+
filename = workbox.__filename__()
479+
QApplication.clipboard().setText(filename)
480+
468481
def copy_workbox_name(self, workbox, index):
469482
"""Copy the workbox name to clipboard.
470483

preditor/gui/loggerwindow.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import warnings
1212
from builtins import bytes
1313
from datetime import datetime, timedelta
14+
from enum import IntEnum
1415
from functools import partial
1516
from pathlib import Path
1617

@@ -61,7 +62,7 @@
6162
PRUNE_PATTERN = re.compile(PRUNE_PATTERN)
6263

6364

64-
class WorkboxPages:
65+
class WorkboxPages(IntEnum):
6566
"""Nice names for the uiWorkboxSTACK indexes."""
6667

6768
Options = 0
@@ -521,7 +522,6 @@ def workbox_for_id(self, workbox_id, show=False, visible=False):
521522
to ensure that it is initialized and its text is loaded.
522523
visible (bool, optional): Make the this workbox visible if found.
523524
"""
524-
# pred = self.instance()
525525
workbox = None
526526
for box_info in self.uiWorkboxTAB.all_widgets():
527527
temp_box = box_info[0]
@@ -849,24 +849,24 @@ def setGuiFont(self, newSize=None, newFont=None):
849849
tabbar_class = current.tabBar().__class__
850850
menubar_class = self.menuBar().__class__
851851
label_class = self.uiStatusLBL.__class__
852-
children = self.findChildren(tabbar_class, QtCore.QRegExp(".*"))
853-
children.extend(self.findChildren(menubar_class, QtCore.QRegExp(".*")))
854-
children.extend(self.findChildren(label_class, QtCore.QRegExp(".*")))
855-
children.extend(self.findChildren(QToolButton, QtCore.QRegExp(".*")))
856-
children.extend(self.findChildren(QMenu, QtCore.QRegExp(".*")))
857-
children.extend(self.findChildren(QToolTip, QtCore.QRegExp(".*")))
852+
children = self.findChildren(tabbar_class, None)
853+
children.extend(self.findChildren(menubar_class, None))
854+
children.extend(self.findChildren(label_class, None))
855+
children.extend(self.findChildren(QToolButton, None))
856+
children.extend(self.findChildren(QMenu, None))
857+
children.extend(self.findChildren(QToolTip, None))
858858

859859
for child in children:
860+
if not hasattr(child, "setFont"):
861+
continue
860862
if newFont is None:
861863
newFont = child.font()
862864
if newSize is None:
863865
newSize = newFont.pointSize()
864866
newFont.setPointSize(newSize)
865867
child.setFont(newFont)
866-
# child.resize()
867868
self.setFont(newFont)
868869
QToolTip.setFont(newFont)
869-
# self.resize()
870870

871871
def setFontSize(self, newSize):
872872
"""Update the font size in the console and current workbox.
@@ -1045,8 +1045,6 @@ def setFileMonitoringEnabled(self, filename, state):
10451045
if not filename:
10461046
return
10471047

1048-
filename = Path(filename).as_posix()
1049-
10501048
if state:
10511049
self.openFileMonitor.addPath(filename)
10521050
else:
@@ -1065,9 +1063,8 @@ def fileMonitoringEnabled(self, filename):
10651063
if not filename:
10661064
return False
10671065

1068-
filename = Path(filename).as_posix()
1069-
watched_files = self.openFileMonitor.files()
1070-
return filename in watched_files
1066+
watched_files = [Path(file) for file in self.openFileMonitor.files()]
1067+
return Path(filename) in watched_files
10711068

10721069
def prefsPath(self, name='preditor_pref.json'):
10731070
"""Get the path to this core's prefs, for the given name
@@ -1089,10 +1086,9 @@ def linkedFileChanged(self, filename):
10891086
Args:
10901087
filename (str): The file which triggered the file changed signal
10911088
"""
1092-
prefs_path = Path(self.prefsPath()).as_posix()
10931089

10941090
# Either handle prefs or workbox
1095-
if filename == prefs_path:
1091+
if Path(filename) == Path(self.prefsPath()):
10961092
# First, save workbox prefs. Don't save preditor.prefs because that
10971093
# would just overwrite whatever changes we are responding to.
10981094
self.getBoxesChangedByInstance()
@@ -1171,6 +1167,10 @@ def recordPrefs(self, manual=False, disableFileMonitoring=False):
11711167
if not manual and not self.autoSaveEnabled():
11721168
return
11731169

1170+
# When applying a change to editor class, we may essentially auto-save
1171+
# prefs, in order to reload on the next class. In doing so, we may be
1172+
# changing workbox filename(s), if any, so let's remove them from file
1173+
# monitoring. They will be re-added during restorePrefs.
11741174
if disableFileMonitoring:
11751175
for editor_info in self.uiWorkboxTAB.all_widgets():
11761176
editor = editor_info[0]

preditor/gui/ui/loggerwindow.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ at the indicated line in the specified text editor.
10631063
<string>Increase Gui Font Size</string>
10641064
</property>
10651065
<property name="toolTip">
1066-
<string>..or Alt+Scroll Up</string>
1066+
<string>..or Ctrl+Alt+Scroll Up</string>
10671067
</property>
10681068
<property name="shortcut">
10691069
<string>Ctrl+Alt++</string>
@@ -1085,7 +1085,7 @@ at the indicated line in the specified text editor.
10851085
<string>Decrease Gui Font Size</string>
10861086
</property>
10871087
<property name="toolTip">
1088-
<string>..or Alt+Scroll Down</string>
1088+
<string>..or Ctrl+Alt+Scroll Down</string>
10891089
</property>
10901090
<property name="shortcut">
10911091
<string>Ctrl+Alt+-</string>

preditor/prefs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def get_file_group(core_name, workbox_id):
203203
workbox_id (str): The current workbox_id
204204
205205
Returns:
206-
TYPE: Description
206+
files (list): The list of files found for the given workbox_id
207207
"""
208208
directory = Path(get_prefs_dir(core_name=core_name, sub_dir='workboxes'))
209209
workbox_dir = directory / workbox_id
@@ -252,7 +252,7 @@ def get_backup_version_info(core_name, workbox_id, versionType, backup_file=None
252252
Args:
253253
core_name (str): The current core_name
254254
workbox_id (str): The current workbox_id
255-
versionType (TYPE): The VersionType (ie First, Previous, Next, Last)
255+
versionType (VersionType): The VersionType (ie First, Previous, Next, Last)
256256
backup_file (None, optional): The currently loaded backup file.
257257
258258
Returns:
@@ -312,9 +312,9 @@ def update_pref_args(core_name, pref_dict, old_name, update_data):
312312
313313
Args:
314314
core_name (str): The current core_name
315-
pref_dict (TYPE): The pref to update
316-
old_name (TYPE): Original pref name, which may be updated
317-
update_data (TYPE): Dict to define ways to update the values, which
315+
pref_dict (dict): The pref to update
316+
old_name (str): Original pref name, which may be updated
317+
update_data (str): Dict to define ways to update the values, which
318318
currently only supports str.replace.
319319
"""
320320
workbox_dir = Path(get_prefs_dir(core_name=core_name, create=True))
@@ -352,8 +352,8 @@ def update_prefs_args(core_name, prefs_dict, prefs_updates):
352352
353353
Args:
354354
core_name (str): The current core_name
355-
prefs_dict (TYPE): The PrEditor prefs to update
356-
prefs_updates (TYPE): The update definition dict
355+
prefs_dict (dict): The PrEditor prefs to update
356+
prefs_updates (dict): The update definition dict
357357
358358
Returns:
359359
prefs_dict (dict): The updated dict

0 commit comments

Comments
 (0)