Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'executed': 0.07; 'suppress': 0.07; 'subject:question': 0.08; '(use': 0.09; 'called.': 0.09; 'handlers': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'calendar': 0.16; 'sequence:': 0.16; 'subject:PyQt': 0.16; 'text):': 0.16; 'wrote:': 0.17; 'widget': 0.17; 'app': 0.19; 'trying': 0.21; 'bit': 0.21; 'import': 0.21; 'sorry,': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:addr:python.org': 0.25; 'header:User-Agent:1': 0.26; 'appear': 0.26; 'skip:s 60': 0.27; 'trouble': 0.28; 'run': 0.28; 'occurred': 0.29; 'reset': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; "i'm": 0.29; 'button': 0.30; 'gets': 0.32; 'print': 0.32; 'skip:s 30': 0.33; 'date.': 0.33; 'changed': 0.34; 'skip:b 20': 0.34; 'false': 0.35; 'pm,': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'actions': 0.36; 'moment': 0.37; 'subject:: ': 0.38; 'perform': 0.38; 'some': 0.38; 'advice': 0.39; 'instead': 0.39; 'release': 0.39; 'received:192': 0.39; 'called': 0.39; 'received:192.168': 0.40; 'john': 0.60; 'real': 0.61; 'first': 0.61; 'different': 0.63; 'within': 0.64; 'click': 0.76; 'received:167': 0.84; 'subject:events': 0.84 Date: Mon, 16 Jul 2012 15:58:05 -0400 From: John Posner Subject: Re: Re: PyQt QCalendarWidget events question In-reply-to: To: tinnews@isbd.co.uk MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7BIT X-Enigmail-Version: 1.4.2 References: User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 99 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342470497 news.xs4all.nl 6924 [2001:888:2000:d::a6]:36044 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25436 On 7/16/2012 12:28 PM, tinnews@isbd.co.uk wrote: > tinnews@isbd.co.uk wrote: >> I am trying to use the PyQt4 calendar widget to perform some different >> actions on specific dates. There are three events available:- >> >> selectionChanged() >> activated(QDate) >> clicked(QDate) >> >> On trying all these out it would appear that the event handlers get >> called as follows:- >> >> The clicked(QDate) event gets called if you click on an already >> selected date. >> >> The selectionChanged() and then the clicked(QDate) events are >> called when you click on a new date. >> >> The selectionChanged(), then the clicked(QDate) and then the >> activated(QDate) events are called if you double-click on a new date. >> >> The clicked(QDate) and then the activated(QDate) events are called >> if you double-click on an already selected date. >> >> >> How can I get a single-click on a date to get 'Action1' and double-click >> on a date to get 'Action2'? > I'm sorry, this got sent a bit before I'd completed it. The trouble > is that I want to run Action1 if I single-click on a date whether or > not it's a changed date and I want to run Action2 if I double-click on > a date whether or not it's a changed date. However I don't see how I > can do this because of the order in which the event handlers are > called. > > Is there any way to manipulate this so I can get the result I want? > At the moment the only way I can see to do it is to wait a while after > a click and then look at what actions occurred but this seems a real > bodge. I suspect that the consensus would be "don't do that" -- having single-click and double click perform unrelated actions. But here's an implementation based on the advice at http://www.qtcentre.org/threads/7858-Double-Click-Capturing (use Ctrl-Break to break out of the event loop) import PyQt4.QtCore as C import PyQt4.QtGui as G class Button(G.QPushButton): def __init__(self, text): G.QPushButton.__init__(self, text) # flag to suppress second mouseReleaseEvent # in this double-click event sequence: # 1. mousePressEvent # 2. mouseReleaseEvent # 3. mouseDoubleClickEvent # 4. mouseReleaseEvent self.double_clicked = False def mouseReleaseEvent(self, evt): # executed for first mouseReleaseEvent if not self.double_clicked: self.first_click_timer = C.QTimer() self.first_click_timer.setSingleShot(True) # double-click must occur within 1/4 second of first-click release self.first_click_timer.setInterval(250) self.first_click_timer.timeout.connect(self.single_click_action) self.first_click_timer.start() # executed for second mouseReleaseEvent else: # reset the flag self.double_clicked = False def single_click_action(self): print "Performing single-click action" def mouseDoubleClickEvent(self, evt): # suppress the single-click action; perform double-click action instead self.first_click_timer.stop() print "Performing double-click action" # prepare for second mouseReleaseEvent self.double_clicked = True # main program app = G.QApplication([]) button = Button("Click or double-click me") button.show() app.exec_() HTH, John