Skip to content

Commit

Permalink
Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
NADOOITChristophBa committed Apr 13, 2024
1 parent 4a0d2ea commit 58ce29f
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,29 @@

from {{ cookiecutter.app_name|lower|replace('-', '_') }}.components.Startfenster import Startfenster
from {{ cookiecutter.app_name|lower|replace('-', '_') }}.components.SettingsWindow import SettingsWindow
from {{ cookiecutter.app_name|lower|replace('-', '_') }}.components.SettingsWindow import SettingsWindow
from {{ cookiecutter.app_name|lower|replace('-', '_') }}.components.SettingUserCode import SettingUserCode
from {{ cookiecutter.app_name|lower|replace('-', '_') }}.components.SettingNadooitAPISchluessel import SettingNadooitAPISchluessel

from screeninfo import get_monitors

class {{ cookiecutter.app_name|lower|replace('-', '_') }}(toga.App):

# Define the action handlers for the commands
def show_settings(self, widget):
# Instantiate the LicenseWindow
license_window = SettingsWindow(title="Einstellungen")

# Liste von Settings Elementen die im SettingsWindow angezeigt werden sollen
settings_elemente = []

# Show the license window
license_window.show()
settings_elemente.append(SettingUserCode())
settings_elemente.append(SettingNadooitAPISchluessel())


# Instantiate the LicenseWindow
license_window = SettingsWindow(title="Einstellungen",settings_elemente=settings_elemente)

# Show the license window
license_window.show()
def show_license(self, widget):
# Instantiate the LicenseWindow
license_window = LicenseWindow(title="Lizenzinformationen")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from nadoo_telemarketing.components.SettingsElement import SettingsElement
import toga
from toga.style import Pack
from nadoo_telemarketing.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 nadoo_telemarketing.components.SettingsElement import SettingsElement
import toga
from toga.style import Pack
from toga.style.pack import ROW
from nadoo_telemarketing.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 nadoo_telemarketing.components.SettingsElement import SettingsElement
import toga
from toga.style import Pack
from nadoo_telemarketing.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 nadoo_telemarketing.services import get_settings,set_user_code, set_api_key
from nadoo_telemarketing.components.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()

0 comments on commit 58ce29f

Please sign in to comment.