wxpython - pyinstaller exe with pubsub -


i have written wxpython application uses several different threads of need write log window (textctrl box). because of followed tutorial

http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/

and used wx.callafter , pubsub.

this original code

from wx.lib.pubsub import publisher  publisher().subscribe(self.messenger, "update")  wx.callafter(publisher().sendmessage, "update", "thread finished!")  def messenger(self, msg):     self.logtxtctrl.writetext(msg.data) 

this code worked brilliantly , thought easy use pyinstaller create exe code.

how wrong i!!

so after reading comments seems there 2 versions of pubsub api, using this

http://wiki.wxpython.org/wxlibpubsub

i tweaked code following

from wx.lib.pubsub import setuparg1  wx.lib.pubsub import pub  pub.subscribe(self.messenger, "update")  wx.callafter(pub.sendmessage, "update", data="program success")  def messenger(self, data):     self.logtxtctrl.writetext(data) 

this code works , again tried use pyinstaller , still no luck.

so read following articles

how pubsub work pyinstaller?

http://www.pyinstaller.org/ticket/312

both of useful , tried different variations of changing hook files , different spec files, still cannot work.

these posts 2 years ago , have thought adding pubsub solved.

can please explain process of hooks need, have in spec file , other elements need work?

if there no solution how else can thread safe communications widgets?

try

from wx.lib.pubsub import setupkwargs wx.lib.pubsub import pub 

i have program you're looking for. relevant pieces of code use below. i'd recommend creating function such logger rather using writetext, it's saved me pain down road changes come through.

class frame(wx.frame):     def __init__(self, *args, **kwargs):         super(frame, self).__init__(*args, **kwargs)         self.initui()         self.setsize((380,340))         self.show()         self.count = 0         self.threads = []         pub.subscribe(self.__statuschanged, 'status.changed')      def __statuschanged(self, asset, time, status):         if status:             msg = 'online'         else:             msg = 'offline'         self.logger('{}: {} - {}\n'.format(time, asset, msg))      def logger(self, msg):         self.txtresults.appendtext(msg)  class pingassets(threading.thread):     def __init__(self, threadnum, asset, window):         threading.thread.__init__(self)         self.threadnum = threadnum         self.window = window         self.asset = asset         self.signal = true         self.status = none      def run(self):         while self.signal:             logging.debug("thread {} started run sequence.".format(self.threadnum))             start_time = datetime.now().strftime(self.fmt)             try:                 newstatus = onlinecheck.check_status(self.asset)                 if newstatus != self.status or self.verbose:                     self.status = newstatus                     pub.sendmessage('status.changed', asset=self.asset,                                     time=start_time, status=self.status) 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -