Kivy AttributeError: 'NoneType' object has no attribute 'ids'

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

ich habe des jetzt so gemacht:

Code: Alles auswählen

 def update_all(self, dt):
        try:
            j.cancel()
        except:
            pass
und es funktioniert :D

EDIT:
aber ich galube du hast mal in einem andren thema mit den datenabnken mal zu mir gesagt ich soll try except nicht verwenden ist das immer noch so?
Benutzeravatar
__blackjack__
User
Beiträge: 13004
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

@MupfSpace: Das sollte so aber nicht funktionieren, weil das bedeutet das `j` jetzt eine globale Variable ist. Aber ich vermute mal das Dir das egal ist und Du kein Python und nicht programmieren lernen willst…
“Most people find the concept of programming obvious, but the doing impossible.” — Alan J. Perlis
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

__blackjack__ hat geschrieben: Sonntag 3. Februar 2019, 18:14 Aber ich vermute mal das Dir das egal ist und Du kein Python und nicht programmieren lernen willst…
das stimmt gar nicht wenn ich nicht programmieren lernen wollen würde dann würde ich das alles nicht machen.
:cry: :cry: :cry:
Sirius3
User
Beiträge: 17711
Registriert: Sonntag 21. Oktober 2012, 17:20

@MupfSpace: woher kommt denn `j`? Wann erwartest Du welche Exception? `update_all` ist wohl auch der falsche Ort, wenn Du bei einer Konfigurationsänderung das Updaten abschalten willst.
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

j kommt von der if Bedingung in auto_update()
Das bedeutet wohl dass da auch das cancel stattfinden soll.
Wahrscheinlich ist es auch eine gute Idee j immer zu beenden wenn die Einstellungen verändert werden damit wenn die Zahl verändert nicht alle -alte Zahl sekunden- und alle -neue Zahl sekunden- Updatet.
Aber ich habe fest gestellt (bitte korrigiert mich wenn ich falsch liege) in einer zeile nach der Erstellung von j und in der gleichen if Bedingung geschehen muss aber wie ist das möglich wenn die if Bedingung nur geschieht wenn die Einstellungen stimmt.
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

Was gibt es dann für eine Möglichkeit
__deets__
User
Beiträge: 14493
Registriert: Mittwoch 14. Oktober 2015, 14:29

Du musst doch nichts canceln. Du kannst einfach eine Bedingung in deinem Programm prüfen. Und eben einfach nichts machen. Dann muss auch nichts wieder gestartet werden.
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

ich hab das jetzt folgen der maßen gemacht:

Code: Alles auswählen

    def auto_update(self):
        while True:
            with open(os.path.join(APP_PATH, "AutoUpdate.val"), "r") as response:
                auto_update_bool = response.read()
            with open(os.path.join(APP_PATH, "AutoUpdateTime.val"),"r") as response:
                auto_update_time = response.read()
            if auto_update_bool == "1":
                self.update_all("*")
            else:
                pass
            time.sleep(int(auto_update_time))
und es funktioniert :mrgreen:
allerdings halt jetz wieder mit _thread
__deets__
User
Beiträge: 14493
Registriert: Mittwoch 14. Oktober 2015, 14:29

_thread NICHT BENUTZEN. Das ist ein internes Modul. Wo die Leute das immer herhaben...

Wenn du schon threading benutzen willst, dann

import threading

Vor allem aber geht das nicht. Du denkst es geht. Das ist so als ob du einfach ohne zu gucken ueber die Strasse gehst. Geht gut. Solange, bis es das mal nicht tut. Man darf GUI-Code nicht aus anderen Threads aufrufen (und self.update_all tut das doch garantiert). Damit riskierst du schlimme Fehler und Abstuerze. Benutz den Timer, der ist dafuer gedacht. Wir empfehlen diese Dinge nicht grundlos.
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

aber wenn ich das mit Clock.schedule mache dann habe ich nur ein weißes Bild
__deets__
User
Beiträge: 14493
Registriert: Mittwoch 14. Oktober 2015, 14:29

