Skip to content

Commit 96c7bdf

Browse files
Merge pull request #71 from DiamondLightSource/I04_1-396
I04 1 396
2 parents 20eeb22 + d9c59ab commit 96c7bdf

20 files changed

+116
-96
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
language: python
22
sudo: required
33
python:
4-
- "3.4"
4+
- "3.5"
55
virtualenv:
6-
system_site_packages: true
6+
system_site_packages: false
77

88
install:
9-
- sudo apt-get install -y python3-pyqt4 python3-sip
9+
- pip install --upgrade pip
1010
- pip install -r requirements.txt | cat
1111

1212
script:

dls_barcode/config/barcode_config_dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .camera_config_control import CameraConfigControl
33
from .store_directory_config_control import StoreDirectoryConfigControl
44

5-
from PyQt4.QtGui import QStyle
5+
from PyQt5.QtWidgets import QStyle
66

77

88
class BarcodeConfigDialog(ConfigDialog):

dls_barcode/config/camera_config_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cv2
22

3-
from PyQt4.QtGui import QLabel, QVBoxLayout, QHBoxLayout, QMessageBox, QLineEdit, QPushButton
3+
from PyQt5.QtWidgets import QLabel, QVBoxLayout, QHBoxLayout, QMessageBox, QLineEdit, QPushButton
44
from dls_util.config import ConfigControl
55
from dls_util.cv import CameraStream
66

dls_barcode/config/store_directory_config_control.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os.path
2-
from PyQt4 import QtGui
2+
from PyQt5.QtWidgets import QMessageBox
33

44
from dls_util.config import DirectoryConfigControl
55

@@ -18,10 +18,10 @@ def before_apply(self):
1818

1919
confirm_msg = "The Startup Store Directory was changed from " + current_dir + " to\n" + new_dir + ".\n\n"\
2020
"This change will only take effect at the next startup."
21-
reply = QtGui.QMessageBox.information(self, 'Startup Store Directory',
22-
confirm_msg, QtGui.QMessageBox.Ok, QtGui.QMessageBox.Cancel)
21+
reply = QMessageBox.information(self, 'Startup Store Directory',
22+
confirm_msg, QMessageBox.Ok, QMessageBox.Cancel)
2323

24-
if reply == QtGui.QMessageBox.Cancel:
24+
if reply == QMessageBox.Cancel:
2525
self.is_confirmed = False
2626

2727

dls_barcode/gui/barcode_table.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import os
44

5-
from PyQt4 import QtGui
6-
from PyQt4.QtCore import Qt
7-
from PyQt4.QtGui import QGroupBox, QVBoxLayout, QHBoxLayout
5+
from PyQt5.QtCore import Qt
6+
from PyQt5.QtWidgets import QGroupBox, QVBoxLayout, QHBoxLayout, QPushButton, QTableWidget, QLabel, QTableWidgetItem
7+
from PyQt5 import QtGui
88

99
from dls_barcode.plate import NOT_FOUND_SLOT_SYMBOL, EMPTY_SLOT_SYMBOL
1010

@@ -18,24 +18,26 @@ def __init__(self, options):
1818
self._options = options
1919

2020
self.setTitle("Plate Barcodes")
21+
self.setMaximumWidth(160)
22+
self.setMinimumWidth(160)
2123
self._init_ui()
2224
self.clear()
2325

2426
def _init_ui(self):
2527
# Plate being displayed
26-
self._plate_lbl = QtGui.QLabel()
28+
self._plate_lbl = QLabel()
2729

2830
# Create barcode table - lists all the barcodes in a record
29-
self._table = QtGui.QTableWidget()
30-
self._table.setMinimumWidth(110)
31+
self._table = QTableWidget()
32+
self._table.setMinimumWidth(70)
3133
self._table.setMinimumHeight(600)
3234
self._table.setColumnCount(1)
3335
self._table.setRowCount(10)
3436
self._table.setHorizontalHeaderLabels(['Barcode'])
35-
self._table.setColumnWidth(0, 100)
37+
self._table.setMinimumWidth(200)
3638

