Skip to content

Commit e1c9fa7

Browse files
committed
I04_1-172: Small refactorisation
to make the main window class smallelr
1 parent 0324156 commit e1c9fa7

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

dls_barcode/gui/main_window.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,19 @@ def __init__(self, config_file, version):
6767
def _init_ui(self):
6868
""" Create the basic elements of the user interface.
6969
"""
70-
self._init_icons()
70+
self._window_icon = QtGui.QIcon("..\\resources\\icons\\qr_code_32.png")
7171

7272
self.setGeometry(100, 100, 1020, 650)
7373
self.setWindowTitle('Diamond Puck Barcode Scanner')
7474
self.setWindowIcon(self._window_icon)
7575

76-
self._menu_bar = MenuBar(self.menuBar(), self._version, self._cleanup, self._on_options_action_clicked,
77-
self._on_about_action_clicked, self._exit_icon, self._config_icon, self._about_icon)
76+
self._menu_bar = MenuBar(self.menuBar(), self._version, self._cleanup, self._on_options_action_clicked,self._on_about_action_clicked)
7877

7978
# Barcode table - lists all the barcodes in a record
8079
self._barcode_table = BarcodeTable(self._config)
8180

8281
# Scan button - start/stop scan
83-
self._scan_button = ScanButton('Start/stop scan', self._stop_capture_icon, self._start_capture_icon,
84-
self._on_scan_action_clicked)
82+
self._scan_button = ScanButton('Start/stop scan', self._on_scan_action_clicked)
8583

8684
# Image frame - displays image of the currently selected scan record
8785
self._image_frame = ImageFrame("Plate Image")
@@ -118,14 +116,6 @@ def _init_ui(self):
118116

119117
self.show()
120118

121-
def _init_icons(self):
122-
self._window_icon = QtGui.QIcon("..\\resources\\icons\\qr_code_32.png")
123-
self._start_capture_icon = self.style().standardIcon(QtGui.QStyle.SP_MediaPlay)
124-
self._stop_capture_icon = self.style().standardIcon(QtGui.QStyle.SP_MediaStop)
125-
self._exit_icon = self.style().standardIcon(QtGui.QStyle.SP_DialogCloseButton)
126-
self._config_icon = self.style().standardIcon(QtGui.QStyle.SP_FileDialogDetailedView)
127-
self._about_icon = self.style().standardIcon(QtGui.QStyle.SP_FileDialogInfoView)
128-
129119
def _on_about_action_clicked(self):
130120
QtGui.QMessageBox.about(self, 'About', "Version: " + self._version)
131121

dls_barcode/gui/menu_bar.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
from __future__ import division
22

3-
from PyQt4.QtGui import qApp, QAction, QMainWindow
3+
from PyQt4.QtGui import qApp, QAction, QMainWindow, QStyle
44

55

66
class MenuBar(QMainWindow):
77
""" GUI component. Displays a start/stop button
88
"""
99

10-
def __init__(self, mainMenu, version, clean_up, on_options_action_clicked, on_about_action_clicked, exit_icon, config_icon,
11-
about_icon):
10+
def __init__(self, mainMenu, version, clean_up, on_options_action_clicked, on_about_action_clicked):
1211
super(MenuBar, self).__init__()
1312
self._version = version
1413
self._cleanup = clean_up
1514
self._on_options_action_clicked = on_options_action_clicked
1615
self._on_about_action_clicked = on_about_action_clicked
17-
self._exit_icon = exit_icon
18-
self._config_icon = config_icon
19-
self._about_icon = about_icon
16+
17+
self._exit_icon = self.style().standardIcon(QStyle.SP_DialogCloseButton)
18+
self._config_icon = self.style().standardIcon(QStyle.SP_FileDialogDetailedView)
19+
self._about_icon = self.style().standardIcon(QStyle.SP_FileDialogInfoView)
20+
2021
self._mainMenu = mainMenu
2122

2223
self._init_ui()

dls_barcode/gui/scan_button.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
from __future__ import division
22

33

4-
from PyQt4.QtGui import QPushButton, QGroupBox, QVBoxLayout
4+
from PyQt4.QtGui import QPushButton, QGroupBox, QVBoxLayout, QStyle
55
from PyQt4.QtCore import Qt
66

77

88
class ScanButton(QGroupBox):
99
""" GUI component. Displays a start/stop button
1010
"""
11-
def __init__(self, title, icon_stop, icon_start, on_scan_action_clicked):
11+
def __init__(self, title, on_scan_action_clicked):
1212
super(ScanButton, self).__init__()
1313
self._on_scan_action_clicked = on_scan_action_clicked
14-
self._stop_capture_icon = icon_stop
15-
self._start_capture_icon = icon_start
14+
self._start_capture_icon = self.style().standardIcon(QStyle.SP_MediaPlay)
15+
self._stop_capture_icon = self.style().standardIcon(QStyle.SP_MediaStop)
1616
self.setTitle(title)
1717

1818
self._init_ui()

tests/unit_tests/test_dls_barcode/test_camera/test_camera_switch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_given_a_new_switch_then_we_can_stop_the_stream(self):
3737
switch = self._create_switch()
3838

3939
# Act
40-
switch.stop_live_capture()
40+
switch._stop_live_capture()
4141

4242
# Assert
4343
self._mock_scanner.stop_scan.assert_called_once()
@@ -47,7 +47,7 @@ def test_given_a_new_switch_when_stopping_the_stream_then_there_is_no_top_scan_t
4747
switch = self._create_switch()
4848

4949
# Act
50-
switch.stop_live_capture()
50+
switch._stop_live_capture()
5151

5252
# Assert
5353
self.assertFalse(switch.is_top_scan_timeout())
@@ -162,7 +162,7 @@ def test_given_capture_started_from_top_when_capture_is_stopped_then_timeout_is_
162162
switch.restart_live_capture_from_top()
163163

164164
# Act
165-
switch.stop_live_capture()
165+
switch._stop_live_capture()
166166

167167
# Assert
168168
time.sleep(timeout)

0 commit comments

Comments
 (0)