import interface from g import g class MyEventHandler(interface.IEventHandler): def raw_event(self, event): if event.type == pygame.QUIT: g.done = True class MyWindow(interface.window.IWindow): def load(self): textboxes = interface.IExclusiveGroup(self) interface.text.ITextBox(textboxes, x=2.5,y=2.5,w=6,text="BAH HUMBUG") interface.text.ITextBox(textboxes, x=2.5,y=4,w=6,text="BAH HUMBUG") MoveButton(self, x=1,y=1) class MoveButton(interface.button.IButton): def handle_click(self, lx, ly): if self.archon.p.get('movable', False): if self.archon.mouse_follow: self.archon.mouse_follow = None else: x, y = pygame.mouse.get_pos() x = self.archon.rect.x-x y = self.archon.rect.y-y self.archon.mouse_follow = x,y class DragSpawn(interface.button.ITextButton): #drop_destination = True def handle_unclick(self, lx, ly): self.start_drag(g.resources.get("Image", self.p.get("thing"))) #def accept_drop(self, item, x, y): # if not self.rect.collidepoint(x,y): return False # print "Accepted this:", item # return True #def handle_drop(self, item): # print "this was dropped:", item class DragReceptor(interface.button.ITextButton): drop_destination = True p_text="Drop" #def handle_unclick(self, lx, ly): # self.start_drag(g.resources.get("Image", "Splat")) #def accept_drop(self, item, x, y): # if not self.rect.collidepoint(x,y): return False # print "Accepted this:", item # return True def handle_drop(self, item): print "this was dropped:", item class ShifterButton(interface.button.ITextButton): def handle_unclick(self, lx, ly): import random self.archon.go_to(random.randint(100,700), random.randint(50,400), 20) class GraphicConfigButton(interface.button.ITextButton): def handle_unclick(self, lx, ly): self.archon.window_manager.use_configuration(self.p['wconfig']) class Shower(object): def get_message(self, a, b): print ">>>>>>>", a, b def setup(): # illustrating two ways of configuraitn objects: directly, as here, # or via subclassing, as for MyWindow. foo = interface.window.IWindow(None, w=20,h=10,movable=True,name='foo') interface.text.ITextBox( foo, w=5, h=2, x=6, y=2) MoveButton(foo, w=1,x=1,y=1) ShifterButton( foo, text="Fly around", w=5, x=1, y=5) GraphicConfigButton( foo, text="default config",x=1, w=5, y=7, wconfig='default') foo.set_target(400,320) bar = interface.window.IWindow( None, w=20,h=10,movable=True,name='bar') DragSpawn(bar, w=2, h=2, x=10, y=2,text="Tool", thing="Hammer") DragSpawn(bar, w=2, h=2, x=13, y=2,text="Splat", thing="Splat") receptacle = interface.dragging.IDragReceptacle(bar, w=3, h=3, x=10, y=5) interface.dragging.IDragReceptacle(foo, w=3, h=3, x=9, y=5) im = g.resources.get('Image', 'Splat') dragobj = interface.dragging.IDragObject(None, image=im) receptacle.set_value(dragobj) bar.set_target(0,420) MoveButton( bar, w=1,x=1,y=1) interface.modal.IMenuGenerator(bar, w=5, h=1, x=2, y=4,name='tester', text="Two", options=[('One', 1, False), ('Two', 2, True), ('Three', 3, False) ]) #interface.modal.IMenuItem(menu, text="FOO", x=0, y=0, w=5) #interface.modal.IMenuItem(menu, text="BAR", x=0, y=1, w=5) #interface.modal.IMenuItem(menu, text="ZOT", x=0, y=2, w=5) pb = interface.bar.IHealthBar(bar,y=4,x=18, h=4, c=5, color=(196, 64, 0), maximum=150) pb.set_value(10) class UpdateButton(interface.button.ITextButton): def handle_unclick(self, lx, ly): import random pb.set_value(random.randrange(151), flashfirst=True) UpdateButton(bar, y=5, x=13.5, h=1, w=4, text="Randomize") grbgroup = interface.IExclusiveGroup( foo) i = 0 while i < 5: interface.button.IButton(grbgroup, x=12, y=2+i, sticky=True, circular=True) i += 1 return [MyWindow( None, w=16, h=8, movable=True, name='humbug'), foo,bar] def configurations(): return {'default': [('humbug', 0, 450), ('foo', 450, 200),('bar',0,0)]}