Re: [PyQt] Composite widgets?

2010-09-06 Thread Dan Kripac
Hi Peter,

I find that a lot of my use with PyQt is composing compound widget
subclasses that combine other widgets in a particular arrangement and
behaviour that I need. You can easily design the way they behave in terms of
signals emitted, and you can capture mouse and keyboard events simply by
overriding particular methods from the base QWidget class.

Not sure if there are many pre-existing libraries of these (that I know).
Perhaps because it's easy to do once you get the hang of it. For example, to
make a combined label and line edit:

class myTextField(QWidget):
def __init__(self,label=My Text Field, parent=None):
super(myTextField,self).__init__(parent)
layout = QHBoxLayout()
self.label = QLabel(label)
layout.addWidget( self.label )
self.lineEdit = QLineEdit()
layout.addWidget( self.lineEdit )
self.setLayout( layout )

You can get much more sophisticated than this, but just a quick example
really.

Hope this helps.

Dan

On 6 September 2010 02:13, Peter Milliken peter.milli...@gmail.com wrote:

 Prior to embarking on learning PyQt, I wrote my GUI applications using
 Tkinter and Pmw. The Pmw widget set is quite nice and provides a library of
 composite classes using the Tkinter widgets.

 My question is:

 Is there any (similar) composite widgets in PyQt? i.e. Pmw has the
 EntryField widget, which combines the (commonly used case) of a Label and a
 LineEdit into the one class - much more convenient than always having to
 specify the two entities separately, which seems to be the case with PyQt?
 The EntryField widget offers far more than just conveniently creating a
 Label and a LineEdit in the one class, it also allows definition of entry
 validation as well, so you can see that the composite classes provide quite
 a high level of functional behaviour to the user.

 Pmw defines other composite widgets like: RadioSelect - which groups radio
 buttons (well, you have the choice of defining it to handle radio buttons,
 check buttons or normal buttons). Of course in PyQt I have found the
 QGroupBox class, but this only performs a (small) part of what the Pmw
 RadioSelect widget does.

 Do such composite widgets exist? am I missing something in the PyQt
 documentation?

 Thanks
 Peter


 ___
 PyQt mailing listPyQt@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Composite widgets?

2010-09-06 Thread Dan Kripac
On having a quick look at pmw, I can definitely say that a lot of that
functionality is available as PyQt native widgets (plus much much more) and
the few exceptions would be able to be made with code not much more complex
than the example I gave.

It may seem overwhelming at first, but it would be a good way to learn PyQt
and python as well I reckon ;-)

Cheers
Dan

On 6 September 2010 11:18, Peter Milliken peter.milli...@gmail.com wrote:

 Thanks Dan, but I was really looking for something much more elaborate :-)
 The structure of the Pmw library/widgets is difficult to describe, but I
 found it an amazingly powerful library that allow some pretty nice (and
 easy) extensions once you understood how it worked. Whilst I have never
 delved into the inner workings, I might try some form of a basic port of the
 code to PyQt (assuming there is nothing else available) - I'll have to look
 into it, because I suspect it might be a pretty big job! It will certainly
 stretch my knowledge of Python! :-)

 Thanks anyway,
 Peter


 On Mon, Sep 6, 2010 at 5:16 PM, Dan Kripac dankri...@gmail.com wrote:

 Hi Peter,

 I find that a lot of my use with PyQt is composing compound widget
 subclasses that combine other widgets in a particular arrangement and
 behaviour that I need. You can easily design the way they behave in terms of
 signals emitted, and you can capture mouse and keyboard events simply by
 overriding particular methods from the base QWidget class.

 Not sure if there are many pre-existing libraries of these (that I know).
 Perhaps because it's easy to do once you get the hang of it. For example, to
 make a combined label and line edit:

 class myTextField(QWidget):
 def __init__(self,label=My Text Field, parent=None):
 super(myTextField,self).__init__(parent)
 layout = QHBoxLayout()
 self.label = QLabel(label)
 layout.addWidget( self.label )
 self.lineEdit = QLineEdit()
 layout.addWidget( self.lineEdit )
 self.setLayout( layout )

 You can get much more sophisticated than this, but just a quick example
 really.

 Hope this helps.

 Dan

 On 6 September 2010 02:13, Peter Milliken peter.milli...@gmail.comwrote:

 Prior to embarking on learning PyQt, I wrote my GUI applications using
 Tkinter and Pmw. The Pmw widget set is quite nice and provides a library of
 composite classes using the Tkinter widgets.

 My question is:

 Is there any (similar) composite widgets in PyQt? i.e. Pmw has the
 EntryField widget, which combines the (commonly used case) of a Label and a
 LineEdit into the one class - much more convenient than always having to
 specify the two entities separately, which seems to be the case with PyQt?
 The EntryField widget offers far more than just conveniently creating a
 Label and a LineEdit in the one class, it also allows definition of entry
 validation as well, so you can see that the composite classes provide quite
 a high level of functional behaviour to the user.

 Pmw defines other composite widgets like: RadioSelect - which groups
 radio buttons (well, you have the choice of defining it to handle radio
 buttons, check buttons or normal buttons). Of course in PyQt I have found
 the QGroupBox class, but this only performs a (small) part of what the Pmw
 RadioSelect widget does.

 Do such composite widgets exist? am I missing something in the PyQt
 documentation?

 Thanks
 Peter


 ___
 PyQt mailing listPyQt@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt




