2017-07-05 18 views
1

Kivyのツリービューには、どれだけ大きいかによって時間がかかります。別のスレッドで実行されているKivyポップアップ

ツリーが大きく、しばらく時間がかかる場合は、ポピュレート中にポップアップを表示して、プログラムがフリーズしていないことをユーザーが認識しているのを確認して、ツリーをポピュレートするロジックが終了したらこのポップアップを閉じます。ここで

は、私はこのトピックに関するいくつかの研究を通じて出ているものですが、ポップアップはまだツリーが移入終了するとだけ来るようだ:

def show(self, *args): 
     self.error_popup.open() 

def populate_tree(self, model): 
     #Clock.schedule_once(self.error_popup.open()) 
     popup_thread = threading.Thread(target=self.show()) 
     popup_thread.start() 

     # order the dictionary for better user experience 
     ordered_data = collections.OrderedDict(sorted(model.items())) 

     # logic to populate tree 
     for county, value in ordered_data.items(): 

      if county != "model_name": 
       # set initial county dropdowns in tree 
       county_label = self.treeview.add_node(TreeViewButton(text=str(county), on_press=self.edit_node)) 
       i = 0 # keep count of rules 

       # add rules children to county 
       for rule_obj, rule_list in value.items(): 
        for rule in rule_list: 
         i += 1 
         # set rule number in tree 
         rule_label = self.treeview.add_node(TreeViewButton(text='Rule ' + str(i), on_press=self.edit_node), county_label) 
         # add conditions children to rule 
         for condition in rule: 
          self.treeview.add_node(TreeViewButton(text=condition, on_press=self.edit_node), rule_label) 

     #Clock.schedule_once(self.error_popup.dismiss()) 
     #somehow close popup_thread 

私は場合それでkivy時計の試みを含め私が探しているものの正しい軌道上にありますが、現在のところ、ポップアップを開いてしまい、ツリーにデータを入力することはありません。私はGUIプログラミングとイベントのコールバックに新しいので、どんな助けも大歓迎です。

もっとコードが必要な場合は、私に教えてください。

答えて

-1

あなたはこれを分類できましたか?

ポップアップを表示するのではなく、ツリーをポピュレートするためにスレッドを使用するとうまくいくと思います。ツリーを移入した後、同じスレッドであなたが見てみましょう()

main.pyファイルPopup.dismissを使用して

from kivy.app import App 
from kivy.uix.popup import Popup 
from kivy.uix.label import Label 
from kivy.uix.boxlayout import BoxLayout 
import time, threading 

class popupTestApp(App): 
    def waitSec(self): 
     time.sleep(5) 
     self.p.dismiss() 

    def popUpFunc(self): 
     self.p = Popup(title='Test Popup', content=Label(text='This is a test'), size_hint=(None,None), size=(400,400)) 
     self.p.open() 
     popUpThread = threading.Thread(target=self.waitSec) 
     popUpThread.start() 

if __name__ == '__main__': 
    popupTestApp().run() 

popuptest.kvファイル

BoxLayout: 
    BoxLayout: 
     id:LeftPane 
     Button: 
      id:MyButton 
      text:'Pop it up!' 
      on_release:app.popUpFunc() 
    BoxLayout: 
     id:RightPane 
     Label: 
      text: 'Another Pane' 

をポップアップ閉じることができますこれがよく説明されている下のリンクにあります。

Building a simple progress bar or loading animation in Kivy

関連する問題