473,394 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

GUI freezes when executing def function. Use threads?

6
Hi,
I've made a small program which has 2 buttons and each does certain thing. Here's a simplified version of the code.

Thing is it works fine except that the button freezes and stays in a clicked position and whole GUI freezes until the command is completed.
As far as I know threads would be best to use in this situation, but I have no idea how to implement it in this example.

I use glade and pygtk for gui.

Expand|Select|Wrap|Line Numbers
  1. def do1:
  2.         t = 2
  3.         #do something
  4.         time.sleep(t)
  5.         #do something
  6.         time.sleep(t)
  7. def do2:
  8.         t = 3
  9.         #do something
  10.         time.sleep(t)
  11.         #do something
  12.         time.sleep(t)
  13.  
  14. class we:
  15.         wTree = None
  16.         def __init__( self ):                
  17.                 self.wTree = gtk.glade.XML( "ui.glade" )
  18.  
  19.                 dic = {
  20.                         "on_buttonSone" : self.sone,
  21.                         "on_buttonStwo" : self.stwo,
  22.                 }
  23.                 self.wTree.signal_autoconnect( dic )              
  24.                 gtk.main()
  25.  
  26.         def sone(self, widget):
  27.                 i = 0
  28.                 while i < 3:
  29.                         t = 1
  30.                         #do something
  31.                         i += 1
  32.                         time.sleep(t)           
  33.                 self.wTree.get_widget("entryResult").set_text("Done.")
  34.         def stwo(self, widget):
  35.                 start = time.clock()
  36.                 array = ['A','B']
  37.                 adict = {'A':do1,'B':do2}
  38.                 for f in array:
  39.                         adict[f]()
  40.                 end = time.clock()
  41.                 elapsed = end - start
  42.                 gg = round(elapsed,2)             
  43.                 self.wTree.get_widget("entryResult").set_text(str(gg))             
  44.  
  45. go=we()
  46.  
  47.  
Apr 9 '10 #1
0 975

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Maxwell Hammer | last post by:
An application I am developing executes many threads and then has a "monitor" part that waits for certain events. One of these events causes the application to have to shutdown. On shutdown the...
2
by: Tony Liu | last post by:
Hi, I want to get the name of the calling function of an executing function, I use the StackTrace class to do this and it seems working. However, does anyone think that there any side effect...
10
by: Paul | last post by:
Hi Guys, I have an application which uses COM object to connect to a "pick" database. With this object I can run some select statemnts, however when the select command is send to the server, my...
2
by: Joe Bloggs | last post by:
I have a Windows form application that has a start button, a progress bar and also writes information to the status bar the code is C#. My problem is that when you hit the start button and the...
0
by: Jesse | last post by:
I have a C# application that runs fine on any computer (XP, 2000, 98). I have just installed on a PC that also has a POS which runs in kiosk mode. The problem is that when my application start...
3
by: Ralf Müller | last post by:
In a WindowsForms application it works just fine. Why not in ASP.NET? The interop assembly used was in both cases auto-generated by Visual Studio ..NET from the same .dll The code is exactly...
1
by: petermichaux | last post by:
Hi, setTimeout(code, delay) When the delay of a setTimeout expires it is time to execute the code. If the browser is executing some other JavaScript will the setTimeout code interupt or wait...
5
by: soulkitchen | last post by:
After I change a fairly complex stored procedure and I run a report against it, crystal hangs at "assesing database". I have verified the database. When I run a trace on SQL is shows repeated...
13
by: Edwin Smith | last post by:
I have a form which displays a DataGridView table generated with the VS2005 tools. The database is a Pervasive v.9 with an ODBC driver. The DataGridView works great except when I'm done and I...
4
by: Craig Allen | last post by:
I have followed the GIL debate in python for some time. I don't want to get into the regular debate about if it should be gotten rid of (though I am curious about the status of that for Python...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.