3739
# Clipboard button - copy the selected barcodes to the clipboard
38-
self._btn_clipboard = QtGui.QPushButton('Copy To Clipboard')
40+
self._btn_clipboard = QPushButton('Copy To Clipboard')
3941
self._btn_clipboard.setToolTip('Copy barcodes for the selected record to the clipboard')
4042
self._btn_clipboard.resize(self._btn_clipboard.sizeHint())
4143
self._btn_clipboard.clicked.connect(self.copy_to_clipboard)
@@ -87,8 +89,8 @@ def _populate_table(self):
8789
cell_color.a = 192
8890

8991
# Set table item
90-
barcode = QtGui.QTableWidgetItem(barcode)
91-
barcode.setBackgroundColor(cell_color.to_qt())
92+
barcode = QTableWidgetItem(barcode)
93+
barcode.setBackground(cell_color.to_qt())
9294
barcode.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
9395
self._table.setItem(index, 0, barcode)
9496

@@ -111,7 +113,11 @@ def copy_to_clipboard(self):
111113
pyperclip.copy(sep.join(clipboard_barcodes))
112114

113115
def _update_plate_label(self):
114-
text = "Plate : " + str(self._holder_barcode) if self._has_barcodes() else "Plate:"
116+
barcode_holder = str(self._holder_barcode)
117+
text = "Plate : " + barcode_holder if self._has_barcodes() else "Plate:"
118+
myFont = QtGui.QFont()
119+
myFont.setBold(True)
120+
self._plate_lbl.setFont(myFont)
115121
self._plate_lbl.setText(text)
116122

117123
def _has_barcodes(self):

dls_barcode/gui/image_frame.py

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

3-
from PyQt4.QtCore import Qt
4-
from PyQt4.QtGui import QLabel, QGroupBox, QVBoxLayout
3+
4+
5+
from PyQt5.QtCore import Qt, QSize
6+
from PyQt5.QtWidgets import QLabel, QGroupBox, QVBoxLayout
7+
8+
from dls_barcode.gui.image_widget import ImageWidget
59

610

711
class ImageFrame(QGroupBox):
812
""" GUI component. Displays an image of the currently selected barcode.
913
"""
1014
def __init__(self, title):
1115
super(ImageFrame, self).__init__()
12-
1316
self.setTitle(title)
1417
self._init_ui()
1518

1619
def _init_ui(self):
1720
# Image frame - displays image of the currently selected scan record
18-
self._frame = QLabel()
21+
self._frame = ImageWidget()
1922
self._frame.setStyleSheet("background-color: white; color: red; font-size: 30pt; text-align: center")
20-
self._frame.setMinimumWidth(500)
21-
self._frame.setMinimumHeight(500)
23+
self._frame.setMinimumWidth(700)
2224
self._frame.setAlignment(Qt.AlignCenter)
23-
2425
vbox = QVBoxLayout()
2526
vbox.addWidget(self._frame)
2627

dls_barcode/gui/image_widget.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from PyQt5 import QtCore, QtWidgets
2+
from PyQt5.QtWidgets import QLabel
3+
4+
# Resize button in the right corner didn't work correctly for the image
5+
# I had to add a event filter to the class so that the pixmap is scaled when resizing happens.
6+
7+
8+
class ImageWidget(QLabel):
9+
10+
def __init__(self, parent=None):
11+
super(ImageWidget, self).__init__(parent)
12+
self.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored)
13+
self.installEventFilter(self)
14+
15+
def eventFilter(self, source, event):
16+
if source is self and event.type() == QtCore.QEvent.Resize:
17+
ma = self.pixmap()
18+
if ma is not None:
19+
self.setPixmap(ma.scaled(self.size(), QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation))
20+
return QtWidgets.QWidget.eventFilter(self, source, event)

dls_barcode/gui/main_window.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from PyQt4 import QtGui
2+
from PyQt5 import QtWidgets, QtGui
33

44
from dls_barcode.config import BarcodeConfigDialog
55

@@ -13,13 +13,14 @@
1313
from .menu_bar import MenuBar
1414

1515

16-
class DiamondBarcodeMainWindow(QtGui.QMainWindow):
16+
class DiamondBarcodeMainWindow(QtWidgets.QMainWindow):
1717
""" Main GUI window for the Barcode Scanner App.
1818
"""
1919

