lundi 30 janvier 2017

Kivy python- class variables passing

i dont know how to pass a variable from the Builder.Load_String to the Send_File() function in another class. i want to send the specific word from the specific button clicked.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.graphics import Color, Ellipse, Line
import socket
import sys
import os
import webbrowser
from server import send_file
import thread
import random
import multiprocessing
lines = open("words.txt").readlines()
word_list = []
for x in range(0, 3):
    isexist = True
    line = lines[0] 
    words = line.split() 
    myword = random.choice(words)
    while isexist:
        if myword not in word_list:
            word_list.append(myword)
            print myword
            isexist = False
        myword = random.choice(words)

Builder.load_string("""
<MenuScreen>:
    BoxLayout:
        Button:
            text: 'Start Game'
            on_press: root.manager.current = 'settings'
        Button:
            text: 'quit'

<SettingsScreen>:
    BoxLayout:
        Button:
            text: """ + "'" + word_list[0]+ "'" + """
            size_hint: 0.25,1
            on_press: root.manager.current = 'paint'

        Button:
            text: """+ "'" + word_list[1]+ "'" + """
            size_hint: 0.25,1
            on_press: root.manager.current = 'paint'
        Button:
            text: """+ "'" + word_list[2]+ "'" + """
            size_hint: 0.25,1
            on_press: root.manager.current = 'paint'
        Button:
            text: 'Back to menu'
            size_hint: 0.25,1
            on_press: root.manager.current = 'menu'
<MyPaintScreen>:
    BoxLayout:            
""")

# Declare both screens
class MenuScreen(Screen):
    pass
class MyPaintScreen(Screen):  
    def on_enter(self):
        multiprocessing.Process(target=MyPaintApp().run).start()
class SettingsScreen(Screen):
    pass
class WordsScreen(Screen):
    pass

# Create the screen manager
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(SettingsScreen(name='settings'))
sm.add_widget(MyPaintScreen(name='paint'))

class MyPaintWidget(Widget):
    def __init__(self):
        super(MyPaintWidget, self).__init__()
        self.lineSize = 5
    def on_touch_down(self, touch):
        with self.canvas:
            touch.ud['Line'] = Line(points=(touch.x, touch.y), width=self.lineSize)

    def on_touch_move(self, touch):
        touch.ud['Line'].points += [touch.x, touch.y]

class TestApp(App):
    def build(self):
        return sm

class MyPaintApp(App):
    def build(self):
        self.parent = Widget()
        self.painter = MyPaintWidget()

        self.parent.add_widget(finishbtn)

        return self.parent
    def finish(self,obj):
        photo =self.parent.export_to_png("C:\Users\student\Desktop\yoav.png")
        send_file(myword)

if name == 'main': TestApp().run()




Aucun commentaire:

Enregistrer un commentaire