Code: Alles auswählen
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.clock import Clock
import json
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"
}
]
)
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 verfuegbar"
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 guenstigem Preis"
Switch:
id:CheapNotSwitch
on_active: app.CheapNotSwitched(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 verfuegbar\\nwarte auf Updates und versuche es dann erneut"
# Button:
# size_hint: None, None
# height: 125
# width: 750
# text:"Auf Updates pruefen"
# 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 verfuegbar\\nwarte auf Updates und versuche es dann erneut"
Button:
size_hint: None, None
height: 125
width: 750
text:"Auf Updates pruefen"
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 verfuegbar\\nwarte auf Updates und versuche es dann erneut"
Button:
size_hint: None, None
height: 125
width: 750
text:"Auf Updates pruefen"
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 verfuegbar\\nwarte auf Updates und versuche es dann erneut"
Button:
size_hint: None, None
height: 125
width: 750
text:"Auf Updates pruefen"
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):
def __init__(self):
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!\n"
"Du kannst in den Einstellungen die Preise verändern bei denen du Benachrichtigugen erhalten willst!")
with open(os.path.join(APP_PATH, "CheapNotify.val", "w")) as output:
output.write(str(value))
@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 = request.read().decode(request.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(url, labels):
with urllib.request.urlopen(URL + "/Versionen/latest.vers") as response:
prices = request.read().decode(request.headers.get_content_charset() or "ASCII")
for label, price in zip(label, prices.split(';')):
label.text = price
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.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 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": True})
def build_settings(self,settings):
settings.add_json_panel('Einstellungen', self.config, data=setting_json)
def main():
app = TankstellenApp()
Clock.schedule_interval(app.on_start, 30)
app.run()
if __name__ == '__main__':
main()
Code: Alles auswählen
[INFO ] [Logger ] Record log in C:\Users\MupfSpace\.kivy\logs\kivy_19-01-28_3.txt
[INFO ] [Kivy ] v1.10.1
[INFO ] [Python ] v3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)]
[INFO ] [Factory ] 194 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used <glew>
[INFO ] [GL ] OpenGL version <b'4.5.0 - Build 22.20.16.4771'>
[INFO ] [GL ] OpenGL vendor <b'Intel'>
[INFO ] [GL ] OpenGL renderer <b'Intel(R) HD Graphics 620'>
[INFO ] [GL ] OpenGL parsed version: 4, 5
[INFO ] [GL ] Shading version <b'4.50 - Build 22.20.16.4771'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Text ] Provider: sdl2
[WARNING] [Call to deprecated function __init__ in C]\Python37\lib\site-packages\kivy\uix\listview.py line 845.Called from C:\Python37\lib\site-packages\kivy\lang\builder.py line 582 by _apply_rule().
[WARNING] [Call to deprecated function __init__ in C]\Python37\lib\site-packages\kivy\adapters\simplelistadapter.py line 49.Called from C:\Python37\lib\site-packages\kivy\uix\listview.py line 859 by __init__().
[WARNING] [Call to deprecated function __init__ in C]\Python37\lib\site-packages\kivy\adapters\adapter.py line 111.Called from C:\Python37\lib\site-packages\kivy\adapters\simplelistadapter.py line 55 by __init__().
[WARNING] [Call to deprecated function __init__ in C]\Python37\lib\site-packages\kivy\uix\abstractview.py line 42.Called from C:\Python37\lib\site-packages\kivy\uix\listview.py line 865 by __init__().
[INFO ] [GL ] NPOT texture support is available
[WARNING] [Call to deprecated function __init__ in C]\Python37\lib\site-packages\kivy\adapters\listadapter.py line 185.Called from <string> line 433 by <module>().
[WARNING] [Call to deprecated function __init__ in C]\Python37\lib\site-packages\kivy\adapters\adapter.py line 111.Called from C:\Python37\lib\site-packages\kivy\adapters\listadapter.py line 186 by __init__().
Traceback (most recent call last):
File "c:\Users\MupfSpace\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\ptvsd_launcher.py", line 45, in <module>
main(ptvsdArgs)
File "c:\Users\MupfSpace\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd\__main__.py", line 265, in main
wait=args.wait)
File "c:\Users\MupfSpace\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd\__main__.py", line 256, in handle_args
run_main(addr, name, kind, *extra, **kwargs)
File "c:\Users\MupfSpace\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd\_local.py", line 52, in run_main
runner(addr, name, kind == 'module', *extra, **kwargs)
File "c:\Users\MupfSpace\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd\runner.py", line 32, in run
set_trace=False)
File "c:\Users\MupfSpace\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd\_vendored\pydevd\pydevd.py", line 1283, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "c:\Users\MupfSpace\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd\_vendored\pydevd\pydevd.py", line 1290, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "c:\Users\MupfSpace\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd\_vendored\pydevd\_pydev_imps\_pydev_execfile.py", line 25, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "c:\Users\MupfSpace\Desktop\App test1\for.py", line 781, in <module>
main()
File "c:\Users\MupfSpace\Desktop\App test1\for.py", line 778, in main
app.run()
File "C:\Python37\lib\site-packages\kivy\app.py", line 797, in run
if not self.built:
AttributeError: 'TankstellenApp' object has no attribute 'built'