Hi

I am expecting to see text written into each of the coloured squares but I can only see text in the last square; why is this?

Cheers
Colin Brown

Code as run on MacOSX:


from GUI import Application, Document, Window, FileType, View
from GUI.StdColors import black, green

class myApp(Application):
  def __init__(self):
    Application.__init__(self)
    self.item_type = FileType(name="Item Document", suffix = 'itm')
    self.file_type = self.item_type
  def open_app(self):
    self.new_cmd()
  def make_document(self, fileref):
    return ItemDoc(file_type = self.item_type)
  def make_window(self, document):
win = Window(size=(300,160), title='Named block test', document=document)
    view = ItemView(model=document)
    win.place(view, left=0, top=0, right=0, bottom=0, sticky='nsew')
    win.show()
  def zero_windows_allowed(self):
    return

class ItemView(View):
  def __init__(self,*args, **kargs):
    View.__init__(self,*args, **kargs)
    for n in range(5):
      for m in range(2):
self.model.add_item(Item((50*(n+1),50*(m+1)), 'x%sy%s' % (n,m)))
  def draw(self, canvas, update_rect):
    canvas.fillcolor = green
    canvas.pencolor = black
    for item in self.model.items:
      item.draw(canvas)

class ItemDoc(Document):
  def new_contents(self):
    self.items = []
  def add_item(self, item):
    self.items.append(item)
    self.changed()
    self.notify_views('item_changed', item)

class Item:
  def __init__(self, c, t):
    self.rect, self.text = (c[0]-20,c[1]-20,c[0]+20,c[1]+20), t
  def contains(self, x, y):
    return pt_in_rect((x,y), self.rect)
  def draw(self, canvas):
    l,t,r,b = self.rect
    canvas.moveto(l,t)
    canvas.lineto(r,t)
    canvas.lineto(r,b)
    canvas.lineto(l,b)
    canvas.closepath()
    canvas.fill_stroke()
    canvas.moveto(l+9,t+24)
    canvas.show_text(self.text)

myApp().run()

_______________________________________________
Pygui mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pygui

Reply via email to