473,326 Members | 2,114 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,326 software developers and data experts.

Statement orders

Hi I am making a gui based tool. When user preses a perticular button I
am running a heavy command, before this I want to say user to wait with
a image showing infront of her.
My code is like:
def loadData(self):
top=Toplevel(self.parent)
top.focus_set()
self.parent.wm_title("Loading Data...")

os.system('a heavy command')
os.system('another heavy command)
top.destroy()

Now when I apply it, it first runs the os.system commands then it shows
the top level.
I tried with putting sleep just before os.system() it didn't help.
Is some statement reordering going on, or I am missing something?

Oct 2 '05 #1
5 1021
Monu Agrawal wrote:
Hi I am making a gui based tool. When user preses a perticular button I
am running a heavy command, before this I want to say user to wait with
a image showing infront of her.

My code is like:

def loadData(self):
top=Toplevel(self.parent)
top.focus_set()
self.parent.wm_title("Loading Data...")
+ top.update() # flush the event queue
os.system('a heavy command')
os.system('another heavy command)
top.destroy()


</F>

Oct 2 '05 #2
Fredrik Lundh wrote:
Monu Agrawal wrote:
Hi I am making a gui based tool. When user preses a perticular button I
am running a heavy command, before this I want to say user to wait with
a image showing infront of her.

My code is like:

def loadData(self):
top=Toplevel(self.parent)
top.focus_set()
self.parent.wm_title("Loading Data...")


+ top.update() # flush the event queue
os.system('a heavy command')
os.system('another heavy command)
top.destroy()


</F>


I had a very similar problem and adding an update call solved it, but
in some tk documentation i read that one should be careful with adding
update calls to callbacks and prefer update_idletasks. in my case the
update method is even called one time before the mainloop is entered,
yet everything seems to work fine, so exactly when is it dangerous to
call update? (or is it dangerous at all?)

David.
Oct 2 '05 #3
Here's one case where it's bad to call update.

def perform_longrunning_calculation():
time.sleep(1)
app.update()
time.sleep(1)

suppose you kick this off with a keybinding, such as:
app.bind("c", lambda e: perform_longrunning_calculation())
the calculation takes 2 seconds, and after 1 second update() is called,
possibly to make sure that the user interface is repainted.

But imagine that in the first second, "c" has been pressed. That event will
be handled, and perform_longrunning_calculation will be entered *again*,
recursively. The nesting looks something like this:
app's mainloop
handling keypress
perform_longrunning_calculation()
app.update()
handling keypress
perform_longrunning_calculation()
by calling update_idletasks instead of update, the keypress event is not
handled, so it's impossible to enter perform_longrunning_calculation a
second time.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDQC+sJd01MZaTXX0RAm8wAJwJIr7c0mKmPdtoOoozvY 06T6hDAACfdcgV
BQGWxacx32Rg6eVMj1jZMjQ=
=vNvV
-----END PGP SIGNATURE-----

Oct 2 '05 #4
je****@unpythonic.net wrote:
Here's one case where it's bad to call update.

def perform_longrunning_calculation():
time.sleep(1)
app.update()
time.sleep(1)


would it be advisable to guard against this with something like this?

def perform_longrunning_calculation():
if not app.busy:
app.busy = 1
time.sleep(1)
app.update()
time.sleep(1)
app.busy = 0

or does this have flaws i'm not seeing?

David.
Oct 2 '05 #5
> would it be advisable to guard against this with something like this?

def perform_longrunning_calculation():
if not app.busy:
app.busy = 1

[...]
By using that kind of construct, instead of using update_idletasks(),
you force all code to be aware of and manage the app.busy flag.

Another difference is that with the original code changed to use
update_idletasks(), perform_longrunning_calculation *will* be called
twice, the second time after the first one completes. With your code,
it will be called once if the second keypress comes within one second, and
twice if called after one second is up. (though a second update before setting
busy back to false will make it be called only once)

So in also depends on what you want your application to do in these cases.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDQEkaJd01MZaTXX0RAnAzAJ92hHz2t6DgV6qQ7skXbD i+gVAyfgCghyo/
eUggQQ0eb2NIlONP9et6Opg=
=Fhrq
-----END PGP SIGNATURE-----

Oct 2 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeff Mason | last post by:
Consider the following (questionable, to be sure, but syntactally legal) stored procedure (using the Northwind database): Create Procedure Test As Return (Select Count(*) From Orders) Select *...
2
by: David | last post by:
Hi, I have part of my SQL statement in my asp page as follows: WHERE ((pcbforecast.ShipETA < '31/12/2005') and (products.BBProductName = ....... The problem I am having is that I want the...
3
by: Chris | last post by:
Hi guys, I am having some difficulties making a sql-statement. I took the Northwind database as an example. I want to return the customernumbers from the orders-table, where the orderdate is...
6
by: HeadScratcher | last post by:
I am trying to speed up my update statements by removing inner select statements. Example: update orders set shipname = (select contactName from customers where customerid = orders.customerID)...
11
by: Colleyville Alan | last post by:
I posted that I was having trouble with a SQL statement that was working in the SQL window, but not in VBA. I have since discovered that when I create the string in VBA it is over 1023 characters...
14
by: Siv | last post by:
Hi, I just discovered that if in an ADO.NET query I use: "Select * from Invoices Where InvoiceDate BETWEEN StartDate AND EndDate;" In this case StartDate would be 1st of month and EndDate...
15
by: Hexman | last post by:
Hello All, How do I limit the number of detail records selected in a Master-Detail set using SQL? I want to select all master records for a date, but only the first 3 records for the details...
6
by: Twobridge | last post by:
I hope someone can help me out with my problem. I have found a sql statement that basically pulls all bills filed within a certain time period and the payments made on those bills with in the...
4
by: Anja | last post by:
Hi everyone, I am trying to use the expression builder to create input to a control in an Access report. I have a table called Records and I want to select the minimum date for a record where...
9
imrosie
by: imrosie | last post by:
Hello Experts, It's going to take one to figure this out. My Order form is supported by a query of two tables (Customers and Orders). There is a subform within the Form for entering in the new...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.