def init_app(): global app app = _app() # ss = 8 # --- top x, y, h = 0, 0, 0 # menus e = gui.Menus(menus) e.rect.w, e.rect.h = e.resize() app.add(e, x, y) x, h = x + e.rect.w, max(h, e.rect.h) menus_height = e.rect.h # --- row x, y, h = 0, y + h, 0 # --- vspace y += ss # --- hspace x += ss # tools e = gui.Toolbox(tools, 1, 0, value='tile') # ,"icons48") e.rect.w, e.rect.h = e.resize() def _set_mode(value): cmd_mode(value.value) e.connect(gui.CHANGE, _set_mode, e) app.add(e, x, y) app.tools = e.tools x, h = x + e.rect.w, max(h, e.rect.h) toolbox_width = e.rect.w # --- hspace x += ss # vdraw dw = app.screen_w - (toolbox_width + app.tiles.get_width() + ss * 4) dh = app.screen_h - (menus_height + ss * 2) app.view_init(dw, dh) e = app.vwrap = vwrap() app.vdraw = e.vdraw e.rect.w, e.rect.h = e.resize() app.add(e, x, y) x, h = x + e.rect.w, max(h, e.rect.h) # --- hspace x += ss # tpicker e = app.tpicker = tpicker() e.rect.w, e.rect.h = e.resize() # --- right x = app.screen_w - e.rect.w - ss app.add(e, x, y) x, h = x + e.rect.w, max(h, e.rect.h) tpicker_height = e.rect.h # cpicker e = app.cpicker = cpicker() e.rect.w, e.rect.h = e.resize() # --- right x = app.screen_w - e.rect.w - ss app.add(e, x, y + tpicker_height + ss) x, h = x + e.rect.w, max(h, e.rect.h) pygame.key.set_repeat(500, 30) app.screen.fill((255, 255, 255, 255))
def __init__(self,**params): gui.Desktop.__init__(self,**params) self.connect(gui.QUIT,self.quit,None) c = gui.Container(width=940,height=980) spacer = 8 self.fname = 'untitled.tga' self.new_d = NewDialog() self.new_d.connect(gui.CHANGE,self.action_new,None) self.open_d = OpenDialog() self.open_d.connect(gui.CHANGE,self.action_open,None) self.save_d = SaveDialog() self.save_d.connect(gui.CHANGE,self.action_saveas,None) self.quit_d = QuitDialog() self.quit_d.connect(QUIT,self.quit,None) self.help_d = HelpDialog() self.about_d = AboutDialog() ##Initializing the Menus, we connect to a number of Dialog.open methods for each of the dialogs. ##:: menus = gui.Menus([ ('File/New',self.new_d.open,None), ('File/Open',self.open_d.open,None), ('File/Save',self.action_save,None), ('File/Save As',self.save_d.open,None), ('File/Exit',self.quit_d.open,None), ('Help/Help',self.help_d.open,None), ('Help/About',self.about_d.open,None), ]) ## c.add(menus,0,0) menus.rect.w,menus.rect.h = menus.resize() #print 'menus',menus.rect ##We utilize a Toolbox. The value of this widget determins how drawing is done in the Painter class. ##:: self.mode = mode = gui.Toolbox([ ('Draw','draw'), ('Box','box'), ('Circle','circle'), ('Cuzco','cuzco'), ],cols=1,value='draw') ## c.add(mode,0,menus.rect.bottom+spacer) mode.rect.x,mode.rect.y = mode.style.x,mode.style.y mode.rect.w,mode.rect.h = mode.resize() #mode._resize() default = "#000000" self.color = color = gui.Color(default,width=mode.rect.w,height=mode.rect.w) self.color_d = ColorDialog(default) color.connect(gui.CLICK,self.color_d.open,None) # Updates the toolbox color picker with the value in the color dialog box def change_cb(*args): self.color.value = self.color_d.value self.color_d.connect(gui.CHANGE, change_cb) c.add(self.color,0,mode.rect.bottom+spacer) self.color.rect.w,self.color.rect.h = self.color.resize() #self.color._resize() self.painter = Painter(width=c.rect.w-mode.rect.w-spacer*2,height=c.rect.h-menus.rect.h-spacer*2,style={'border':1}) c.add(self.painter,mode.rect.w+spacer,menus.rect.h+spacer) self.painter.init({'width':956,'height':956,'color':'#ffffff'}) self.painter.rect.w,self.painter.rect.h = self.painter.resize() #self.painter._resize() welcome_d = WelcomeDialog() self.connect(gui.INIT,welcome_d.open,None) self.widget = c
def init_app(): global app app = _app() # colors_height = 64 ss = 8 #--- top x, y, h = 0, 0, 0 #menus e = gui.Menus(menus) e.rect.w, e.rect.h = e.resize() app.add(e, x, y) x, h = x + e.rect.w, max(h, e.rect.h) menus_height = e.rect.h #--- row x, y, h = 0, y + h, 0 #--- vspace y += ss #--- hspace x += ss #tools e = gui.Toolbox(tools, 1, 0, value='draw') #,"icons48") e.rect.w, e.rect.h = e.resize() def _set_mode(value): cmd_mode(value.value) e.connect(gui.CHANGE, _set_mode, e) app.add(e, x, y) #--- vspace y += ss #--- switchbox for saving. sx, sy = x, y + (max(h, e.rect.h)) savelabel = gui.Label("Save on") app.add(savelabel, sx, sy) savelabel2 = gui.Label("focus:") app.add(savelabel2, sx, sy + (ss * 2)) #--- vspace y += (ss * 5) sy += (ss * 5) save_activeevent_switch = gui.Switch(False) app.add(save_activeevent_switch, sx, sy) app.save_activeevent_switch = save_activeevent_switch x, h = x + e.rect.w, max(h, e.rect.h) toolbox_width = e.rect.w #--- hspace x += ss y -= ss * 6 #undo what was done above to the y val #tdraw #tdraw-calcs dw = app.screen_w - (toolbox_width + app.tiles.get_width() + ss * 4) dh = app.screen_h - (menus_height + colors_height + ss * 2) if dw / float(app.tile_w) > dh / float(app.tile_h): dw = dh / float(app.tile_h) * app.tile_w else: dh = dw / float(app.tile_w) * app.tile_h e = app.tdraw = tdraw(dw, dh) app.add(e, x, y) x, h = x + e.rect.w, max(h, e.rect.h) #--- hspace x += ss #tpicker e = app.tpicker = tpicker() e.rect.w, e.rect.h = e.resize() #--- right x = app.screen_w - e.rect.w - ss app.add(e, x, y) h = max(h, e.rect.h) #tpreview y = y + e.rect.h e = app.tpreview = tpreview() e.rect.w, e.rect.h = e.resize() app.add(e, x, y) #--- bottom x, y, h = 0, app.screen_h - colors_height, 0 #cpreview colors_width = toolbox_width + ss * 2 e = app.cpreview = cpreview(colors_width, colors_height) e.rect.w, e.rect.h = e.resize() app.add(e, x, y) x, h = x + e.rect.w, max(h, e.rect.h) #cpicker if os.path.isfile(cfg['palette']): pal = pygame.image.load(cfg['palette']) else: #default to EGA / NES palette pw, ph = 16, 6 pdata = [ (0, 0, 0, 255), (0, 0, 170, 255), (0, 170, 0, 255), (0, 170, 170, 255), (170, 0, 0, 255), (170, 0, 170, 255), (170, 85, 0, 255), (170, 170, 170, 255), (85, 85, 85, 255), (85, 85, 255, 255), (85, 255, 85, 255), (85, 255, 255, 255), (255, 85, 85, 255), (255, 85, 255, 255), (255, 255, 85, 255), (255, 255, 255, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (255, 255, 255, 255), (173, 243, 255, 255), (223, 214, 255, 255), (255, 190, 255, 255), (255, 176, 255, 255), (255, 177, 237, 255), (255, 191, 185, 255), (255, 217, 145, 255), (237, 246, 128, 255), (185, 255, 138, 255), (145, 255, 173, 255), (128, 255, 223, 255), (138, 255, 255, 255), (197, 197, 197, 255), (0, 0, 0, 255), (0, 0, 0, 255), (255, 255, 255, 255), (129, 200, 255, 255), (179, 171, 255, 255), (231, 146, 255, 255), (255, 132, 244, 255), (255, 133, 194, 255), (255, 148, 141, 255), (244, 173, 101, 255), (194, 202, 84, 255), (141, 227, 94, 255), (101, 240, 129, 255), (84, 240, 179, 255), (94, 225, 231, 255), (120, 120, 120, 255), (0, 0, 0, 255), (0, 0, 0, 255), (192, 192, 192, 255), (57, 128, 200, 255), (108, 99, 217, 255), (160, 74, 207, 255), (200, 61, 172, 255), (217, 61, 122, 255), (207, 76, 70, 255), (172, 102, 30, 255), (122, 130, 13, 255), (70, 155, 23, 255), (30, 169, 57, 255), (13, 168, 108, 255), (23, 153, 160, 255), (61, 61, 61, 255), (0, 0, 0, 255), (0, 0, 0, 255), (128, 128, 128, 255), (16, 87, 159, 255), (67, 58, 176, 255), (119, 34, 166, 255), (159, 20, 131, 255), (176, 20, 81, 255), (166, 35, 29, 255), (131, 61, 0, 255), (81, 89, 0, 255), (29, 114, 0, 255), (0, 128, 16, 255), (0, 127, 67, 255), (0, 112, 119, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255) ] pal = pygame.Surface((pw, ph), SWSURFACE, 32) n = 0 for py in range(0, ph): for px in range(0, pw): pal.set_at((px, py), pdata[n]) n += 1 e = app.cpicker = cpicker(app.screen_w - colors_width, colors_height, pal) e.rect.w, e.rect.h = e.resize() app.add(e, x, y) x, h = x + e.rect.w, max(h, e.rect.h) pygame.key.set_repeat(500, 30) app.screen.fill((255, 255, 255, 255))