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_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 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()
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 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 _get_custom_fields(self): # Handle all fields here that we don't have a basic handler for fields_layout = None def on_input(id, value): global gDirty gDirty = True try: self.theme[self.path][id] = safe_eval.safe_eval(value) except kytten.safe_eval.Unsafe_Source_Error: self.theme[self.path][id] = value def on_delete(id): self.do_delete_field(fields_layout, id) fields = [] items = self.theme[self.path].items() items.sort(lambda x, y: cmp(x[0], y[0])) index = 0 for k, v in items: if not k.startswith('image') and not isinstance(v, dict): if not k.endswith('color'): fields.append([ kytten.Label(k), kytten.Input(id=k, text=str(v), on_input=on_input), kytten.Button("Delete", id=k, on_click=on_delete) ]) else: fields.append([ kytten.Label(k), ColorSelector(id=k, color=v, on_select=on_input), kytten.Button("Delete", id=k, on_click=on_delete) ]) index += 1 fields_layout = kytten.GridLayout(fields) # Pop up a dialog if we want to add a new field def on_add_field(): self.do_add_new_field(fields_layout, on_input, on_delete) return [ kytten.FoldingSection( "Custom Fields", kytten.VerticalLayout([ kytten.GridLayout(fields, anchor=kytten.ANCHOR_LEFT), kytten.Button("Add Field", on_click=on_add_field), ])) ]
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_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)