“Scriptler/events.py” içerisindeki Event sınıfındaki “current_text” değişkenini güncellemek için “EventWindow” içinde etiketin metnini almaya çalışıyorum. Cevabın “current_text” i “ct” ye bağlayabileceğini, ancak sadece “AttributeError: class Event'in özniteliği‘ bind ’” ile sonuçlandığını anlıyorum. Bu çözümle yanlış bir ağaç havlıyorsam, başka bir yönteme çok yakışırdım. Aşağıda Kivy - Başka bir Sınıftaki Bir Değişkenin Label'in Metni Bağlama
ilgili kod parçacıkları, ancak tam proje bulunmaktadır: https://github.com/DinkWerksmain.py
from kivy.properties import ObjectProperty, StringProperty
from kivy.app import App
# Utility Imports
import yaml
# Game Imports
from scripts.events import Event
# File Loads
loc_file = file('data/location.yml')
loc_dat = yaml.load(loc_file)
# Bind Classes
event = Event()
class EventWindow(BoxLayout):
ct = StringProperty('')
def __init__(self, **kwargs):
super(EventWindow, self).__init__(**kwargs)
self.ct = event.current_text
# Error occurs below. Comment out too see semi-functional app.
Event.bind(current_text=self.setter('ct'))
komut/events.py
from kivy.properties import StringProperty
...
from player import Player
from enemy import Enemy
class Event(Player):
open_events = file('data/event.yml', 'r')
event_file = yaml.load(open_events)
current_text = StringProperty('1234')
def __init__(self):
Player.__init__(self)
self.events = Event.event_file
self.selection = ''
self.current_text = '1234'
def event_name(self):
...
def event_selector(self, eid):
...
def parse(self):
driver = 1
variables = ('Name', 'Is_Person', 'Level', 'Gold')
poss_commands = ("[Next Slide]", "[Query]", "[Terminate]", "[Combat]")
while driver >= 0:
text = self.events[self.selection][driver]
lexer = shlex(text)
lexer.quotes = '/'
output = ''
command = ''
for token in lexer:
if token in variables:
output += str(eval('Player.' + token))
elif token.replace('/', '') in poss_commands:
command += token.replace('/', '')
else:
output += token.replace('/', '')
self.current_text = output
driver += self.controller(command)
self.modifier()
def modifier(self):
...
def controller(self, cmd):
...
text.kv
<EventWindow>:
BoxLayout:
pos: 100,100
size_hint: .4,.7
orientation: 'vertical'
Image:
source: 'maps/map.jpg'
pos: self.pos
size: self.size
ScrollView:
canvas.before:
Color:
rgba: [.2,.2,.2,.8]
Rectangle:
size: self.size
pos: self.pos
Label:
id: text_area
text: root.ct
padding: 15,10
text_size: self.width, None
size_hint_y: None
height: self.texture_size[1]
<Foo>:
id: bl
popup: popup.__self__
header: header
BoxLayout:
orientation: 'vertical'
BoxLayout:
...
FloatLayout:
id: mapspace
canvas:
...
EventWindow:
id: event
Popup:
...
Teşekkürler!
'Event', kivy tarafından kullanılan olaylarla başa çıkmak için uygulanan yöntem ve mekanizmalara sahip değildir. “Player” sınıfınızın sadece çalışması gereken garip şeyler yapmadığı sürece, bunu ['EventDispatcher'] 'ın bir alt sınıfı yapmaya çalışın (https://kivy.org/docs/api-kivy.event.html). – zeeMonkeez
Bu mükemmel çalışır ve mutlak anlamda mantıklıdır. Bu şekilde yeniden göndermek isterseniz, bunu doğru yanıt olarak memnuniyetle kaydederim. – DinkWerks