def OnImport(self, event): """Import scale, context or mvcontext to current project""" choices = files_categories.values() dialog = wx.SingleChoiceDialog( self, "Choose a category of the file you trying to import", "Choose a category", choices ) if dialog.ShowModal() == wx.ID_OK: category = dialog.GetStringSelection() wildcard = "*.cxt files (*.cxt)|*.cxt|" "Tab-separated files (*.txt)|*.txt|" "All files (*.*)|*.*" dlg = wx.FileDialog(self, "Choose a file to import.", ".", "", wildcard, wx.OPEN) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() ext = os.path.splitext(path)[1] if category == "Scales" and ext == ".cxt": new_element = fca.Scale(fca.read_cxt(path)) self.current_project.add_element(new_element) self.tree.add_new_element("scales", new_element) elif category == "Contexts": if ext == ".cxt": new_element = fca.read_cxt(path) elif ext == ".txt": new_element = fca.read_txt(path) self.current_project.add_element(new_element) self.tree.add_new_element("contexts", new_element) elif category == "Many-valued contexts": new_element = fca.read_mv_txt(path) self.current_project.add_element(new_element) self.tree.add_new_element("mvcontexts", new_element) elif category == "Concept Systems": new_element = fca.read_xml(path) self.current_project.add_element(new_element) self.tree.add_new_element("concept_systems", new_element) else: MsgDlg(self, "Not supported yet", "Error!", wx.OK) self.project_save()
def GetScaledContext(item, workspace): dialog = ScalingDialog(item, workspace) result = dialog.ShowModal() if result == wx.ID_OK: scales = dialog.GetListOfScales() mvcontext = fca.read_mv_txt(item.path) context = fca.scale_mvcontext(mvcontext, scales) default_path = item.path[:-4] + "-scaled.cxt" newpath = default_path i = 1 while (os.path.exists(newpath)): newpath = default_path[:-4] + "-{0}".format(i) + newpath[-4:] i += 1 fca.uwrite_cxt(context, newpath) newpath = [newpath] else: newpath = [] dialog.Destroy() return newpath