Skip to content

Commit

Permalink
Scanners configureable
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton committed Jul 3, 2019
1 parent ebe400b commit d782e8b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 19 deletions.
70 changes: 54 additions & 16 deletions gui.py
Expand Up @@ -9,11 +9,12 @@
import os
import queue
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QSystemTrayIcon, QMenu, QAction, QStyle, qApp, QFileDialog
from PyQt5.QtWidgets import QMainWindow, QApplication, QSystemTrayIcon, QMenu, QAction, QStyle, qApp, QFileDialog, QMessageBox
from PyQt5.QtCore import QThread, pyqtSignal, Qt
from PyQt5 import uic

from config import PadmissConfigManager, PadmissConfig, ScannerConfig, DeviceConfig
from hid import listDevices
from daemon import PadmissDaemon
from thread_utils import start_and_wait_for_threads

Expand Down Expand Up @@ -87,6 +88,7 @@ def __init__(self, scanner: ScannerConfig):
self.idProduct.setText(scanner.id_product)
self.portNumber.setText(str(scanner.port_number) if scanner.port_number is not None else "")
self.bus.setText(str(scanner.bus) if scanner.bus is not None else "")
self.pickDeviceButton.clicked.connect(self.findScanner)

def getConfig(self):
return ScannerConfig(
Expand All @@ -96,6 +98,21 @@ def getConfig(self):
bus=int(self.bus.text()) if self.bus.text() else None
)

def findScanner(self):
reply = QMessageBox.information(self, 'Padmiss', 'Make sure the device is disconnected')
devices = listDevices()
reply = QMessageBox.information(self, 'Padmiss', 'Plug the device in, and wait 5 seconds')
newDevices = listDevices()

new = [x for x in newDevices if x not in devices]
if not new:
reply = QMessageBox.information(self, 'Padmiss', 'Device not found')
else:
device = new[0]
self.idVendor.setText(device['idVendor'])
self.idProduct.setText(device['idProduct'])
self.portNumber.setText(str(device['port_number']))
self.bus.setText(str(device['bus']))

class DeviceConfigWidget(Ui_DeviceConfigWidget, DeviceConfigWidgetBaseClass):
def __init__(self, device: DeviceConfig):
Expand All @@ -105,12 +122,15 @@ def __init__(self, device: DeviceConfig):

self.device = device
self.path.setText(device.path)
self.browsePath.clicked.connect(self.pickBackupDir)

self.configWidget = None

if device.type == 'scanner':
self.configWidget = ScannerConfigWidget(device.config)

self.deviceSpecificContent.addWidget(self.configWidget)
self.tabCloseRequested.connect(self.closeTab)

def getConfig(self):
if self.device.type == 'scanner':
Expand All @@ -122,10 +142,15 @@ def getConfig(self):

return None

def pickBackupDir(self):
folder = str(QFileDialog.getExistingDirectory(self, "Select profile directory"))
if folder:
self.path.setText(folder)

class ConfigWindow(Ui_ConfigWindow, ConfigWindowBaseClass):
configManager = None
callBack = None
config = None

# Override the class constructor
def __init__(self):
Expand All @@ -138,6 +163,7 @@ def __init__(self):
self.backup_dir_browse.clicked.connect(self.pickBackupDir)
self.scores_dir_browse.clicked.connect(self.pickScoresDir)
self.save.clicked.connect(self.saveAndClose)
self.newScannerButton.clicked.connect(self.newScanner)

def showEvent(self, event):
if self.configManager.hasValidConfig():
Expand Down Expand Up @@ -179,21 +205,33 @@ def saveAndClose(self):
self.configManager.save_config(config)
self.close()

def closeEvent(self, event):
if self.callBack != None:
if not self.configManager.hasValidConfig():
event.ignore()
else:
self.callBack()
self.callBack = None

def quitEvent(self, event):
if self.callBack != None:
if not self.configManager.hasValidConfig():
event.ignore()
else:
self.callBack()
self.callBack = None
#def closeEvent(self, event):
# if self.callBack != None:
# if not self.configManager.hasValidConfig():
# event.ignore()
# else:
# self.callBack()
# self.callBack = None

#def quitEvent(self, event):
#if self.callBack != None:
# if not self.configManager.hasValidConfig():
# event.ignore()
# else:
# self.callBack()
# self.callBack = None

def newScanner(self):
empty = DeviceConfig(
type = 'scanner',
path = '',
config = ScannerConfig(
id_vendor = '',
id_product = ''
)
)

self.deviceTabs.addTab(DeviceConfigWidget(empty), str(len(self.deviceTabs) + 1))


class MainWindow(Ui_MainWindow, MainWindowBaseClass):
Expand Down
9 changes: 6 additions & 3 deletions scanner-config-widget.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>145</height>
<height>167</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -63,10 +63,13 @@
<item row="4" column="1">
<widget class="QPushButton" name="pickDeviceButton">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Pick a device... (TODO)</string>
<string>Pick a device...</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
Expand Down

0 comments on commit d782e8b

Please sign in to comment.