Skip to content

Commit 2f9c57c

Browse files
authored
Merge pull request #2161 from smoe/docs29_mac_5_equiv_to_PR_against_master
docs29_mac_5
2 parents 22cc930 + 74d6ea0 commit 2f9c57c

7 files changed

Lines changed: 295 additions & 484 deletions

docs/src/gui/qtvcp-code-snippets.adoc

Lines changed: 79 additions & 137 deletions
Large diffs are not rendered by default.

docs/src/gui/qtvcp-custom-widgets.adoc

Lines changed: 44 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@
66

77
== Overview
88

9-
Building custom widgets allows one to *use the Qt Designer editor to
10-
place a custom widget* _rather than doing it manually in a handler file_.
9+
Building custom widgets allows one to *use the Qt Designer editor to place a custom widget*
10+
_rather than doing it manually in a handler file_.
1111

12-
A useful custom widgets would be a great way to contribute back to
13-
LinuxCNC.
12+
A useful custom widgets would be a great way to contribute back to LinuxCNC.
1413

1514
=== Widgets
1615

17-
*Widget* is the _general name for the UI objects_ such as buttons and
18-
labels in PyQt.
16+
*Widget* is the _general name for the UI objects_ such as buttons and labels in PyQt.
1917

20-
There are also *special widgets made for LinuxCNC* that make integration
21-
easier.
18+
There are also *special widgets made for LinuxCNC* that make integration easier.
2219

23-
All these widgets can be _placed with Qt Designer editor_ - allowing one
24-
to _see the result_ before actually loading the panel in LinuxCNC.
20+
All these widgets can be _placed with Qt Designer editor_ - allowing one to _see the result_
21+
before actually loading the panel in LinuxCNC.
2522

2623
=== Qt Designer
2724

@@ -31,15 +28,13 @@ placing PyQt widgets_.
3128
It's original intend was for building the graphic widgets for programs. +
3229
We leverage it to *build screens and panels for LinuxCNC*.
3330

34-
In Qt Designer, on the left side of the editor, you find *three
35-
categories of LinuxCNC widgets*:
31+
In Qt Designer, on the left side of the editor, you find *three categories of LinuxCNC widgets*:
3632

3733
* _HAL only widgets_.
3834
* _LinuxCNC controller widgets_.
3935
* _dialog widgets_.
4036

41-
For Qt Designer to _add custom widgets_ to it's editor it must have a
42-
*plugin* added to the right folder.
37+
For Qt Designer to _add custom widgets_ to it's editor it must have a *plugin* added to the right folder.
4338

4439
//FIXME Aren't the following two sub-sections duplicates of the 'startup
4540
// to shutdown section in qtvcp-development.adoc ?
@@ -57,24 +52,19 @@ This includes:
5752
* Calling an _extra setup function_
5853
* Calling a _closing cleanup function_ at shutdown.
5954

60-
These functions are not called when the Qt Designer editor displays the
61-
widgets.
55+
These functions are not called when the Qt Designer editor displays the widgets.
6256

6357
When QtVCP builds a screen from the `.ui` file:
6458

6559
. It searches for all the HAL-ified widgets.
66-
. It finds the `ScreenOptions` widget, to collect information it needs
67-
to inject into the other widgets
68-
. It instantiates each widget and if it is a HAL-ified widget, calls the
69-
`hal_init()` function. +
60+
. It finds the `ScreenOptions` widget, to collect information it needs to inject into the other widgets
61+
. It instantiates each widget and if it is a HAL-ified widget, calls the `hal_init()` function. +
7062
*`hal_init()`* is defined in the base class and it:
7163
.. Adds variables such as the preference file to every HAL-ified widget.
7264
.. Call `+_hal_init()+` on the widget. +
73-
`+_hal_init()+` allows the widget designer to do setup that requires
74-
access to the extra variables.
65+
`+_hal_init()+` allows the widget designer to do setup that requires access to the extra variables.
7566

76-
Here is a description of the extra variables injected into "HAL-ified"
77-
widgets:
67+
Here is a description of the extra variables injected into "HAL-ified" widgets:
7868

7969
*`self.HAL_GCOMP`*:: The _HAL component instance_
8070
*`self.HAL_NAME`*:: This _widget's name_ as a string
@@ -86,16 +76,13 @@ widgets:
8676

