ich habe das deshalb mit schedule_once gemacht weil dann jedes mal beim aufrufen die zeit aktualisiert werden kann.
weil es ja praktisch die gleiche Fuktion aufruft in der schedule_once steht das heist es ist ja das gleiche wie interval blos halt mit ständig aktualisierender zeit.
Code: Alles auswählen
# -*- coding: iso-8859-1 -*-
import os
from io import BytesIO
from plyer import notification
import time
import urllib.request
import urllib
from zipfile import ZipFile
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.settings import SettingsWithSidebar
from kivy.uix.screenmanager import Screen
from kivy.uix.settings import SettingItem
from kivy.clock import Clock
import json
import _thread
import requests
STORAGE = "/storage/emulated/0"
APP_PATH = os.path.join(STORAGE, "TankstellenApp")
URL = "http://mscpiserver/TankstellenApp"
setting_json = json.dumps(
[
{"type":"title",
"title":"Automatische Preis-Aktualisierung"
},
{"type":"bool",
"key":"AutoUpdate",
"section":"settings",
"title":"Automatische Preis-Aktualisierung durchf�hren",
"desc":"Stelle die Automatische Preis-Aktualisierung An und Aus"
},
{"type":"numeric",
"key":"AutoUpdateTime",
"section":"settings",
"title":"Zeitabstand zwischen den einzelnen Automatischen Preis-Aktualisierungen",
"desc":"Setze den Zeitabstand zwischen den Automatischen Preis-Aktualisierungen fest"
},
{"type":"title",
"title":"Push-Benachrichtigungen"
},
{"type":"bool",
"key":"CheapNotify",
"section":"settings",
"title":"Pusch-Benachrichtigungen bei g�nstigen Preisen",
"desc":"Stelle Push-Benachrichtigungen bei g�nstigen Preisen AN und Aus"
}
]
)
g=Builder.load_string("""
#: import ListAdapter kivy.adapters.listadapter.ListAdapter
#: import ListItemButton kivy.uix.listview.ListItemButton
<ListItemButton>:
selected_color: 0,0,5,5
deselected_color: 0,0,0,0
size: (100, 175)
on_press: app.version_selected(self)
ScreenManager:
Screen
name:'main'
TabbedPanel:
tab_width: 375
pos: 0,-100
do_default_tab: False
TabbedPanelItem:
text:"OMV-Neubiberg"
BoxLayout:
padding: 120
orientation:"vertical"
pos_hint:{'top':1}
size_hint: None, None
height: 775
spacing: "100"
BoxLayout:
spacing:"300"
orientation:"horizontal"
BoxLayout:
spacing:"300"
orientation: "horizontal"
Label:
id: sorte1
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis1
height: 15
size_hint: None, None
text:"Preis: "
BoxLayout:
orientation: "horizontal"
spacing:"300"
Label:
id: sorte2
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis2
size_hint: None, None
height: 15
text:"Preis:"
BoxLayout:
orientation:"horizontal"
spacing:"300"
Label:
id: sorte3
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis3
size_hint: None, None
height: 15
text:"Preis:"
BoxLayout:
orientation:"horizontal"
spacing:"300"
Label:
id: sorte4
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis4
size_hint: None, None
height: 15
text: "Preis:"
BoxLayout:
orientation:"horizontal"
spacing:"300"
Label:
id: sorte5
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis5
size_hint: None, None
height: 15
text:"Preis:"
TabbedPanelItem:
text:"DriversIn-Putzbrunn"
BoxLayout:
padding: 120
orientation:"vertical"
pos_hint:{'top':1}
size_hint: None, None
height: 775
spacing: "100"
BoxLayout:
spacing:"300"
orientation:"horizontal"
BoxLayout:
spacing:"300"
orientation: "horizontal"
Label:
id: sorte1DVP
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis1DVP
height: 15
size_hint: None, None
text:"Preis: "
BoxLayout:
orientation: "horizontal"
spacing:"300"
Label:
id: sorte2DVP
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis2DVP
size_hint: None, None
height: 15
text:"Preis:"
BoxLayout:
orientation:"horizontal"
spacing:"300"
Label:
id: sorte3DVP
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis3DVP
size_hint: None, None
height: 15
text:"Preis:"
BoxLayout:
orientation:"horizontal"
spacing:"300"
Label:
id: sorte4DVP
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis4DVP
size_hint: None, None
height: 15
text: "Preis:"
BoxLayout:
orientation:"horizontal"
spacing:"300"
Label:
id: sorte5DVP
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis5DVP
size_hint: None, None
height: 15
text:"Preis:"
TabbedPanelItem:
width:300
text:"Shell-Kehferloh/Grasbrunn"
BoxLayout:
padding: 120
orientation:"vertical"
pos_hint:{'top':1}
size_hint: None, None
height: 775
spacing: "100"
BoxLayout:
spacing:"300"
orientation:"horizontal"
BoxLayout:
spacing:"300"
orientation: "horizontal"
Label:
id: sorte1KGS
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis1KGS
height: 15
size_hint: None, None
text:"Preis: "
BoxLayout:
orientation: "horizontal"
spacing:"300"
Label:
id: sorte2KGS
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis2KGS
size_hint: None, None
height: 15
text:"Preis:"
BoxLayout:
orientation:"horizontal"
spacing:"300"
Label:
id: sorte3KGS
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis3KGS
size_hint: None, None
height: 15
text:"Preis:"
BoxLayout:
orientation:"horizontal"
spacing:"300"
Label:
id: sorte4KGS
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis4KGS
size_hint: None, None
height: 15
text: "Preis:"
BoxLayout:
orientation:"horizontal"
spacing:"300"
Label:
id: sorte5KGS
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis5KGS
size_hint: None, None
height: 15
text:"Preis:"
BoxLayout:
orientation:"horizontal"
spacing:"300"
Label:
id: sorte6KGS
size_hint: None, None
height: 15
text:"Benzinsorte:"
Label:
id: preis6KGS
size_hint: None, None
height: 15
text:"Preis:"
BoxLayout:
padding: 350
Button:
id: refBUT
background_color: 0,0,0,0
size_hint: None, None
height: 100
width: 100
on_press: app.on_start()
on_release: app.on_start()
Image:
source: "C.png"
y: self.parent.y + self.parent.height - 100
x: self.parent.x
size: 100, 100
allow_stretch: True
ActionBar:
id: UpdInf
background_color: 5,5,5,5
pos_hint:{'bottom':1}
ActionView:
id: UpdInfView
use_separator: True
ActionPrevious:
app_icon: "Cl.png"
with_previous: False
title:"Update verf�gbar"
on_press: app.updateinfo_gone(self)
ActionButton:
icon:"Dow.png"
ActionBar:
pos_hint: {'top':1}
ActionView:
use_separator: True
ActionPrevious:
title: 'Tankstellen App'
with_previous: False
#app_icon: 'Transparent.png'
ActionButton:
#icon:'C.png'
ActionButton:
text: 'Einstellugen'
on_press: root.current='settings'
ActionButton:
text: 'Navigation'
on_press: root.current='NAV'
ActionButton:
text: 'Versionen'
on_press: root.current='Versions'
ActionGroup:
text: 'Hilfe'
ActionButton:
text: 'Anleitung'
on_press: root.current='guide'
ActionButton:
text: 'Quickstart'
on_press: root.current='QUICKSTART-Main'
ActionButton:
text: 'Support'
on_press: root.current='SUPPORT'
Screen:
name:'settings'
BoxLayout:
orientaation:"vertical"
BoxLayout:
Label:
text:" Benachrichtigung erhalten\\n bei g�nstigem Preis"
Switch:
id:CheapNotSwitch
on_active: app.cheap_not_switched(self, self.active)
on_active: app.open_settings()
# BoxLayout:
# orientation:"vertical"
# Label:
# text_size: self.size
# halign: 'center'
# valign: 'middle'
# font_size: dp(25)
# text:"Noch nicht verf�gbar\\nwarte auf Updates und versuche es dann erneut"
# Button:
# size_hint: None, None
# height: 125
# width: 750
# text:"Auf Updates pr�fen"
# on_press: root.current='Versions'
ActionBar:
pos_hint:{'top':1}
ActionView:
use_seperator: True
ActionPrevious:
title:"Einstellungen"
with_previous: True
app_icon:'S.png'
on_press: root.current='main'
Screen:
name:'NAV'
BoxLayout:
orientation:"vertical"
Label:
text_size: self.size
halign: 'center'
valign: 'middle'
font_size: dp(25)
text:"Noch nicht verf�gbar\\nwarte auf Updates und versuche es dann erneut"
Button:
size_hint: None, None
height: 125
width: 750
text:"Auf Updates pr�fen"
on_press: root.current='Versions'
ActionBar:
pos_hint:{'top':1}
ActionView:
use_separator: True
ActionPrevious:
title:"Navigation"
with_previous: True
app_icon:'N.png'
on_press: root.current='main'
Screen:
name:"SUPPORT"
BoxLayout:
orientation:"vertical"
Label:
text_size: self.size
halign: 'center'
valign: 'middle'
font_size: dp(25)
text:"Noch nicht verf�gbar\\nwarte auf Updates und versuche es dann erneut"
Button:
size_hint: None, None
height: 125
width: 750
text:"Auf Updates pr�fen"
on_press: root.current='Versions'
ActionBar:
pos_hint:{'top':1}
ActionView:
use_seperator: True
ActionPrevious:
title:"Support"
with_previous: True
app_icon:"Su.png"
on_press: root.current="main"
Screen:
name:"Versions"
BoxLayout:
orientation:"vertical"
Label:
size_hint: None, None
pos_hint:{'top':1}
text:""
BoxLayout:
orientation:"horizontal"
Button:
text:"Info"
Button:
text:"Instalieren"
ListView:
adapter: ListAdapter(data=['foo', 'bar', 'baz'], cls=ListItemButton)
size_hint: None, None
width: 725
height: 1100
ActionBar:
pos_hint:{'top':1}
ActionView:
use_separator: True
ActionPrevious:
title:"Versionen"
app_icon:"V.png"
with_previous: True
on_press: root.current='main'
Screen:
name:"guide"
BoxLayout:
orientation:"vertical"
Label:
text_size: self.size
halign: 'center'
valign: 'middle'
font_size: dp(25)
text:"Noch nicht verf�gbar\\nwarte auf Updates und versuche es dann erneut"
Button:
size_hint: None, None
height: 125
width: 750
text:"Auf Updates pr�fen"
on_press: root.current='Versions'
ActionBar:
pos_hint:{'top':1}
ActionView:
use_separator: True
ActionPrevious:
title:"Anleitung"
app_icon:"I.png"
with_previous: True
on_press: root.current='main'
Screen:
name:'QUICKSTART-Main'
BoxLayout:
ActionBar:
background_color: 0,0,0,0
pos_hint:{'top':1}
ActionView:
use_separator: True
ActionPrevious:
app_icon:"Transparent.png"
with_previous: False
ActionButton:
icon:"Cl.png"
on_press: root.current='main'
ActionBar:
background_color: 0,0,0,0
pos_hint:{'Bottom':1}
ActionView:
use_separator: True
ActionPrevious:
with_previous: False
app_icon:"NBa.png"
ActionButton:
icon:"Cg.gif"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Ne.png"
on_press: root.current='QUICKSTART-s2'
Screen:
name:'QUICKSTART-s2'
BoxLayout:
ActionBar:
background_color: 0,0,0,0
pos_hint:{'top':1}
ActionView:
use_separator: True
ActionPrevious:
app_icon:"Transparent.png"
with_previous: False
ActionButton:
icon:"Cl.png"
on_press: root.current='main'
ActionBar:
background_color: 0,0,0,0
pos_hint:{'Bottom':1}
ActionView:
use_separator: True
ActionPrevious:
with_previous: False
app_icon:"Ba.png"
on_press: root.current='QUICKSTART-Main'
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cg.gif"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Ne.png"
on_press: root.current='QUICKSTART-s3'
Screen:
name:'QUICKSTART-s3'
BoxLayout:
ActionBar:
background_color: 0,0,0,0
pos_hint:{'top':1}
ActionView:
use_separator: True
ActionPrevious:
app_icon:"Transparent.png"
with_previous: False
ActionButton:
icon:"Cl.png"
on_press: root.current='main'
ActionBar:
background_color: 0,0,0,0
pos_hint:{'Bottom':1}
ActionView:
use_separator: True
ActionPrevious:
with_previous: False
app_icon:"Ba.png"
on_press: root.current='QUICKSTART-s2'
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cg.gif"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Ne.png"
on_press: root.current="QUICKSTART-s4"
Screen:
name:'QUICKSTART-s4'
BoxLayout:
ActionBar:
background_color: 0,0,0,0
pos_hint:{'top':1}
ActionView:
use_separator: True
ActionPrevious:
app_icon:"Transparent.png"
with_previous: False
ActionButton:
icon:"Cl.png"
on_press: root.current='main'
ActionBar:
background_color: 0,0,0,0
pos_hint:{'Bottom':1}
ActionView:
use_separator: True
ActionPrevious:
with_previous: False
app_icon:"Ba.png"
on_press: root.current='QUICKSTART-s3'
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cg.gif"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Ne.png"
on_press: root.current="QUICKSTART-s5"
Screen:
name:'QUICKSTART-s5'
BoxLayout:
ActionBar:
background_color: 0,0,0,0
pos_hint:{'top':1}
ActionView:
use_separator: True
ActionPrevious:
app_icon:"Transparent.png"
with_previous: False
ActionButton:
icon:"Cl.png"
on_press: root.current='main'
ActionBar:
background_color: 0,0,0,0
pos_hint:{'Bottom':1}
ActionView:
use_separator: True
ActionPrevious:
with_previous: False
app_icon:"Ba.png"
on_press: root.current='QUICKSTART-s4'
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cw.png"
ActionButton:
icon:"Cg.gif"
ActionButton:
icon:"NNe.png"
""")
class TankstellenApp(App):
y=0
def __init__(self):
super().__init__()
self.blink = True
self.update = False
def cheap_not_switched(self, instance, value):
if value:
notification.notify(message="Du erh�lst ab jetzt Benachrichtigungem bei g�nstigem Preis!")
@staticmethod
def download_files():
if not os.path.exists(APP_PATH):
with urllib.request.urlopen(URL + "/Appfiles/files.zip") as response:
data = BytesIO(response.read())
with ZipFile(data) as files:
files.extractall(STORAGE)
def check_version(self):
with urllib.request.urlopen(URL + "/Versionen/latest.vers") as response:
version = response.read().decode(response.headers.get_content_charset() or "ASCII")
with open(os.path.join(APP_PATH, "vers")) as data:
current_version = data.read()
self.update = version != current_version
def update_prices(self, url, labels):
with urllib.request.urlopen(URL + url) as response:
prices = response.read().decode(response.headers.get_content_charset() or "ASCII")
print(prices)
for label, price in zip(labels, prices.split(';')):
label.text = price
def update_all(self, dt):
self.download_files()
self.check_version()
self.root.ids.UpdInf.pos_hint = {'bottom' if self.update else 'top': 1}
ids = self.root.ids
self.update_prices("/PreisErmitlung/OMVNBB.pri", [
ids.sorte1, ids.preis1,
ids.sorte2, ids.preis2,
ids.sorte3, ids.preis3,
ids.sorte4, ids.preis4,
ids.sorte5, ids.preis5,
])
self.update_prices("/PreisErmitlung/DRIVERSINPB.pri", [
ids.sorte1DVP, ids.preis1DVP,
ids.sorte2DVP, ids.preis2DVP,
ids.sorte3DVP, ids.preis3DVP,
ids.sorte4DVP, ids.preis4DVP,
ids.sorte5DVP, ids.preis5DVP,
])
self.update_prices("/PreisErmitlung/SHELLKGB.pri", [
ids.sorte1KGS, ids.preis1KGS,
ids.sorte2KGS, ids.preis2KGS,
ids.sorte3KGS, ids.preis3KGS,
ids.sorte4KGS, ids.preis4KGS,
ids.sorte5KGS, ids.preis5KGS,
ids.sorte6KGS, ids.preis6KGS,
])
def on_start(self):
self.root.ids.refBUT.background_color=(0,0,0,0) if self.blink else (0,0,9,9)
self.blink = not self.blink
self.update_all("*")
def updateinfo_gone(self, ActionPrevious):
self.root.ids.UpdInf.pos_hint={'top':1}
def version_selected(self, ListItemButton):
print("^")
def build(self):
self.settings_cls = SettingsWithSidebar
self.use_kivy_settings= False
return g
def build_config(self, config):
self.config.setdefaults('settings',{"AutoUpdate": 1, "AutoUpdateTime": 30, "CheapNotify": 0})
def build_settings(self,settings):
settings.add_json_panel('Einstellungen', self.config, data=setting_json)
def auto_update(self, dt):
#while True:
with open(os.path.join(APP_PATH, "AutoUpdate.val"), "r") as auto_update_bool:
auto_update_bool = auto_update_bool.read()
with open(os.path.join(APP_PATH, "AutoUpdateTime.val"),"r") as auto_update_time:
auto_update_time = auto_update_time.read()
if auto_update_bool == "1":
self.update_all("*")
else:
pass
auto_update_time = (int(auto_update_time)*60)
Clock.schedule_once(self.auto_update, auto_update_time)
#time.sleep(int(auto_update_time)*60)
def on_config_change(self, config, section, key, value):
if key == "AutoUpdate":
with open(os.path.join(APP_PATH, "AutoUpdate.val"),"w") as auto_update_bool:
auto_update_bool.write(value)
if key == "CheapNotify":
with open(os.path.join(APP_PATH , "CheapNotify.val"),"w") as cheap_notify_bool:
cheap_notify_bool.write(value)
if key == "AutoUpdateTime":
with open (os.path.join(APP_PATH, "AutoUpdateTime.val"),"w") as auto_update_time:
auto_update_time.write(value)
def main():
app = TankstellenApp()
app.download_files()
#_thread.start_new_thread(app.auto_update, ())
Clock.schedule_once(app.auto_update, 0)
app.run()
if __name__ == '__main__':
main()
...