示例#1
0
 def size(self, dialog):
     Control.size(self, dialog)
     if self.swatch is None:
         self.swatch = dialog.theme[self.path]['image'].generate(
             dialog.theme[self.path]['gui_color'], dialog.batch,
             dialog.fg_group)
     if self.vlist is None:
         self.vlist = dialog.batch.add(4, gl.GL_QUADS,
                                       dialog.highlight_group,
                                       ('v2i', self._get_vlist_vertices()),
                                       ('c4B', self.color * 4))
     if self.swatch_label is None:
         self.swatch_label = Label(repr(self.color))
     self.swatch_label.size(dialog)
     swatch_width, swatch_height = self.swatch.get_needed_size(
         self.content_width, self.content_height)
     self.height = max(self.swatch_label.height, swatch_height)
     self.width = swatch_width + 4 + self.swatch_label.width
示例#2
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)
            ]))
示例#3
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)
        ]))
示例#4
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]))
示例#5
0
 def size(self, dialog):
     Control.size(self, dialog)
     if self.swatch is None:
         self.swatch = dialog.theme[self.path]["image"].generate(
             dialog.theme[self.path]["gui_color"], dialog.batch, dialog.fg_group
         )
     if self.vlist is None:
         self.vlist = dialog.batch.add(
             4, gl.GL_QUADS, dialog.highlight_group, ("v2i", self._get_vlist_vertices()), ("c4B", self.color * 4)
         )
     if self.swatch_label is None:
         self.swatch_label = Label(repr(self.color))
     self.swatch_label.size(dialog)
     swatch_width, swatch_height = self.swatch.get_needed_size(self.content_width, self.content_height)
     self.height = max(self.swatch_label.height, swatch_height)
     self.width = swatch_width + 4 + self.swatch_label.width
示例#6
0
class ToolDialog(Dialog):
    def __init__(self):
        self.selectedToolLabel = None
        self.iconsheetFilename = gui.config.get('tools', 'ICONSHEET_FILENAME')
        initialMenuSelection = 'Pan'
        frame = self.createLayout(initialMenuSelection)
        super(ToolDialog, self).__init__(frame,
                                         window=window,
                                         batch=batch,
                                         anchor=kytten.ANCHOR_TOP_LEFT,
                                         theme=theme)
        self.selectTool(initialMenuSelection)

    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)
        ]))

    def onToolMenuSelect(self, toolId):
        window.makeSoundEffect("MENUCLICK")
        self.selectTool(toolId)

    def selectTool(self, toolId):
        tool = window.selectTool(toolId.strip())
        if self.selectedToolLabel is not None:
            self.selectedToolLabel.set_text(toolId)
            # pan is only tool not in micropolistool types
            if toolId == "Pan" or \
                            tool.getToolCost() == 0:
                self.selectedToolPriceLabel.set_text("Free")
            else:
                self.selectedToolPriceLabel.set_text("$" + str(tool.getToolCost()))
示例#7
0
class ColorSelector(Control):
    """
    Depicts a small color-filled box.  When clicked upon, creates a pop-up
    dialog which can be used to set the color.
    """
    path = ['colorselector', 'swatch']

    def __init__(self, color, width=16, height=16,
		 id=None, on_select=None):
	Control.__init__(self, id=id)
	self.color = color
	self.content_width = width
	self.content_height = height
	self.swatch_label = None
	self.swatch = None
	self.vlist = None
	self.on_select = on_select
	self.select_dialog = None
	self.wheel = None
	self.red_input = None
	self.green_input = None
	self.blue_input = None
	self.slider = None
	self.accept_button = None
	self.cancel_button = None

    def _delete_select_dialog(self):
        if self.select_dialog is not None:
            self.select_dialog.window.remove_handlers(self.select_dialog)
            self.select_dialog.teardown()
            self.select_dialog = None
	    self.wheel = None
	    self.red_input = None
	    self.green_input = None
	    self.blue_input = None
	    self.slider = None
	    self.accept_button = None
	    self.cancel_button = None

    def _get_vlist_vertices(self):
	if self.swatch is None:
	    return [0, 0, 0, 0, 0, 0, 0, 0]
	x, y, width, height = self.swatch.get_content_region()
	return [x, y, x + width, y, x + width, y + height, x, y + height]

    def delete(self):
	Control.delete(self)
	if self.swatch_label is not None:
	    self.swatch_label.delete()
	    self.swatch_label = None
	if self.swatch is not None:
	    self.swatch.delete()
	    self.swatch = None  # deleted as part of layout
	if self.vlist is not None:
	    self.vlist.delete()
	    self.vlist = None
	self._delete_select_dialog()

    def layout(self, x, y):
	Control.layout(self, x, y)
	if self.swatch is not None:
	    width, height = self.swatch.get_needed_size(
		self.content_width, self.content_height)
	    self.swatch.update(self.x, self.y, width, height)
	    if self.vlist is not None:
		self.vlist.vertices = self._get_vlist_vertices()
	if self.swatch_label is not None:
	    self.swatch_label.layout(
		x + self.swatch.width + 4,
		y + (self.height - self.swatch_label.height) / 2)

    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)

    def size(self, dialog):
	Control.size(self, dialog)
	if self.swatch is None:
	    self.swatch = dialog.theme[self.path]['image'].generate(
                dialog.theme[self.path]['gui_color'],
                dialog.batch,
                dialog.fg_group)
	if self.vlist is None:
	    self.vlist = dialog.batch.add(4, gl.GL_QUADS,
                dialog.highlight_group,
                ('v2i', self._get_vlist_vertices()),
                ('c4B', self.color * 4))
	if self.swatch_label is None:
	    self.swatch_label = Label(repr(self.color))
	self.swatch_label.size(dialog)
	swatch_width, swatch_height = self.swatch.get_needed_size(
	    self.content_width, self.content_height)
	self.height = max(self.swatch_label.height, swatch_height)
	self.width = swatch_width + 4 + self.swatch_label.width

    def teardown(self):
	Control.teardown(self)
	if self.select_dialog is not None:
	    self.select_dialog.teardown()
	    self.select_dialog = None
