473,785 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

QTimer and PyQt

I'm using a QTimer object to expire certain password protected GUI options
in my application after 2 minutes. Currently, the timer is reset each time
the user presses the 'OK' button. This is not ideal. A user may spend 2
minutes entering data into the GUI before pressing OK in which case the
timer expires before they have pressed OK.

I want the timer to timeout after 2 minutes of keyboard inactivity (i.e. no
events sent) instead of 2 minutes following the last 'OK' click.

I can imagine 2 ways to do this -:

1. Reset the timer (timer.stop(), timer.start()) each time a keystroke
event is received
-- or --
2. At timeout, check if any fields have changed (using the isChanged()
method.) and if so, reset the timer.

The problem is, I don't know how to do either in PyQt! I think option 2
would be more efficient. Is it possible to check the parent widget for any
changes to child widgets or do I have to iterate over each widget on the
form, checking each indivually?

Cheers.
Adrian.
Jul 18 '05 #1
4 7146
On Tuesday 20 July 2004 12:41 pm, Adrian Casey wrote:
I'm using a QTimer object to expire certain password protected GUI options
in my application after 2 minutes. Currently, the timer is reset each time
the user presses the 'OK' button. This is not ideal. A user may spend 2
minutes entering data into the GUI before pressing OK in which case the
timer expires before they have pressed OK.

I want the timer to timeout after 2 minutes of keyboard inactivity (i.e. no
events sent) instead of 2 minutes following the last 'OK' click.

I can imagine 2 ways to do this -:

1. Reset the timer (timer.stop(), timer.start()) each time a keystroke
event is received
-- or --
2. At timeout, check if any fields have changed (using the isChanged()
method.) and if so, reset the timer.

The problem is, I don't know how to do either in PyQt! I think option 2
would be more efficient. Is it possible to check the parent widget for any
changes to child widgets or do I have to iterate over each widget on the
form, checking each indivually?


Note that these questions are Qt questions, not PyQt questions. You may get
better answers from a Qt mailing list.

For 1., you can detect a keystroke by reimplementing an object's event()
method. A better solution would be to sub-class from QTimer and use it as an
event filter (see QObject.install EventFilter()) for all the fields you want
to watch for keystrokes - then restart the timer when you see a relevant
keystroke event.

For 2., you would have to iterate over each widget.

Check out the section "Events and Event Filters" in the Qt documentation.

Phil
Jul 18 '05 #2


Adrian Casey wrote:
[...]
2. At timeout, check if any fields have changed (using the isChanged()
method.) and if so, reset the timer.

Wouldn't this defeat the purpose of your login? e.g. I log in to your
app, edit something, step away for 3 hours, bob comes in, clicks OK on
the edited dialog and voila, still validated in the system.

Why not simply pop up a password box when the OK button is pressed if
the user is no longer logged in?

As in:
User starts app and validates himself via a password
User edits a record (or whatever)
User stops typing for 3 minutes.
You let the timer expire.
User clicks OK.
User has no access, so pop up a password dialog appears to re-validate him.

Jul 18 '05 #3
Jim
Phil Thompson wrote:
On Tuesday 20 July 2004 12:41 pm, Adrian Casey wrote:
2. At timeout, check if any fields have changed (using the isChanged()
method.) and if so, reset the timer.
For 2., you would have to iterate over each widget.


Most input widgets emit a signal when their value changes ("textChange d",
"currentChanged ", "valueChang ed", "clicked", etc). You could connect all of
the signals from the widgets to a single slot which resets the timer.

See both the Qt and PyQt docs on signals and slots.

I liked the suggestion about revalidating the user when the user presses
"ok" better though.

Jim

Jul 18 '05 #4
Jim wrote:
Phil Thompson wrote:
On Tuesday 20 July 2004 12:41 pm, Adrian Casey wrote:
2. At timeout, check if any fields have changed (using the isChanged()
method.) and if so, reset the timer.

For 2., you would have to iterate over each widget.


Most input widgets emit a signal when their value changes ("textChange d",
"currentChanged ", "valueChang ed", "clicked", etc). You could connect all
of the signals from the widgets to a single slot which resets the timer.

See both the Qt and PyQt docs on signals and slots.