20-
def __init__(self, config, version):
21-
super(DiamondBarcodeMainWindow, self).__init__()
20+
def __init__(self, config, version, flags, *args, **kwargs):
21+
#super(DiamondBarcodeMainWindow, self).__init__(None, None)
2222

23+
super().__init__(flags, *args, **kwargs)
2324
self._config = config
2425
self._version = version
2526
self._cleanup = None
@@ -39,11 +40,11 @@ def _init_ui(self):
3940
"""
4041
self._window_icon = QtGui.QIcon("..\\resources\\icons\\qr_code_32.png")
4142

42-
self.setGeometry(100, 100, 1020, 650)
43+
self.setGeometry(50, 50, 1500, 650) #950
4344
self.setWindowTitle('Diamond Puck Barcode Scanner')
4445
self.setWindowIcon(self._window_icon)
4546

46-
self._menu_bar = MenuBar(self.menuBar(), self._version)
47+
self._menu_bar = MenuBar(self.menuBar(), self._version, None)
4748

4849
# Barcode table - lists all the barcodes in a record
4950
self._barcode_table = BarcodeTable(self._config)
@@ -62,25 +63,25 @@ def _init_ui(self):
6263

6364
# Create layout
6465

65-
hbox = QtGui.QHBoxLayout()
66+
hbox = QtWidgets.QHBoxLayout()
6667
hbox.setSpacing(10)
6768

68-
table_vbox = QtGui.QVBoxLayout()
69+
table_vbox = QtWidgets.QVBoxLayout()
6970
table_vbox.addWidget(self._record_table)
7071
table_vbox.addWidget(self._scan_button)
7172

7273
hbox.addLayout(table_vbox)
7374
hbox.addWidget(self._barcode_table)
7475

75-
img_vbox = QtGui.QVBoxLayout()
76+
img_vbox = QtWidgets.QVBoxLayout()
7677
img_vbox.addWidget(self._image_frame)
7778
img_vbox.addWidget(self._message_box)
7879
hbox.addLayout(img_vbox)
7980

80-
vbox = QtGui.QVBoxLayout()
81+
vbox = QtWidgets.QVBoxLayout()
8182
vbox.addLayout(hbox)
8283

83-
main_widget = QtGui.QWidget()
84+
main_widget = QtWidgets.QWidget()
8485
main_widget.setLayout(vbox)
8586
self.setCentralWidget(main_widget)
8687

@@ -101,7 +102,7 @@ def _to_run_on_table_clicked(self):
101102
self._scan_button.setStartLayout()
102103

103104
def _on_about_action_clicked(self):
104-
QtGui.QMessageBox.about(self, 'About', "Version: " + self._version)
105+
QtWidgets.QMessageBox.about(self, 'About', "Version: " + self._version)
105106

106107

107108
def _on_scan_action_clicked(self):

dls_barcode/gui/menu_bar.py

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

3-
from PyQt4.QtGui import qApp, QAction, QMainWindow, QStyle
3+
from PyQt5.QtWidgets 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):
11-
super(MenuBar, self).__init__()
10+
def __init__(self, mainMenu, version, flags, *args, **kwargs):
11+
#super(MenuBar, self).__init__(mainMenu, version)
12+
super().__init__(flags, *args, **kwargs)
1213
self._version = version
1314

1415
self._exit_icon = self.style().standardIcon(QStyle.SP_DialogCloseButton)

dls_barcode/gui/message_box.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from PyQt4.QtGui import QLabel, QGroupBox, QVBoxLayout
2-
from PyQt4 import QtCore
1+
from PyQt5.QtWidgets import QLabel, QGroupBox, QVBoxLayout
2+
from PyQt5 import QtCore
33

44
from dls_util.message import MessageType
55

66
RED = "; color: red"
77
BLACK = "; color: black"
88
BASIC_STYLE_SHEET = "font-size: 14pt"
99

10+
1011
class MessageBox(QGroupBox):
1112
"""GUI component. Displays messages for the user."""
1213
def __init__(self):

0 commit comments

Comments
 (0)