2014-03-27 3 views
0

나는 Rhythmbox 플러그인에서 작업 중이므로 진행 표시 줄이있는 대화 상자를 표시해야합니다.파이썬에서 진행 막대를 사용하여 대화 창을 표시하는 방법

def download_all_lyrics_action_callback(self, action): 
     progressbar = Gtk.ProgressBar(); 

     dialog = Gtk.Dialog(_('lLyrics Preferences'), self.shell.get_property('window'), 
       Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_OK, Gtk.ResponseType.OK)) 

     content_area = dialog.get_content_area() 
     content_area.pack_start(progressbar, True, True, 0) 

     dialog.show_all() 

     dialog.run() 

     total = len(self.shell.props.library_source.props.query_model) 
     i = 1; 
     for row in self.shell.props.library_source.props.query_model: 
      entry = row[0] 
      title = entry.get_string(RB.RhythmDBPropType.TITLE) 
      artist = entry.get_string(RB.RhythmDBPropType.ARTIST) 
      print(title + " - " + artist) 

      self.get_lyrics_for_song(title, artist) 
      progressbar.set_fraction(i/total) 
     dialog.hide() 

문제는이 dialog.run() 명령에 그만이다 다음은 내 코드입니다. 나는 발견했지만 성공하지 못한 코드도 테스트했다. 이 문제를 해결하도록 도와 주시겠습니까?

답변

1

dialog.run() 사용자가 대화 상자를 닫거나 응답 버튼 중 하나를 누를 때까지 실행되는 메인 루프를 시작합니다. 원하는 것을 얻으려면 dialog.show()으로 전화하는 것이 좋습니다.

각 통화 후에 주 루프 (while Gtk.events_pending(): Gtk.main_iteration(False))를 실행하여 진행률 막대를 변경해야합니다. 유휴 기능에서 진행률 막대를 업데이트하십시오. 그렇지 않으면 변경 사항이 표시되지 않습니다.

관련 문제