I liked the suggestion about revalidating the user when the user presses
"ok" better though.

Jim


So do I Jim. I settled on Phil's suggestion and implemented an eventFilter
for each QLineEdit object (using queryList("QLin eEdit")) and the
installEventFil ter method. Works like a champ!

Essentially, the eventFilter checks the events registered by each field and,
if they are keystrokes, a self.timer.chan geinterval(1200 00) is done to
restart the timer with a 2 minute timeout.

Thanks again for your responses.

Regards.
Adrian.
Jul 18 '05 #5

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

Similar topics

10
2861
by: Ilya Knizhnik | last post by:
Dear All, I am fairly new to Python. I have found it an easy language to learn and a very usefull one for many tasks. Currently I am working on a python project that involves a GUI and it was suggested that PyQt is the best way to design that GUI. However since PyQt is rather new, I have not found much documentation on it, or examples in it. The only useful tutorial/book I have found is at www.opendocspublishing.com/pyqt/ but it is...
35
7768
by: Vamsi Mudrageda | last post by:
I am kind of new to Python, and after trying and using wxPython, I found it kind of lacking in easy-to-read documentation, speed at loading, and GUI response-time. So I am looking for an another GUI toolkit that is cross-platform for Python, and am leaning toward PyQt (PyGTK is kind of dull looking in comparison). Unfortunately, although TrollTech says Qt is cross-platform, its license strategy has me a bit confused. So here is to...
8
4853
by: simo | last post by:
OK, so I'm at the stage where I want to make a choice between wxPython and PyQt. Currently I'm using wxPython mainly due to the fact that it has GPL Linux and Windows versions. I prefer Qt to wxWindows, but am confused with all the Windows licensing issues. For the moment this is just for my own tinkering and utility apps, but
10
2210
by: svenn.are | last post by:
Hi, I wanted to run a program that is written in PyQt on my mac, and went over to Riverbank to get PyQ 3.13 and SIP 4.1.1 sources. I followed the installation guide except for the compiling python as Macosx already has python. I had no problem with compiling SIP and also no problem with compiling PyQt nor did I have any error message during make install.
3
2073
by: Fabio | last post by:
Hi all, I'm about to write an application, and I'd like to use PyQt, but before choosing this toolkit I would like to clarify some particular licensing issues; if some user has already touched these, I would like to hear from his experiences. This app should be cross-platform, so, given qt licensing policies, I would buy a commercial PyQt license and a commercial Qt license. Could I license the application under the GPL for Gnu/Linux...
10
2164
by: Simon John | last post by:
After quite a while of wxPython I'm getting back into PyQt, mainly due to the announcement by Trolltech that they will make a GPL version of Qt4 for Windows (and Phil-T said he will make a PyQt to go with it eventually!) I'm currently using PyQt 3.12 that comes with the BlackAdder demo, it seems to work fine with Python 2.3.5 except that it doesn't support the WinXP look'n'feel, the QStyle "WindowsXP" isn't included, and using a...
4
2211
by: Phil Thompson | last post by:
Riverbank Computing is pleased to announce the release of PyQt v3.14 available from http://www.riverbankcomputing.co.uk/. Changes since the last release include support for QScintilla v1.5. PyQt is a comprehensive set of Qt bindings for the Python programming language and supports the same platforms as Qt. Like Qt, PyQt is available under the GPL (for UNIX, Linux and MacOS/X), a commercial license (for Windows, UNIX, Linux and...
1
10765
by: Armin Menzel | last post by:
Hi everybody. I would like to do something like that: QTimer::singleShot(update_interval,this,SLOT(RapidFire(def_number))); Unfortunately trolltech Qt 3.3 does not support parameters (here: def_number) in that context. What can I do? Thanks Armin
3
2073
by: Phil Thompson | last post by:
Riverbank Computing is pleased to announce the release of PyQt v4.0beta1 available from http://www.riverbankcomputing.co.uk/pyqt/. PyQt is a comprehensive set of Qt bindings for the Python programming language and supports the same platforms as Qt (Windows, Linux and MacOS/X). Like Qt, PyQt is available under the GPL and a commercial license. PyQt v4 supports Qt v4 (http://www.trolltech.com/products/qt/index.html). PyQt v3 is still...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.