Re: [PyKDE] Aligning Text in a Table

2003-06-30 Thread Bob Parnes
On Sun, Jun 29, 2003 at 09:39:20PM +0200, Simon Edwards wrote:
> * BobTable stores the contents of the cells somewhere. (array of strings if 
> the cells hold strings etc).
> 
> * paintCell() looks up the contents of the cell (i.e. grab it's string 
> contents) and draws the string on the QPainter object.
> 
> * BobTable has a method for changing a cell's contents (i.e. 
> setStuff(row,col,newstring) )
> 
> * setStuff() modifies the internal array of strings (cell contents) and then 
> calls QTable's updateCell(row,col). This tells Qt to repaint (redraw) that 
> cell.
> 
> * When Qt is ready. Qt will call paintCell() for any cells that need 
> repainting.
> 
> For a C++ example of how to do this kind of thing look at Guarddog's 
> checktablelistitem.cpp file:
> 
> http://www.simonzone.com/software/guarddog/
> 
> cheers,
> 
> -- 
> Simon Edwards | Guarddog Firewall
> [EMAIL PROTECTED]   | http://www.simonzone.com/software/
> Nijmegen, The Netherlands | "ZooTV? You made the right choice."
> 
> ___
> PyKDE mailing list[EMAIL PROTECTED]
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

I have it working now, thank you.

-- 
Bob Parnes
[EMAIL PROTECTED]

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Aligning Text in a Table

2003-06-29 Thread Bob Parnes
On Sun, Jun 29, 2003 at 09:39:20PM +0200, Simon Edwards wrote:
> Hi,
> 
> On Sunday 29 June 2003 01:00, Bob Parnes wrote:
> > I did not read your post carefully enough and thought that I had to make
> > the call to paintCell. However, it is confusing, because now I do not
> > understand the purpose of the arguments beyond the row and column.
> 
> The other args specify if the cell is selected (and therefore should be drawn 
> in the selected state) and which colours should be used etc.
> 
> > Anyway, I did manage to successfully draw an example, so long as the
> > code was in the paintCell implementation.
> 
> That is correct.
> 
> > But I could not write 
> > to the table at a later time.
> 
> * BobTable stores the contents of the cells somewhere. (array of strings if 
> the cells hold strings etc).
> 
> * paintCell() looks up the contents of the cell (i.e. grab it's string 
> contents) and draws the string on the QPainter object.
> 
> * BobTable has a method for changing a cell's contents (i.e. 
> setStuff(row,col,newstring) )
> 
> * setStuff() modifies the internal array of strings (cell contents) and then 
> calls QTable's updateCell(row,col). This tells Qt to repaint (redraw) that 
> cell.
> 
> * When Qt is ready. Qt will call paintCell() for any cells that need 
> repainting.
> 
> For a C++ example of how to do this kind of thing look at Guarddog's 
> checktablelistitem.cpp file:
> 
> http://www.simonzone.com/software/guarddog/
> 
> cheers,
> 
> -- 
> Simon Edwards | Guarddog Firewall
> [EMAIL PROTECTED]   | http://www.simonzone.com/software/
> Nijmegen, The Netherlands | "ZooTV? You made the right choice."
> 
> ___
> PyKDE mailing list[EMAIL PROTECTED]
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Thanks. I just downloaded guarddog and will look it up.
-- 
Bob Parnes
[EMAIL PROTECTED]

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Aligning Text in a Table

2003-06-29 Thread Simon Edwards
Hi,

On Sunday 29 June 2003 01:00, Bob Parnes wrote:
> I did not read your post carefully enough and thought that I had to make
> the call to paintCell. However, it is confusing, because now I do not
> understand the purpose of the arguments beyond the row and column.

The other args specify if the cell is selected (and therefore should be drawn 
in the selected state) and which colours should be used etc.

> Anyway, I did manage to successfully draw an example, so long as the
> code was in the paintCell implementation.

