python - Creating multiple QtGui.QWidget dynamically -


what want do:

  • list of names changes on time
  • an infinite loop ("while true:") creates qtgui.qwidget each name in list - when new name pops in list --> create new qtgui.qwidget

what have far:

    pyqt4 import qtcore, qtgui     import sys      try:         _fromutf8 = qtcore.qstring.fromutf8     except attributeerror:         def _fromutf8(s):             return s      try:         _encoding = qtgui.qapplication.unicodeutf8         def _translate(context, text, disambig):             return qtgui.qapplication.translate(context, text, disambig, _encoding)     except attributeerror:         def _translate(context, text, disambig):             return qtgui.qapplication.translate(context, text, disambig)      class ui_form(qtgui.qwidget):         def __init__(self, player_name):             self.player_name = player_name             qtgui.qwidget.__init__(self)             self.setupui(self)          def setupui(self, form):         ...       app = qtgui.qapplication(sys.argv)     ex = ui_form('player_1')     ex.show()     sys.exit(app.exec_()) 

now code above works fine creating widget 'player_1'. can create more 1 ui_form without issue.

for example:

    app = hud.qtgui.qapplication(sys.argv)     ex_1 = hud.ui_form('player_1')     ex_2 = hud.ui_form('player_2')     ex_1.show()     ex_2.show()     sys.exit(app.exec_()) 

my question now: there way create widgets dynamically? example in loop list:

    player in player_list:         app = qtgui.qapplication(sys.argv)         ex = ui_form('player')         ex.show()         sys.exit(app.exec_()) 

"i know code above not correct shows idea."

is not possible due ".exec_()" , fact blocking till app closed?

update:

based on suggestion of robert jacobs tried using separate threads each player , works.

here code:

from subprocess import call threading import thread import time, os  class myclassa(thread):     def __init__(self, player_name):         thread.__init__(self)         self.daemon = true         self.player_name = player_name         self.start()      def run(self):         call(["python","widget.py",self.player_name])  test_list = ['player_1','player_2']  in test_list:     myclassa(i)     time.sleep(1) 

so doing calling first script "widget.py" each player in separate thread 2nd script.

without "time.sleep(1)" @ end first of 2 windows opens, idea why?

is there way check if window same title (the title of window = player_name) exists?


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -