2016-11-05 15 views
0

NiceGraphクラスからグラフを.kvファイルにインポートしたいのですが、どうやってそれを行うのか分かりません。Kivyの別のクラスからグラフをインポートするには?

私はドキュメントを読みましたが、クラスでクラスを使用することについて何も見つかりませんでした。

これは私の試みです。

class NiceGraph(BoxLayout): 
    graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, 
    x_ticks_major=25, y_ticks_major=1, 
    y_grid_label=True, x_grid_label=True, padding=5, 
    x_grid=True, y_grid=True, xmin=-0, xmax=100, ymin=-1, ymax=1) 
    plot = MeshLinePlot(color=[1, 0, 0, 1]) 
    plot.points = [(x, sin(x/10.)) for x in range(0, 101)] 
    graph.add_plot(plot) 

class KivyTesting(BoxLayout): 
    pass 

class KivyTestingApp(App): 
    def build(self): 
     return KivyTesting() 

kivy_testing_app = KivyTestingApp() 
kivy_testing_app.run() 

そして.kvファイルがあります

<KivyTesting>: 
    orientation: 'vertical' 
    padding: 10 
    slider_colors: 0, 0, 0 
    canvas.before: 
     Color: 
      rgb: root.slider_colors 
     Rectangle: 
      pos: root.pos 
      size: root.size 

    BoxLayout: 
     size_hint_y: 200 
     Slider: 
      size_hint_x: 2 
      max: 1 
      value: 0 
      on_value: root.slider_colors[0] = self.value 
     Slider: 
      size_hint_x: 2 
      max: 1 
      min: 0 
      value: 0 
      on_value: root.slider_colors[1] = self.value 
     Slider: 
      size_hint_x: 2 
      max: 1 
      min: 0 
      value: 0 
      on_value: root.slider_colors[2] = self.value 

    BoxLayout: 
     size_hint_y: 600 
     NiceGraph: 
      graph: 

答えて

0

class NiceGraph(BoxLayout): 
    global graph 

    graph = Graph(xlabel='X', ylabel='Y', 
    x_ticks_minor=5, 
    x_ticks_major=25, y_ticks_major=1, 
    y_grid_label=True, x_grid_label=True, padding=5, 
    x_grid=True, y_grid=True, xmin=-0, xmax=100, ymin=-1, ymax=1) 
    plot = MeshLinePlot(color=[1, 0, 0, 1]) 
    plot.points = [(x, sin(x/10.)) for x in range(0, 101)] 
    graph.add_plot(plot) 

class KivyTesting(BoxLayout): 
    graph1 = graph 

を使用してみてくださいと<KivyTesting>:

root.graph1オブジェクトと連携
関連する問題