4.2.6. Adding a Dock Widget and Logs Widget
So far, all what we have used comes from the CUT, Qt of Taurus libraries. Now we will introduce a widget that comes from the CII elt-qt-widgets collection: the LogsWidget.
This widget monitors and gather new logs in a specific directory. The directory is determined either by configuration of the widget, or by its defaults priority list:
CII_LOGS
environment variable$INTROOT/logsink
/etc/ciisrv/logsink
It will monitor every file in that directory, and present the most recent entries ordered by date.
This is the design we want to achieve:
This new design has a Dock Widget and a LogsWidget.
4.2.6.1. Dock Widget
QDockWidget are a special kind of widgets. They are capable of floating separately fromm the QMainWindow, and by default are tied to one of the borders of the QMainWindow.
Note
QDockWidget are not dialogs and do not start a separate QEventLoop.
We start by dragging a Dock Widget from the Widget Box on top of the MainWindow. While in the drag and drop operation, you will see that Qt Designer will always select for you the whole MainWindow as its intended drop target. The default starting position of the QDockWidget can be select from its dockWidgetArea property. Using the Property Editor in the Designer, look for the dockWidgetArea property and set it to BottomDockWidgetArea. Taking the oportunity, change as well the windowTitle property to Logs.
4.2.6.2. Logs Widget
This widget is very simple to use. Just drag a new LogsWidget from the Widget Toolbox, and place it inside the Dock Widget. Now please set a layout right clicking on any empty area of the Dock Widget and select the entry in the .
A closer look at the GUI, will reveal that there is extra margins around the widget that do not match the upper section section of the GUI. This is due to the fact that the QDockWidget and the Layout both introduces Margins. Please remove the margins on the Vertical Layout by selecting it from the Object Inspector, and then use the Property Editor and set to 0 these 5 properties:
layoutLeftMargin
layoutRightMargin
layoutTopMargin
layoutBottomMargin
layoutSpacing
As mentioned before, the LogsWidget will monitor the default directory, or the one set in the directory property. LogsWidget works without any extra programming.
LogsWidget ships with CII services and since python looks dynamically for its library on runtime this example will just work. But it is good practice to check in the configure() section of the project’s wscript for the python module. Please introduce this line in the project’s wscript.
cnf.check_python_module('CiiWidgets')
4.2.6.3. Trying it out
An easy way to test it, would be to use the logSend application from CII Logging services. Use a terminal, and type the following commands.
$ logSend "Hello World!"
$ logSend "Hello World!" -lt "TRACE"
$ logSend "Hello World!" -lt "DEBUG"
$ logSend "Hello World!" -lt "INFO"
$ logSend "Hello World!" -lt "WARN"
$ logSend "Hello World!" -lt "ERROR"
$ logSend "Hello World!" -lt "FATAL"
If you repeat this lines, over and over, you will see that the LogWidget will autoscroll to the latest entry. This is useful, but not for every case. If you right click on the entries of the table, a context menu will appear. The Autoscroll to end entry is on by default. Click it, to turn it off. This will allow you to browse the table with ease while receiving new entries.
On the other hand, if you do not want to received new entries, select the context menu entry Pause. This will pause the LogsWidget from adding new entries to the table. Continue will allow you to go back to the normal behavior.
You can also show and hide the default and extra columns. For example with this logSend command, we will add additional contents to an error log.
$ logSend "Hello World!" -lt "ERROR" -em "This is an intentional error"
This extra information is not shown by default. You can right click on the header of the Table, and select Error Message context menu entry to show it.
You can also resize and reorder the colums, by using the drag and drop operation on the headers of the table. The last column will always strecht to the rest of the available space.
You can also use the LogsWidget as a standalone application using the command line tool qt-widgets-log-demo.