def create_scrollable_dialog(): def on_select(choice): print("Kytten is %s" % choice) def on_set(value): print("Kytten rating is %0.0f" % value) dialog = kytten.Dialog(kytten.Frame( kytten.Scrollable(kytten.VerticalLayout([ kytten.Label("Rate Kytten from 1 to 10:"), kytten.Slider(7.0, 1.0, 10.0, steps=9, on_set=on_set), kytten.Label("This slider is disabled:"), kytten.Slider( 1.0, 1.0, 10.0, steps=9, on_set=on_set, disabled=True), kytten.Label("Kytten is..."), kytten.Menu(options=[ "Awesome", "Cute", "-Disabled Option", "Excellent", "Fantastic", "Great", "Supercalifragilistiexpialidocious", "Terrific" ], align=kytten.HALIGN_LEFT, on_select=on_select), ], align=kytten.HALIGN_LEFT), width=200, height=150)), window=window, batch=batch, group=fg_group, anchor=kytten.ANCHOR_CENTER, theme=kytten.themes.felyne_light, on_escape=on_escape)
def mainDialog(self): def brushMenu(command): if command == 'Increase Brush Size' or command =='Decrease Brush Size': self.canvas.setBrushSize(command) elif command == 'Pencil': self.canvas.setPencil() elif command == 'Eraser': self.canvas.setEraser() # Set up a Dialog to choose test dialogs to show dialog = kytten.Dialog( kytten.Frame( kytten.HorizontalLayout([ kytten.Dropdown(['Save File', 'Open File'], on_select=self.on_select, text="File"), kytten.Dropdown(['Copy', 'Cut', 'Paste'], on_select=self.on_select, text="Edit"), kytten.Dropdown(['Pencil', 'Eraser', 'Increase Brush Size', 'Decrease Brush Size'], on_select=brushMenu, text="Brush"), ], padding=0, align=kytten.VALIGN_TOP) ), window=self.window, batch=self.canvas.batch, group=self.fg_group, anchor=kytten.ANCHOR_TOP_LEFT, on_mouse_release=self.on_mouse_release, theme=self.cobalt)
def create_document_dialog(): document = pyglet.text.decode_attributed(''' With {bold True}kytten{bold False}, you can harness the power of {underline (255, 255, 255, 255)}pyglet{underline None}'s documents in a scrollable window! {font_name "Courier New"}Change fonts{font_name Lucia Grande}, {italic True}italicize your text,{italic False} and more! {align "center"}Center yourself!{align "left"}{} {align "right"}Or go right.{align "left"} {color (128, 255, 128, 255)} Express {color (255, 128, 128, 255)} yourself {color (128, 128, 255, 255)} colorfully! {color (255, 255, 255, 255} ''') dialog = kytten.Dialog(kytten.Frame( kytten.Document(document, width=300, height=150)), window=window, batch=batch, group=fg_group, anchor=kytten.ANCHOR_CENTER, theme=kytten.themes.felyne_light, on_escape=on_escape)
def do_save_as(self): if self.popup is not None: self.popup.teardown() def do_cancel_save_as(dialog): self.popup.teardown() self.popup = None def do_set_filename(dialog): form = dialog.get_values() filename = form['name'] if filename: name = os.path.join(self.theme_dir, filename) if os.path.isfile(name): self.popup_message("%s already exists" % filename) elif not filename.endswith('.json'): self.popup_message("%s must end in .json" % filename) else: self.name = filename self.file_label.label.text = 'File: %s' % self.name self.do_save() else: self.popup_message("Please select a file") self.popup = kytten.Dialog(kytten.Frame( kytten.HorizontalLayout( [kytten.Label("Filename"), kytten.Input(id='name')])), theme=gTheme, window=self.window, on_enter=do_set_filename, on_escape=do_cancel_save_as)
def on_show_state(self, window, manager): BaseState.on_show_state(self, window, manager) def on_theme_file_cancel(dialog): self.manager.pop() def on_theme_file_enter(dialog): form = dialog.get_values() filename = form['name'] if filename: name = os.path.join(self.theme_dir, filename) if os.path.isfile(name): self.popup_message("%s already exists" % filename) elif not filename.endswith('.json'): self.popup_message("%s must end in .json" % filename) else: self.set_theme_file(filename) else: self.popup_message("Please select a file") self.dialog = kytten.Dialog(kytten.TitleFrame( "kytten Theme Editor", kytten.VerticalLayout([ kytten.Label("Please select a theme file name"), kytten.Input(id='name') ]), ), window=window, anchor=kytten.ANCHOR_CENTER, theme=gTheme, on_escape=on_theme_file_cancel, on_enter=on_theme_file_enter)
def on_show_state(self, window, manager): BaseState.on_show_state(self, window, manager) def on_theme_file_select(filename): if filename: self.select_theme_file(filename) else: self.popup_message("Please select a file") def on_theme_file_cancel(dialog): self.manager.pop() json_files = glob.glob(os.path.join(self.theme_dir, '*.json')) json_files = [os.path.basename(x) for x in json_files] self.dialog = kytten.Dialog(kytten.TitleFrame( "kytten Theme Editor", kytten.VerticalLayout([ kytten.Label("Please select a theme file"), kytten.Menu(options=['(New File)'] + json_files, on_select=on_theme_file_select) ]), ), window=window, anchor=kytten.ANCHOR_CENTER, theme=gTheme, on_escape=on_theme_file_cancel)
def layerDialog(self): # Set up a Dialog to choose test dialogs to show def createLayer(): self.canvas.addLayer() dialog.teardown() self.layerDialog() def focusLayer(foo): def func(): self.canvas.setCurrentLayer(foo) return func def incLayer(foo): def func(): self.canvas.incrementLayer(foo) dialog.teardown() self.layerDialog() return func def decLayer(foo): def func(): self.canvas.decrementLayer(foo) dialog.teardown() self.layerDialog() return func def delLayer(foo): def func(): self.canvas.deleteLayer(foo) dialog.teardown() self.layerDialog() return func content = [item for sublist in [ [kytten.HorizontalLayout([ kytten.Button("S", on_click=focusLayer(layer.index)), kytten.Checkbox(layer.name, is_checked=layer.visible, on_click=layer.toggleVisibility), kytten.Button("^", on_click=incLayer(layer.index)), kytten.Button("v", on_click=decLayer(layer.index)) ]) ] for layer in self.canvas.layers] for item in sublist] content.append(kytten.Button("Create Layer", on_click=createLayer)) dialog = kytten.Dialog( kytten.Frame( kytten.VerticalLayout( content, padding=0, align=kytten.VALIGN_TOP) ), window=self.window, batch=self.canvas.batch, group=self.fg_group, anchor=kytten.ANCHOR_TOP_RIGHT, on_mouse_release=self.on_mouse_release, theme=self.cobalt)
def do_add_new_field(self, fields_layout, on_input, on_delete): if self.popup is not None: self.popup.teardown() def do_cancel_add(dialog=None): self.popup.teardown() self.popup = None def do_add_field(dialog=None): global gDirty gDirty = True form = self.popup.get_values() self.popup.teardown() self.popup = None name = form['name'] if self.theme[self.path].has_key(name): self.popup_message("%s is already a field name!" % name) return try: value = safe_eval.safe_eval(form['value']) except kytten.safe_eval.Unsafe_Source_Error: value = form['value'] self.theme[self.path][name] = value fields_layout.add_row([ kytten.Label(name), kytten.Input(id=name, text=str(value), on_input=on_input), kytten.Button("Delete", id=name, on_click=on_delete) ]) if not self.delete_button.is_disabled(): self.delete_button.disable() self.dialog.set_needs_layout() self.popup = kytten.Dialog(kytten.Frame( kytten.VerticalLayout([ kytten.GridLayout([[ kytten.Label('Name'), kytten.Input(id='name', text='new_field') ], [ kytten.Label('Value'), kytten.Input(id='value', text='new_value') ]]), kytten.HorizontalLayout([ kytten.Button("Add", on_click=do_add_field), None, kytten.Button("Cancel", on_click=do_cancel_add) ]) ])), window=self.window, theme=gTheme, on_enter=do_add_field, on_escape=do_cancel_add)
def do_add_new_image(self): if self.popup is not None: self.popup.teardown() def do_cancel_add(dialog=None): self.popup.teardown() self.popup = None def do_add_image(dialog=None): global gDirty gDirty = True form = self.popup.get_values() self.popup.teardown() self.popup = None name = form['name'] if self.theme[self.path].has_key(name): self.popup_message("%s is already a field name!" % name) return if not name.startswith('image'): self.popup_message("Image names must begin with 'image'") texture = self.textures[form['texture']] self.theme[self.path][name] = FrameTextureGraphicElementTemplate( self.theme, texture, [0, 0, texture.width, texture.height], # stretch [0, 0, 0, 0]) # padding self.manager.push( ImageEditState(self.theme_dir, self.theme, self.textures, self.path, name)) self.popup = kytten.Dialog(kytten.Frame( kytten.VerticalLayout([ kytten.GridLayout([[ kytten.Label('Name'), kytten.Input(id='name', text='image') ], [ kytten.Label('Texture'), kytten.Dropdown( id='texture', options=self.textures.keys(), selected=self.textures.keys()[0]) ]]), kytten.HorizontalLayout([ kytten.Button("Add", on_click=do_add_image), None, kytten.Button("Cancel", on_click=do_cancel_add) ]) ])), window=self.window, theme=gTheme, on_enter=do_add_image, on_escape=do_cancel_add)
def create_folding_dialog(): document1 = pyglet.text.decode_attributed(""" Click on the section headers below to open them up. Jellicle Cats is, of course, copyrighted by T. S. Eliot. """) document2 = pyglet.text.decode_attributed(""" Jellicle cats come out tonight{} Jellicle cats come one, come all{} The Jellicle moon is shining bright{} Jellicles come to the Jellicle ball """) document3 = pyglet.text.decode_attributed(""" Jellicle cats are black and white{} Jellicle cats are rather small{} Jellicle cats are merry and bright{} And pleasant to hear when we caterwaul """) document4 = pyglet.text.decode_attributed(""" Jellicle cats have cheerful faces{} Jellicle cats have bright black eyes{} We like to practice our airs and graces{} And wait for the Jellicle moon to rise """) dialog = kytten.Dialog(kytten.Frame( kytten.Scrollable(kytten.VerticalLayout([ kytten.SectionHeader("Jellicle Cats"), kytten.Document(document1, width=300), kytten.FoldingSection( "Verse 1", kytten.VerticalLayout([ kytten.Document(document2, width=300), ])), kytten.FoldingSection("Verse 2", kytten.VerticalLayout([ kytten.Document(document3, width=300), ]), is_open=False), kytten.FoldingSection("Verse 3", kytten.VerticalLayout([ kytten.Document(document4, width=300), ]), is_open=False), ], align=kytten.HALIGN_LEFT), height=400)), window=window, batch=batch, group=fg_group, anchor=kytten.ANCHOR_CENTER, theme=kytten.themes.felyne_light, on_escape=on_escape)
def on_show_state(self, window, manager): BaseState.on_show_state(self, window, manager) def on_escape(dialog): self.manager.pop() content = self._get_content() self.dialog = kytten.Dialog(kytten.TitleFrame( "kytten Image Editor", kytten.Scrollable(kytten.VerticalLayout(content), width=750, height=500)), window=window, anchor=kytten.ANCHOR_CENTER, theme=gTheme, on_escape=on_escape)
def do_change_texture(self): if self.popup is not None: self.popup.teardown() def do_cancel_change(dialog=None): self.popup.teardown() self.popup = None def do_change_texture(dialog=None): global gDirty gDirty = True form = self.popup.get_values() self.popup.teardown() self.popup = None texture = self.textures[form['texture']] self.theme[self.path][self.image] = \ FrameTextureGraphicElementTemplate( self.theme, texture, [0, 0, texture.width, texture.height], # stretch [0, 0, 0, 0]) # padding manager = self.manager manager.pop() manager.push( ImageEditState(self.theme_dir, self.theme, self.textures, self.path, self.image)) self.popup = kytten.Dialog(kytten.Frame( kytten.VerticalLayout([ kytten.HorizontalLayout([ kytten.Label('Texture'), kytten.Dropdown(id='texture', options=self.textures.keys(), selected=self.textures.keys()[0]) ]), kytten.HorizontalLayout([ kytten.Button("Change", on_click=do_change_texture), None, kytten.Button("Cancel", on_click=do_cancel_change) ]), ])), window=self.window, theme=gTheme, on_enter=do_change_texture, on_escape=do_cancel_change)
def on_show_state(self, window, manager): BaseState.on_show_state(self, window, manager) content = self._get_content() def on_escape(dialog): self.manager.pop() self.dialog = kytten.Dialog(kytten.TitleFrame( 'kytten Theme Editor', kytten.Scrollable(kytten.VerticalLayout(content, align=kytten.HALIGN_LEFT), height=500)), window=window, anchor=kytten.ANCHOR_CENTER, theme=gTheme, on_escape=self.on_exit or on_escape)
def do_add_new_component(self): if self.popup is not None: self.popup.teardown() def do_cancel_add(dialog=None): self.popup.teardown() self.popup = None def do_add_component(dialog=None): global gDirty gDirty = True form = self.popup.get_values() self.popup.teardown() self.popup = None name = form['name'] if self.theme[self.path].has_key(name): self.popup_message("%s is already a field name!" % name) return self.theme[self.path][name] = {} self.manager.push( _NodeEditState(self.theme_dir, self.theme, self.textures, self.path + [name])) self.popup = kytten.Dialog(kytten.Frame( kytten.VerticalLayout([ kytten.HorizontalLayout([ kytten.Label('Name'), kytten.Input(id='name', text='new_component') ]), kytten.HorizontalLayout([ kytten.Button("Add", on_click=do_add_component), None, kytten.Button("Cancel", on_click=do_cancel_add) ]) ])), window=self.window, theme=gTheme, on_enter=do_add_component, on_escape=do_cancel_add)
def create_dropdown_dialog(): def on_select(choice): print("Selected: %s" % choice) dialog = kytten.Dialog(kytten.Frame( kytten.VerticalLayout([ kytten.Label("Select a letter:"), kytten.Dropdown([ 'Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', 'Iota', 'Kappa', 'Lambda', 'Mu', 'Nu', 'Xi', 'Omicron', 'Pi', 'Rho', 'Sigma', 'Tau', 'Upsilon', 'Phi', 'Chi', 'Psi', 'Omega' ], on_select=on_select), kytten.Label("This dropdown is disabled"), kytten.Dropdown(['Disabled', 'Enabled'], disabled=True), ]), ), window=window, batch=batch, group=fg_group, anchor=kytten.ANCHOR_CENTER, theme=kytten.themes.felyne_light, on_escape=on_escape)
pyglet.clock.schedule(update) # Set up a background which changes when user hits left or right arrow # background = Background(batch=batch, group=bg_group) # window.push_handlers(background) # Set up a Dialog to choose test dialogs to show dialog = kytten.Dialog(kytten.TitleFrame( "Kytten Demo", kytten.VerticalLayout([ kytten.Label("Select dialog to show"), kytten.Menu(options=[ "Document", "Form", "Scrollable", "Folding", "Dropdown", "File Load", "File Save", "Directory Select" ], on_select=on_select), ]), ), window=window, batch=batch, group=fg_group, anchor=kytten.ANCHOR_TOP_LEFT, theme=kytten.themes.felyne_dark) window2 = kytten.Window( "Window", kytten.VerticalLayout([ kytten.Label( "I'm a window, the first widget to be added to felyne."), kytten.Label("I have a close button, wow!") ]),
def create_form_dialog(): dialog = None def on_enter(dialog): print("Form submitted!") for key, value in dialog.get_values().items(): print(" %s=%s" % (key, value)) on_escape(dialog) def on_submit(): on_enter(dialog) def on_cancel(): print("Form canceled.") on_escape(dialog) dialog = kytten.Dialog(kytten.Frame( kytten.Scrollable(kytten.VerticalLayout([ kytten.SectionHeader("Personnel Data", align=kytten.HALIGN_LEFT), kytten.Document( "Try tabbing through fields, " "if offscreen they'll be moved " "automatically", width=500), kytten.GridLayout([ [ kytten.Label("Name"), kytten.Input("name", "Lynx", max_length=20) ], [ kytten.Label("Job"), kytten.Input("job", "Cat", max_length=80) ], [kytten.Label("Hobby"), kytten.Input("hobby", "Programming")], [kytten.Label("Class"), kytten.Input("class", "Druid")], [ kytten.Label("Disabled"), kytten.Input("disabled", "Disabled input", disabled=True) ], [ kytten.Label("Sign"), kytten.Input("sign", "Free to good home") ], [kytten.Label("Blood Type"), kytten.Input("bloodtype", "Red")], [ kytten.Label("Favored Weapon"), kytten.Input("weapon", "Claws") ], ]), kytten.Checkbox("Full-Time", id="fulltime"), kytten.Checkbox("Married", id="married", disabled=True), kytten.SectionHeader("Actions", align=kytten.HALIGN_LEFT), kytten.HorizontalLayout([ kytten.Button("Submit", on_click=on_submit), kytten.Button("Disabled", disabled=True), None, kytten.Button("Cancel", on_click=on_cancel), ]), ], align=kytten.HALIGN_LEFT), height=200, width=360)), window=window, batch=batch, group=fg_group, anchor=kytten.ANCHOR_CENTER, theme=kytten.themes.felyne_light, on_enter=on_enter, on_escape=on_escape)
caption='Kytten Test', resizable = True, vsync = False ) batch = pyglet.graphics.Batch() window.register_event_type('on_update') theme = kytten.Theme( os.path.join(os.getcwd(), 'theme') ) dialog = kytten.Dialog( kytten.TitleFrame( "Kytten Demo", kytten.VerticalLayout( [ kytten.Label("Drag Me!"), ] ), ), window = window, batch = batch, anchor = kytten.ANCHOR_TOP_LEFT, theme = theme ) @window.event def on_draw(): global window global batch window.clear() batch.draw() def update(dt):