def setup_gui(data): b = gui.Box(orientation=gui.Box.HORIZONTAL) b.background = gui.BoxTexture('gui.atlas:bar', [-1], [-1, 1]) b.padding = gui.Rect(6, 6, 6, 6) b.alignment.y = 1 b.fill.x = True b.homogeneous = False b.spacing = 6 play = gui.Button(icon='gui.atlas:play') b.add(play) step = gui.Button(icon='gui.atlas:step') b.add(step) la = gui.Widget(alignment=gui.Alignment(1, 0.5), fill=gui.Fill(True, True)) l = gui.Label(text='time: {:>6.3f}'.format(0)) l.color = gui.Color(1, 1, 1, 1) l.padding = gui.Rect.uniform(3) l.alignment = gui.Alignment(1, 0.5) la.add(l) b.add(la) data.gui.add(b) data.lbl_time = l
def __init__(self): gui.Window.__init__(self, size=(200, 150), title='Detafix') box = gui.Box(self, 'vertical') b = gui.Button(box, 'Select directory...') b.connect('clicked', self.on_sel_dir) self.progress = gui.Progressbar(box, stretch=0.)
def __init__(self): gui.Window.__init__(self, title='Functions', size=(500, 300)) box = gui.Box(self, 'horizontal') # split = gui.Splitter(box, 'horizontal', stretch=1) # self.categories = gui.List(split) self.category = gui.List(box, model=RegModel(registry), stretch=1) self.category.connect('selection-changed', self.on_select_function) self.category.connect('item-activated', self.on_item_activated) rbox = gui.Box(box, 'vertical', stretch=2) toolbar = gui.Toolbar(rbox, stretch=0) toolbar.append(gui.Command('New', '', self.on_new, 'new.png')) toolbar.append(gui.Command('Delete', '', self.on_remove, 'remove.png')) toolbar.append(gui.Command('Save', '', self.on_save, 'save.png')) toolbar._widget.Realize() book = gui.Notebook(rbox) edit = gui.Box(book, 'vertical', page_label='edit') g = gui.Grid(edit, 2, 2, stretch=0, expand=True) g.layout.AddGrowableCol(1) gui.Label(g, 'Name', pos=(0, 0)) gui.Label(g, 'Parameters', pos=(1, 0)) self.name = gui.Text(g, pos=(0, 1), expand=True) self.params = gui.Text(g, pos=(1, 1), expand=True) # self.text = gui.Text(edit, multiline=True, stretch=1) self.text = gui.PythonEditor(edit, stretch=1) extra = gui.Box(book, 'vertical', page_label='extra') # self.extra = gui.Text(extra, multiline=True, stretch=1) self.extra = gui.PythonEditor(extra, stretch=1) self.functions = functions self.function = None
def main(): pygame.init() screen = pygame.display.set_mode((800, 600)) input = gui.Input() the_gui = gui.Gui(input) input.addMouseListener(the_gui) input.addKeyboardListener(the_gui) box = gui.Box() box.setPosition(0, 0) box.setDimensions(10, 10) box.setPaddings(Pad(1, 2, 3, 4)) box.setBorders(Pad(10, 10, 4, 4)) box.setMargins(Pad(9, 10, 11, 12)) container = gui.Container() the_gui.addWidget(container) container.addWidget(box) content_area = box.getContentArea() padded_area = box.getPaddedArea() bordered_area = box.getBorderedArea() whole_area = box.getWholeArea() # Testing parenting: frame = gui.Frame() frame.setPosition(0, 0) #frame.setMargins(EqualPad(4)) frame.setBorders(EqualPad(1)) frame.setPaddings(Pad(2, 2, 20, 2)) frame.setDimensions(200, 200) #frame.setLayout(gui.GridLayout(3,4)) #frame.setLayout(gui.GridLayout(2, 4, Align.TOP)) frame.setLayout(gui.VerticalLayout()) the_gui.addWidget(frame) for i in range(0, 8): box = gui.Box() box.setPosition(0, 0) #size = 10 + random.randint(0,4) width = i * 5 height = i * 5 box.setBorders(Pad(1, 1, 1, 1)) box.setMargins(Pad(5, 5, 5, 5)) frame.addWidget(box) box.setDimensions(width, height) # Testing clipping: frame = gui.Frame() frame.setPosition(340, 0) frame.setMargins(Pad(4, 4, 4, 4)) frame.setBorders(Pad(1, 1, 1, 1)) frame.setDimensions(80, 200) frame.setPaddings(EqualPad(15)) the_gui.addWidget(frame) inner_frame = gui.Frame() inner_frame.setPosition(40, 0) inner_frame.setMargins(Pad(4, 4, 4, 4)) inner_frame.setBorders(Pad(1, 1, 1, 1)) inner_frame.setDimensions(180, 100) frame.addWidget(inner_frame) inner_frame.setLayout(gui.GridLayout(3, 5)) for i in range(0, 12): col = i % 3 row = i / 3 box2 = gui.Box() box2.setPosition(0, 0) #size = 10 + random.randint(0,4) width = col * 10 height = row * 5 box2.setDimensions(width, height) box2.setBorders(Pad(1, 1, 1, 1)) box2.setMargins(Pad(5, 5, 5, 5)) inner_frame.addWidget(box2) img = gui.loadImage("res/aircraft.png") image_widget = gui.Image(img) image_widget.setPosition(0, 0) image_widget.setBorders(Pad(3, 3, 3, 3)) image_widget.setDimensions(100, 100) inner_frame.addWidget(image_widget) # Testing ImageButton img_default = gui.loadImage("res/truck.png") img_pressed = gui.loadImage("res/truck_bnw.png") img_button = gui.ImageButton(img_default, img_pressed) img_button.setPosition(20, 200) img_button.setDimensions(30, 30) the_gui.addWidget(img_button) # Testing elements alignment: frame = gui.Frame() frame.setDimensions(200, 200) frame.setLayout(gui.GridLayout(2, 6)) frame.setPosition(0, 300) the_gui.addWidget(frame) run = True while (run): for event in pygame.event.get(): if event.type == pygame.QUIT: run = False input.handleEvent(event) screen.fill((255, 255, 255)) the_gui.draw(screen) pygame.display.flip() pygame.quit()
def add_object(self, name, objtype, pos, params, events=None): color = (0, 0, 0) #bg_color = (255, 255, 255) bg_color = None no_color = (123, 123, 123) visible = True obj = None onclick = None size = (0, 0) layer = 0 padding = (5, 5, 5, 5) text = "" font_size = 16 font_face = None font_file = None if events is None: events = {} if params.has_key("visible"): visible = params["visible"] if params.has_key("color"): color = params["color"] # fgcolor is an alias of color if params.has_key("fgcolor"): color = params["fgcolor"] if params.has_key("layer"): layer = params["layer"] if params.has_key("text"): text = params["text"] if params.has_key("fontsize"): font_size = params["fontsize"] if params.has_key("fontface"): font_face = params["fontface"] if params.has_key("fontfile"): font_file = params["fontfile"] if params.has_key("bgcolor"): bg_color = params["bgcolor"] if params.has_key("nocolor"): no_color = params["nocolor"] if params.has_key("padding"): padding = params["padding"] if objtype == "background": if params.has_key("path"): obj = pygame.image.load(params["path"]).convert() else: obj = pygame.Surface(self.game.screen.get_size()) obj.fill(color) elif objtype == "image": obj = gui.Box((0, 0), color, path=params["path"]) elif objtype == "textbox": if font_file is not None: font_face = font_file elif font_face is not None: font_face = pygame.font.match_font(font_face) obj = gui.Textbox(pygame.font.Font(font_face, font_size), color, bg_color, no_color, padding=padding, text=text) elif objtype == "textarea": if font_file is not None: font_face = font_file elif font_face is not None: font_face = pygame.font.match_font(font_face) # XXX: NO BG COLOR obj = gui.Textarea(pygame.font.Font(font_face, font_size), color, no_color, padding=padding, text=text) elif objtype == "label": if font_file is not None: font_face = font_file elif font_face is not None: font_face = pygame.font.match_font(font_face) obj = gui.Label(pygame.font.Font(font_face, font_size), color, text) else: raise TypeError("no such scene object type %s" % repr(objtype)) self.objects[name] = SceneObject(name, pos, visible, obj, layer, events)