240 lines
8.2 KiB
Python
240 lines
8.2 KiB
Python
import kivy
|
|
kivy.require('2.1.0')
|
|
from kivy.app import App
|
|
from kivy.lang import Builder
|
|
from kivy.uix.label import Label
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
from kivy.uix.floatlayout import FloatLayout
|
|
from kivy.uix.button import Button
|
|
from kivy.uix.dropdown import DropDown
|
|
from kivy.uix.textinput import TextInput
|
|
from kivy.garden.matplotlib import FigureCanvasKivyAgg
|
|
from awattar.client import AwattarClient
|
|
from kivy.uix.screenmanager import ScreenManager, Screen
|
|
from kivy.uix.togglebutton import ToggleButton
|
|
from kivy.uix.scrollview import ScrollView
|
|
from datetime import datetime, date
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
client = AwattarClient('AT') # or DE for Germany
|
|
|
|
date = datetime(datetime.now().year, datetime.now().month, datetime.now().day)
|
|
|
|
data = client.request(date)
|
|
|
|
plt.style.use('_mpl-gallery')
|
|
|
|
hours = np.arange(24)
|
|
prices = np.array([item.marketprice/1000 for item in data])
|
|
|
|
class DiagramWidget(FigureCanvasKivyAgg):
|
|
def __init__(self, figure, **kwargs):
|
|
super().__init__(figure, **kwargs)
|
|
self.ax = figure.axes[0]
|
|
|
|
class MyBoxLayout(BoxLayout):
|
|
def __init__(self, **kwargs):
|
|
super().__init__(**kwargs)
|
|
self.orientation = 'vertical'
|
|
|
|
# Create the label and button layout
|
|
label_button_layout = BoxLayout(orientation='horizontal', size_hint_y=None, height='50dp')
|
|
label_button_layout.add_widget(Label(text='[b]Strompreise & Stromerzeugung[/b]', markup=True, halign='left', valign='top', font_size='20px'))
|
|
|
|
# Add the button positioned on the right of the label
|
|
settings_button = Button(text='⚙️', size_hint=(None, None), size=('50dp', '50dp'))
|
|
settings_button.bind(on_release=self.open_settings)
|
|
label_button_layout.add_widget(settings_button)
|
|
|
|
self.add_widget(label_button_layout)
|
|
|
|
some_data = np.random.random(24)
|
|
hours = np.arange(24)
|
|
fig2, ax2 = plt.subplots(figsize=(10, 5))
|
|
fig2.subplots_adjust(left=0.075, bottom=0.075)
|
|
ax2.bar(hours, some_data, width=0.5, edgecolor='white', linewidth=0.5)
|
|
ax2.set(xlim=(-1, 24), xticks=hours)
|
|
fig2.canvas.draw()
|
|
diagram_widget2 = DiagramWidget(figure=fig2)
|
|
diagram_widget2.size_hint_y = 0.9
|
|
diagram_box2 = BoxLayout(size_hint_y=0.9)
|
|
diagram_box2.add_widget(diagram_widget2)
|
|
self.add_widget(diagram_box2)
|
|
|
|
toggle_box = BoxLayout(orientation='horizontal', size_hint_y=None, height='50dp')
|
|
toggle_button1 = ToggleButton(text='Button 1')
|
|
toggle_button2 = ToggleButton(text='Button 2')
|
|
toggle_box.add_widget(toggle_button1)
|
|
toggle_box.add_widget(toggle_button2)
|
|
self.add_widget(toggle_box)
|
|
|
|
prices = np.array([item.marketprice/1000 for item in data])
|
|
hours = np.arange(24)
|
|
fig, ax = plt.subplots(figsize=(10, 5))
|
|
fig.subplots_adjust(left=0.075, bottom=0.075)
|
|
ax.bar(hours, prices, width=0.5, edgecolor='white', linewidth=0.5)
|
|
ax.set(xlim=(-1, 24), xticks=hours)
|
|
fig.canvas.draw()
|
|
diagram_widget = DiagramWidget(figure=fig)
|
|
diagram_widget.size_hint_y = 0.9
|
|
diagram_box = BoxLayout(size_hint_y=0.9)
|
|
diagram_box.add_widget(diagram_widget)
|
|
self.add_widget(diagram_box)
|
|
|
|
def open_settings(self, instance):
|
|
app = App.get_running_app()
|
|
app.root.current = 'settings'
|
|
|
|
class SettingsScreen(Screen):
|
|
def __init__(self, **kwargs):
|
|
super().__init__(**kwargs)
|
|
self.dropdown = DropDown()
|
|
self.create_dropdown()
|
|
self.create_input_boxes()
|
|
|
|
def create_dropdown(self):
|
|
main_button = Button(text='Select Option', size_hint=(None, None), size=(150, 50))
|
|
main_button.bind(on_release=self.dropdown.open)
|
|
self.dropdown.bind(on_select=self.select_option)
|
|
|
|
options = ['Option 1', 'Option 2', 'Option 3']
|
|
|
|
for option in options:
|
|
btn = Button(text=option, size_hint_y=None, height=44)
|
|
btn.bind(on_release=lambda btn: self.dropdown.select(btn.text))
|
|
self.dropdown.add_widget(btn)
|
|
|
|
self.add_widget(main_button)
|
|
|
|
def select_option(self, instance, text):
|
|
print('Selected option:', text)
|
|
|
|
def create_input_boxes(self):
|
|
scroll_view = ScrollView()
|
|
input_box_layout = BoxLayout(orientation='vertical', size_hint_y=None, spacing=10, padding=10)
|
|
input_box_layout.bind(minimum_height=input_box_layout.setter('height'))
|
|
|
|
|
|
latitude = TextInput(hint_text=f'Breitengrad[°]', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(latitude)
|
|
|
|
longitude = TextInput(hint_text=f'Längengrad[°]', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(longitude)
|
|
|
|
azimuth = TextInput(hint_text=f'Azimut', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(azimuth)
|
|
|
|
tilt = TextInput(hint_text=f'Neigung', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(tilt)
|
|
|
|
peak = TextInput(hint_text=f'Peakleistung der Zellen', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(peak)
|
|
|
|
surface = TextInput(hint_text=f'Fläche der Zellen', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(surface)
|
|
|
|
efficiency = TextInput(hint_text=f'Wirkungsgrad der Zellen', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(efficiency)
|
|
|
|
temp_coeff = TextInput(hint_text=f'Temperaturkoeffizient', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(temp_coeff)
|
|
|
|
efficiency_dif = TextInput(hint_text=f'Effizienz diffuse Strahlung', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(efficiency_dif)
|
|
|
|
albedo = TextInput(hint_text=f'Albedo', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(albedo)
|
|
|
|
invert_perf = TextInput(hint_text=f'Wechselrichterleistung', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(invert_perf)
|
|
|
|
invert_eff = TextInput(hint_text=f'Wechselrichtereffizient', size_hint=(1, None), height='40dp')
|
|
input_box_layout.add_widget(invert_eff)
|
|
|
|
|
|
scroll_view.add_widget(input_box_layout)
|
|
|
|
# Create a vertical box layout to hold the "Back" button and the scroll view
|
|
content_layout = BoxLayout(orientation='vertical')
|
|
|
|
# Create the "Back" button
|
|
back_button = Button(text='Back', size_hint=(None, None), size=('100dp', '50dp'))
|
|
back_button.bind(on_release=self.go_back)
|
|
|
|
# Add the "Back" button to the content layout
|
|
content_layout.add_widget(back_button)
|
|
|
|
# Add the scroll view to the content layout
|
|
content_layout.add_widget(scroll_view)
|
|
|
|
# Add the content layout to the screen
|
|
self.add_widget(content_layout)
|
|
|
|
def go_back(self, instance):
|
|
app = App.get_running_app()
|
|
app.root.current = 'WattWatchMain'
|
|
|
|
# ... Rest of the code remains unchanged ...
|
|
|
|
|
|
class MainScreen(Screen):
|
|
pass
|
|
|
|
Builder.load_string('''
|
|
<WattWatchMain>:
|
|
GridLayout:
|
|
cols: 1
|
|
size_hint_y: 1
|
|
BoxLayout:
|
|
id: my_box
|
|
size_hint_y: .8
|
|
pos_hint: {'top': 1}
|
|
BoxLayout:
|
|
id: top_bar
|
|
orientation: 'horizontal'
|
|
size_hint_y: .1
|
|
pos_hint: {'top': 1}
|
|
Button:
|
|
text: 'Back'
|
|
size_hint: None, None
|
|
size: '100dp', '50dp'
|
|
on_release: app.root.current = 'WattWatchMain'
|
|
|
|
<SettingsScreen>:
|
|
BoxLayout:
|
|
orientation: 'vertical'
|
|
BoxLayout:
|
|
Button:
|
|
text: 'Back'
|
|
size_hint: None, None
|
|
size: '100dp', '50dp'
|
|
on_release: app.root.current = 'WattWatchMain'
|
|
|
|
<MainScreen>:
|
|
Label:
|
|
text: 'Main Screen'
|
|
''')
|
|
|
|
class WattWatchMain(Screen):
|
|
pass
|
|
|
|
class WattWatchApp(App):
|
|
title = 'WattWatch'
|
|
icon = 'wwicon.png'
|
|
|
|
def build(self):
|
|
sm = ScreenManager()
|
|
my_screen = WattWatchMain(name='WattWatchMain')
|
|
my_screen.ids.my_box.add_widget(MyBoxLayout())
|
|
sm.add_widget(my_screen)
|
|
|
|
settings_screen = SettingsScreen(name='settings')
|
|
sm.add_widget(settings_screen)
|
|
|
|
sm.current = 'WattWatchMain'
|
|
return sm
|
|
|
|
if __name__ == '__main__':
|
|
WattWatchApp().run()
|