示例#8
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)
示例#9
0
class ColorSelector(Control):
    """
    Depicts a small color-filled box.  When clicked upon, creates a pop-up
    dialog which can be used to set the color.
    """
    path = ['colorselector', 'swatch']

    def __init__(self, color, width=16, height=16, id=None, on_select=None):
        Control.__init__(self, id=id)
        self.color = color
        self.content_width = width
        self.content_height = height
        self.swatch_label = None
        self.swatch = None
        self.vlist = None
        self.on_select = on_select
        self.select_dialog = None
        self.wheel = None
        self.red_input = None
        self.green_input = None
        self.blue_input = None
        self.slider = None
        self.accept_button = None
        self.cancel_button = None

    def _delete_select_dialog(self):
        if self.select_dialog is not None:
            self.select_dialog.window.remove_handlers(self.select_dialog)
            self.select_dialog.teardown()
            self.select_dialog = None
            self.wheel = None
            self.red_input = None
            self.green_input = None
            self.blue_input = None
            self.slider = None
            self.accept_button = None
            self.cancel_button = None

    def _get_vlist_vertices(self):
        if self.swatch is None:
            return [0, 0, 0, 0, 0, 0, 0, 0]
        x, y, width, height = self.swatch.get_content_region()
        return [x, y, x + width, y, x + width, y + height, x, y + height]

    def delete(self):
        Control.delete(self)
        if self.swatch_label is not None:
            self.swatch_label.delete()
            self.swatch_label = None
        if self.swatch is not None:
            self.swatch.delete()
            self.swatch = None  # deleted as part of layout
        if self.vlist is not None:
            self.vlist.delete()
            self.vlist = None
        self._delete_select_dialog()

    def layout(self, x, y):
        Control.layout(self, x, y)
        if self.swatch is not None:
            width, height = self.swatch.get_needed_size(
                self.content_width, self.content_height)
            self.swatch.update(self.x, self.y, width, height)
            if self.vlist is not None:
                self.vlist.vertices = self._get_vlist_vertices()
        if self.swatch_label is not None:
            self.swatch_label.layout(
                x + self.swatch.width + 4,
                y + (self.height - self.swatch_label.height) / 2)

    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)

    def size(self, dialog):
        Control.size(self, dialog)
        if self.swatch is None:
            self.swatch = dialog.theme[self.path]['image'].generate(
                dialog.theme[self.path]['gui_color'], dialog.batch,
                dialog.fg_group)
        if self.vlist is None:
            self.vlist = dialog.batch.add(4, gl.GL_QUADS,
                                          dialog.highlight_group,
                                          ('v2i', self._get_vlist_vertices()),
                                          ('c4B', self.color * 4))
        if self.swatch_label is None:
            self.swatch_label = Label(repr(self.color))
        self.swatch_label.size(dialog)
        swatch_width, swatch_height = self.swatch.get_needed_size(
            self.content_width, self.content_height)
        self.height = max(self.swatch_label.height, swatch_height)
        self.width = swatch_width + 4 + self.swatch_label.width

    def teardown(self):
        Control.teardown(self)
        if self.select_dialog is not None:
            self.select_dialog.teardown()
            self.select_dialog = None
示例#10
0
class ToolDialog(Dialog):
    def __init__(self):
        self.selectedToolLabel = None
        self.iconsheetFilename = gui.config.get('tools', 'ICONSHEET_FILENAME')
        initialMenuSelection = 'Pan'
        frame = self.createLayout(initialMenuSelection)
        super(ToolDialog, self).__init__(frame,
                                         window=window,
                                         batch=batch,
                                         anchor=kytten.ANCHOR_TOP_LEFT,
                                         theme=theme)
        self.selectTool(initialMenuSelection)

    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)
            ]))

    def onToolMenuSelect(self, toolId):
        window.makeSoundEffect("MENUCLICK")
        self.selectTool(toolId)

    def selectTool(self, toolId):
        tool = window.selectTool(toolId.strip())
        if self.selectedToolLabel is not None:
            self.selectedToolLabel.set_text(toolId)
            # pan is only tool not in micropolistool types
            if toolId == "Pan" or \
                            tool.getToolCost() == 0:
                self.selectedToolPriceLabel.set_text("Free")
            else:
                self.selectedToolPriceLabel.set_text("$" +
                                                     str(tool.getToolCost()))
示例#11
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]))