def apply_changes (self): """ Add changes to undo stack and tidy up """ dirty_list = self.model.get_dirty_property_list() command = '' undo_command = '' if len(dirty_list) > 0: # Get redo and undo commands for prop in dirty_list: new_command = self.model.get_string_command( prop['name'], prop['value'], self.model.get_object() ) init_value = self.model.init_values[prop['name']]['value'] new_undo_command = self.model.get_string_command( prop['name'], init_value[0], self.model.get_object() ) if new_command is None or new_undo_command is None: break; command += new_command undo_command += new_undo_command # Put commands in undo server servers.get_command_server().newcommand( str(command[:-1]), str(undo_command[:-1]) ) self.tidy_up_for_close()
def on_save_button(self, evt): # Send a enter key event to property for update values event = wx.KeyEvent(wx.wxEVT_CHAR) event.m_keyCode = wx.WXK_RETURN self.cmds_pg.GetEventHandler().ProcessEvent(event) # make this object the current nebulagui.nebula_object = self.object # Get redo command self.redo = self.__get_redo_command() # Get undo command self.undo = self.__get_undo_command() # new command servers.get_command_server().newcommand(str(self.redo), str(self.undo)) self.draw_state_commands(self.object) if self.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty( self.object, True) elif self.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty( self.object, True) if self.object.isa("nscenenode"): self.object.loadresources() self.object.setobjectdirty(True)
def on_change_undo(self, event): mem_mb = self.int_ctrl_undo.GetValue() mem_bytes = format.mb2bytes(mem_mb) servers.get_command_server().setmemorylimit(mem_bytes) set_repository_setting_value( guisettings.ID_UndoMemory, mem_mb )
def update_undo_memory(self): mem_used = servers.get_command_server().getmemoryused() mem_limit = servers.get_command_server().getmemorylimit() # Format to ###.# Xb mem_used = format.bytes2best_str(mem_used) mem_limit = format.bytes2best_str(mem_limit) self.SetStatusText("Undo memory: " + mem_used + "/" + mem_limit, ID_UndoMemory)
def __do_command(self, function_name, new_value, old_value): # redo redo = self.cmd_init redo = redo + "noreport = viewport." + function_name redo = redo + "(" + str(new_value) + "); del viewport" # undo undo = self.cmd_init undo = undo + "noreport = viewport." + function_name undo = undo + "(" + str(old_value) + "); del viewport" # new command servers.get_command_server().newcommand(redo, undo)
def __do_int_command(self, attribute, new_value, old_value): # redo redo = self.cmd_init redo = redo + "noreport = fog.setintvariable('" + attribute + "', " redo = redo + str(new_value) + ");del fog" # undo undo = self.cmd_init undo = undo + "noreport = fog.setintvariable('" + attribute + "', " undo = undo + str(old_value) + ");del fog" # new command servers.get_command_server().newcommand(redo,undo)
def __do_float_command(self, attribute, new_value, old_value): # redo redo = self.cmd_init redo = redo + "noreport = light.setfloatoverride('" + attribute + "', " redo = redo + str(new_value) + ");del light" # undo undo = self.cmd_init undo = undo + "noreport = light.setfloatoverride('" + attribute + "', " undo = undo + str(old_value) + ");del light" # new command servers.get_command_server().newcommand(redo, undo)
def __do_float_command(self, attribute, new_value, old_value): # redo redo = self.cmd_init redo = redo + "noreport = light.setfloatoverride('" + attribute + "', " redo = redo + str(new_value) + ");del light" # undo undo = self.cmd_init undo = undo + "noreport = light.setfloatoverride('" + attribute + "', " undo = undo + str(old_value) + ");del light" # new command servers.get_command_server().newcommand(redo,undo)
def on_redo(self, event): """Redo the last undone command""" try: # Apply redo on current editor if it implements it... active_editor = self.get_frame().GetActiveChild() if active_editor.handle_redo(): return except: pass # ...otherwise delegate the redo to the command server servers.get_command_server().redo() # and update any inspector whose values may have changed due to undo self.get_frame().refresh_scene_values()
def on_attribute_toggled(self, event): # Update the toggled attribute for all the selected waypoints waypoints = self.__get_selected_waypoints() if len(waypoints) > 0: index = event.GetSelection() value = self.clbox.IsChecked(index) cmd = ["", ""] for each_waypoint in waypoints: self.__append_set_attribute_cmd(each_waypoint, index, value, cmd) servers.get_command_server().newcommand(cmd[0], cmd[1]) # Update the attribute label self.__update_label(index, waypoints)
def __delete_selected_layer(self): layer_id = self.get_id_for_selected_layer() layer_name = self.get_name_for_selected_layer() cmd_server = servers.get_command_server() redo = "noreport = pynebula.lookup" \ "('/sys/servers/layermanager')." \ "removelayerbyname('%s');" \ "del noreport" % layer_name undo = "noreport = pynebula.lookup" \ "('/sys/servers/layermanager')." \ "createnewlayer2('%s',%s);" \ "del noreport" % (layer_name, layer_id) cmd_server.newcommand( str(redo), str(undo) ) # delete layer control self.__delete_layer_ctrl(self.layer_selected) self.__refresh_layers() self.save_layers_state() # select first layer by default self.layer_selected = self.layers[0] self.layer_selected.select()
def __execute_property (self, property, value, object, undo=False): writeshared.set_object(object) # Execute each setter with his value if value != []: command = self.__get_command(property, value, object) if undo == False: # Run the command servers.get_python_server().run(str(command)) else: init_value = self.init_values[property["name"]]["value"] undo_cmd = self.__get_command(property, init_value[0], object) servers.get_command_server().newcommand(str(command), str(undo_cmd)) self.values[property['name']]['value'] = [readshared.get_result()] object.setobjectdirty( True ) return readshared.get_result()
def __execute_property(self, property, value, object, undo=False): writeshared.set_object(object) # Execute each setter with his value if value != []: command = self.__get_command(property, value, object) if undo == False: # Run the command servers.get_python_server().run(str(command)) else: init_value = self.init_values[property["name"]]["value"] undo_cmd = self.__get_command(property, init_value[0], object) servers.get_command_server().newcommand( str(command), str(undo_cmd)) self.values[property['name']]['value'] = [readshared.get_result()] object.setobjectdirty(True) return readshared.get_result()
def __do_color_command(self, attribute, new_color, old_color): # redo rgba = format.byte_rgb_2_unit_rgba(new_color) redo = self.cmd_init redo = redo + "noreport = fog.setvectoroverride('" + attribute + "', " redo = redo + str(rgba[0]) + ", " redo = redo + str(rgba[1]) + ", " redo = redo + str(rgba[2]) + ", " redo = redo + str(rgba[3]) + ");del fog" # undo rgba = format.byte_rgb_2_unit_rgba(old_color) undo = self.cmd_init undo = undo + "noreport = fog.setvectoroverride('" + attribute + "', " undo = undo + str(rgba[0]) + ", " undo = undo + str(rgba[1]) + ", " undo = undo + str(rgba[2]) + ", " undo = undo + str(rgba[3]) + ");del fog" # new command servers.get_command_server().newcommand(redo,undo)
def on_toggle_ai(self, event): enable = event.Checked() or app.is_in_gameplay_mode() self.Check(ID_ToggleAI, enable) self.get_frame().get_toolbar().ToggleTool(ID_ToggleAI, enable) if enable: try: try: wx.BeginBusyCursor() servers.get_command_server().clean() servers.get_conjurer().saveeditorstate() app.get_ai_tester().enablegameplayupdating() finally: wx.EndBusyCursor() except: # make sure any errors are not hidden raise else: app.get_ai_tester().disablegameplayupdating() servers.get_conjurer().restoreeditorstate()
def __do_color_command(self, attribute, new_color, old_color): # redo rgba = format.byte_rgb_2_unit_rgba(new_color) redo = self.cmd_init redo = redo + "noreport = light.setvectoroverride('" + attribute + "', " redo = redo + str(rgba[0]) + ", " redo = redo + str(rgba[1]) + ", " redo = redo + str(rgba[2]) + ", " redo = redo + str(rgba[3]) + ");del light" # undo rgba = format.byte_rgb_2_unit_rgba(old_color) undo = self.cmd_init undo = undo + "noreport = light.setvectoroverride('" + attribute + "', " undo = undo + str(rgba[0]) + ", " undo = undo + str(rgba[1]) + ", " undo = undo + str(rgba[2]) + ", " undo = undo + str(rgba[3]) + ");del light" # new command servers.get_command_server().newcommand(redo,undo)
def on_attribute_toggled(self, event): # Update the toggled attribute for all the selected waypoints waypoints = self.__get_selected_waypoints() if len(waypoints) > 0: index = event.GetSelection() value = self.clbox.IsChecked(index) cmd = ["", ""] for each_waypoint in waypoints: self.__append_set_attribute_cmd( each_waypoint, index, value, cmd ) servers.get_command_server().newcommand( cmd[0], cmd[1] ) # Update the attribute label self.__update_label(index, waypoints)
def prelevel_process(is_new_level): # Forbid any level operation while in game mode if app.is_in_gameplay_mode(): cjr.show_error_message( "Operation not allowed while in game mode" ) return False # Exit from any test mode app.get_ai_tester().disablegameplayupdating() app.get_ai_tester().disablesoundsources() # Clear undo buffer servers.get_command_server().clean() if not is_new_level: return True # Discard deleted entities servers.get_entity_object_server().discarddeletedobjects() servers.get_entity_class_server().discarddeletedclasses() # What follows should be done only for new and open level commands # Clear selection app.get_object_state().resetselection() # Make terrain state release some buffers if servers.get_conjurer().getcurrentstate() == 'terrain': trn.get_terrain_module().setoutdoor(None) # Begin a persist-restore process to close those invalid windows for # the new level and refresh the valid ones (continue in postlevel_process) # Persist guiDialog windows frame = app.get_top_window() prelevel_process.child_data = [] for child in frame.get_child_dialogs(): data = persist_window(child) if data is not None: prelevel_process.child_data.insert(0, data) return True
def apply_changes(self): """ Add changes to undo stack and tidy up """ dirty_list = self.model.get_dirty_property_list() command = '' undo_command = '' if len(dirty_list) > 0: # Get redo and undo commands for prop in dirty_list: new_command = self.model.get_string_command( prop['name'], prop['value'], self.model.get_object()) init_value = self.model.init_values[prop['name']]['value'] new_undo_command = self.model.get_string_command( prop['name'], init_value[0], self.model.get_object()) if new_command is None or new_undo_command is None: break command += new_command undo_command += new_undo_command # Put commands in undo server servers.get_command_server().newcommand(str(command[:-1]), str(undo_command[:-1])) self.tidy_up_for_close()
def prelevel_process(is_new_level): # Forbid any level operation while in game mode if app.is_in_gameplay_mode(): cjr.show_error_message("Operation not allowed while in game mode") return False # Exit from any test mode app.get_ai_tester().disablegameplayupdating() app.get_ai_tester().disablesoundsources() # Clear undo buffer servers.get_command_server().clean() if not is_new_level: return True # Discard deleted entities servers.get_entity_object_server().discarddeletedobjects() servers.get_entity_class_server().discarddeletedclasses() # What follows should be done only for new and open level commands # Clear selection app.get_object_state().resetselection() # Make terrain state release some buffers if servers.get_conjurer().getcurrentstate() == 'terrain': trn.get_terrain_module().setoutdoor(None) # Begin a persist-restore process to close those invalid windows for # the new level and refresh the valid ones (continue in postlevel_process) # Persist guiDialog windows frame = app.get_top_window() prelevel_process.child_data = [] for child in frame.get_child_dialogs(): data = persist_window(child) if data is not None: prelevel_process.child_data.insert(0, data) return True
def on_save_button (self, evt): # Send a enter key event to property for update values event = wx.KeyEvent(wx.wxEVT_CHAR) event.m_keyCode = wx.WXK_RETURN self.cmds_pg.GetEventHandler().ProcessEvent(event) # make this object the current nebulagui.nebula_object = self.object # Get redo command self.redo = self.__get_redo_command() # Get undo command self.undo = self.__get_undo_command() # new command servers.get_command_server().newcommand(str(self.redo), str(self.undo)) self.draw_state_commands(self.object) if self.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty( self.object, True ) elif self.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty( self.object, True ) if self.object.isa("nscenenode"): self.object.loadresources() self.object.setobjectdirty(True)
def __del__ (self): """ Unbind used signals """ pynebula.pyUnbindTargetObject( app.get_object_state(), 'singleentityplaced', self.entity_browser ) pynebula.pyUnbindTargetObject( servers.get_command_server(), 'entitymodified', self.entity_browser ) pynebula.pyUnbindTargetObject( app.get_object_state(), 'selectionchanged', self.entity_browser )
def __delete_selected_layer(self): layer_id = self.get_id_for_selected_layer() layer_name = self.get_name_for_selected_layer() cmd_server = servers.get_command_server() redo = "noreport = pynebula.lookup" \ "('/sys/servers/layermanager')." \ "removelayerbyname('%s');" \ "del noreport" % layer_name undo = "noreport = pynebula.lookup" \ "('/sys/servers/layermanager')." \ "createnewlayer2('%s',%s);" \ "del noreport" % (layer_name, layer_id) cmd_server.newcommand(str(redo), str(undo)) # delete layer control self.__delete_layer_ctrl(self.layer_selected) self.__refresh_layers() self.save_layers_state() # select first layer by default self.layer_selected = self.layers[0] self.layer_selected.select()
def execute(inspector_win): # Send a enter key event to property for update values event = wx.KeyEvent(wx.wxEVT_CHAR) event.m_keyCode = wx.WXK_RETURN inspector_win.cmds_pg.GetEventHandler().ProcessEvent(event) # make this object the current nebulagui.nebula_object = inspector_win.object # Construct the command string to be called. # A variable will be use for storage the return value/s arg = inspector_win.cmd_proto_name.rsplit('_') command = "import nebulagui;" command = command + "result = nebulagui.nebula_object.%s" % inspector_win.cmds.GetValue()+ "(" i = 0 for field in inspector_win.in_elements: if arg[2][i] == 's': command = command + "'%s'," % field.GetValueAsString(0) elif arg[2][i] == 'o': command = command + "lookup('%s')," % field.GetValueAsString(0) else: command = command + "%s," % field.GetValueAsString(0) i = i + 1 if i > 0: command = command[:-1] command = command + ")" # Make undo command if possible normal_execute = True if re.compile("set.*").match(inspector_win.cmds.GetValue()): name = inspector_win.cmds.GetValue()[3:] num_getcmd = inspector_win.cmds.FindString(str("get"+name)) if num_getcmd != wx.NOT_FOUND: proto_cmd = inspector_win.get_dict[str("get"+name)] get_arg = proto_cmd.rsplit('_') if get_arg[2] == 'v': # Execute the get for get undo values get_cmd = "import nebulagui;import savecmdsinspector;" get_cmd = get_cmd + "savecmdsinspector.ret = nebulagui.nebula_object.%s" \ % str("get"+name) + "()" pynebula.lookup('/sys/servers/persist/npythonserver').\ run(str(get_cmd)) # Create undo command i = 0 undo_cmd = "import nebulagui;" undo_cmd = undo_cmd + "nebulagui.nebula_object.%s" % str("set"+name) + "(" for i in xrange(len(get_arg[0])): if len(get_arg[0]) > 1: element = ret[i] else: element = ret if get_arg[0][i] == 's': undo_cmd = undo_cmd + "'%s'," % str(element) elif get_arg[0][i] == 'o': undo_cmd = undo_cmd + "lookup('%s')," % str(element) else: undo_cmd = undo_cmd + "%s," % str(element) i = i + 1 undo_cmd = undo_cmd[:-1] + ")" # New command servers.get_command_server().newcommand(str(command), str(undo_cmd)) normal_execute = False if normal_execute: # Run the command servers.get_python_server().run(str(command)) # Look for return values. If it have, extract it from the result # and fill the propertygrid fields. if arg[0][0] != 'v': if len(arg[0]) > 1: for i in xrange(len(arg[0])): value = servers.get_python_server().\ run("import savecmdsinspector;"\ "savecmdsinspector.ret = "\ "result[" + str(i) +"]") draw_return_values(inspector_win, ret, arg[0], inspector_win.out_elements[i]) else: value = servers.get_python_server().\ run("import savecmdsinspector;"\ "savecmdsinspector.ret = "\ "result") draw_return_values(inspector_win, ret, arg[0], inspector_win.out_elements[0]) # delete temp variable servers.get_python_server().run(str("del result")) # if is a entity dirt the object. # TODO: Ugly hack! Find a better way to do this if inspector_win.object.hascommand("beginnewobjectentityclass"): servers.get_entity_class_server().setentityclassdirty(inspector_win.object, True) elif inspector_win.object.hascommand("getid"): servers.get_entity_object_server().setentityobjectdirty(inspector_win.object, True) # Refresh control inspector_win.cmds_pg.CollapseAll() inspector_win.cmds_pg.ExpandAll() inspector_win.executed = True
def on_clean_undos(self, evt): """Clean the undo server's buffer""" servers.get_command_server().clean()
def on_change_undo(self, event): mem_mb = self.int_ctrl_undo.GetValue() mem_bytes = format.mb2bytes(mem_mb) servers.get_command_server().setmemorylimit(mem_bytes) set_repository_setting_value(guisettings.ID_UndoMemory, mem_mb)
def restore_undo(): """Restore undo preferences""" undo_memory = get_repository_setting_value('undo memory') servers.get_command_server().setmemorylimit(format.mb2bytes(undo_memory))
def restore_undo(): """Restore undo preferences""" undo_memory = get_repository_setting_value('undo memory') servers.get_command_server().setmemorylimit( format.mb2bytes(undo_memory) )