That is correct.

> But I could not write 
> to the table at a later time.

* BobTable stores the contents of the cells somewhere. (array of strings if 
the cells hold strings etc).

* paintCell() looks up the contents of the cell (i.e. grab it's string 
contents) and draws the string on the QPainter object.

* BobTable has a method for changing a cell's contents (i.e. 
setStuff(row,col,newstring) )

* setStuff() modifies the internal array of strings (cell contents) and then 
calls QTable's updateCell(row,col). This tells Qt to repaint (redraw) that 
cell.

* When Qt is ready. Qt will call paintCell() for any cells that need 
repainting.

For a C++ example of how to do this kind of thing look at Guarddog's 
checktablelistitem.cpp file:

http://www.simonzone.com/software/guarddog/

cheers,

-- 
Simon Edwards | Guarddog Firewall
[EMAIL PROTECTED]   | http://www.simonzone.com/software/
Nijmegen, The Netherlands | "ZooTV? You made the right choice."

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Aligning Text in a Table

2003-06-28 Thread Bob Parnes
On Sat, Jun 28, 2003 at 03:01:12PM +0100, Phil Thompson wrote:
> On Saturday 28 June 2003 2:10 pm, Simon Edwards wrote:
> > Hi,
> >
> > > Thanks for your response. I got lost trying to follow your idea. In the
> > > past I have subclassed my own classes and reimplemented methods in order
> > > to make changes suiting the subclass. But here I cannot even make the
> > > simplest reimplementation of paintCell. For example, the method,
> > >
> > >   def paintCell(self,p,row,col,r,selected):
> > >   QTable.paintCell(self,p,row,col,r,selected)
> >
> > Does this work?:
> >
> > def paintCell(self,p,row,col,r,selected,cg):
> > QTable.paintCell(self,p,row,col,r,selected,cg)
> >
> > Maybe PyQt doesn't have the 6 arg version (it's depreciated BTW),
> 
> This was discussed on the mailing list within the last 2 weeks. Both the 6 and 
> 7 argument variations are implemented but, because Python doesn't support 
> function overloading, your re-implementation must handle both.
> 
> In other words...
> 
> def paintCell(self,p,row,col,r,selected,cg = None):
> if cg:
> QTable.paintCell(self,p,row,col,r,selected,cg)
> else:
> QTable.paintCell(self,p,row,col,r,selected)
> 
> Phil
> 
> ___
> PyKDE mailing list[EMAIL PROTECTED]
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Thank you, I'm sorry I missed the discussion.


-- 
Bob Parnes
[EMAIL PROTECTED]

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Aligning Text in a Table

2003-06-28 Thread Bob Parnes
On Sat, Jun 28, 2003 at 03:10:40PM +0200, Simon Edwards wrote:
> Hi,
> 
> > Thanks for your response. I got lost trying to follow your idea. In the
> > past I have subclassed my own classes and reimplemented methods in order 
> > to make changes suiting the subclass. But here I cannot even make the
> > simplest reimplementation of paintCell. For example, the method,
> > 
> >   def paintCell(self,p,row,col,r,selected):
> >   QTable.paintCell(self,p,row,col,r,selected)
> 
> Does this work?:
> 
> def paintCell(self,p,row,col,r,selected,cg):
> QTable.paintCell(self,p,row,col,r,selected,cg)
> 
> Maybe PyQt doesn't have the 6 arg version (it's depreciated BTW),

Yes, it does work, although I used Phil Thompson's version.

> 
> > Furthermore, I don't know how to identify the QPainter object that Qt
> > passes. I could not find any place in the documentation that describes
> > how to do this. In my attempt above, I created one.
> 
> e... You don't need to identify anything. YOu just draw with the QPainter 
> that you get.
> 
> cheers,
> 
> -- 
> Simon Edwards | Guarddog Firewall
> [EMAIL PROTECTED]   | http://www.simonzone.com/software/
> Nijmegen, The Netherlands | "ZooTV? You made the right choice."
> 

