Skip to content

Commit c0678cd

Browse files
committed
Run code when the LoggerWindow instance is first crated
This lets an application integration configure the instance to better work with the application.
1 parent 25abe6e commit c0678cd

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

preditor/config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self):
4848
self._name = None
4949
self._logging = False
5050
self._headless_callback = None
51+
self._on_create_callback = None
5152
self._parent_callback = None
5253
self._error_dialog_class = True
5354
self._excepthooks = []
@@ -63,6 +64,7 @@ def dump(self, indent=0):
6364
f"{' ' * indent}logging: {self.logging}",
6465
f"{' ' * indent}headless_callback: {self.headless_callback!r}",
6566
f"{' ' * indent}parent_callback: {self.parent_callback!r}",
67+
f"{' ' * indent}on_create_callback: {self.on_create_callback!r}",
6668
]
6769
return '\n'.join(ret)
6870

@@ -233,6 +235,20 @@ def name(self, name):
233235
# If the core name was changed attempt to update the logging config.
234236
self.update_logging()
235237

238+
@property
239+
def on_create_callback(self):
240+
"""A pointer to a method that is called on LoggerWindow instance create.
241+
242+
This callback accepts the instance and can be used to customize the
243+
LoggerWindow instance when it is first created.
244+
"""
245+
return self._on_create_callback
246+
247+
@on_create_callback.setter
248+
@set_if_unlocked()
249+
def on_create_callback(self, cb):
250+
self._on_create_callback = cb
251+
236252
@property
237253
def parent_callback(self):
238254
"""A pointer to a method that is called by `self.root_window`.

preditor/gui/loggerwindow.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from .. import (
2929
DEFAULT_CORE_NAME,
3030
about_preditor,
31-
core,
31+
config,
3232
debug,
3333
get_core_name,
3434
osystem,
@@ -1338,18 +1338,16 @@ def instance(
13381338
parent, name=name, run_workbox=run_workbox, standalone=standalone
13391339
)
13401340

1341-
# RV has a Unique window structure. It makes more sense to not parent a
1342-
# singleton window than to parent it to a specific top level window.
1343-
if core.objectName() == 'rv':
1344-
inst.setParent(None)
1345-
inst.setAttribute(Qt.WA_QuitOnClose, False)
1346-
13471341
# protect the memory
13481342
inst.setAttribute(Qt.WA_DeleteOnClose, False)
13491343

13501344
# cache the instance
13511345
LoggerWindow._instance = inst
13521346

1347+
# Allow customization when the instance is first created.
1348+
if config.on_create_callback:
1349+
config.on_create_callback(inst)
1350+
13531351
return LoggerWindow._instance
13541352

13551353
def installLogToFile(self):

0 commit comments

Comments
 (0)