Created
April 14, 2015 20:13
-
-
Save OlyDLG/a84bcb3a93f4034cec60 to your computer and use it in GitHub Desktop.
Demo of Q re: how to access something after runTouchApp() has been called
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.uix.screenmanager import Screen, ScreenManager | |
from kivy.garden.graph import Graph | |
class appInternalsScreen(Screen): | |
def __init__(self, **kwargs): | |
super(appInternalsScreen, self).__init__(**kwargs) | |
G = Graph(x_grid_label=True, y_grid_label=True, | |
x_ticks_major = 10, y_ticks_major = 10) | |
self.add_widget(G) | |
class appInternalsApp(App): | |
def build(self): | |
self.sm = ScreenManager() | |
self.sm.add_widget(appInternalsScreen(name='home')) | |
return self.sm | |
if __name__ == '__main__': | |
IA = appInternalsApp() | |
IA.run() |
Working solution:
from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.garden.graph import Graph
from functools import partial
def remove_end_labels(axis, parent, obj):
if len(obj) and all(obj) and not eval('parent.been_thru_' + axis):
reduced_list = obj[1:-1]
exec('parent.been_thru_' + axis + ' = True')
exec('parent._' + axis + '_grid_label = reduced_list')
reduced_list = eval('parent._ticks_major' + axis)[1:-1]
exec('parent._ticks_major' + axis + ' = reduced_list')
remove_end_labels_x = partial(remove_end_labels, 'x')
remove_end_labels_y = partial(remove_end_labels, 'y')
class appInternalsScreen(Screen):
def __init__(self, **kwargs):
super(appInternalsScreen, self).__init__(**kwargs)
G = Graph(x_grid_label=True, y_grid_label=True,
x_ticks_major = 10, y_ticks_major = 10)
G.been_thru_x = G.been_thru_y = False
G.bind(_x_grid_label=remove_end_labels_x,
_y_grid_label=remove_end_labels_y)
self.add_widget(G)
class appInternalsApp(App):
def build(self):
self.sm = ScreenManager()
self.sm.add_widget(appInternalsScreen(name='home'))
return self.sm
if __name__ == '__main__':
IA = appInternalsApp()
IA.run()
Nice solution, just started messing with Kivy this week and couldn't find info anywhere else about this. 😄
I was interested in finding out why it worked and ended up writing a StackOverflow answer with my findings. Check it out @ http://stackoverflow.com/questions/24664181/how-do-i-run-a-function-once-the-form-is-loaded-kivy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.garden.graph import Graph
class appInternalsScreen(Screen):
class appInternalsApp(App):
if name == 'main':
IA = appInternalsApp()
IA.run()