8777
=== cleanup process
8878

89-
When QtVCP closes, it calls the *`+_hal_cleanup()+`* function
90-
_on all HAL-ified widgets_.
79+
When QtVCP closes, it calls the *`+_hal_cleanup()+`* function _on all HAL-ified widgets_.
9180

92-
The base class creates an empty `+_hal_cleanup()+` function, which can
93-
be redefined in the custom widget subclass.
81+
The base class creates an empty `+_hal_cleanup()+` function, which can be redefined in the custom widget subclass.
9482

9583
This can be used to do such things as record preferences, etc.
9684

97-
This function is not called when the Qt Designer editor displays the
98-
widgets.
85+
This function is not called when the Qt Designer editor displays the widgets.
9986

10087
== Custom HAL Widgets
10188

@@ -127,8 +114,7 @@ In this case we need access to:
127114
<3> QtVCP's widget `baseclass` 's *`_HalSensitiveBase`* for _automatic
128115
HAL pin setup_ and to _disable/enable the widget_ (also known as
129116
input sensitivity). +
130-
There is also `_HalToggleBase`, and `_HalScaleBase` functions
131-
available in the library.`_HalToggleBase`, and `_HalScaleBase`
117+
There is also `_HalToggleBase`, and `_HalScaleBase` functions available in the library.`_HalToggleBase`, and `_HalScaleBase`.
132118
//TODO explain `_HalToggleBase` and `_HalScaleBase` too
133119

134120
.In the 'WIDGET' section
@@ -169,14 +155,11 @@ Line by Line:
169155

170156
== Custom Controller Widgets Using `STATUS`
171157

172-
Widget that interact with LinuxCNC's controller are only a little more
173-
complicated and they require some _extra libraries_.
158+
Widget that interact with LinuxCNC's controller are only a little more complicated and they require some _extra libraries_.
174159

175-
In this cut down example we will add properties that can be changed in
176-
Qt Designer.
160+
In this cut down example we will add properties that can be changed in Qt Designer.
177161

178-
This LED indicator widget will respond to selectable LinuxCNC controller
179-
states.
162+
This LED indicator widget will respond to selectable LinuxCNC controller states.
180163

181164
//TODO Link external file for code block content, or as a linked asset to
182165
// strip the looong listing as it is detailed chunk by chunk beneath ?
@@ -293,11 +276,9 @@ STATUS = Status()
293276
----
294277

295278
Typically we instantiated the library _outside of the widget class_ so
296-
that the reference to it is *global* - meaning you don't need to use
297-
`self.` in front of it.
279+
that the reference to it is *global* - meaning you don't need to use `self.` in front of it.
298280

299-
By convention we use _all capital_ letters in the name for global
300-
references.
281+
By convention we use _all capital_ letters in the name for global references.
301282

302283
=== In The 'Custom Widget Class Definition' Section
303284

@@ -316,13 +297,10 @@ class StateLed(LED): # <1>
316297
self.invert_state = False
317298
----
318299

319-
<1> Defines the *name* _of our custom widget_ and what other _class it
320-
inherits from_. +
321-
In this case we inherit `LED` - a QtVCP widget that represents a
322-
status light.
300+
<1> Defines the *name* _of our custom widget_ and what other _class it inherits from_. +
301+
In this case we inherit `LED` - a QtVCP widget that represents a status light.
323302
<2> Typical of most widgets - called when the widget is first made.
324-
<3> Typical of most widgets - calls the parent (super) widget
325-
initialization code.
303+
<3> Typical of most widgets - calls the parent (super) widget initialization code.
326304
+
327305
Then we set some attributes:
328306

@@ -343,22 +321,18 @@ The other attributes are for the selectable options of our widget.
343321
STATUS.connect('state-off', lambda w:self._flip_state(False))
344322
----
345323

346-
This function connects `STATUS` (LinuxCNC status message library) to our
347-
widget so that the LED will on or off based on the selected state of the
348-
controller.
324+
This function connects `STATUS` (LinuxCNC status message library) to our widget,
325+
so that the LED will on or off based on the selected state of the controller.
349326

