Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LottoExtended] bugfix: input of greater number blocks #777

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions LottoExtended/src/LottoTippConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def setDateDay(self):
cur_day = fDate.weekday()
if tag == "0":
return 0
elif tag == "1": #Samstag
elif tag == "1": # Samstag
if cur_day < 5:
self.handleKey(KEY_RIGHT, "mydummy")
return 1
elif cur_day > 5:
self.handleKey(KEY_LEFT, "mydummy")
return 1
elif tag == "2" or tag == "3": #Mittwoch ; Mi +Sa
elif tag == "2" or tag == "3": # Mittwoch ; Mi +Sa
if cur_day < 2:
self.handleKey(KEY_RIGHT, "mydummy")
return 1
Expand All @@ -85,19 +85,16 @@ def handleKey(self, key, dummy):
if tag == "0":
pass
elif key == KEY_LEFT: # prev date
if tag == "1": #Samstag
if tag == "1": # Samstag
increment = (cur_day + 2) % 7 or 7
elif tag == "2": # Mittwoch
increment = (cur_day + 5) % 7 or 7
elif tag == "3": # Mi+Sa
if cur_day <= 2 or cur_day == 6:
increment = (cur_day + 2) % 7
else:
increment = cur_day - 2
increment = (cur_day + 2) % 7 if cur_day <= 2 or cur_day == 6 else cur_day - 2
newDate = fDate - timedelta(days=increment)
self.value = int(mktime(newDate.timetuple()))
elif key == KEY_RIGHT: # next date
if tag == "1": #Samstag
if tag == "1": # Samstag
increment = (12 - cur_day) % 7 or 7
elif tag == "2": # Mittwoch
increment = (9 - cur_day) % 7 or 7
Expand All @@ -108,7 +105,6 @@ def handleKey(self, key, dummy):
increment = 5 - cur_day
else:
increment = 9 - cur_day

newDate = fDate + timedelta(days=increment)
self.value = int(mktime(newDate.timetuple()))
# elif key == KEY_HOME or key == KEY_END:
Expand Down Expand Up @@ -146,6 +142,9 @@ def switchNormalSystem(self):
def setLimitDefault(self, count):
self.default = [0 for i in range(count)]
self.limits = [(1, 49) for i in range(count)]
self.blockLen = [len(str(x[1])) for x in self.limits]
self.totalLen = sum(self.blockLen) - 1
self.markedPos = 0

def cancel(self):
self.load()
Expand All @@ -157,26 +156,23 @@ def save(self):
self.value.sort()
try:
self.saved_value = self.toString(self.value) # bei openATV 7.x
except:
except Exception:
self.saved_value = self.tostring(self.value) # bei openATV 6.x
self.marked_pos = 0

def validate(self):
max_pos = 0
num = 0

for i in self._value:
max_pos += len(str(self.limits[num][1]))
if self._value[num] > self.limits[num][1]:
self._value[num] = self.limits[num][1]
num += 1

if self.marked_pos >= max_pos:
if self.endNotifier:
for x in self.endNotifier:
x(self)
self.marked_pos = max_pos - 1

if self.marked_pos < 0:
self.marked_pos = 0

Expand All @@ -188,7 +184,7 @@ def load(self):
sv = self.saved_value
try:
self.value = [0 for i in range(6)] if sv is None else self.fromString(sv) # bei openATV 7.x
except:
except Exception:
self.value = [0 for i in range(6)] if sv is None else self.fromstring(sv) # bei openATV 6.x
count = len(self.value)
self.setLimitDefault(count)
Expand All @@ -204,8 +200,7 @@ def __init__(self):
for tippnum in range(0, config.plugins.lotto.tippcount.value):
self.new()

# Add a new tipp or load a configsection if existing
def new(self):
def new(self): # Add a new tipp or load a configsection if existing
newTippConfigSubsection = ConfigSubsection()
config.plugins.lotto.tipps.append(newTippConfigSubsection)
newTippConfigSubsection.name = ConfigText("Tipp %s" % self.getTippCount(), False)
Expand Down Expand Up @@ -376,12 +371,12 @@ def validateSpiel(self, spiel):
dups = []
for i in spiel.value:
if i == 0:
self.session.open(MessageBox, _(("Ungültige Zahl (0) in %s\n\nNur 01 - 49 erlaubt." % (name))), MessageBox.TYPE_WARNING)
self.session.open(MessageBox, _(("Ungültige Zahl (0) in %s\n\nNur 01 - 49 erlaubt." % (name))), MessageBox.TYPE_WARNING, timeout=3, close_on_any_key=True)
return False
if dups.count(i) == 0 and spiel.value.count(i) > 1: # doppelte werte nicht zulassen
if dups.count(i) == 0 and spiel.value.count(i) > 1: # doppelte Werte nicht zulassen
dups.append(i)
if len(dups) > 0:
self.session.open(MessageBox, _(("Doppelte Zahl(en) in %s:\n\n%s" % (name, str(dups)))), MessageBox.TYPE_WARNING)
self.session.open(MessageBox, _(("Doppelte Zahl(en) in %s:\n\n%s" % (name, str(dups)))), MessageBox.TYPE_WARNING, timeout=3, close_on_any_key=True)
return False
return True

Expand All @@ -390,12 +385,11 @@ def keyDeleteSpiel(self):
if isinstance(spiel, LottoConfigSequence):
if spiel._value != spiel.default:
name = self["config"].getCurrent()[0]
self.session.openWithCallback(self.deleteSpiel, MessageBox, ("Soll '%s' wirklich gelöscht werden?" % name))
self.session.openWithCallback(self.deleteSpiel, MessageBox, ("Soll '%s' wirklich gelöscht werden?" % name), MessageBox.TYPE_YESNO, timeout=20, default=False)

def deleteSpiel(self, result):
if result:
spiel = self.getCurrentConfigPath()
# ix = self["config"].getCurrentIndex()
spiel.toDefault()
self["config"].invalidateCurrent()

Expand All @@ -406,8 +400,8 @@ def setDeleteButtonText(self, cfgentry):
self["statuslabel"].setText(" ")
txt = self["key_blue"].getText()
if isinstance(cfgentry, LottoConfigSequence):
if txt != "Delete Spiel":
self["key_blue"].setText("Delete Spiel")
if txt != "Lösche Spiel":
self["key_blue"].setText("Lösche Spiel")
else:
if txt != " ":
self["key_blue"].setText(" ")
Expand Down Expand Up @@ -460,7 +454,7 @@ def isChanged(self):

def keyCancel(self):
if self.isChanged():
self.session.openWithCallback(self.cancelCallback, MessageBox, "Sollen die Änderungen wirklich rückgängig gemacht werden?")
self.session.openWithCallback(self.cancelCallback, MessageBox, "Sollen die Änderungen wirklich rückgängig gemacht werden?", MessageBox.TYPE_YESNO, timeout=20, default=False)
else:
self.close(False, self.tipp)

Expand Down
Loading