Lass mich raten - du machst dann ein sleep? Das darf man in einer GUI eben nicht. Ich bin sicher, das wurde hier auch schonmal erwaehnt. In einer GUI darf man eben nichts tun was lange blockiert.

Bitte zeig mal deinen GESAMTEN Code, damit man mal beurteilen kann, was du da eigentlich wie machst.
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

Ja aber ein thread behindert ja nichts sondern läuft neben bei
Benutzeravatar
__blackjack__
User
Beiträge: 13004
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

@MupfSpace: Der Thread darf aber nichts an der GUI ändern. Wenn Du das vom Thread aus tust, und sich in der GUI auf Deinem Bildschirm aber nichts tut, dann ist das genau so ein Phänomen was auftreten kann. Neben beliebigen Anderen, wie harten Programmabstürzen oder das das Programm einfriert bei 100% CPU-Auslastung, oder…
“Most people find the concept of programming obvious, but the doing impossible.” — Alan J. Perlis
__deets__
User
Beiträge: 14493
Registriert: Mittwoch 14. Oktober 2015, 14:29

MupfSpace hat geschrieben: Mittwoch 6. Februar 2019, 18:20 Ja aber ein thread behindert ja nichts sondern läuft neben bei
Das denkst du nur. In dem Moment, wo der nebenlaeufige Thread anfaengt, an den Innereien der GUI rumzufummeln, kommt er sich mit dem Main-Thread in die Quere. Und es kracht. Das tueckische daran ist, dass das nicht *zwangslaeufig* so ist. So wie mit meinem Beispiel mit der Strasse. Du kannst 100mal einfach auf die Strasse rennen, und alles geht gut. Irgendwann rennst du vor ein Auto, und brichst dir ein Bein oder schlimmeres. Und so ist das mit dem Thread auch. Nur weil du das nicht beobachtest, heisst es nicht, dass das Risiko nicht da ist.
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

so in etwa?

Code: Alles auswählen

    def auto_update(self):
        #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
        Clock.schedule_once(self.auto_update, int(auto_update_time))
        #time.sleep(int(auto_update_time)*60)            
funktionieren tuts auf jeden fall :D
__deets__
User
Beiträge: 14493
Registriert: Mittwoch 14. Oktober 2015, 14:29

Aber das ist doch komplett geraten. Du hast hier doch schonmal ein laufendes Beispiel von scheduling gehabt. Was soll denn bei deinem (mal abgesehen von dem Rechtschreibfehler) bei schedule_once rumkommen? Wenn ich dir sage "Mupfspace, mach was in 10 Sekunden" - was machst du dann? Nix. Ich habe dir naemlich nicht gesagt, WAS du in 10 Sekunden machen willst. Und du hast das hier auch nicht getan. Also kann die Antwort nur lauten 'nein, so nicht'.

Es ist schoen, dass du programmieren lernen willst. Aber du hast dir ein grossen, umfangreiches Problem gesucht, bei dem du mit raten versuchst, daran rum zu schrauben. Das wird leider nichts werden. Du hast ausserdem immer noch nicht deinen gesamten Code gezeigt, so dass man beurteilen koennte, was da wie ineinander greift. Woher die Dateien kommen, die du da auswertest zum Beispiel. Ich bin mir 100%ig sicher, dass man das besser machen kann, ganz ohne Dateien.
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

ich habe das deshalb mit schedule_once gemacht weil dann jedes mal beim aufrufen die zeit aktualisiert werden kann.

außerdem reicht doch once 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()

...
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

Ist dass dann das gleiche Problem wie bei dem thread und dem Beispiel mit der Straße?
__deets__
User
Beiträge: 14493
Registriert: Mittwoch 14. Oktober 2015, 14:29

Es ist schon besser. Allerdings hast du natürlich das Problem, dass dein autoupdate nie wieder beginnt. Ich würde also schedule_interval machen, aber dann in auto_update einfach prüfen, ob man was machen soll. Wenn nicht, einfach nichts machen.

Damit Sparst du dir die Komplexität das an und aus zu schalten. Etc.
MupfSpace
User
Beiträge: 169
Registriert: Montag 25. Dezember 2017, 20:26

Aber dann kann man die Zeit nicht verändern
Antworten