@@ -225,7 +225,7 @@ In that folder, QtVCP will load any of the available following files:
225225
226226There are _three ways_ to customize a screen/panel.
227227
228- . Minor StyleSheet Changes
228+ ==== Minor StyleSheet Changes
229229Stylesheets can be used to *set Qt properties*.
230230If a widget uses properties then they usually can be modified by stylesheets.
231231
@@ -239,8 +239,9 @@ State_LED #name_of_led{
239239 }
240240----
241241
242- . Minor Python Code Changes
242+ ==== Minor Python Code Changes
243243Another Python file can be used to *add commands* to the screen, after the handler file is parsed.
244+ This can be useful for minor changes while still honouring standard handler updates from linuxcnc repositoies.
244245
245246In the _INI file_ under the `[DISPLAY]` heading add *`USER_COMMAND_FILE = _PATH_`* +
246247
@@ -258,20 +259,78 @@ The default path is in the configuration directory as a hidden file using the sc
258259
259260This file will be read and executed as Python code in the *handler file context*.
260261
261- *Only local functions and local attributes* can be referenced.
262- Global libraries can not be referenced.
263- These are usually seen as all capital words with no preceding self.
262+ *Only local functions and local attributes* can be referenced. +
263+ Global libraries defined in the screen's handler file can be referenced but must be preceded with 'self.' +
264+ These are usually seen as all capital words with no preceding self. +
265+ 'self' references the window class +
266+ 'self.w' typically references the widgets
264267
265268What can be used can vary by screen and development cycle.
266269
267- For a valid example:
270+ .A simple example
271+ Reference the main window to change the title (Won't show if using INI entries for title change)
268272
269273[source,python]
270274----
271275self.w.setWindowTitle('My Title Test')
272276----
273277
274- .Full Creative Control
278+ .An advanced instance patching example
279+ This could work with the Qtdragon screen's handler file. +
280+ Here we show how to add new functions and override existing ones.
281+
282+ [source,python]
283+ ----
284+ # needed to instance patch
285+ # reference: https://ruivieira.dev/python-monkey-patching-for-readability.html
286+ import types
287+
288+ # This is actually an unbounded function with 'obj' as a parameter.
289+ # You call this function without the usual preceding 'self.'
290+ # This is because will will not be patching it into the original handler class instance
291+ # It will only be called from code in this file
292+ def test_function(obj):
293+ print(dir(obj))
294+
295+ # This is a new function we will added to the existing handler class instance.
296+ # Notice it calls the unbounded function with 'self' as an parameter
297+ # 'self' is the only global reference available. It references the window instance
298+ def on_keycall_F10(self,event,state,shift,cntrl):
299+ if state:
300+ print ('F10')
301+ test_function(self)
302+
303+ # This will be used to override an existing function in the existing handler class instance
304+ # note we also call a copy of the original function too
305+ # this shows how to extend an existing function to do extra functions
306+ def on_keycall_F11(self,event,state,shift,cntrl):
307+ if state:
308+ self.on_keycall_F11_super(event,state,shift,cntrl)
309+ print ('Hello')
310+
311+ # We are referencing the KEYBIND library that was instantiated in the
312+ # original handler class instance by adding 'self.' to it.
313+ # This function tells KEYBIND to call 'on_keycall_F10' when F10 is pressed
314+ self.KEYBIND.add_call('Key_F10','on_keycall_F10')
315+
316+ # Here we are instance patching the original handler file to add a new
317+ # function that calls our new function (of the same name)
318+ # defined in this file
319+ self.on_keycall_F10 = types.MethodType(on_keycall_F10, self)
320+
321+ # Here we are defining a copy of the original 'on_keycall_F11' function
322+ # so we can call it later. we can use any valid, unused function name.
323+ # We need to do this before overriding the original function.
324+ self.on_keycall_F11_super = self.on_keycall_F11
325+
326+ # Here we are instance patching the original handler file to override
327+ # an existing function to point to our new function (of the same name)
328+ # defined in this file
329+ self.on_keycall_F11 = types.MethodType(on_keycall_F11, self)
330+
331+ ----
332+
333+ ==== Full Creative Control with custom handler/ui files
275334If you wish to *modify a stock screen* with full control, _copy it's UI
276335and handler file to your configuration folder_.
277336
@@ -285,8 +344,9 @@ qtvcp copy_dialog
285344
286345* Select the screen and destination folder in the dialog
287346* If you wish to *name your screen* differently than the builtin screen's default name, change the _basename_ in the edit box.
347+ * There should be a folder in the config folder; for screens: named '<CONFIG FOLDER>/qtvcp/screens/' for panels: named '<CONFIG FOLDER>/qtvcp/panels/' add the folders if ther are missing and copy your folder/files in it.
288348* Validate to copy all the files
289- * Delete the files you don't wish to modifyso that the original files will be used.
349+ * Delete the files you don't wish to modify so that the original files will be used.
290350
291351[[sec:qtvcp:vcp-panels]]
292352== VCP Panels
0 commit comments