Thursday, April 09, 2009

GNUmed plugin development - part 7

Now on to the real stuff. Looking at

class gmCardiacDevicePlugin(gmPlugin.cNotebookPlugin):

        def GetWidget (self, parent):
                self._widget = gmMedDocWidgets.cSelectablySortedDocTreePnl(parent, -1)
                return self._widget
in tells me that in the case of the Document archive plugin we borrowed from the class cSelectablySortedDocTreePnl is located in the file gmMedDocWidgets. The name implies that this is a collection of classes of medical document widgets. The device parameters are essentially measurements.

There is a file called gmMeasurementWidgets available and I am going to extend that one. I added a class cCardiacDeviceMeasurementsPnl to the file just before the __main__ statement.

class cCardiacDeviceMeasurementsPnl(wxgCardiacDevicePluginPnl.wxgCardiacDevicePluginPnl, gmRegetMixin.cRegetOnPaintMixin):

        """Panel holding a number of widgets to manage implanted cardiac devices. Used as notebook page."""

        def __init__(self, *args, **kwargs):

                wxgCardiacDevicePluginPnl.wxgCardiacDevicePluginPnl.__init__(self, *args, **kwargs)
        # event handling

An extended import is needed as well.

from Gnumed.wxGladeWidgets import wxgMeasurementsPnl, wxgMeasurementsReviewDlg
from Gnumed.wxGladeWidgets import wxgMeasurementEditAreaPnl
from Gnumed.wxGladeWidgets import wxgCardiacDevicePluginPnl

Now back to to reflect the changes.

class gmCardiacDevicePlugin(gmPlugin.cNotebookPlugin):

        def GetWidget (self, parent):
                self._widget = gmMeasurementWidgets.cCardiacDeviceMeasurementsPnl(parent, -1)
                return self._widget

A change in the import statements is needed here too.
from Gnumed.wxpython import gmMeasurementWidgets, gmPlugin
instead of

from Gnumed.wxpython import gmMedDocWidgets, gmPlugin, images_Archive_plugin
If you followed the above steps you might notice that the plugin throws many errors in the file gnumed.log. This file can be viewed directly from within GNUmed. It does not show up. The reason is simple. I use a complex set of widgets that are scattered across the files gmMeasurementWidgets and gmNarrativeWidgets.

The errors are that widgets found in gmNarrativeWidgets are not found, most likely because I put the class cCardiacDeviceMeasurementsPnl(parent, -1) in gmMeasurementWidgets. It could help to move the class into narrative widgets but that is not what I want. I could as well start another file called gmDeviceWidgets.

Lets see what the mailing list has to say about that.

What I have learned so far. First I need to create a mockup gui, store it in the wxg directory, create python code from it and store it in the directory wxGladeWidgets. Then in the wxpython/gui directory a file called gmPluginName is needed. When created from scratch or copied over from a template make sure to have the class name reflect the filename, the tab name set and the menu entry configured.  Last but not least the GetWidget line needs to be filled to reflect what GUI code to load.

No comments: