Verified Commit 20220937 authored by Robin Trioux's avatar Robin Trioux Committed by Sli
Browse files

IP selector & Counter selector added

parent 596b1dc0
......@@ -14,3 +14,5 @@ client
defaultHistory.json
transactionHistory.json
*.zip
data
venv/
......@@ -25,14 +25,17 @@ class MachineConfig(swagger_client.Configuration, metaclass=MachineConfigSinglet
def __init__(self):
super().__init__()
self.counterID = 1
#self.host = "http://127.0.0.1:5000"
self.host = "http://192.168.2.101:5000"
self.counterDict = {} # Ordered as dictionary
self.counterList = [] # Ordered as list
self.host = "http://127.0.0.1:5000"
# self.host = "http://192.168.2.101:5000"
self.defaultItemFileName = "ItemModel.json"
def setHost(host):
def setHost(self, host):
self.host = host
def setCounterID(counterID):
def setCounterID(self, counterID):
self.counterID = counterID
......@@ -164,4 +167,3 @@ def requestTransfert(sender, receiver, amount):
return None
except MaxRetryError as e:
return None
This diff is collapsed.
......@@ -75,6 +75,13 @@ class QItemSelectorModel(QTreeModel):
itemRegister = QItemRegister()
itemRegister.priceUpdated[QVariant].connect(self.updatePrice)
def updateModel(self, data):
self.rootItem.removeChildren(0, self.rootItem.childCount())
self.itemList = []
if data is not None:
self.setupModelData(data, self.rootItem)
self.layoutChanged.emit() # Force update of the model
def data(self, index, role):
if not index.isValid():
......
......@@ -11,6 +11,8 @@ import json
from babel.numbers import format_currency
from Client import *
# Server response emulation
import uuid
......@@ -59,7 +61,7 @@ class QItemRegister(QObject, metaclass=QItemRegisterSingleton):
QObject.__init__(self)
self.itemDict = {} # BASE OF ITEMS, WITHOUT TREE LOGIC
self.itemTree = {} # List of items ordered by category
self.timer = QTimer(self)
self.timer.setInterval(1000)
# self.timer.start()
......@@ -156,7 +158,11 @@ class QItemRegister(QObject, metaclass=QItemRegisterSingleton):
def updatePrice(self):
"""Check for each timeout if the price have to be updated"""
h, m, s = QTime.currentTime().hour(), QTime.currentTime().minute(), QTime.currentTime().second()
h, m, s = (
QTime.currentTime().hour(),
QTime.currentTime().minute(),
QTime.currentTime().second(),
)
time = h + m / 60
for uid in self.happyHour:
if self.__isValid(self.happyHour[uid]):
......@@ -179,7 +185,9 @@ class QItemRegister(QObject, metaclass=QItemRegisterSingleton):
if self.__latchHappyHour[uid][interval[0]] == 1:
self.__latchHappyHour[uid][interval[0]] = 0
self.itemDict[uid]["currentPrice"] = self.itemDict[uid]["defaultPrice"]
print("Fin happy hour pour", uid, "nouveau prix", self.itemDict[uid]["currentPrice"])
print(
"Fin happy hour pour", uid, "nouveau prix", self.itemDict[uid]["currentPrice"],
)
self.priceUpdated.emit(uid)
else:
pass
......@@ -261,9 +269,7 @@ class QConnector(QObject, metaclass=QConnectorSingleton):
self.balanceInfoUpdated.emit(newBalance)
class QSimpleNumberInputDialog(QWidget):
valueSelected = pyqtSignal(float)
class QAbstractInputDialog(QWidget):
def __init__(self, questionText, parent=None):
super().__init__(parent)
# Definitions
......@@ -271,13 +277,13 @@ class QSimpleNumberInputDialog(QWidget):
self.questionLabel = QLabel()
self.inputBar = QLineEdit()
self.okButton = QPushButton()
self.errorDialog = QErrorDialog("Erreur de saisie", "Erreur de saisie", "Veuillez saisir un nombre réel.")
self.errorDialog = QErrorDialog("Erreur de saisie", "Erreur de saisie", "Erreur")
# Settings
self.questionLabel.setText(questionText)
self.setWindowTitle(questionText)
self.okButton.setText("OK")
self.inputBar.setText("2")
self.inputBar.setText("")
# Links
......@@ -289,15 +295,69 @@ class QSimpleNumberInputDialog(QWidget):
self.setLayout(self.mainHBoxLayout)
class QSimpleNumberInputDialog(QAbstractInputDialog):
valueSelected = pyqtSignal(float)
def __init__(self, questionText, parent=None):
super().__init__(parent)
self.errorDialog = QErrorDialog("Erreur de saisie", "Erreur de saisie", "Veuillez saisir un nombre réel.")
self.inputBar.setText("2")
def sendValue(self):
try:
self.valueSelected.emit(float(self.inputBar.text()))
self.inputBar.setText("2")
self.close()
except:
self.errorDialog.setWindowIcon(self.style().standardIcon(QStyle.SP_MessageBoxWarning))
self.errorDialog.show()
center(self.errorDialog)
self.inputBar.setText("2")
class QIpInputDialog(QAbstractInputDialog):
valueSelected = pyqtSignal(str)
def __init__(self, questionText, parent=None):
super().__init__(parent)
config = MachineConfig()
self.errorDialog = QErrorDialog("Erreur de saisie", "Erreur de saisie", "Veuillez saisir une Ip V4 valide")
self.inputBar.setText(config.host[len("http://") :])
def sendValue(self):
config = MachineConfig()
ipParser = self.inputBar.text().replace(" ", "").split(".")
valid = True
if len(ipParser) == 4:
for i in ipParser:
try:
if 0 <= int(i) and int(i) <= 255:
pass
else: # invalid ip
valid = False
except: # Not a number
portParser = i.split(":")
if len(portParser) == 2:
try:
if 0 <= int(portParser[0]) and int(portParser[0]) <= 255 and int(portParser[1]) > 0:
pass
else:
valid = False
except:
valid = False
else:
valid = False
else:
valid = False
if valid is True:
self.inputBar.setText(self.inputBar.text().replace(" ", ""))
self.valueSelected.emit(self.inputBar.text())
config.setHost("http://" + self.inputBar.text())
api_instance = swagger_client.DefaultApi(swagger_client.ApiClient(config))
self.close()
else:
self.errorDialog.setWindowIcon(self.style().standardIcon(QStyle.SP_MessageBoxWarning))
self.errorDialog.show()
center(self.errorDialog)
......@@ -10,14 +10,14 @@ if __name__ == "__main__":
app = QApplication(sys.argv)
MainWindow = QMainMenu()
FakeCard = QFakeCard()
FakeCard.LinkWidget(MainWindow.MainTab.TabCounter.NFCDialog)
# FakeCard = QFakeCard()
# FakeCard.LinkWidget(MainWindow.MainTab.TabCounter.NFCDialog)
# W.Layout.addStretch(1)
# la fenêtre est rendue visible
# MainWindow.showMaximized()
MainWindow.show()
FakeCard.show()
# FakeCard.show()
# exécution de l'application, l'exécution permet de gérer les événements
app.exec_()
astroid==2.2.5
Babel==2.7.0
certifi==2019.11.28
entrypoints==0.3
flake8==3.7.8
isort==4.3.21
lazy-object-proxy==1.4.1
mccabe==0.6.1
numpy==1.17.0
pycodestyle==2.5.0
pyflakes==2.1.1
pylint==2.3.1
PyQt5==5.13.0
PyQt5-sip==4.19.18
pyscard==1.9.8
python-dateutil==2.8.1
pytz==2019.2
six==1.12.0
swagger-client==1.0.0
typed-ast==1.4.0
urllib3==1.25.8
wrapt==1.11.2
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment