Fwd: pygtk Digest, Vol 128, Issue 4

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Fwd: pygtk Digest, Vol 128, Issue 4

Peter Irbizon
Hi Tim, thanks for your reply. Unfortunatelly I have no idea how to edit my code to make it working properly. I need to treat long running process (that's because I use threading) and leave my app window "unfreezed" during this process. I tried it with my code but I am not able to call deiconify function from this running process (especially it should make program window visible when something happens - e.g. exception raises, or I want to tell something to user, etc). Could you please provide me with short code of working example? I am newbie and appreciate your help. 

thank you! 

---------- Forwarded message ----------
From: <[hidden email]>
Date: 2013/10/18
Subject: pygtk Digest, Vol 128, Issue 4
To: [hidden email]


Send pygtk mailing list submissions to
        [hidden email]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.daa.com.au/mailman/listinfo/pygtk
or, via email, send a message with subject or body 'help' to
        [hidden email]

You can reach the person managing the list at
        [hidden email]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of pygtk digest..."


Today's Topics:

   1. python deiconify and show is not working with threading
      (Peter Irbizon)
   2. Re: python deiconify and show is not working with threading
      (Tim Evans)


----------------------------------------------------------------------

Message: 1
Date: Thu, 17 Oct 2013 20:17:40 +0200
From: Peter Irbizon <[hidden email]>
To: [hidden email]
Subject: [pygtk] python deiconify and show is not working with
        threading
Message-ID:
        <CABFuWSwfjaJcx9-fz4psJCF3sQAtAwN-OzxeBspKUvTe2En=[hidden email]>
Content-Type: text/plain; charset="iso-8859-1"

Hello,
please in function topko there are deiconify() and show() in my code but it
will not show my window. Please how can should I change it?

my code:
# -*- coding: utf-8 -*-
import sys
import traceback
import os
import threading
import psutil

def we_are_frozen():
  return hasattr(sys, "frozen")

def module_path():
  encoding = sys.getfilesystemencoding()
  if we_are_frozen():
    return os.path.dirname(unicode(sys.executable, encoding))
  return os.path.dirname(unicode(__file__, encoding))

os.environ['LANGUAGE'] = "en"
import elib.intl
import pygtk
pygtk.require("2.0")
import gtk
import gobject
import urllib2
import datetime
import time, platform
from _winreg import *
import warnings
warnings.simplefilter('ignore', Warning)


def hooo(err, ret=None, error=''):
  print traceback.format_exc()
  print err
  while gtk.events_pending():
    gtk.main_iteration()
  gtk.gdk.flush()
  gtk.threads_leave()
  topko()
  topko()

def topko():
  app.okno.deiconify()
  gdkwin = app.okno.window
  gdkwin.set_keep_above(True)
  gdkwin.set_keep_above(False)
  gdkwin.show()

class jj:
    def __init__(self):

        local_path=os.path.join(module_path(), "lg")
        elib.intl.install('translation', local_path)
        self.okno = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.okno.iconify()
        self.okno.resize(400,50)
        self.okno.show_all()

        #self.xx()

    def play(self):
        threading.Thread(target=self.xx).start()

    def xx(self):
      db="a.s"
      if os.path.isfile(db.decode('utf8').replace('\\','/')) == False:
        hooo('5','')
        return False

if __name__ == "__main__":
    gtk.threads_init()
    app = jj()
    app.play()

    gtk.threads_enter()
    gtk.main()
    gtk.threads_leave()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20131017/b5900ecd/attachment-0001.html>

------------------------------

Message: 2
Date: Fri, 18 Oct 2013 10:29:09 +1300
From: Tim Evans <[hidden email]>
To: [hidden email]
Subject: Re: [pygtk] python deiconify and show is not working with
        threading
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=UTF-8; format=flowed

On 2013-10-18 07:17, Peter Irbizon wrote:
> Hello,
> please in function topko there are deiconify() and show() in my code but
> it will not show my window. Please how can should I change it?

 From the import of _winreg I can tell you're working on Windows.

On Windows, you cannot interact with gtk widgets from a background
thread. It will just lock up your app, or not work in other ways. This
is caused by the underlying win32 "HWND" belonging to the main thread;
operating on it from another thread needs to be done differently and
carefully and GTK (rightly IMO) doesn't try to do that for you.

The best way to fix this is to do everything GTK-related in the main
thread. The easiest way to do that is via glib.idle_add().

     def update_the_ui():
         with gtk.gdk.lock:
             # put code here that interacts with the UI
             return False

     def function_in_another_thread():
         glib.idle_add(update_the_ui)

Unlike other GTK functions, glib.idle_add() *is* thread safe, so you can
call it from anywhere. The function you pass it will then run in the
main thread and can interact with GTK with no problems.

--
Tim Evans


------------------------------

_______________________________________________
pygtk mailing list [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


End of pygtk Digest, Vol 128, Issue 4
*************************************


_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/