Skip to content

Commit ca06135

Browse files
committed
qtvcp -docs: add handler subclassing info for panels
1 parent ab14d0f commit ca06135

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

docs/src/gui/qtvcp-vcp-panels.adoc

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ EMBED_TAB_LOCATION=tabWidget_utilities
411411

412412
*'EMBED_TAB_NAME'*:: will typically be the title of the tab.
413413
*'EMBED_TAB_LOCATION'*:: will be specific to the screen and specifies the tabWidget or stackedWidget to embed into.
414-
*'EMBED_TAB_COMMAND'*:: is the command used to invoke loading of the panel. For native embedded panels the first word will always be 'qtvcp', the second will be the panel to load. You cannot currently add any switches to the command line. The panel will follow the debugging mode setting of the main screen.
414+
*'EMBED_TAB_COMMAND'*:: is the command used to invoke loading of the panel. For native embedded panels the first word will always be 'qtvcp', the last will be the panel name to load. You can also pass options to the panel with -o switches in the command line between 'qtvcp' and the panel name. The panel will follow the debugging mode setting of the main screen.
415415

416416
=== Location of builtin Panels
417417
There are panels available that are included with LinuxCNC. To see a list open a terminal and type 'qtvcp' and press return. +
@@ -465,5 +465,53 @@ When using Python command option in Action Button widgets of an embedded panel:
465465

466466
If the panel is not embedded, both refer to the panel window.
467467

468+
=== Handler Patching - Subclassing Builtin Panels
468469

470+
We can have QtVCP load a subclassed version of the standard handler file. in that file we can manipulate the original functions or add new ones. +
471+
Subclassing just means our handler file first loads the original handler file and adds our new code on top of it - so a patch of changes. +
472+
This is useful for changing/adding behaviour while still retaining standard handler updates from LinuxCNC repositories. +
473+
474+
You may still need to use the handler copy dialog to copy the original handler file to decide how to patch it.
475+
476+
There should be a folder in the config folder; for panel: named '<CONFIG FOLDER>/qtvcp/panels/<PANEL NAME>/' +
477+
add the handle patch file there, named like so <ORIGINAL PANEL NAME>_handler.py +
478+
ie for cam_align the file would be called 'cam_align_handler.py' +
479+
480+
Here is a sample to change the circle color in cam_align: +
481+
482+
[source,python]
483+
----
484+
import sys
485+
import os
486+
import importlib
487+
from PyQt5.QtCore import Qt
488+
from qtvcp.core import Path
489+
490+
PATH = Path()
491+
492+
# get reference to original handler file so we can subclass it
493+
sys.path.insert(0, PATH.PANELDIR)
494+
panel = os.path.splitext(os.path.basename(os.path.basename(__file__)))[0]
495+
base = panel.replace('_handler','')
496+
module = "{}.{}".format(base,panel)
497+
mod = importlib.import_module(module, PATH.PANELDIR)
498+
sys.path.remove(PATH.PANELDIR)
499+
HandlerClass = mod.HandlerClass
500+
501+
# return our subclassed handler object to Qtvcp
502+
def get_handlers(halcomp, widgets, paths):
503+
return [UserHandlerClass(halcomp, widgets, paths)]
504+
505+
# subclassed from HandlerClass which was imported above
506+
class UserHandlerClass(HandlerClass):
507+
print('Custom subclassed panel handler loaded\n')
508+
509+
def initialized__(self):
510+
# call original handler initialized function
511+
super().initialized__()
512+
513+
# add our customization
514+
self.w.camview.circle_color = Qt.green
515+
516+
----
469517
// vim: set syntax=asciidoc:

0 commit comments

Comments
 (0)