def __init__(self,items,player): self.player = player self.parent = player.map.parent self.screen = ui.Box(parent = globals.screen_root, pos = Point(0.06,0.1), tr = Point(0.94,0.9), colour = (0.8,0.8,0.8,0.6)) self.screen.title = ui.TextBox(self.screen, bl = Point(0,0.8), tr = Point(1,0.99), text = 'Inventory', textType = drawing.texture.TextTypes.SCREEN_RELATIVE, colour = (0,0,0,1), scale = 5) self.screen.current_name = ui.TextBox(self.screen, bl = Point(0,0), tr = Point(1,0.08), text = ' ', textType = drawing.texture.TextTypes.SCREEN_RELATIVE, colour = (1,0,0,1), scale = 4, alignment = drawing.texture.TextAlignments.CENTRE) self.screen.selected = ui.Box(parent = self.screen, pos = Point(0,0), tr = Point(0,0), colour = drawing.constants.colours.red, extra = 2) self.screen.slots = [] self.width = 5 self.height = 3 box_width = 0.1 interbox_width = (1.0-self.width*box_width)/(self.width+1) box_height = 0.2 interbox_height = (1.0-self.height*box_height)/(self.height+1) inter = Point(interbox_width,interbox_height) box_size = Point(box_width,box_height) self.selected_coords = [] for i in xrange(self.width * self.height): x = i%self.width ypos = i/self.width if ypos >= self.height: break y = self.height-1-ypos bl = Point((interbox_width*(x+1)) + (box_width*x), (interbox_height*(y+1)) + (box_height*y)) tr = bl + box_size box = ui.Box(parent = self.screen, pos = bl, tr = tr, colour = (0.4,0.4,0.4,1),extra = 1) self.selected_coords.append( (Point(bl.x,bl.y-0.2*box_height),Point(tr.x,bl.y-0.05*box_height)) ) self.screen.slots.append(box) self.items = [item for item in items][:len(self.screen.slots)] if len(items) < len(self.screen.slots): self.items += [None]*(len(self.screen.slots)-len(items)) self.SetSelected(0) self.screen.Disable() self.num_items = 0
def __init__(self, parent): self.parent = parent self.blurb = self.blurb self.blurb_text = None pygame.mixer.music.load('end_music.ogg') pygame.mixer.music.play(-1) pygame.mixer.music.set_volume(0.6) self.handlers = { TitleStages.TEXT: self.TextDraw, TitleStages.SCROLL: self.Wait, TitleStages.WAIT: self.Wait } self.backdrop = ui.Box(parent=globals.screen_root, pos=Point(0, 0), tr=Point(1, 1), colour=(0, 0, 0, 0.6)) bl = Point(0.3, 0.5) tr = Point(0.7, 0.7) self.blurb_text = ui.TextBox( parent=globals.screen_root, bl=bl, tr=tr, text=self.blurb, textType=drawing.texture.TextTypes.SCREEN_RELATIVE, scale=3) self.start = None self.blurb_text.EnableChars(0) self.stage = TitleStages.TEXT self.played_sound = False self.skipped_text = False self.letter_duration = 20 self.continued = False
def create_component_to_find(self, page) : (difference_pos, difference_size) = self.difference_box # TODO : implement other modes than pixels relative to original image ? (pos_x, pos_y) = difference_pos (width, height) = difference_size delta_x = (width * (1 - self.game.ratio_x)) / 2.0 delta_y = (height * (1 - self.game.ratio_y)) / 2.0 difference_pos = (pos_x + delta_x, pos_y + delta_y) difference_size = (width * self.game.ratio_x, height * self.game.ratio_y) coords_converter = ui.Coordinates_converter(page, Rect((0,0), page.modified_image.original_size), page.modified_image.rect) difference_pos = coords_converter.get_coords_px2pc(difference_pos) difference_size = coords_converter.get_size_px2pc(difference_size) # component = ui.Box(page, difference_pos, difference_size, constants.box_color, 100) # the trick is that the box is invisible (alpha = 0) # yet the player can click on it component = ui.Box(page, difference_pos, difference_size, constants.box_color, 0) component.set_associated_object(self) return component
def __init__(self, parent): self.parent = parent self.blurb = self.blurb self.blurb_text = None self.handlers = { TitleStages.TEXT: self.TextDraw, TitleStages.SCROLL: self.Wait, TitleStages.WAIT: self.Wait } self.backdrop = ui.Box(parent=globals.screen_root, pos=Point(0, 0), tr=Point(1, 1), colour=(0, 0, 0, 0.6)) bl = self.parent.GetRelative(Point(0, 0)) tr = bl + self.parent.GetRelative(globals.screen) self.blurb_text = ui.TextBox( parent=globals.screen_root, bl=bl, tr=tr, text=self.blurb, textType=drawing.texture.TextTypes.SCREEN_RELATIVE, scale=3) self.start = None self.blurb_text.EnableChars(0) self.stage = TitleStages.TEXT self.played_sound = False self.skipped_text = False self.letter_duration = 20 self.continued = False
def display_quit(self): self.remove_all() self.append( ui.Box(self, (10, 39), (80, 22), constants.button_box_color)) self.append( ui.Text(self, i18n.get_text(self.language, 1105), (10, 40), (80, 10), self.fonts, constants.text_color, 1)) self.quit_yes = ui.TextBox(self, i18n.get_text(self.language, 100), (10, 50), (40, 10), self.fonts, constants.text_color, 11, constants.stop_icon) self.quit_no = ui.TextBox(self, i18n.get_text(self.language, 101), (50, 50), (40, 10), self.fonts, constants.text_color, 11, constants.go_next_icon) self.append(self.quit_yes) self.append(self.quit_no) self.page_type = "DIALOG_BOX_QUIT" self.draw() return [self.screen.get_rect()]
def __init__(self): self.dish_door = None self.atlas = globals.atlas = drawing.texture.TextureAtlas( 'tiles_atlas_0.png', 'tiles_atlas.txt') self.map = GameMap('level1.txt', self) self.map.world_size = self.map.size * globals.tile_dimensions self.viewpos = Viewpos(Point(915, 0)) self.player_direction = Point(0, 0) self.game_over = False self.computer = None self.info_box = ui.Box(parent=globals.screen_root, pos=Point(0, 0), tr=Point(1, 0.05), colour=(0, 0, 0, 0.9)) self.info_box.text = ui.TextBox( self.info_box, bl=Point(0, 0), tr=Point(1, 0.7), text='Space to interact, I for inventory, DEL to toggle music', textType=drawing.texture.TextTypes.SCREEN_RELATIVE, colour=(1, 1, 0, 1), scale=3, alignment=drawing.texture.TextAlignments.CENTRE) self.info_box.Disable() #pygame.mixer.music.load('music.ogg') self.music_playing = False super(GameView, self).__init__(Point(0, 0), globals.screen) #skip titles for development of the main game self.mode = modes.Titles(self) #self.mode = modes.LevelOne(self) super(GameView, self).__init__(Point(0, 0), Point(*self.map.world_size))
def __init__(self): self.atlas = globals.atlas = drawing.texture.TextureAtlas( 'tiles_atlas_0.png', 'tiles_atlas.txt') self.sentry_lights = [] self.enemies = [] globals.ui_atlas = drawing.texture.TextureAtlas('ui_atlas_0.png', 'ui_atlas.txt', extra_names=False) self.enemy_positions = [] self.map = GameMap('level1.txt', self) self.map.world_size = self.map.size * globals.tile_dimensions self.viewpos = Viewpos(Point(100, 400)) self.player_direction = Point(0, 0) self.game_over = False self.mouse_world = Point(0, 0) self.mouse_pos = Point(0, 0) #pygame.mixer.music.load('music.ogg') #self.music_playing = False super(GameView, self).__init__(Point(0, 0), globals.screen) #skip titles for development of the main game self.mode = modes.Titles(self) self.light = drawing.Quad(globals.light_quads) self.light.SetVertices(Point(0, 0), globals.screen_abs - Point(0, 0), 0) self.nightlight = drawing.Quad(globals.nightlight_quads) self.nightlight.SetVertices(Point(0, 0), globals.screen_abs - Point(0, 0), 0.01) self.timeofday = TimeOfDay(0.1) #self.mode = modes.LevelOne(self) self.StartMusic() self.fixed_light = actors.FixedLight(Point(11, 38), Point(26, 9)) self.interact_box = ui.Box(parent=globals.screen_root, pos=Point(0.3, 0.0), tr=Point(0.5, 0.08), colour=(0.5, 0.5, 0.5, 0.7)) self.interact_box.title = ui.TextBox( self.interact_box, bl=Point(0, 0), tr=Point(1, 1), text='Opening...', textType=drawing.texture.TextTypes.SCREEN_RELATIVE, colour=(0, 0, 0, 1), scale=9, alignment=drawing.texture.TextAlignments.CENTRE) self.interact_box.progress = ui.PowerBar( self.interact_box, pos=Point(0.1, 0.3), tr=Point(0.9, 0.6), level=0.6, bar_colours=(drawing.constants.colours.red, drawing.constants.colours.yellow, drawing.constants.colours.green), border_colour=drawing.constants.colours.white) self.interact_box.Disable() for pos in self.enemy_positions: self.enemies.append(actors.Enemy(self.map, pos))
def display_games_by_type(self): self.fade_out() self.remove_all() self.append(self.second_background_image) self.append( ui.Box(self, self.legend_text_pos, self.legend_text_size, constants.button_box_color)) if (len(self.games_to_display) > 0): circle_icons = Circle_icons(self, self.omnitux_logo_image.rect.center, self.omnitux_logo_image.rect.size, 2.1, len(self.games_to_display)) index = 0 for games in self.games_to_display: #x_pos = index % amount_x #y_pos = index // amount_x #offset_x = step_x * x_pos #offset_y = step_y * y_pos text = games.get_title(self.language) icon = ui.Image(self, (0, 0), (11, 11), games.get_thumb()) icon.set_associated_text(text) self.listen_to_mouse_over(icon) icon.set_associated_object(games) icon.set_center_abs(circle_icons.get_center()) self.append(icon) index = index + 1 self.go_back_icon = ui.Image(self, constants.go_left_icon_pos, constants.go_left_icon_size, constants.go_left_icon) self.append(self.go_back_icon) self.draw() self.page_type = "GAME_SELECTION" return [self.screen.get_rect()]
def Box(self, parent, x, y, width, heigh, color): tmpBox = ui.Box() if parent: tmpBox.SetParent(parent) if color: tmpBox.SetColor(color) tmpBox.SetPosition(x, y) tmpBox.SetSize(width, heigh) tmpBox.Show() return tmpBox
def __init__(self, pos, terminal_type, parent): super(Computer, self).__init__(pos) self.terminal = None self.parent = parent self.terminal_type = terminal_type self.last_keyrepeat = None bl = Point(0, 0.45) + (Point(6, 6).to_float() / globals.screen) tr = Point(1, 1) - (Point(6, 6).to_float() / globals.screen) self.screen = ui.Box(parent=globals.screen_root, pos=Point(0, 0), tr=Point(1, 1), colour=drawing.constants.colours.black) self.screen.Disable()
def __init__(self, pos, combination, parent): super(Locker, self).__init__(pos) self.combination = [c for c in combination[:4]] self.parent = parent self.screen = ui.Box(parent=globals.screen_root, pos=Point(0.415, 0.465), tr=Point(0.585, 0.54), colour=drawing.constants.colours.white) self.current = ['0', '0', '0', '0'] self.screen.combo = ui.TextBox( parent=self.screen, bl=Point(0, 0), tr=Point(1, 1), text=''.join(self.current), textType=drawing.texture.TextTypes.SCREEN_RELATIVE, colour=(0, 0, 0, 1), scale=8) self.selected = 0 self.screen.selected = ui.Box(parent=self.screen, pos=Point(0, -0.05), tr=Point(0.25, 0.15), colour=drawing.constants.colours.red, extra=2) self.screen.Disable()
def __init__(self): self.start_time_hours = 0 self.tutorial = False self.atlas = globals.atlas = drawing.texture.TextureAtlas( 'tiles_atlas_0.png', 'tiles_atlas.txt') self.game_over = False self.sky = LoopingQuad(Point(0, 0), 0, 'sky.png', 0.1) self.hills = LoopingQuad(Point(0, -50), 0.05, 'hills.png', 0.6) self.tracks = LoopingQuad(Point(0, -84), 0.1, 'tracks.png', 1.0) self.start_time = globals.time self.incline = 0 self.train = Train(self) self.last = None self.box = ui.Box(parent=globals.screen_root, pos=Point(0.005, 0.74), tr=Point(0.995, 0.99), colour=(1, 1, 1, 0.5), z=5) self.text = ui.TextBox( parent=globals.screen_root, bl=Point(-0.045, 0.71), tr=Point(1.2, 0.81), text= 'Pressure Speed Regulator Brake Coal Health Reverser Time Distance', textType=drawing.texture.TextTypes.SCREEN_RELATIVE, colour=drawing.constants.colours.black, scale=2) self.tutorial_text = ui.TextBox( parent=globals.screen_root, bl=Point(-0.02, 0), tr=Point(1, 0.1), text=' ', textType=drawing.texture.TextTypes.SCREEN_RELATIVE, colour=drawing.constants.colours.white, scale=2, alignment=drawing.texture.TextAlignments.LEFT) self.tutorial_text.Disable() self.text.Disable() #pygame.mixer.music.load('music.ogg') #self.music_playing = False super(GameView, self).__init__(Point(0, 0), globals.screen) #skip titles for development of the main game self.mode = modes.MainMenu(self) self.StartMusic() self.Reset()
def TabControl(self, parent, width, heigh, *tabv): self.tabs = [] for arg in tabv: tab_item = {"TAB": arg[0], "TAB_NAME": arg[1]} self.tabs.append(tab_item) x = -70 self.tabPageList = {} self.tabList = {} for tabs in self.tabs: x += 80 Tab = ui.RadioButton() Tab.SetParent(parent) Tab.SetPosition(x, 30) Tab.SetUpVisual( "d:/ymir work/ui/game/windows/tab_button_large_01.sub") Tab.SetOverVisual( "d:/ymir work/ui/game/windows/tab_button_large_02.sub") Tab.SetDownVisual( "d:/ymir work/ui/game/windows/tab_button_large_03.sub") Tab.SetText(tabs["TAB_NAME"]) Tab.SetEvent(lambda arg=tabs["TAB"]: self.TabEvent(arg)) Tab.SetUp() Tab.Show() Page = ui.Box() Page.SetParent(parent) Page.SetPosition(8, 50) Page.SetSize(width - 16, heigh - 60) Page.SetColor(grp.GenerateColor(0.0, 0.0, 0.5, 0.3)) Page.Show() self.tabList[tabs["TAB"]] = Tab self.tabPageList[tabs["TAB"]] = Page if self.tabs: self.SetState(self.tabs[0]["TAB"]) return (self.tabPageList, self.tabList)
def __init__(self, parent): self.parent = parent self.start = pygame.time.get_ticks() self.stage = TitleStages.STARTED self.handlers = { TitleStages.STARTED: self.Startup, TitleStages.COMPLETE: self.Complete } bl = self.parent.GetRelative(Point(0, 0)) tr = bl + self.parent.GetRelative(globals.screen) self.blurb_text = ui.TextBox( parent=self.parent, bl=bl, tr=tr, text=self.blurb, textType=drawing.texture.TextTypes.GRID_RELATIVE, colour=(1, 1, 1, 1), scale=4) self.backdrop = ui.Box(parent=globals.screen_root, pos=Point(0, 0), tr=Point(1, 1), colour=(0, 0, 0, 0)) self.backdrop.Enable()
def __init__(self, map, pos): self.mouse_pos = Point(0, 0) self.has_key = False super(Player, self).__init__(map, pos) self.light = ActorLight(self) self.tilium = False self.flare = None self.comms = None self.last_damage_sound = 0 self.torch = Torch( self, Point(-(self.width / globals.tile_dimensions.x) * 0.6, 0)) self.info_box = ui.Box(parent=globals.screen_root, pos=Point(0, 0), tr=Point(1, 0.08), colour=(0, 0, 0, 0.7)) self.info_box.health_text = ui.TextBox( self.info_box, bl=Point(0.8, 0), tr=Point(1, 0.7), text='\x81:%d' % self.initial_health, textType=drawing.texture.TextTypes.SCREEN_RELATIVE, colour=(1, 0, 0, 1), scale=10, alignment=drawing.texture.TextAlignments.CENTRE) self.info_box.torch_data = ui.UIElement(self.info_box, pos=Point(0.5, 0), tr=Point(0.85, 1)) self.info_box.torch_data.text = ui.TextBox( self.info_box.torch_data, bl=Point(0, 0), tr=Point(0.57, 0.7), text='Torch power:', textType=drawing.texture.TextTypes.SCREEN_RELATIVE, colour=(1, 0, 0, 1), scale=8, alignment=drawing.texture.TextAlignments.CENTRE) self.info_box.torch_data.power = ui.PowerBar( self.info_box.torch_data, pos=Point(0.5, 0.36), tr=Point(1, 0.66), level=0.6, bar_colours=(drawing.constants.colours.red, drawing.constants.colours.yellow, drawing.constants.colours.green), border_colour=drawing.constants.colours.white) self.info_box.torch_data.Disable() self.inv_quads = [ drawing.Quad(globals.screen_texture_buffer, tc=globals.ui_atlas.TextureUiCoords('empty.png')) for i in xrange(4) ] self.sel_quads = [ drawing.Quad(globals.screen_texture_buffer, tc=globals.ui_atlas.TextureUiCoords('selected.png')) for i in xrange(4) ] box_size = 48 sep_x = int((self.info_box.absolute.size.x * 0.2 - box_size * 3) / 4) sep_y = int((self.info_box.absolute.size.y - box_size) / 2) for i in xrange(4): bl = self.info_box.absolute.bottom_left + Point( self.info_box.absolute.size.x * 0.03, 0) + Point( ((i + 1) * sep_x) + (i * box_size), sep_y) tr = bl + Point(box_size, box_size) self.inv_quads[i].SetVertices(bl, tr, 9000) self.sel_quads[i].SetVertices(bl, tr, 9001) self.inv_quads[i].Enable() self.sel_quads[i].Disable() self.inventory = [None, None, None, None] self.num_items = 0 self.current_item = 0 self.attacking = False self.AddItem(Hand(self)) #self.AddItem(CommsItem(self)) self.Select(self.num_items - 1) self.weapon = self.inventory[self.current_item] self.interacting = None
def __init__(self): now = dt.datetime.now() graphics.Scene.__init__(self) self.notebook = ui.Notebook(tab_position = "top-left", scroll_position="end", show_scroll = "auto_invisible", scroll_selects_tab = False) # boxes packed and nested horizontally and vertically, with a draggable corner self.box = ui.HBox(spacing = 3, x=10, y=10) self.button = ui.Button("My image changes position", image = graphics.Image("assets/hamster.png"), fill = False) self.button.connect("on-click", self.on_button_click) self.box.add_child(*[ui.VBox([self.button, ui.ToggleButton("I'm a toggle button! Have a tooltip too!", image = graphics.Image("assets/day.png"), fill = True, tooltip="Oh hey there, i'm a tooltip!"), ui.Label("I'm a label \nand we all can wrap", image = graphics.Image("assets/week.png"), spacing = 5, padding = 5, x_align = 0), ui.Entry("Feel free to edit me! I'm a rather long text that will scroll nicely perhaps. No guarantees though!", expand = False), ui.Entry("And me too perhaps", expand = False)], spacing = 5, padding = 10), Rectangle(20, expand = False), graphics.Label("rrrr", color="#666"), Rectangle(20, expand = False), ui.VBox([Rectangle(fill = False), Rectangle(), Rectangle()], spacing = 3) ]) box_w, box_h = self.box.get_min_size() self.corner = graphics.Rectangle(10, 10, fill="#666", x = self.box.x + box_w, y = self.box.y + box_h, draggable=True, interactive=True, z_order = 100) self.corner.connect("on-drag", self.on_corner_drag) # a table self.table = ui.Table(3, 3, snap_to_pixel = False, padding=10) self.table.attach(Rectangle(fill_color = "#f00", expand_vert = False), 0, 3, 0, 1) # top self.table.attach(Rectangle(fill_color = "#0f0", expand = False), 2, 3, 1, 2) # right self.table.attach(Rectangle(fill_color = "#f0f", expand_vert = False), 0, 3, 2, 3) # bottom self.table.attach(Rectangle(fill_color = "#0ff", expand = False), 0, 1, 1, 2) # left center = Rectangle() center.connect("on-mouse-over", self.on_table_mouse_over) center.connect("on-mouse-out", self.on_table_mouse_out) self.table.attach(center, 1, 2, 1, 2) # a scroll area with something to scroll in it self.scroll = ui.ScrollArea(border = 0) self.scroll.add_child(ui.Container(ui.Button("Scroll me if you can!", width = 1000, height = 300, fill=False), fill = False, padding=15)) # bunch of different input elements inputs = ui.Panes(padding=10) listitem = ui.ListItem(["Sugar", "Spice", "Everything Nice", "--", "Feel", "Free", "To", "Click", "On", "Me", {'markup': "<span color='red'>And</span>"}, "Use", "The", "Arrows!", "Ah", "And", "It", "Seems", "That", "There", "Are", "So", "Many", "Elements"]) def print_selection(listitem, item): print "selection", item def print_change(listitem, item): print "change", item listitem.connect("on-change", print_change) listitem.connect("on-select", print_selection) inputs.add_child(listitem) one = ui.ToggleButton("One", margin=[15, 10, 20, 30], id="one") group1 = ui.Group([one, ui.ToggleButton("Two", scale_x = 0.5, scale_y = 0.5, expand=False, id="two"), ui.ToggleButton("Three", id="three"), ui.ToggleButton("Four", id="four")], expand = False, allow_no_selection=True) label1 = ui.Label("Current value: none selected", x_align=0, expand = False) def on_toggle1(group, current_item): if current_item: label1.text = "Current value: %s" % current_item.label else: label1.text = "No item selected" group1.connect("on-change", on_toggle1) group2 = ui.Group([ui.RadioButton("One"), ui.RadioButton("Two"), ui.RadioButton("Three"), ui.RadioButton("Four")], horizontal = False) label2 = ui.Label("Current value: none selected", x_align = 0, expand=False) def on_toggle2(group, current_item): label2.text = "Current value: %s" % current_item.label group2.connect("on-change", on_toggle2) slider = ui.Slider(range(100), expand = False, snap_to_ticks = False, range=True, selection=(23, 80), grips_can_cross = False, snap_points = [5, 20, 50, 75], snap_on_release = True) slider_value = ui.Label(" ") def on_slider_change(slider, value): slider_value.text = str(value) slider.connect("on_change", on_slider_change) spinner = ui.Spinner(active = False, expand=False, width = 40) spinner_button = ui.Button("Toggle spin", expand=False) spinner_button.spinner = spinner def on_spinner_button_click(button, event): button.spinner.active = not button.spinner.active spinner_button.connect("on-click", on_spinner_button_click) combo = ui.ComboBox(["Sugar", "Spice", "Everything Nice", "And", "Other", "Nice", "Things"], open_below=True, expand = False) inputs.add_child(ui.VBox([combo, group1, label1, ui.HBox([group2, ui.VBox([ui.CheckButton("And a few of those", expand = False), ui.CheckButton("Check boxes", expand = False), ui.CheckButton("Which don't work for groups", expand = False)]) ]), label2, slider, slider_value, ui.HBox([spinner, spinner_button], expand=False, spacing = 10), ui.HBox([ui.ScrollArea(ui.Label(sample_text * 3, overflow = pango.WrapMode.WORD, fill=True, padding=[2, 5]), height=45, scroll_horizontal=False), ui.SpinButton(expand = False, fill=False)], expand = False), ], expand = False, spacing = 10)) combo.rows = ["some", "things", "are", "made", "of", "bananas", "and", "icecream"] menu = ui.Menu([ui.MenuItem(label="One", menu=ui.Menu([ui.MenuItem(label="One one", menu=ui.Menu([ui.MenuItem(label="One one one"), ui.MenuItem(label="One one two"), ui.MenuSeparator(), ui.MenuItem(label="One one three")])), ui.MenuSeparator(), ui.MenuItem(label="One two", mnemonic="Ctrl+1"), ui.MenuItem(label="One three", mnemonic="Alt+1")])), ui.MenuItem(label="Two", menu=ui.Menu([ui.MenuItem(label="Two one", mnemonic="Ctrl+Alt+2"), ui.MenuItem(label="Two two", mnemonic="Ctrl+2"), ui.MenuSeparator(), ui.MenuItem(label="Two three", mnemonic="Alt+2")])), ui.MenuItem(label="Three", menu=ui.Menu([ui.MenuItem(label="Three one", mnemonic="Ctrl+Alt+3"), ui.MenuItem(label="Three two", mnemonic="Ctrl+3"), ui.MenuSeparator(), ui.MenuItem(label="Three three", mnemonic="Alt+3")])), ui.MenuItem(label="Four", menu=ui.Menu([ui.MenuItem(label="Four one", mnemonic="Ctrl+Alt+4"), ui.MenuItem(label="Four two", mnemonic="Ctrl+4"), ui.MenuSeparator(), ui.MenuItem(label="Four three", mnemonic="Alt+4")])), ], horizontal=True) self.menu_selection_label = ui.Label("Pick a menu item!", expand = False, x_align = 1) def on_menuitem_selected(menu, item, event): self.menu_selection_label.text = item.label menu.connect("selected", on_menuitem_selected) # adding notebook and attaching pages self.notebook.add_page(ui.NotebookTab(image=graphics.Image("assets/day.png"), label="boxes", padding=[1,5]), ui.Fixed([self.box, self.corner], x = 10, y = 10)) self.notebook.add_page(ui.NotebookTab("Table", tooltip="Oh hey, i'm a table!"), self.table) self.notebook.add_page("Scroll Area", self.scroll) self.notebook.add_page("Input Elements", inputs) self.notebook.add_page("Menu", ui.VBox([menu, self.menu_selection_label, ui.HBox(ui.Menu([ui.MenuItem(label="", image = graphics.Image("assets/day.png"), submenu_offset_x = 0, submenu_offset_y = 0, menu=ui.Menu([ui.MenuItem(label="", image = graphics.Image("assets/month.png")), ui.MenuItem(label="", image = graphics.Image("assets/hamster.png")), ui.MenuSeparator(), ui.MenuItem(label="", image = graphics.Image("assets/hamster.png")), ui.MenuItem(label="", image = graphics.Image("assets/month.png"))], horizontal=True)), ui.MenuItem(label="", image = graphics.Image("assets/hamster.png"),submenu_offset_x = 0, submenu_offset_y = 0, menu=ui.Menu([ui.MenuItem(label="", image = graphics.Image("assets/month.png")), ui.MenuItem(label="", image = graphics.Image("assets/month.png")), ui.MenuItem(label="", image = graphics.Image("assets/week.png")), ui.MenuSeparator(), ui.MenuItem(label="", image = graphics.Image("assets/month.png"))], horizontal=True)), ui.MenuItem(label="", image = graphics.Image("assets/month.png"), submenu_offset_x = 0, submenu_offset_y = 0, menu=ui.Menu([ui.MenuItem(label="", image = graphics.Image("assets/week.png")), ui.MenuItem(label="", image = graphics.Image("assets/week.png")), ui.MenuSeparator(), ui.MenuItem(label="", image = graphics.Image("assets/week.png")), ui.MenuItem(label="", image = graphics.Image("assets/month.png"))], horizontal=True)), ], horizontal=False, spacing=50, hide_on_leave = True, open_on_hover = 0.01), expand=False), ui.Box()], padding=10)) self.slice_image = ui.Image('assets/slice9.png', fill=True, slice_left = 35, slice_right = 230, slice_top = 35, slice_bottom = 220) data = [] image = graphics.Image("assets/day.png") for i in range(10): data.append(["aasdf asdfasdf asdfasdf", "basdfasdf asdfasdf asdfasdf", image, "rrr"]) data.append(["1", "2", None, "rrr"]) data.append(["4", "5", None, "rrr"]) tree = ui.ListItem(data, [ui.LabelRenderer(editable=True), ui.LabelRenderer(editable=True), ui.ImageRenderer(expand=False, width=90)], headers=["Text", "More text", "An icon!"], fixed_headers = False, scroll_border = 0 ) self.notebook.add_page("Tree View", tree) #tree.data[0][1] = "I was actually modified afterwards!" self.notebook.add_page("Accordion", ui.Accordion([ ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm am the first in the row", [ui.Label(accordion_text, overflow = pango.WrapMode.WORD, padding=5)]), ui.AccordionPage("I'm different!", [ ui.VBox([ ui.Button("I'm a button", fill=False, expand=False), ui.Button("I'm another one", fill=False, expand=False), ui.Group([ ui.ToggleButton("We"), ui.ToggleButton("Are"), ui.ToggleButton("Brothers"), ui.ToggleButton("Radio Brothers"), ], expand=False) ], expand=False) ]), ], padding_top = 1, padding_left = 1)) from pie_menu import Menu pie_menu = Menu(0, 0) pie_menu.y_align = 0.45 self.magic_box = ui.VBox([ui.HBox([ui.Button("Hello", expand=False), ui.Button("Thar", expand=False), ui.Label("Drag the white area around", x_align=1)], expand=False, padding=5), pie_menu], x=50, y=50, spacing=50, draggable=True) self.magic_box.width = 500 self.magic_box.height = 400 def just_fill(): box = self.magic_box box.graphics.fill_area(0, 0, box.width, box.height, "#fefefe") self.magic_box.do_render = just_fill self.notebook.add_page("Ordinary Sprite", ui.Fixed(self.magic_box)) for i in range(5): self.notebook.add_page("Tab %d" % i) self.notebook.current_page = 3 # a little button to change tab orientation self.tab_orient_switch = ui.Button("Change tab attachment", expand=False, tooltip="change") self.tab_orient_switch.connect("on-click", self.on_tab_orient_click) self.page_disablist = ui.Button("Enable/Disable current tab", expand=False, tooltip="disable") self.page_disablist.connect("on-click", self.on_page_disablist_click) self.dialog_button = ui.Button("Show a dialog", expand=False, tooltip="show") self.dialog_button.connect("on-click", self.on_dialog_button_click) top_menu = ui.Menu([ui.MenuItem(label="One", menu=ui.Menu([ui.MenuItem(label="One one oh one oh one etc etc", menu=ui.Menu([ui.MenuItem(label="One one one"), ui.MenuItem(label="One one two"), ui.MenuItem(label="One one three")])), ui.MenuItem(label="One two"), ui.MenuItem(label="One three")])), ui.MenuItem(label="Two", menu=ui.Menu([ui.MenuItem(label="Two one"), ui.MenuItem(label="Two two"), ui.MenuItem(label="Two three")])), ui.MenuItem(label="Three", menu=ui.Menu([ui.MenuItem(label="Three one"), ui.MenuItem(label="Three two"), ui.MenuItem(label="Three three")])), ui.MenuItem(label="Four", menu=ui.Menu([ui.MenuItem(label="Four one"), ui.MenuItem(label="Four two"), ui.MenuItem(label="Four three")])), ui.MenuItem(label="Five") ], horizontal=True, disable_toggling=True) # not sure how elegant but let's override the flow for now for demo purposes! dummy_flow = ui.Flow() def flow_resize(): dummy_flow.alloc_w, dummy_flow.alloc_h = top_menu.alloc_w, top_menu.alloc_h dummy_flow.sprites = top_menu.sprites dummy_flow.resize_children() top_menu.height = top_menu.sprites[-1].y + top_menu.sprites[-1].height def flow_height_for_width_size(): dummy_flow.alloc_w, dummy_flow.alloc_h = top_menu.alloc_w, top_menu.alloc_h dummy_flow.sprites = top_menu.sprites w, h = dummy_flow.get_height_for_width_size() return w, h def flow_min_size(): dummy_flow.sprites = top_menu.sprites w, h = dummy_flow.get_min_size() return w+ top_menu.horizontal_padding, h + top_menu.vertical_padding # flow if b0rken ATM for i in range(20): top_menu.add_child(ui.MenuItem(label="flow %d" % i)) top_menu.resize_children = flow_resize #top_menu.get_height_for_width_size = flow_height_for_width_size top_menu.get_min_size = flow_min_size self.add_child(ui.VBox([top_menu, ui.VBox([self.notebook, ui.HBox([self.tab_orient_switch, self.page_disablist, self.dialog_button], expand = False, fill=False, x_align=1), ], padding=20, spacing=10)], spacing = 10)) self.connect("on-click", self.on_click) self.notebook.after_tabs.add_child(ui.Button("Yohoho")) print dt.datetime.now() - now
def __init__(self, parent): self.parent = parent self.items = [] self.played_sounds = [False] * 10 self.power_box = ui.PowerBar( globals.screen_root, pos=Point(0.45, 0.05), tr=Point(0.55, 0.1), level=0.6, bar_colours=(drawing.constants.colours.green, drawing.constants.colours.yellow, drawing.constants.colours.red), border_colour=drawing.constants.colours.white) self.fe_level = ui.PowerBar( globals.screen_root, pos=Point(0.8, 0.05), tr=Point(0.9, 0.1), level=1.0, bar_colours=(drawing.constants.colours.red, drawing.constants.colours.yellow, drawing.constants.colours.green), border_colour=drawing.constants.colours.white) self.fe_level.title = ui.TextBox(parent=self.fe_level, bl=Point(-0.03, 1.0), tr=Point(1.1, 1.5), text='Foam Level', scale=3) self.power_box.Disable() self.fe_level.Disable() self.extra_help_box = ui.Box(globals.screen_root, pos=Point(0.35, 0.0), tr=Point(0.65, 0.04), colour=drawing.constants.colours.black) self.extra_help_box.text = ui.TextBox(parent=self.extra_help_box, bl=Point(0, 0), tr=Point(1, 1), text='Press SPACE to reset', scale=4) self.help_box = ui.Box(globals.screen_root, pos=Point(0.6, 0.6), tr=Point(1, 1), colour=drawing.constants.colours.black) self.help_box.title = ui.TextBox(parent=self.help_box, bl=Point(0.22, 0.8), tr=Point(1, 1), text='Controls', scale=4) p = 0.7 self.help_box.help = [] height = 0.08 for i, (key, action) in enumerate( (('left click', 'grab/push/spray'), ('left hold(while grabbed)', 'push'), ('right click', 'cancel/detach'), ('right hold(with item)', 'throw'), ('h', 'toggle help'), ('middle drag', 'move screen'), ('middle scroll', 'zoom'), ('space', 'reset'), ('tab', 'switch players'), ('DEL', 'toggle music'))): self.help_box.help.append( ui.TextBox(parent=self.help_box, bl=Point(-0.2, p), tr=Point(1.2, p + height), text=('%30s %s' % (key, action)), scale=3)) p -= height self.help_box.Enable() #for name,pos in ((self.shuttle_name,globals.screen*2), #(self.debris_name,globals.screen*Point(0.3,0.3)), #(self.debris_name,globals.screen*Point(0.3,0.6)), # (self.debris_name,globals.screen*Point(0.6,0.3))): # obj = parent.atlas.SubimageSprite(name) # self.items.append(actors.DynamicBox(self.parent.physics, # bl = pos, # tr = pos + obj.size, # tc = parent.atlas.TextureSpriteCoords(name))) self.ResetSceneOne()