From 305dd68a3306a0a6804814c78379e1295c0a3b38 Mon Sep 17 00:00:00 2001 From: "Mr.Servo" Date: Thu, 11 Apr 2024 17:56:42 +0200 Subject: [PATCH] [LottoExtended] bugfix: input of greater number blocks - the input of number blocks greater than 8 now works (special THX to ***@jbleyel** - timeouts for messageboxes added - tiny code improvents --- LottoExtended/src/LottoTippConfig.py | 42 ++++++++++++---------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/LottoExtended/src/LottoTippConfig.py b/LottoExtended/src/LottoTippConfig.py index 438cdbaaa..034a0751a 100644 --- a/LottoExtended/src/LottoTippConfig.py +++ b/LottoExtended/src/LottoTippConfig.py @@ -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 @@ -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 @@ -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: @@ -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() @@ -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 @@ -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) @@ -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) @@ -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 @@ -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() @@ -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(" ") @@ -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)