Skip to content

Commit 94a4157

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 1403f70 commit 94a4157

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
@@ -522,7 +523,6 @@ def workbox_for_id(self, workbox_id, show=False, visible=False):
522523
to ensure that it is initialized and its text is loaded.
523524
visible (bool, optional): Make the this workbox visible if found.
524525
"""
525-
# pred = self.instance()
526526
workbox = None
527527
for box_info in self.uiWorkboxTAB.all_widgets():
528528
temp_box = box_info[0]
@@ -850,24 +850,24 @@ def setGuiFont(self, newSize=None, newFont=None):
850850
tabbar_class = current.tabBar().__class__
851851
menubar_class = self.menuBar().__class__
852852
label_class = self.uiStatusLBL.__class__
853-
children = self.findChildren(tabbar_class, QtCore.QRegExp(".*"))
854-
children.extend(self.findChildren(menubar_class, QtCore.QRegExp(".*")))
855-
children.extend(self.findChildren(label_class, QtCore.QRegExp(".*")))
856-
children.extend(self.findChildren(QToolButton, QtCore.QRegExp(".*")))
857-
children.extend(self.findChildren(QMenu, QtCore.QRegExp(".*")))
858-
children.extend(self.findChildren(QToolTip, QtCore.QRegExp(".*")))
853+
children = self.findChildren(tabbar_class, None)
854+
children.extend(self.findChildren(menubar_class, None))
855+
children.extend(self.findChildren(label_class, None))
856+
children.extend(self.findChildren(QToolButton, None))
857+
children.extend(self.findChildren(QMenu, None))
858+
children.extend(self.findChildren(QToolTip, None))
859859

860860
for child in children:
861+
if not hasattr(child, "setFont"):
862+
continue
861863
if newFont is None:
862864
newFont = child.font()
863865
if newSize is None:
864866
newSize = newFont.pointSize()
865867
newFont.setPointSize(newSize)
866868
child.setFont(newFont)
867-
# child.resize()
868869
self.setFont(newFont)
869870
QToolTip.setFont(newFont)
870-
# self.resize()
871871

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

1049-
filename = Path(filename).as_posix()
1050-
10511049
if state:
10521050
self.openFileMonitor.addPath(filename)
10531051
else:
@@ -1066,9 +1064,8 @@ def fileMonitoringEnabled(self, filename):
10661064
if not filename:
10671065
return False
10681066

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

10731070
def prefsPath(self, name='preditor_pref.json'):
10741071
"""Get the path to this core's prefs, for the given name
@@ -1090,10 +1087,9 @@ def linkedFileChanged(self, filename):
10901087
Args:
10911088
filename (str): The file which triggered the file changed signal
10921089
"""
1093-
prefs_path = Path(self.prefsPath()).as_posix()
10941090

10951091
# Either handle prefs or workbox
1096-
if filename == prefs_path:
1092+
if Path(filename) == Path(self.prefsPath()):
10971093
# First, save workbox prefs. Don't save preditor.prefs because that
10981094
# would just overwrite whatever changes we are responding to.
10991095
self.getBoxesChangedByInstance()
@@ -1172,6 +1168,10 @@ def recordPrefs(self, manual=False, disableFileMonitoring=False):
11721168
if not manual and not self.autoSaveEnabled():
11731169
return
11741170

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