def Version2(data): from framework.project import ProjectView from framework.dialogs import Notify, SelectFiles, Choice projectdata = data.get('projectdata') if projectdata: Notify( _('Project data found in configuration. Please save it as project file.' )) del data['projectdata'] while True: path = SelectFiles(tm.main.save_project_as, save=True, wildcard=ProjectView.msg_wildcard) if path: try: with open(path, 'w') as f: json.dump(dict(data=projectdata), f, 'utf-8', ensure_ascii=False) data['projectfile'] = path break except: if not Choice( tm.main.config_convert_project_file_failed): break else: if Choice(tm.main.config_abort_project_convert): break
def Redo(self): self.uri_list = [self.uri] if self.g.grIsTemplate(self.uri): specs = self.g.grTemplateGetSpecializations(self.uri) if specs: if not Choice(tm.main.template_with_spec_delete_query): return False self.uri_list += specs objs = set() subj = set() self.triples = [] for uri in self.uri_list: triples = self.g.grCollectEntityTriples(uri) self.triples += triples for a in triples: a.deletefrom(self.g) subj.add(a.s) if a.has_object: objs.add(a.o) if not self.triples: return False for o in objs: wizard.W_EntityRelationshipsChanged(self.g, o) for s in subj: if not self.g.grTriplesForSubj(s): wizard.W_EntityDestroyed(self.g, s) return True
def OnPrepare(self): if Choice(tm.main.tests_prepare_warning): for k in self.tests_list.CheckedStrings: self.report.AppendText(tm.main.tests_preparing.format(k)) locals = {'mode': 'prepare'} ec = EnvironmentContext(None, locals) ec.ExecutePythonFile(os.path.join(self.tests_dir, k + '.py')) self.report.AppendText(tm.main.tests_preparing_done)
def TryApply(self): appdata.app.RemoveEventFilter(self.AppEventFilter) if not self.IsValid(): if not Choice(tm.main.prop_dict_invalid_promt): appdata.topwindow.propsdock.activateWindow() self.setFocus() appdata.app.AddEventFilter(self.AppEventFilter) return False self.Reset() self.Apply() return True
def CloseProject(self, exit=False): changed_data = [] if self.changed: text = tm.main.current_project if self.projectfile: projname, ext = os.path.splitext( os.path.basename(self.projectfile)) text += ' ' + projname changed_data.append(text) changed_data += [ doc.name for doc in appdata.documents if doc.doc_state == doc.state_changed ] if changed_data: if exit: if not Choice( tm.main.unsaved_data_exit.format( '\n'.join(changed_data))): return False else: if not Choice( tm.main.unsaved_data_close.format( '\n'.join(changed_data))): return False self.closing = True self.DeleteAutosave() if self.projectfile: self.UpdateRecentProjects() self.projectfile = None self.root.DestroyChildren(True) self.closing = False return True
def LoadProjectFromFile(self, filename): autosavefile = None if filename: fdir, fname = os.path.split(filename) if os.path.exists(os.path.join(fdir, '.$' + fname)): if Choice(tm.main.project_autosave_found): autosavefile = os.path.join(fdir, '.$' + fname) else: os.remove(os.path.join(fdir, '.$' + fname)) if not autosavefile and not os.path.exists(filename): Notify(tm.main.project_not_found.format(filename)) self.projectfile = None else: self.projectfile = filename else: if os.path.exists(self.autosave_file): if Choice(tm.main.project_autosave_found): autosavefile = self.autosave_file else: os.remove(self.autosave_file) if not autosavefile: self.NewProject() return autosavefailed = False projectfailed = False if autosavefile: try: with open(autosavefile, 'r') as f: projectdata = json.load(f, 'utf-8', object_hook=DictDecoder()) ProjectVersionConverter.Check(projectdata) self.LoadProject(projectdata) self.autosavedata = projectdata except: log.exception() autosavefailed = True if self.projectfile: try: with open(self.projectfile, 'r') as f: projectdata = json.load(f, 'utf-8', object_hook=DictDecoder()) ProjectVersionConverter.Check(projectdata) if not autosavefile or autosavefailed: self.LoadProject(projectdata) self.projectdata = projectdata except: log.exception() projectfailed = True if autosavefailed: if projectfailed: Notify(tm.main.project_autosave_failed) self.projectfile = None else: Notify('%s\n%s' % (tm.main.project_autosave_failed, tm.main.project_autosave_skipped)) elif projectfailed: Notify(tm.main.project_load_failed) self.projectfile = None if appconfig.get('projectfile') != self.projectfile: appconfig['projectfile'] = self.projectfile appconfig.SaveSettings() self.RefreshProps() self.UpdateProject()
def IsDestroyAllowed(self): if self.doc and self.doc.doc_owner is self and self.doc.doc_state == self.doc.state_changed: if not Choice(tm.main.unsaved_documents.format(self.doc.name)): return False return True