350327
We have two states we can choose from `is_estopped` or `is_on`. +
351-
Depending on which is active our widget get connected to the appropriate
352-
STATUS messages.
328+
Depending on which is active our widget get connected to the appropriate STATUS messages.
353329

354330
*`+_hal_init()+`* is _called on each widget that inherits_ `+_HalWidgetBase+`,
355331
when QtVCP first builds the screen. +
356-
You might wonder why it's called on this widget since we didn't have
357-
`+_HalWidgetBase+` in our class definition (`class Lcnc_State_Led(Lcnc_Led):`) -
332+
You might wonder why it's called on this widget since we didn't have `+_HalWidgetBase+` in our class definition (`class Lcnc_State_Led(Lcnc_Led):`) -
358333
it's called because `Lcnc_Led` inherits `+_HalWidgetBase+`.
359334

360-
In this function you have access to some extra information (though we
361-
don't use them in this example):
335+
In this function you have access to some extra information (though we don't use them in this example):
362336

363337
*`self.HAL_GCOMP`*:: the _HAL component_ instance
364338
*`self.HAL_NAME`*:: This _widget's name_ as a string
@@ -368,28 +342,23 @@ don't use them in this example):
368342
*`self.PREFS_`*:: the _instance of an optional preference file_
369343
*`self.SETTINGS_`*:: the `Qsettings` _object_
370344

371-
We could use this information to create HAL pins or look up image paths
372-
etc.
345+
We could use this information to create HAL pins or look up image paths etc.
373346

374347
[source,python]
375348
----
376-
STATUS.connect('state-estop', lambda w:self._flip_state(True))
349+
STATUS.connect('state-estop', lambda w:self._flip_state(True))
377350
----
378351

379352
Lets look at this line more closely:
380353

381354
* `STATUS` is very common theme is widget building. +
382-
`STATUS` uses `GObject` message system to send messages to widgets
383-
that register to it. +
355+
`STATUS` uses `GObject` message system to send messages to widgets that register to it. +
384356
This line is the registering process.
385-
* `state-estop` is the message we wish to listen for and act on. There
386-
are many messages available.
387-
* `lambda w:self._flip_state(True)` is what happens when the message is
388-
caught. +
389-
The lambda function accepts the widget instance (`w`) that GObject sends
390-
it and then calls the function `self._flip_state(True)`. +
391-
Lambda was used to strip the (`w`) object before calling the
392-
`self._flip_state` function. +
357+
* `state-estop` is the message we wish to listen for and act on.
358+
There are many messages available.
359+
* `lambda w:self._flip_state(True)` is what happens when the message is caught. +
360+
The lambda function accepts the widget instance (`w`) that GObject sends it and then calls the function `self._flip_state(True)`. +
361+
Lambda was used to strip the (`w`) object before calling the `self._flip_state` function. +
393362
It also allowed use to send `self._flip_state()` the True state.
394363

395364
[source,python]
@@ -594,8 +563,7 @@ It's possible to *have widgets restyled when events change*.
594563
You must explicitly _"polish" the widget_ to have PyQt redo the style. +
595564
This is a relatively expensive function so should be used sparingly.
596565

597-
This example sets an `isHomed` property based on LinuxCNC's homed
598-
state and in turn uses it to change stylesheet properties:
566+
This example sets an `isHomed` property based on LinuxCNC's homed state and in turn uses it to change stylesheet properties:
599567

600568
.This example will set the property isHomed based on LinuxCNC's homed state.
601569
[source,python]
@@ -633,10 +601,8 @@ class HomeLabel(QLabel, _HalWidgetBase):
633601

634602
Here is a sample stylesheet to change text color based on home state.
635603

636-
In this case any widget based on the HomeLabel widget above will change
637-
text color. +
638-
You would usually pick specific widgets using
639-
`HomeLabel #specific_widget_name[homed=true]`:
604+
In this case any widget based on the HomeLabel widget above will change text color. +
605+
You would usually pick specific widgets using `HomeLabel #specific_widget_name[homed=true]`:
640606

641607
[source,{css}]
642608
----
@@ -681,8 +647,7 @@ We must _register our custom widget_ for Qt Designer to use them. +
681647

682648
Here are a typical samples. +
683649
They would need to be added to `qtvcp/plugins/` +
684-
Then `qtvcp/plugins/qtvcp_plugin.py` would need to be adjusted to
685-
_import_ them.
650+
Then `qtvcp/plugins/qtvcp_plugin.py` would need to be adjusted to _import_ them.
686651

687652
//FIXME split samples below in independent py files and simply link them
688653
// as they're not documented, or possibly include them if we really
@@ -780,8 +745,7 @@ class SystemToolButtonPlugin(QPyDesignerCustomWidgetPlugin):
780745

781746
=== Making a plugin with a MenuEntry dialog box
782747

783-
It possible to add an entry to the dialog that pops up when you right
784-
click the widget in the layout.
748+
It possible to add an entry to the dialog that pops up when you right click the widget in the layout.
785749

786750
This can do things such as selecting options in a more convenient way.
787751

docs/src/gui/qtvcp-development.adoc

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@ By providing a _diverse widget_ set and supporting _custom coding_,
1212
QtVCP hopes that development energy will be expended in _one toolkit_
1313
rather than continuous re-invention.
1414

15-
By using the same toolkit across many screens/panels users should have
16-
an easier time customizing/creating these, and developers should find it
17-
easier to help trouble shoot with less effort.
15+
By using the same toolkit across many screens/panels,
16+
users should have an easier time customizing/creating these,
17+
and developers should find it easier to help trouble shoot with less effort.
1818

1919
QtVCP uses a *Qt Designer built `.ui` file* and a *Python handler file*
20-
to *load and control a screen/panel that displays Qt widgets* to *control
21-
LinuxCNC's motion controller or HAL pins*.
2220

23-
There are _builtin screens and panels_, easily loaded by a user, or
24-
users can build/modify one of their own.
21+
* to *load and control a screen/panel that displays Qt widgets* and
22+
* to *control LinuxCNC's motion controller or HAL pins*.
2523

26-
QtVCP uses *libraries and custom widgets* to hide some of the complexity
27-
of interfacing to LinuxCNC. By using QtVCP's library rather than
28-
LinuxCNC's, we can mitigate minor LinuxCNC code changes.
24+
There are _builtin screens and panels_, easily loaded by a user, or users can build/modify one of their own.
25+
26+
QtVCP uses *libraries and custom widgets* to hide some of the complexity of interfacing to LinuxCNC.
27+
By using QtVCP's library rather than LinuxCNC's, we can mitigate minor LinuxCNC code changes.
2928

3029
== Builtin Locations
3130

@@ -35,8 +34,7 @@ Builtin screens and panels are stored in separate folders:
3534
* _Panels_ in `share/qtvcp/panels`
3635
* _Stock images_ in `share/qtvcp/images`
3736

38-
Screens and panels are sorted by their folder name, which is
39-
also the name used to load them.
37+
Screens and panels are sorted by their folder name, which is also the name used to load them.
4038

4139
Inside the folder would be:
4240

@@ -46,8 +44,7 @@ Inside the folder would be:
4644

4745
== QtVCP Startup To Shutdown
4846

49-
*QtVCP source* is located in `+src/emc/usr_intf/qtvcp+` folder of
50-
LinuxCNC source tree.
47+
*QtVCP source* is located in `+src/emc/usr_intf/qtvcp+` folder of LinuxCNC source tree.
5148

5249
=== QtVCP Startup
5350

@@ -83,8 +80,7 @@ Finally when QtVCP is asked to shutdown:
8380

8481
When QtVCP loads it collects paths information.
8582

86-
This is available in the handler file's `+__init__()+` function
87-
as *`path`*:
83+
This is available in the handler file's `+__init__()+` function as *`path`*:
8884

8985
*`IMAGEDIR`*:: Path of builtin images
9086
*`SCREENDIR`*:: Path of builtin motion controller screens
@@ -110,8 +106,7 @@ These try to cover non-obvious situations.
110106

111107
When read, it is *'consumed'*, i.e. _no other object can read it_.
112108

113-
In QtVCP screens, it is recommended to _use the_ `ScreenOptions`
114-
_widget to set up error reading_.
109+
In QtVCP screens, it is recommended to _use the_ `ScreenOptions` _widget to set up error reading_.
115110

116111
_Errors are then *sent to other objects* via_ *`STATUS`* _signals_.
117112

0 commit comments

Comments
 (0)