示例#1
0
    def __init__(self, scene, widget, x=0, y=0):
        GameObject.__init__(self, scene, -1)
        self.widget = widget
        self.widget.id = Globals.WIDGETS
        Globals.WIDGETS += 1

        Dialog.__init__(self, content=GridLayout(content=[
            [self.widget]
        ]),
            window=Globals.WINDOW, batch=scene.batch, group=scene.layers[-1], offset=(x, y), theme=felyne_dark)
示例#2
0
 def teardown(self):
     Dialog.teardown(self)
     self.onDestruction(self.__class__)
示例#3
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)
示例#4
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
示例#5
0
    def __init__(self, title="", properties={}, ok="Ok", cancel="Cancel",
                 window=None, batch=None, group=None, theme=None,
                 on_ok=None, on_cancel=None, has_remove=False,
                 remove="x", has_add=False, add="+", on_add=None):

        def on_ok_click(dialog=None):
            if on_ok is not None:
                on_ok(self)
            #self.teardown()

        def on_cancel_click(dialog=None):
            if on_cancel is not None:
                on_cancel(self)
            #self.teardown()

        self.remove = remove
        self._has_remove = has_remove
        self._has_add = has_add
        property_table = self._make_properties(properties)
        grid = GridLayout(property_table, padding=8)

        def on_type_select(id, choice):
            item = Checkbox() if choice is 'bool' else Input(length=self.INPUT_W)
            for i, row in enumerate(grid.content):
                for cell in row:
                    if isinstance(cell, Dropdown):
                        if cell.id == id:
                            item_id = grid.get(1,i).id
                            item.id = item_id
                            grid.set(row=i, column=1, item=item)
                            break

        def on_add_click(dialog=None):
            if on_add is not None:
                on_add(self)
            else:
                pd = PropertyDialog
                pd._id_count += 1
                grid.add_row([
                    Input(id=pd.ADD_NAME_PRE+str(pd._id_count),
                        length=self.INPUT_W),
                    Input(id=pd.ADD_VALUE_PRE+str(pd._id_count),
                        length=self.INPUT_W),
                    Dropdown(['unicode', 'bool', 'int', 'float'],
                              id=pd.TYPE_PRE+str(pd._id_count),
                              on_select=on_type_select)
                ])

        if self._has_add:
            add_content = (ANCHOR_TOP_LEFT, 0, 0, Button(add, on_click=on_add_click))
            Dialog.__init__(self, content=Frame(Scrollable(
                VerticalLayout([
                    SectionHeader(title, align=HALIGN_LEFT),
                    grid,
                    FreeLayout(content=[add_content]),
                    Spacer(height=30),
                    HorizontalLayout([
                        Button(ok, on_click=on_ok_click),
                        Button(cancel, on_click=on_cancel_click)])
                ]),height=window.height)),
                window=window, batch=batch, group=group,
                theme=theme, movable=True,
                on_enter=on_ok_click, on_escape=on_cancel_click)
        else:
            Dialog.__init__(self, content=Frame(Scrollable(
                VerticalLayout([
                    SectionHeader(title, align=HALIGN_LEFT),
                    grid,
                    Spacer(height=30),
                    HorizontalLayout([
                        Button(ok, on_click=on_ok_click),
                        Button(cancel, on_click=on_cancel_click)])
                ]),height=window.height)),
                window=window, batch=batch, group=group,
                theme=theme, movable=True,
                on_enter=on_ok_click, on_escape=on_cancel_click)
示例#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
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 teardown(self):
     Dialog.teardown(self)
     self.onDestruction(self.__class__)