def read_cache(self): """Read the user cache from persistent storage. Returns False if there was no cache to read.""" try: f = open(self._cache_file, 'r') try: if confirm(None, "It was not possible to connect to the " "permissions server. Instead you can use the settings " "used when you last logged in from this system. If " "you do this then any changes made to settings " "normally held on the permissions server will be lost " "when you next login successfully.\n\nDo you want to " "use the saved settings?") != YES: raise Exception("") try: self.cache = pickle.load(f) except: raise Exception("Unable to read %s." % self._cache_file) finally: f.close() except IOError, e: if e.errno == errno.ENOENT: # There is no cache file. return False raise Exception("Unable to open %s: %s." % (self._cache_file, e))
def _on_exit(self): parent = self.control if confirm(parent, 'exit?') == YES: self.close() return
def close(self, info, isok): # Return True to indicate that it is OK to close the window. if not info.object.saved: response = confirm(info.ui.control, "Value is not saved. Are you sure you want to exit?") return response == YES else: return True
def _editor_closing_changed_for_window(self, editor): """ Handle the editor being closed. """ if (editor is self) and self.dirty: retval = confirm(self.window.control, title="Save Resource", message="'%s' has been modified. Save changes?" % self.name[1:]) if retval == YES: self.save()
def new_model(self, info): """ Handles the new Graph action. """ if info.initialized: retval = confirm(parent = info.ui.control, message = "Replace existing graph?", title = "New Graph", default = YES) if retval == YES: self.model = Graph()
def on_exit(self, info): """ Handles the user attempting to exit Godot. """ if self.prompt_on_exit:# and (not is_ok): retval = confirm(parent = info.ui.control, message = "Exit Godot?", title = "Confirm exit", default = YES) if retval == YES: self._on_close( info ) else: self._on_close( info )
def _on_exit(self): """ Called when the exit action is invoked. """ parent = self.control information(parent, 'Going...') warning(parent, 'Going......') error(parent, 'Gone!') if confirm(parent, 'Should I exit?') == YES: self.close() return
def _delete_clicked(self, info): """Invoked by the "Delete" button.""" role = self._validate(info) if role is None: return if confirm(None, "Are you sure you want to delete the role \"%s\"?" % role.name) == YES: # Delete the data from the database. try: get_permissions_manager().policy_manager.policy_storage.delete_role(role.name) info.ui.dispose() except PolicyStorageError, e: self._ps_error(e)
def reset_run( self, ui_info = None ): '''Save the model into associated pickle file. The source DAT file is unaffected. ''' answer = confirm( self._ui_info.ui.control, 'Really reset? Changes will be lost!', title = 'Reset confirmation', cancel = False, default = YES ) if answer == YES: # ask whether the modified run should be saved # self.load_run( ui_info ) self.redraw() self.model.unsaved = False
def close(self, info, is_ok): """If user is trying to close the main window, look at whether an experiment is currently running. If so, pop a dialog to ask whether it's really OK to close the thing. """ #workbench = info.ui.context['object'] workbench = info.object if workbench.curworker is not None: msg = "An experiment is currently running.\n" \ "Do you really want to interrupt it and\n" \ "close the workbench window?" parent = info.ui.control return confirm(parent, msg) == YES else: return True
def delete_user(self): """Delete a user.""" # Get the data from the user. vuac = _ViewUserAccount(user_db=self) view = _DeleteUserAccountView() handler = _UserAccountHandler() if vuac.edit_traits(view=view, handler=handler).result: # Make absolutely sure. name = vuac.name.strip() if confirm(None, "Are you sure you want to delete the user \"%s\"?" % name) == YES: # Delete the data from the database. try: self.user_storage.delete_user(name) except UserStorageError, e: self._us_error(e)
def delete_user(self): """Delete a user.""" # Get the data from the user. vuac = _ViewUserAccount(user_db=self) view = _DeleteUserAccountView() handler = _UserAccountHandler() if vuac.edit_traits(view=view, handler=handler).result: # Make absolutely sure. name = vuac.name.strip() if confirm( None, "Are you sure you want to delete the user \"%s\"?" % name) == YES: # Delete the data from the database. try: self.user_storage.delete_user(name) except UserStorageError, e: self._us_error(e)
def _reset_model( self, obj, name, old, new ): print 'RESET MODEL' model = self.model if model: # check if the model was changed and ask if it is to be saved # if model.unsaved: answer = confirm( self._ui_info.ui.control, 'Run changed, save it?', title = 'Save confirmation', cancel = False, default = YES ) if answer == YES: # ask whether the modified run should be saved # self.save_run() self.model.unsaved = False self.load_run() self._reset_plot_template_list() self.redraw()
def perform(self, event): """ Perform the action. """ selection = self.window.selection[0] retval = confirm( self.window.control, title="Delete Resources", message="Are you sure you want to delete '%s' from\n" "the file system" % (selection.name+selection.ext) ) if retval == YES: selection.delete() # Close any editors of the deleted resource for editor in self.window.editors[:]: if editor.obj is selection: self.window.close_editor(editor) # Refresh the workspace tree view view = self.window.get_view_by_id(RESOURCE_VIEW) if view is not None: from puddle.resource.i_workspace import IWorkspace workspace = self.window.application.get_service(IWorkspace) # Refresh the parent directory and not the whole tree view.tree_viewer.refresh(workspace)
def activate_function_call(func_def): """ Given a function and its path (optionally), open a function-call. If the function is a user-defined/edited/saved function then make it editable. If the user edits the code of the user-function, overwrite the function and prompt the user to add the function. If the user does not edit the code of the function, just add it as other functions would be added. Parameters: ----------- func_def: FunctionDefinition Contains the function, and its python path. Returns: -------- edited_function: function_object The function that is edited. activated_function: function_object The function that must be activated. python_string: List[Str] includes import and function call to be added to a script. """ if func_def.code is None: msg = "Perhaps your python path is not set correctly or\n" \ "there is an error in the file (or one it imports).\n" error(None, msg, "Error loading function") return None # If it is a user-defined function, one would want to edit it # else it can remain un-editable. path_dir = os.path.dirname(func_def.filename) usr_path = os.path.join(ETSConfig.user_data, USER_MODULE_NAME) if path_dir == usr_path: # This is a user function # We no longer edit the function before dropping it on the canvas #is_ok = edit_user_function(func_def) # Note: If the user edits the code, one should save the # code and ask the user if (s)he wants to continue # adding the function to the block. # If the user does not edit the code, it should be # the same as it is for a regular function, that is, # the user automatically adds the code to the block. if func_def.dirty: func_def.write(overwrite = True) # Ask for confirmation if the user has to add it to # block now or quit without adding. msg= 'The user function \'%s' % func_def.name+ \ '\' has been edited and overwritten at \n' + \ '%s \n\n'% func_def.filename + \ 'Do you wish to add the function to the block?' if confirm(None, msg) == YES: return func_def else: return None else: return func_def else: # This is a sys function which we are trying to override as a new user func # We no longer edit the function before dropping it on the canvas #is_ok = edit_sys_function(func_def) if func_def.dirty: func_def.write(overwrite = False) # Ask for confirmation if the user has to add it to # block now or quit without adding. msg= 'The user function \'%s' % func_def.name+ \ '\' has been written at \n' + \ '%s \n\n'% func_def.filename + \ 'Do you wish to add the function to the block?' if confirm(None, msg) == YES: return func_def else: return None else: return func_def return None