Hi

My first hack at a Patch Panel application is progressing. To facilitate rapid screen redraw I planned to use the Pixmap class. However I cannot understand how the same objects that are absolutely referenced to my main Window and also written to the Pixmap, appear row inverted when retrieved from the Pixmap and displayed alongside the main Window-written set? The graphics positioning is upside down but the text
drawing in the Pixmap is rightside up.

Cheers
Colin Brown

Code on Mac OSX:


from GUI import Application, Document, Window, FileType, View, Frame, Pixmap
from GUI.StdColors import black, yellow, green
from GUI.Geometry import pt_in_rect

class myApp(Application):
  def __init__(self, title=None):
    Application.__init__(self, title=title)
    self.item_type = FileType(name="Item Document", suffix = 'patch')
    self.file_type = self.item_type
    self.pm = Pixmap(450,800)
  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=(950,800), title='Patch Panel', 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, Frame):
  def __init__(self,*args, **kargs):
    View.__init__(self,*args, **kargs)
    for n in range(15):
      for m in range(8):
self.model.add_item(Item((50*(m+1),50*(n+1)), '%03i' % (1+m +8*n,)))
  def draw(self, canvas, update_rect):
    canvas.fillcolor = yellow
    canvas.pencolor = black
    for item in self.model.items:
      item.draw(canvas)
    A.pm.draw(canvas,(0,0,450,800),(500,0,950,800))
  def mouse_move(self, ev):
    print self.model.onItem(ev.position)

class ItemDoc(Document):
  def new_contents(self):
    self.items = []
  def add_item(self, item):
    self.changed()
    self.notify_views('item_changed', item)
    self.items.append(item)
    item.setpm(1)
    A.pm.with_canvas(item.draw)
    item.setpm(0)
  def onItem(self, xy):
    for n in range(len(self.items)):
      if self.items[n].contains(xy):
        return n+1
    return 0

class Item:
  def __init__(self, c, t):
    self.centre = c
    self.rect, self.text = (c[0]-20,c[1]-20,c[0]+20,c[1]+20), t
    self.pm = 0
  def contains(self, xy):
    return pt_in_rect(xy, self.rect)
  def setpm(self,state):
    self.pm = state
  def draw(self, canvas):
    if self.pm:
      canvas.fillcolor = green
      canvas.pencolor = black
    else:
      canvas.fillcolor = yellow
    l,t,r,b = self.rect
    canvas.newpath()
    canvas.moveto(l,t)
    canvas.lineto(r,t)
    canvas.lineto(r,b)
    canvas.lineto((r+l)/2,b+3) # Help debug pixmap drawing problem
    canvas.lineto(l,b)
    canvas.closepath()
    canvas.fill_stroke()
    canvas.moveto(l+9,t+24)
    canvas.show_text(self.text)

A = myApp('Patch Panel')
A.run()

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

Reply via email to