I did not read your post carefully enough and thought that I had to make
the call to paintCell. However, it is confusing, because now I do not
understand the purpose of the arguments beyond the row and column.

Anyway, I did manage to successfully draw an example, so long as the
code was in the paintCell implementation. But I could not write 
to the table at a later time. The attached code, where the pushbutton is
supposed to display the data, shows my attempt. Qt returns a new
QPainter object, but it doesn't draw. So I am still missing something.

I really appreciate your help, and I hope I can see this through
successfully. It has been an education for me.

-- 
Bob Parnes
[EMAIL PROTECTED]
#!/usr/bin/env python

import sys
from qt import *
from qttable import QTable

class newTable(QTable):
  def __init(self,parent,title):
QTable.__init__(self,parent,title)

  def drawText(self):
for row in range(3):
  for col in range(3):
r = self.cellRect(row,col)
if row ==1 and col == 1: print 'p,r at (1,1):',self.p,r
if col == 1:
  self.p.drawText(r,Qt.AlignRight,'text%d%d' % (row,col))
else:
  self.p.drawText(r,Qt.AlignLeft,'text%d%d' % (row,col))

  def paintCell(self,p,row,col,r,selected,cg=None):
self.p = p
if cg:
  QTable.paintCell(self,p,row,col,r,selected,cg)
else:
  QTable.paintCell(self,p,row,col,r,selected)
#r = self.cellRect(row,col)
#if col == 1:
#  p.drawText(r,Qt.AlignRight,'text%d%d' % (row,col))
#else:
#  p.drawText(r,Qt.AlignLeft,'text%d%d' % (row,col))

class Form1(QWidget):
def __init__(self,parent = None,name = None,fl = 0):
QWidget.__init__(self,parent,name,fl)

if not name:
self.setName("Form1")

self.table = newTable(self,"table")
self.table.setGeometry(QRect(50,60,335,104))
self.table.setNumRows(3)
self.table.setNumCols(3)
self.pb = QPushButton(self,'getData')

self.connect(self.pb,SIGNAL('clicked()'),self.getData)
self.languageChange()

self.resize(QSize(458,258).expandedTo(self.minimumSizeHint()))

def getData(self):
self.table.drawText()

def languageChange(self):
self.setCaption(self.tr("Alignment Test"))
self.pb.setText(self.tr("Display Data"))

if __name__ == "__main__":
a = QApplication(sys.argv)
QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
w = Form1()
a.setMainWidget(w)
w.show()
a.exec_loop()


Re: [PyKDE] Aligning Text in a Table

2003-06-28 Thread Phil Thompson
On Saturday 28 June 2003 2:10 pm, Simon Edwards wrote:
> Hi,
>
> > Thanks for your response. I got lost trying to follow your idea. In the
> > past I have subclassed my own classes and reimplemented methods in order
> > to make changes suiting the subclass. But here I cannot even make the
> > simplest reimplementation of paintCell. For example, the method,
> >
> >   def paintCell(self,p,row,col,r,selected):
> >   QTable.paintCell(self,p,row,col,r,selected)
>
> Does this work?:
>
> def paintCell(self,p,row,col,r,selected,cg):
> QTable.paintCell(self,p,row,col,r,selected,cg)
>
> Maybe PyQt doesn't have the 6 arg version (it's depreciated BTW),

This was discussed on the mailing list within the last 2 weeks. Both the 6 and 
7 argument variations are implemented but, because Python doesn't support 
function overloading, your re-implementation must handle both.

In other words...

def paintCell(self,p,row,col,r,selected,cg = None):
if cg:
QTable.paintCell(self,p,row,col,r,selected,cg)
else:
QTable.paintCell(self,p,row,col,r,selected)

Phil

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Aligning Text in a Table

