Kivy Python的屏幕管理器出现问题

时间:2016-05-10 19:02:49

标签: python screen kivy transition

我正在为一个kivy app做一个函数,在第一个屏幕中需要插入一些数据输入。我的想法是在你没有正确输入数据的情况下显示弹出窗口,但我一直在测试我的应用程序,我不知道如何以正确的方式做到这一点。按下按钮时,在进入下一个屏幕之前,会加载并检查输入(此时如果它们不正确,则会显示弹出窗口)。以下是按下按钮时执行的函数的代码:

# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.properties import DictProperty
from kivy.properties import StringProperty
from kivy.uix.popup import Popup


Builder.load_string('''
<Root>:
    Welcome:
        name: 'welcome'
    MainScreen:
        name: 'main'
    AnotherScreen:
        name: 'another'

<GridLayout>
    canvas.before:
        Color:
            rgba: 0.5, 0.5, 0.5, 0.1
        BorderImage:
            # BorderImage behaves like the CSS BorderImage
            border: 10, 10, 10, 10
            source: '../ABRIL/Presentacion/etseib.jpg'
            pos: self.pos
            size: self.size

<FloatLayout>
    canvas.before:
        Color:
            rgba: 0.5, 0.5, 0.5, 0.1
        BorderImage:
            # BorderImage behaves like the CSS BorderImage
            border: 10, 10, 10, 10
            source: '../examples/widgets/sequenced_images/data/images/button_white.png'
            pos: self.pos
            size: self.size

<Welcome>:

    FloatLayout:
        Label:
            text: "" 
            size_hint_y: 0.1
            pos_hint: {'center_x':0.5,'center_y':0.6}
        Label:
            text: "Escriu el teu correu "
            font_size: 25
            size_hint: 0.2, 0.05
            pos_hint: {'center_x':0.3,'center_y':0.20}
        Label:
            text: "Benvingut a l'aplicacio ETSEIB Calendar. Per tal d'obtenir el teu arxiu amb el calendari de practiques de laboratori del GETI, segueix els seguents passos:\\n1.Inserta el teu mail (es recomana plataforma gmail o hotmail.\\n2.Selecciona quan amb quina antelacio vols rebre la notificacio de la practica\\n3.Selecciona les assignatures a la seguent pantalla.\\n4.Inserta els grups.\\n5.Revisa el teu mail i descarrega l'arxiu."
            size_hint_y: 0.5
            pos_hint: {'center_x':0.5,'center_y':0.36}
        Spinner:
            text: 'Selecciona quan vols rebre lavis'
            values:('1 hora abans','8 hores abans','24 hores abans')
            pos_hint: {'center_x':0.5,'center_y':0.28}
            size_hint: 0.2, 0.05
            on_text: root.aff(self.text)
        Button:
            text: "Exit"
            background_color: .7, 1, 6, 1
            on_release:root.close()
            size_hint: 0.4, 0.1
            pos_hint: {'center_x':0.2,'center_y':0.05}

        Button:
            text: "Next"
            font_size: 
            background_color: .7, .7, 1, 1
            size_hint: 0.4, 0.1
            pos_hint: {'center_x':0.8,'center_y':0.05}
            on_release:
                root.ready()
                #root.parent.current='main'
                #root.parent.transition.direction = 'left'
                #root.parent.transition= SwapTransition
        TextInput:
            multiline: False
            size_hint: 0.2, 0.05
            pos_hint: {'center_x':0.5,'center_y':0.20}
            on_text: root.add(self.text)



<MainScreen>:
    GridLayout:
        cols: 2
        Label:
            text: "Select Subjects (1/2)"
            font_size: 15

        Button:
            text: "Main Page"
            background_color: .7, 1, 6, 1
            on_release:
                root.parent.current='welcome'
                root.parent.transition.direction = 'right'
        Button:
            text: "Next"
            font_size: 
            background_color: .7, .7, 1, 1
            on_release:
                root.parent.current='another'
                root.parent.transition.direction = 'left'

''')

class Welcome(Screen):
    def __init__(self, **kw):
        super(Welcome, self).__init__(**kw)
        self.a = App.get_running_app()
    def add(self,p): #emmagatzema els textsinputs   
        self.a.email=p #.encode("utf-8")
    #falta enlazarlo
    def aff(self,p):
    self.a.temps=p[0:2]

    def ready(self):
        if self.a.temps=="default" or self.a.email=="":
            content=Label(text='Insert Valid Data')
            popup = Popup(title='Error',content=content,size_hint=(0.7, 0.5),background_color=(0, 0, 0, 0))
            popup.open()
            content.bind(on_press=popup.dismiss)
        else:

            self.parent.transition.direction = 'left'
            self.parent.current='main'
    def close(self):
        return  App.get_running_app().stop()

class MainScreen(Screen):
    def __init__(self, **kw):
        super(MainScreen, self).__init__(**kw)
        self.a = App.get_running_app()
    def ping(self, n, value): #emmagatzema les caselles marcades
        self.a.big_dict[n] = value
    def close(self):
        return  App.get_running_app().stop()
class AnotherScreen(Screen):      
    def on_pre_enter(self, *args):
        #i=filtro.dic(0)
    a = App.get_running_app()
        t={} #dintre del diccionari t s'emmagatzemaren els inputs
    keys=[] #aquesta llista permetra ordenar les caselles seleccionades per les seguents pantalles, independentment del ordre seleccionat
        def change(self):
        self.parent.transition.direction = 'right'
                self.parent.current='second'

        b2=Button(text='Run',background_color=[0,1,0,1])
        self.add_widget(b2)
    b2.bind(on_release=change)

class Root(ScreenManager):
    pass
class SimpleKivy(App): #aquest diccionari permet emmagatzemar les caselles marcades(inicialment totes desmarcades==FALSE)
    big_dict = DictProperty({'240161': False, '240061': False, '240171': False, '240151': False, '240063': False, '240073': False, '240072': False, '240031': False, '240033': False, '240054': False, '240053': False, '240052': False, '240172': False}
)
    email=StringProperty("")
    temps=StringProperty("default")
    def build(self):
        return Root()
SimpleKivy().run()

我担心的问题可能在于改变屏幕,因为我的做法和kivy语言一样。感谢。

0 个答案:

没有答案