Skip to content

Commit

Permalink
Added date-format option
Browse files Browse the repository at this point in the history
It is now possible to define a date-format in the config file.
Message.py now checks with datetime if the format of date is correct.
config.py now read the date-format.
Remove some time performance checks.
  • Loading branch information
hduelme committed Jul 15, 2020
1 parent f0be2b2 commit 78f2e93
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 40 deletions.
18 changes: 13 additions & 5 deletions Message.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from datetime import datetime

class Message():
hide: bool
comboBox: bool
allowallvalues: bool

def __init__(self,name,typ,default,allowedvalues,allowedcharacter,description,hide):
def __init__(self,name,typ,default,allowedvalues,allowedcharacter,description,hide,dateformate):
self.name = name
self.typ = typ
self.defaultvalues = default
Expand All @@ -29,6 +30,7 @@ def __init__(self,name,typ,default,allowedvalues,allowedcharacter,description,hi
self.comboBox = True
else:
self.comboBox = False
self.dateformate = dateformate

def toString(self):
return "Name: "+self.name+" Typ: "+self.typ+" defaultvalues: "+str(self.defaultvalues)+" allowedvalues: "+self.allowedvalues+" description: "+self.description
Expand Down Expand Up @@ -63,10 +65,16 @@ def checkValue(self,value):
return "Ok"

elif(self.allowedcharacter=="date"):
for l in value:
if(not (self.checkisNumber(l) or self.checkisDot(l))):
return "Muss Datum sein."
return "Ok"
#for l in value:
# if(not (self.checkisNumber(l) or self.checkisDot(l))):
#return "Muss Datum sein."
#return "Ok"
try:
if value != datetime.strptime(value, self.dateformate).strftime(self.dateformate):
raise ValueError
return "Ok"
except ValueError:
return "Muss Datum sein."

elif(self.allowedcharacter=="numbers"):
if(not (self.checkisNumber(value))):
Expand Down
13 changes: 3 additions & 10 deletions config.cfg
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
# Settings for the program
[settings]
lastfile =
linessperpage = 100
encoding = utf-8
dateformate = %%d.%%m.%%Y

# Each section represent one column of the CSV-file.
# 'name' specifiers the name for the column in the CSV-file.
# 'defaultvalues' specifiers the Value, which will be set by default in an new row.
# 'allowedvalues' specifiers the allowed values for the field (separated with a ';')
# 'allowedcharacter' specifiers which characters are allowed (numbers = only numbers, letters = only letters, letters+numbers = letters and numbers no spaces, default = letters, numbers, spaces and ('.','-',':','%','/','`'), date = numbers and dots)
# 'description' add a description for the column.
# 'hide' allow to hide the column.
# In the following are two examples:
[Section0]
name = Test1
typ = M
Expand All @@ -28,4 +20,5 @@ defaultvalues =
allowedvalues = all
allowedcharacter = default
description = missing
hide = True
hide = True

29 changes: 7 additions & 22 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def __init__(self):
self.lastFile=""
self.linesperpage = 100
self.encoding = 'utf-8'
self.dateformate = '%d.%m.%Y'


def createConfig(self,Sections):
Expand Down Expand Up @@ -50,6 +51,10 @@ def read_Config(self):
self.encoding = parser.get(s, 'encoding')
else:
print('Missing encoding-Option')
if('dateformate'in parser.options(s)):
self.dateformate = parser.get(s,'dateformate')
else:
print('Missing dateformate-Option')
else:
name = "?"
typ = "?"
Expand All @@ -72,27 +77,7 @@ def read_Config(self):
print("Missing defaultvalues for: " + s)
if ('allowedvalues' in parser.options(s)):
allowedvalues = parser.get(s, 'allowedvalues')
array = []
from1 = 0
lenght = len(allowedvalues)
if (from1 == lenght):
array.append("")
else:
while(from1<lenght):
temp =""

while(True):
if(from1<lenght):
if(allowedvalues[from1]==";"):
array.append(temp)
from1 += 1
break
else:
temp+=allowedvalues[from1]
from1+=1
else:
array.append(temp)
break
array = allowedvalues.split(';')
else:
print("Missing allowedvalues for: " + s)
if ('allowedcharacter' in parser.options(s)):
Expand All @@ -107,7 +92,7 @@ def read_Config(self):
hide = parser.get(s, 'hide')
else:
print("Missing hide for: " + s)
m = Message.Message(name, typ, defaultvalues, array,allowedcharacter, description,hide)
m = Message.Message(name, typ, defaultvalues, array,allowedcharacter, description,hide,self.dateformate)
self.read_Sections.append(m)

def save_currentFile(self,file):
Expand Down
6 changes: 3 additions & 3 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

import time
#import time


class Ui_MainWindow(QMainWindow):
Expand Down Expand Up @@ -237,7 +237,7 @@ def setCurrentPage(self,fr,to):
#t1 = 0
#for r in range(0,self.tableWidget.rowCount()):
#self.tableWidget.removeRow(r)
start = time.time()
#start = time.time()
self.tableWidget = QTableWidget()
self.setCentralWidget(self.tableWidget)
if (self.hideCols):
Expand Down Expand Up @@ -297,7 +297,7 @@ def setCurrentPage(self,fr,to):
else:
self.tableWidget.setHorizontalHeaderLabels(self.headers)
self.tableWidget.setVerticalHeaderLabels(vertikalHeader)
print("Time: ",time.time()-start)
#print("Time: ",time.time()-start)
self.checkCurrentPage()

def checkCurrentPage(self):
Expand Down

0 comments on commit 78f2e93

Please sign in to comment.