___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] qsqltablemodel - ordering results

2010-09-02 Thread Dan Kripac
Hey Tom (hey - don't I work with you? ;-),

Have you tried looking at making a
QAbstractProxyModelhttp://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qabstractproxymodel.html
subclass
or even better a
QSortFilterProxyModelhttp://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qsortfilterproxymodel.html
class and
putting it between your QSqlTableModel and your QTableView?

You can override the MapFromSource and MapToSource methods and perhaps do
your column swapping in there? Or maybe you could do it all in the sort
filter model?

Cheers
Dan


On 2 September 2010 17:08, Tom Proctor t...@dneg.com wrote:

 I would like to use a subclassed QSqlTableModel to fill a QTableView, but
 I'd like the order of the columns in the table to be different from the
 order of my fields in the database.

 I thought there must be some way to modify the query in .select() but I
 haven't gotten that to work.  Using setQuery only seems to prevent queries
 from returning values.

 I also tried simply changing horizontalHeader().moveSection() on the table,
 but this is ugly as it needs to be reset each time I filter or select again.

 Any ideas?

 Thank you,
 Tom
 ___
 PyQt mailing listPyQt@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Threads, events, signals and slots...

2010-08-25 Thread Dan Kripac
Hi Peter,

When I have done this in my PyQt apps I simply send a signal straight from
the QThread to a function that updates the QProgressBar i.e:

inside QThread.run:

self.emit( SIGNAL('updateProgress(int,int)'), currentTask, numTasks )

then on your window class:

def updateProgressBar( self, currentTask, numTasks ):
self.progress_bar.setValue( int(float(currentTask)/numTasks * 100) )

Seems to work nicely without any Qt warnings.

Cheers
Dan


On 25 August 2010 01:51, Peter Milliken peter.milli...@gmail.com wrote:

 Slowly working my way to learning this stuff but have a question regarding
 how to update GUI elements when threads are running.

 The situation is:

 1. I have some radiobuttons that I use for input and output: input by the
 user and then for output to display progress during an operation (the
 operation is a task that runs in a QThread instance). The radiobuttons are
 grouped into a QGroupBox are there are 3 of them to indicate 3 phases of a
 total operation. The user selects a start phase and then instigates a
 process (via a QCommandLinkButton), as the process progresses from the start
 phase to the final phase the phase buttons must be updated.

 2. I have a QProgressBar to indicate the progress (0 - 100%) within each
 phase (indicated by the previously mentioned phase buttons). So each phase
 progresses through 0 - 100% completion before advancing to the next phase.

 So basically the user selects which phase they want to start at (0, 1 or 2)
 and then press a button to instigate a QThread that performs the actions.
 The progress is communicated back from the thread via messages in a pipe. To
 receive the messages and update the GUI elements I start another QThread -
 this is one of the methods of the application GUI class and goes into a
 while loop, receiving messages from the thread that is doing the job and
 directly making calls to GUI elements like:

 self.phase_0.setChecked(True) and
 self.progress_bar.setValue(X)

 At the end of the while loop I do a time.sleep() command to allow the Qt
 event loop to run and presumably update any GUI elements that need
 updating. So the code looks like this (mix of pseudo code and real code
 :-)):

 while True:
   if pipe.poll():
 msg = pipe.rcv()
 if msg is phase 0:
   self.phase_0.setChecked(True)
 elif msg = progress:
   self.progress_bar.setValue(X)
 elif msg = stop
break
   time.sleep(0.05)


 This seems to work quite well, however, every now and again, when switching
 between Windows applications etc while the process that I have tasked is
 running, I get an error/warning message:

 QWidget::repaint: Recursive repaint detected

 Should I be using signals/slots to update the GUI elements from within the
 2nd task? If so, what would it look like (please use an example that would
 see one of the phase radiobuttons updated).

 Thanks for reading this and providing any help you can :-)

 Peter



 ___
 PyQt mailing listPyQt@riverbankcomputing.com
 http://www.riverbankcomputing.com/mailman/listinfo/pyqt

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt