[PyQt] Pyqt, repainting on a customize widget.
Hello there. Im learning pyqt using "rapid gui programing with pyqt" book, Im making a change on the chapter's 11 exercise solution given by the book. I want the widget to change the focus on each rectangle automatically every half of a second. So i replace the mouse and key event handlers for a method to do the work. It looks .update() method doest work properly,the widget shows the widget at the initial state and then it isn't updated can any of you guys give me a hint: The move method does change the focus on each rectangle (x,y)the grid. this is the code: class CountersWidget(QWidget): def __init__(self, parent=None): super(CountersWidget, self).__init__(parent) self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.grid = [[BLANK] * 3 for i in range(3)] self.selected = [0, 0] self.setMinimumSize(self.minimumSizeHint()) def sizeHint(self): return QSize(200, 200) def minimumSizeHint(self): return QSize(100, 100) def move(self): if self.selected[0] == 2: self.selected=([0,self.selected[1]+1] if not self.selected[1]==2 else [0,0]) else: self.selected = [self.selected[0]+1, self.selected[1]] x, y = self.selected cell= self.grid[x][y] print (self.selected) self.grid[x][y]=cell self.update() self.emit(SIGNAL("movido")) def delay(self): time.sleep(0.5) self.emit(SIGNAL("delay")) def paintEvent(self, event=None): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing, True) xOffset = self.width() / 3 yOffset = self.height() / 3 for x in range(3): for y in range(3): cell = self.grid[x][y] rect = (QRectF(x * xOffset, y * yOffset, xOffset, yOffset).adjusted(0.5, 0.5, -0.5, -0.5)) color = None if [x, y] == self.selected: painter.setPen(QPen(Qt.blue, 3)) else: painter.setPen(Qt.black) painter.drawRect(rect) QTimer.singleShot(0,self.delay) if __name__ == "__main__": import sys app = QApplication(sys.argv) form = CountersWidget() form.setWindowTitle("Counters") form.show() app.exec_() -- View this message in context: http://old.nabble.com/Pyqt%2C-repainting-on-a-customize-widget.-tp31140528p31140528.html Sent from the PyQt mailing list archive at Nabble.com. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Editor alignment in QTreeView
A Dilluns, 14 de març de 2011 00:42:54, Hans-Peter Jansen va escriure: > I don't believe, that > alignment is the issue here. By the way, alignment seems to be the issue. I didn't mention it in the first place, but if I return LeftAlign in the AlignmentRole in the model, the QLineEdit is positioned correctly. -- Albert Cervera i Areny http://www.NaN-tic.com OpenERP Partners Tel: +34 93 553 18 03 skype: nan-oficina http://twitter.com/albertnan http://www.nan-tic.com/blog ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Editor alignment in QTreeView
On Sunday 13 March 2011, 11:37:43 Albert Cervera i Areny wrote: > Hi, > in our application we right-align dates and numbers in QTreeViews > using the TextAlignmentRole. The problem is that Qt shows the editor > (QLineEdit) for those items, over the column on the right of the > current cell. I tried to ensure QLineEdit's alignment was > 'RightAlign' so at least it would go over current cell but that > didn't work. Looks like a genuine off by one problem to me. I don't believe, that alignment is the issue here. Editors are positioned on the fields that display the data. Don't showing the grid in the screenshot doesn't help either. > I attach a small image showing the problem. The edited text > "23/02/2011" should be shown right after the rest of the dates. ^ I guess, you mean below. > Anyone have an idea how to solve that? Check your code or provide a minimum runnable script, that demonstrates the problem. Pete ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] thoughts about dip interfaces and python abstract base classes
On Sun, Mar 13, 2011 at 3:01 PM, Darren Dale wrote: > I've been learning about python's abstract base classes at > http://www.python.org/dev/peps/pep-3119/ and > http://docs.python.org/py3k/library/abc.html . The PEP mentions that > there is considerable overlap between ABCs and interfaces, and I'm > rereading the dip documentation on interfaces now. If I understand > correctly, dip's "implements" decorator is similar (perhaps based on) > python's abstract base class "register" class method. Is it ever the > case that dip classes actually subclass a dip interface, as python > classes would subclass one or more abstract base class? It also occurs to me that, if Interface were/is based on abstract base classes with properties and methods decorated with @abstractmethod, dip classes that actually subclass such an Interface would benefit from python's built-in checks that prevent instantiation of an object that has not overridden all the necessary methods declared in the interface: from dip.model import Interface, Str class IDownload(Interface): # The URL to download from. url = Str() @url.default @abstractmethod def url(self): pass @abstractmethod def download(self): """ Download the file. """ class Download(Model, IDownload) @IDownload.url.default def url(self): return '' def download(self): """ Download the file using urllib. """ Then if we have a class that needs to be adapted to IDownload: class FileDownloader: def __init__(self, target_file): # Save the URL for later. self.target_file = target_file def get_file(self): # Download the file self.target_file The "adapt" decorator could register the adapter class with the appropriate Interfaces that it identifies in FileDownloaderIDownloadAdapter's superclasses: from dip.model import adapt, Adapter, DelegatedTo @adapt(FileDownloader) class FileDownloaderIDownloadAdapter(Adapter, IDownload): """ This adapts FileDowloader to IDownload. """ url = DelegatedTo('adaptee.target_file') def download(self): """ Implement IDownload.download(). """ return self.adaptee.get_file() This way, Interfaces are more closely unified with python's abstract base classes, one can be certain that a class deriving from an interface has fully implemented it, while still benefiting from dip's adaptation. Cheers, Darren ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] question about PyQT and ArcGIS
Hi: Thank you for your efforts to produce one of the best GUI software . i'm ArcGIS software user and i decide to learn customizing ArcGIS software with Python because ArcGIS new version(10) support Python 2.6 . i try to learn GUI programming in ArcGISÂ . does PyQT support ArcGIS Geoprocessing ? please help me . sincerely ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Problem with pyuic4 etc. on Mac Snow Leopard
I downloaded the latest snapshots of sip and pyqt for mac. Used the following tutorial: http://blog.oak-tree.us/index.php/2010/05/27/pyqt-snow-leopard The make process seemed to finish properly. Did a make install. Now, I find that pyuic4 and other command line tools have not been installed anywhere. They are present in the source tree though. What gives ? ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] thoughts about dip interfaces and python abstract base classes
I've been learning about python's abstract base classes at http://www.python.org/dev/peps/pep-3119/ and http://docs.python.org/py3k/library/abc.html . The PEP mentions that there is considerable overlap between ABCs and interfaces, and I'm rereading the dip documentation on interfaces now. If I understand correctly, dip's "implements" decorator is similar (perhaps based on) python's abstract base class "register" class method. Is it ever the case that dip classes actually subclass a dip interface, as python classes would subclass one or more abstract base class? Also, this morning I suggested on python-ideas a small tweak to python's builtin "property" which would allow an abstract properties to be declared using the decorator syntax. I thought it might be of interest to dip: import abc class Property(property): def __init__(self, *args, **kwargs): super(Property, self).__init__(*args, **kwargs) if (getattr(self.fget, '__isabstractmethod__', False) or getattr(self.fset, '__isabstractmethod__', False) or getattr(self.fdel, '__isabstractmethod__', False)): self.__isabstractmethod__ = True class C(metaclass=abc.ABCMeta): @Property @abc.abstractmethod def x(self): return 1 @x.setter @abc.abstractmethod def x(self, val): pass try: # Can't instantiate C, C.x getter and setter are abstract c=C() except TypeError as e: print(e) class D(C): @C.x.getter def x(self): return 2 try: # Can't instantiate D, the D.x setter is still abstract d=D() except TypeError as e: print(e) class E(D): @D.x.setter def x(self, val): pass # E is now instantiable print(E()) ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Editor alignment in QTreeView
Hi, in our application we right-align dates and numbers in QTreeViews using the TextAlignmentRole. The problem is that Qt shows the editor (QLineEdit) for those items, over the column on the right of the current cell. I tried to ensure QLineEdit's alignment was 'RightAlign' so at least it would go over current cell but that didn't work. I attach a small image showing the problem. The edited text "23/02/2011" should be shown right after the rest of the dates. Anyone have an idea how to solve that? Thanks in advance! -- Albert Cervera i Areny http://www.NaN-tic.com OpenERP Partners Tel: +34 93 553 18 03 skype: nan-oficina http://twitter.com/albertnan http://www.nan-tic.com/blog <>___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Qt Exception Translation in Signal Handlers
On Sun, 6 Mar 2011 20:04:17 -0600, Aron Bierbaum wrote: > I have attached a sample test suite that shows an issue that we are running > into. The basic issue is that if an exception is raised in a method that is > connected to a Qt signal, the exception is only printed. I know that > translating the exception from Python to C++ and then back into Python is > difficult. But as the example shows the test suite can ignore real test > failures. Is there some way that PyQt could be changed to at least > translate > the exception type that can pass through C++ and back into Python? > > Thanks, > Aron The normal technique is to use sys.excepthook. Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt