Пример #1
0
 def __init__(self, options=[], align=HALIGN_CENTER, padding=4,
              on_select=None):
     names = list()
     for option in options:
         names.append(option[0])
     self.align = align
     menu_options = self._make_options(options)
     self.options = dict(list(zip(names, menu_options)))
     self.on_select = on_select
     self.selected = None
     VerticalLayout.__init__(self, menu_options,
                             align=align, padding=padding)
Пример #2
0
 def __init__(self,
              options=[],
              align=HALIGN_CENTER,
              padding=4,
              on_select=None):
     names = list()
     for option in options:
         names.append(option[0])
     self.align = align
     menu_options = self._make_options(options)
     self.options = dict(list(zip(names, menu_options)))
     self.on_select = on_select
     self.selected = None
     VerticalLayout.__init__(self,
                             menu_options,
                             align=align,
                             padding=padding)
Пример #3
0
    def createLayout(self):
        title = Label(text="Micropylis")
        if window.cityLoaded():
            options = [
                "Back", "New City", "Load City", "Save City", "Options",
                "Credits", "Quit"
            ]
        else:
            options = ["New City", "Load City", "Options", "Credits", "Quit"]
        self.menu = widgets.ClickMenu(options,
                                      on_select=self.on_select_menu,
                                      option_padding_x=76,
                                      option_padding_y=16)

        return Frame(VerticalLayout([title, Spacer(height=2), self.menu]))
Пример #4
0
    def createLayout(self, initialMenuSelection):
        iconSize = gui.config.getInt('tools', 'TOOLICONSIZE')
        iconSheet = pyglet.resource.image(self.iconsheetFilename)
        rows = iconSheet.height // iconSize
        columns = iconSheet.width // iconSize
        iconSheet = pyglet.image.TextureGrid(
            pyglet.image.ImageGrid(iconSheet, rows, columns))

        toolSet = []
        i = 0
        with pyglet.resource.file("res/toolsorder") as tOFile:
            for line in tOFile:
                name = line.strip().lower().title()
                row = rows - 1 - (i // columns)
                column = i % columns
                toolSet.append((name, iconSheet[row, column]))
                i += 1

        # Create options from images to pass to Palette
        palette_options = [[]]
        for i in xrange(rows - 1):
            palette_options.append([])
        for i, pair in enumerate(toolSet):
            option = widgets.PaletteOption(name=pair[0],
                                           image=pair[1],
                                           padding=2)
            # Build column down, 3 rows
            palette_options[i % 8].append(option)
        self.toolMenu = widgets.PaletteMenu(
            palette_options,
            on_select=self.onToolMenuSelect,
            initialSelection=initialMenuSelection)

        self.selectedToolLabel = Label("")
        self.selectedToolPriceLabel = Label("")

        return Frame(
            VerticalLayout([
                self.selectedToolLabel, self.selectedToolPriceLabel,
                self.toolMenu,
                Spacer(height=4)
            ]))
Пример #5
0
 def teardown(self):
     self.on_select = None
     VerticalLayout.teardown(self)
Пример #6
0
    def on_mouse_release(self, x, y, button, modifiers):
        if self.is_disabled():
            return

        if self.select_dialog is not None:
            self._delete_select_dialog()  # if it's already up, close it
            return

        # Setup some callbacks for the dialog
        root = self.saved_dialog.get_root()

        def on_escape(dialog):
            self._delete_select_dialog()

        def on_color_set(color):
            self.color = color
            if self.red_input is not None:
                self.red_input.set_text(str(color[0]))
            if self.green_input is not None:
                self.green_input.set_text(str(color[1]))
            if self.blue_input is not None:
                self.blue_input.set_text(str(color[2]))

        def on_red_set(red):
            red = min(max(int(red), 0), 255)
            print "red = %s" % red
            self.color = [red] + self.color[1:]
            self.wheel.set_color(self.color)

        def on_green_set(green):
            green = min(max(int(green), 0), 255)
            print "green = %s" % green
            self.color = [self.color[0], green] + self.color[2:]
            self.wheel.set_color(self.color)

        def on_blue_set(blue):
            blue = min(max(int(blue), 0), 255)
            print "blue = %s" % blue
            self.color = self.color[:2] + [blue, self.color[3]]
            self.wheel.set_color(self.color)

        def on_alpha_set(alpha):
            self.wheel.set_alpha(int(alpha))

        def on_set_color_button():
            if self.on_select is not None:
                if self.id is not None:
                    self.on_select(self.id, repr(self.color))
                else:
                    self.on_select(repr(self.color))
            if self.vlist is not None:
                self.vlist.delete()
                self.vlist = None
            if self.swatch_label is not None:
                self.swatch_label.set_text(repr(self.color))
            self._delete_select_dialog()
            self.saved_dialog.set_needs_layout()

        def on_cancel_button():
            self._delete_select_dialog()
            self.saved_dialog.set_needs_layout()

        # We'll need the root window to get window size
        width, height = root.window.get_size()

        # Now to setup the dialog
        self.wheel = ColorWheel(self.color, on_select=on_color_set)
        self.slider = Slider(value=self.wheel.alpha,
                             min_value=0.0,
                             max_value=255.0,
                             steps=8,
                             width=256,
                             on_set=on_alpha_set)
        self.accept_button = Button("Set Color", on_click=on_set_color_button)
        self.cancel_button = Button("Cancel", on_click=on_cancel_button)
        self.red_input = Input(text=str(self.color[0]),
                               on_input=on_red_set,
                               length=3,
                               max_length=3)
        self.green_input = Input(text=str(self.color[1]),
                                 on_input=on_green_set,
                                 length=3,
                                 max_length=3)
        self.blue_input = Input(text=str(self.color[2]),
                                on_input=on_blue_set,
                                length=3,
                                max_length=3)
        self.select_dialog = Dialog(Frame(
            VerticalLayout([
                self.wheel,
                HorizontalLayout([
                    Label("Red"), self.red_input, None,
                    Label("Green"), self.green_input, None,
                    Label("Blue"), self.blue_input
                ]),
                HorizontalLayout([
                    Label("Alpha"),
                    self.slider,
                ]),
                HorizontalLayout(
                    [self.accept_button, None, self.cancel_button]),
            ])),
                                    window=root.window,
                                    batch=root.batch,
                                    group=root.root_group.parent,
                                    theme=root.theme,
                                    movable=True,
                                    anchor=ANCHOR_CENTER,
                                    on_escape=on_escape)
        root.window.push_handlers(self.select_dialog)
Пример #7
0
 def teardown(self):
     self.on_select = None
     VerticalLayout.teardown(self)
Пример #8
0
    def createLayout(self):
        title = Label(text="City Budget")
        self.menu = widgets.ClickMenu(options=["Stuff here"],
                                      on_select=self.on_select_menu)

        return Frame(VerticalLayout([title, Spacer(height=2), self.menu]))