Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
NADOOITLaurinK committed Apr 10, 2024
1 parent 4a0d2ea commit 6884990
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from {{ cookiecutter.module_name }}.components.SettingsElement import SettingsElement
import toga
from toga.style import Pack
from {{ cookiecutter.module_name }}.services import set_api_key, get_settings

class SettingNadooitAPISchluessel(SettingsElement):

def __init__(self):
super().__init__()
# Eingabefeld für den User Code erstellen
self.api_key_input = toga.TextInput(
placeholder="NADOO API Schlüssel",
)

setting_lable = toga.Label(
"NADOO API Schlüssel", style=Pack(padding_bottom=10)
)

self.gui.add(setting_lable)
self.gui.add(self.api_key_input)
self.load_settings()

def save(self):
set_api_key(self.api_key_input.value)

def load_settings(self):
settings = get_settings()
self.api_key_input.value = settings.get("api_key", "")
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from {{ cookiecutter.module_name }}.components.SettingsElement import SettingsElement
import toga
from toga.style import Pack
from toga.style.pack import ROW
from {{ cookiecutter.module_name }}.services import set_uhrzeit_nächsten_werktag_wechsel, get_settings

class SettingUhrzeitWerktagswechsel(SettingsElement):

def __init__(self):
super().__init__()

# Dropdown-Menü für die Stunde erstellen
self.stunde_dropdown = toga.Selection(
items=[f"{stunde:02d}" for stunde in range(24)],
style=Pack(flex=1)
)

# Dropdown-Menü für die Minute erstellen
self.minute_dropdown = toga.Selection(
items=[f"{minute:02d}" for minute in range(0, 60, 15)],
style=Pack(flex=1)
)

# Dropdown-Menüs nebeneinander platzieren
dropdown_box = toga.Box(
children=[self.stunde_dropdown, self.minute_dropdown],
style=Pack(direction=ROW)
)

setting_lable = toga.Label(
"Uhrzeit für den nächsten Werktag wechseln", style=Pack(padding_bottom=10)
)

self.gui.add(setting_lable)
self.gui.add(dropdown_box)
self.load_settings()

def save(self):
stunde = self.stunde_dropdown.value
minute = self.minute_dropdown.value
uhrzeit = f"{stunde}:{minute}:00"
set_uhrzeit_nächsten_werktag_wechsel(uhrzeit)

def load_settings(self):
settings = get_settings()
uhrzeit = settings.get("uhrzeit_nächsten_werktag_wechsel", "16:00:00")
stunde, minute, _ = uhrzeit.split(":")
self.stunde_dropdown.value = stunde
self.minute_dropdown.value = minute
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from {{ cookiecutter.module_name }}.SettingsElement import SettingsElement
import toga
from toga.style import Pack
from {{ cookiecutter.module_name }}.services import set_user_code, get_settings

class SettingUserCode(SettingsElement):

def __init__(self):
super().__init__()
# Eingabefeld für den User Code erstellen
self.user_code_input = toga.TextInput(
placeholder="User Code",
)

setting_lable = toga.Label(
"NADOO Nutzercode", style=Pack(padding_bottom=10)
)

self.gui.add(setting_lable)
self.gui.add(self.user_code_input)
self.load_settings()

def save(self):
set_user_code(self.user_code_input.value)

def load_settings(self):
settings = get_settings()
self.user_code_input.value = settings.get("user_code", "")
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import toga
from toga.style import Pack
from toga.style.pack import COLUMN

class SettingsElement:

def __init__(self):
self.gui = toga.Box(style=Pack(direction=COLUMN, padding_bottom=5))
pass

def save(self):
pass

def load_settings(self):
pass
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
import os
import json
from typing import List, Optional
import toga
from toga.style import Pack
from toga.style.pack import COLUMN

from nadoo_travel.src.nadoo_travel.services import set_settings, get_settings,set_user_code, set_api_key
from {{ cookiecutter.module_name }}.services import get_settings,set_user_code, set_api_key
from {{ cookiecutter.module_name }}.SettingsElement import SettingsElement



class SettingsWindow(toga.Window):
def __init__(self, title, width=400, height=400):
def __init__(self, title, settings_elemente:Optional[List[SettingsElement]] = None, width=400, height=400):
super().__init__(title, size=(width, height))

self.settings_elemente = settings_elemente or []

self.content = self.build()
self.load_settings()

def build(self):
# Hauptcontainer für den Inhalt erstellen
box = toga.Box(style=Pack(direction=COLUMN, padding=10, flex=1))


# Eingabefeld für den User Code erstellen
self.user_code_input = toga.TextInput(
placeholder="User Code",
style=Pack(padding_bottom=10)
)
box.add(self.user_code_input)

# Eingabefeld für den NADOO API Schlüssel erstellen
self.api_key_input = toga.TextInput(
placeholder="NADOO API Schlüssel",
style=Pack(padding_bottom=10)
)
box.add(self.api_key_input)
for elemnt in self.settings_elemente:
box.add(elemnt.gui)

# Speichern-Button hinzufügen
save_button = toga.Button(
Expand All @@ -53,10 +49,6 @@ def close_window(self, widget):


def save_settings(self, widget):
set_user_code(self.user_code_input.value)
set_api_key(self.api_key_input.value)

def load_settings(self):
settings = get_settings()
self.user_code_input.value = settings.get("user_code", "")
self.api_key_input.value = settings.get("api_key", "")

for settings_element in self.settings_elemente:
settings_element.save()
Loading

0 comments on commit 6884990

Please sign in to comment.