Skip to content

Commit

Permalink
Combine capture/try again button and disable ‘OK’ until frame is capt…
Browse files Browse the repository at this point in the history
…ured.
  • Loading branch information
astrofrog committed Mar 26, 2015
1 parent 7f4d225 commit 0d8d32f
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 82 deletions.
25 changes: 20 additions & 5 deletions glue-exp/importers/webcam/webcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,26 @@ def __init__(self):
self.pil_image = None
self.ui = loadUi(UI_FILE, self)
self._webcam_preview = WebcamView()
self.ui.image.addWidget(self._webcam_preview)
self.ui.capture.clicked.connect(self._webcam_preview.freeze)
self.ui.again.clicked.connect(self._webcam_preview.resume)
self.ui.cancel.clicked.connect(self.reject)
self.ui.ok.clicked.connect(self.finalize)
self.image.addWidget(self._webcam_preview)
self.capture.clicked.connect(self.flip_capture_button)
self.cancel.clicked.connect(self.reject)
self.ok.clicked.connect(self.finalize)
self.ok.setEnabled(False)
self.capture.setDefault(True)

def flip_capture_button(self):
if self._webcam_preview._frozen:
self._webcam_preview.resume()
self.capture.setText("Capture")
self.capture.setDefault(True)
self.ok.setEnabled(False)
else:
self._webcam_preview.freeze()
self.capture.setText("Try again")
self.capture.setDefault(False)
self.ok.setEnabled(True)
self.ok.setDefault(True)


def finalize(self):
self.pil_image = Image.fromarray(self._webcam_preview._frame[:,:,::-1])
Expand Down
164 changes: 87 additions & 77 deletions glue-exp/importers/webcam/webcam.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,88 +6,98 @@
<rect>
<x>0</x>
<y>0</y>
<width>518</width>
<height>493</height>
<width>529</width>
<height>506</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>501</width>
<height>371</height>
</rect>
</property>
<layout class="QVBoxLayout" name="image"/>
</widget>
<widget class="QPushButton" name="capture">
<property name="geometry">
<rect>
<x>150</x>
<y>390</y>
<width>114</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Capture</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
</widget>
<widget class="QPushButton" name="cancel">
<property name="geometry">
<rect>
<x>290</x>
<y>460</y>
<width>114</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton" name="ok">
<property name="geometry">
<rect>
<x>400</x>
<y>460</y>
<width>114</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>OK</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="again">
<property name="geometry">
<rect>
<x>260</x>
<y>390</y>
<width>114</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Try Again</string>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="image"/>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="capture">
<property name="text">
<string>Capture</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ok">
<property name="text">
<string>OK</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
Expand Down

0 comments on commit 0d8d32f

Please sign in to comment.