11.5. Discussion of cameraWindow.py¶
This section provides additional explanation to the demo script cameraWindow.py provided with itom. The demo script shows integrated use of basic grabber functionality. Additional informations on how to use grabbers is found in Getting started with grabbers.
11.5.1. Purpose¶
cameraWindow.py, along with the ui file cameraWindow.ui defines a set of functions, connects them to GUI buttons and hereby provides the functionality to view live images, change integration times, toggle autograbbing and take snapshots.
Some sections are discussed in more detail than others. However, the complete python code is printed on the bottom of this page.
11.5.2. GUI overview¶
The GUI is build in QT designer. It basically consist of an Itom2dQwtPlot widget, two QPushButtons for showing live images or taking snapshots, three QRadioButtons for different integration times and a QCheckBox for toggling autograbbing.
11.5.3. Script overview¶
11.5.3.1. Init grabber¶
The script uses a dummyGrabber, assigned to handle cam. Every other 2D grabber may be used instead.
2 | cam = dataIO("DummyGrabber")
|
11.5.3.2. Create GUI instance¶
Next, an GUI instance named win is opend using the file cameraWindow.ui. As ui type, ui.TYPEWINDOW is chosen, which is the simplest type. Keyword childOfMainWindow = True sets the GUI to be a child of our main GUI.
4 | win = ui("cameraWindow.ui", ui.TYPEWINDOW, childOfMainWindow = True)
|
11.5.3.3. Define functions¶
Now, four functions are defined, which will later be connected to GUI items and provide their functionality.
11.5.3.3.1. Change integration time¶
The funtion integrationTime_changed checks the current state of the 3 radio buttons indicating the desired integration time and sets the correspondent value using the the plugin parameter integration_time. It will later be connected to click-events of the radio buttons.
6 7 8 9 10 11 12 | def integrationTime_changed():
if(win.radioInt1["checked"]):
cam.setParam("integration_time", 0.005)
elif(win.radioInt2["checked"]):
cam.setParam("integration_time", 0.010)
else:
cam.setParam("integration_time", 0.060)
|
11.5.3.3.2. Toggle autograbbing¶
autoGrabbing_changed is to be connected to change events of the checkbox. It toggles autograbbing according the check status.
14 15 16 17 18 | def autoGrabbing_changed(checked):
if(checked):
cam.enableAutoGrabbing()
else:
cam.disableAutoGrabbing()
|
11.5.3.3.3. Take a snapshot¶
The function snap will be connected to the snap push button, It triggers and displays a snapshot. This requires multiple steps:
Create a dataObject
Start the grabber
Acquire image
Require image
Provide snapshot for display
Stop the grabber
Additionally, this function checks whether autograbbing is disabled or not, pauses it if neccessary and restores the initial status after taking the snapshot.
20 21 22 23 24 25 26 27 28 29 30 | def snap():
d = dataObject()
cam.startDevice()
autoGrabbingStatus = cam.getAutoGrabbing()
cam.disableAutoGrabbing()
cam.acquire()
cam.getVal(d)
win.plot["source"] = d
if(autoGrabbingStatus):
cam.enableAutoGrabbing()
cam.stopDevice()
|
11.5.3.3.4. Live plot¶
live provides a live image of the grabber for the plot window. It will be called by pressing the live push button.
32 33 | def live():
win.plot["camera"] = cam
|
11.5.3.4. Wire the GUI¶
Now that all functions are defined, the signals of the GUI items have to be wired to their respectice function’s slots: * Clicking on one the radio buttons will call integrationTime_changed * Clicking the snapshot button will clal snap * Clicking the live button will call live * Clicking the autograbbing check box will call autoGrabbing_changed and submit the actual check status
36 37 38 39 40 41 42 43 | win.radioInt1.connect("clicked()", integrationTime_changed)
win.radioInt2.connect("clicked()", integrationTime_changed)
win.radioInt3.connect("clicked()", integrationTime_changed)
win.btnSnap.connect("clicked()", snap)
win.btnLive.connect("clicked()", live)
win.checkAutoGrabbing.connect("clicked(bool)", autoGrabbing_changed)
|
11.5.3.5. Init values for GUI elements¶
As init values, we check for the current autograbbing status and select the 0.005s radio button.
46 47 | win.checkAutoGrabbing["checked"] = cam.getAutoGrabbing()
win.radioInt1["checked"] = True
|
11.5.3.6. Let the show begin¶
Now, all we have left to do is make the GUI visible. Parameter 0 indicates, that our GUI will be modal.
49 | win.show(0)
|
11.5.4. Complete script¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #open dummy camera
cam = dataIO("DummyGrabber")
win = ui("cameraWindow.ui", ui.TYPEWINDOW, childOfMainWindow = True)
def integrationTime_changed():
if(win.radioInt1["checked"]):
cam.setParam("integration_time", 0.005)
elif(win.radioInt2["checked"]):
cam.setParam("integration_time", 0.010)
else:
cam.setParam("integration_time", 0.060)
def autoGrabbing_changed(checked):
if(checked):
cam.enableAutoGrabbing()
else:
cam.disableAutoGrabbing()
def snap():
d = dataObject()
cam.startDevice()
autoGrabbingStatus = cam.getAutoGrabbing()
cam.disableAutoGrabbing()
cam.acquire()
cam.getVal(d)
win.plot["source"] = d
if(autoGrabbingStatus):
cam.enableAutoGrabbing()
cam.stopDevice()
def live():
win.plot["camera"] = cam
#initialize all signal/slots
win.radioInt1.connect("clicked()", integrationTime_changed)
win.radioInt2.connect("clicked()", integrationTime_changed)
win.radioInt3.connect("clicked()", integrationTime_changed)
win.btnSnap.connect("clicked()", snap)
win.btnLive.connect("clicked()", live)
win.checkAutoGrabbing.connect("clicked(bool)", autoGrabbing_changed)
#initialize gui elements
win.checkAutoGrabbing["checked"] = cam.getAutoGrabbing()
win.radioInt1["checked"] = True
win.show(0)
|