2003-06-28 Thread Simon Edwards
Hi,

> Thanks for your response. I got lost trying to follow your idea. In the
> past I have subclassed my own classes and reimplemented methods in order 
> to make changes suiting the subclass. But here I cannot even make the
> simplest reimplementation of paintCell. For example, the method,
> 
>   def paintCell(self,p,row,col,r,selected):
>   QTable.paintCell(self,p,row,col,r,selected)

Does this work?:

def paintCell(self,p,row,col,r,selected,cg):
QTable.paintCell(self,p,row,col,r,selected,cg)

Maybe PyQt doesn't have the 6 arg version (it's depreciated BTW),

> Furthermore, I don't know how to identify the QPainter object that Qt
> passes. I could not find any place in the documentation that describes
> how to do this. In my attempt above, I created one.

e... You don't need to identify anything. YOu just draw with the QPainter 
that you get.

cheers,

-- 
Simon Edwards | Guarddog Firewall
[EMAIL PROTECTED]   | http://www.simonzone.com/software/
Nijmegen, The Netherlands | "ZooTV? You made the right choice."

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Aligning Text in a Table

2003-06-28 Thread Bob Parnes
On Fri, Jun 27, 2003 at 05:18:07PM +0200, Simon Edwards wrote:
> Hi,
> 
> On Friday 27 June 2003 16:49, Bob Parnes wrote:
> > Sorry for posing trivial questions, but I do not understand how to use
> > paintCell. Attached is a demo to right-align text in a table cell.
> > There is no error message, but the code is ignored. So I assume that I
> > misinterpreted the documentation.
> 
> You've got yourself fairly mixed up. The idea is that you subclass QTable 
> (i.e. FooTable), and reimplement the paintCell() method. When Qt wants your 
> FooTable to paint a cell it will call your paintCell() method and pass in a 
> QPainter object. In paintCell() you then draw the cell contents on the 
> QPainter object that you received.
> 
> cheers,
> 
> -- 
> Simon Edwards | Guarddog Firewall
> [EMAIL PROTECTED]   | http://www.simonzone.com/software/
> Nijmegen, The Netherlands | "ZooTV? You made the right choice."
> 
> ___
> PyKDE mailing list[EMAIL PROTECTED]
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Thanks for your response. I got lost trying to follow your idea. In the
past I have subclassed my own classes and reimplemented methods in order
to make changes suiting the subclass. But here I cannot even make the
simplest reimplementation of paintCell. For example, the method,

  def paintCell(self,p,row,col,r,selected):
QTable.paintCell(self,p,row,col,r,selected)

produces an error message (13 times, yet):
  TypeError: paintCell() takes exactly 6 arguments (7 given)

Furthermore, I don't know how to identify the QPainter object that Qt
passes. I could not find any place in the documentation that describes
how to do this. In my attempt above, I created one.

I did try other approaches, but they did not work either. If you could
suggest a reference to code, I would be grateful. Thanks.
  
-- 
Bob Parnes
[EMAIL PROTECTED]

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Aligning Text in a Table

2003-06-27 Thread Simon Edwards
Hi,

On Friday 27 June 2003 16:49, Bob Parnes wrote:
> Sorry for posing trivial questions, but I do not understand how to use
> paintCell. Attached is a demo to right-align text in a table cell.
> There is no error message, but the code is ignored. So I assume that I
> misinterpreted the documentation.

You've got yourself fairly mixed up. The idea is that you subclass QTable 
(i.e. FooTable), and reimplement the paintCell() method. When Qt wants your 
FooTable to paint a cell it will call your paintCell() method and pass in a 
QPainter object. In paintCell() you then draw the cell contents on the 
QPainter object that you received.

cheers,

-- 
Simon Edwards | Guarddog Firewall
[EMAIL PROTECTED]   | http://www.simonzone.com/software/
Nijmegen, The Netherlands | "ZooTV? You made the right choice."

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde