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 GetFilteredConcepts(item): dialog = FilteringDialog() result = dialog.ShowModal() if result == wx.ID_OK: options = dialog.GetOptions() cs = uread_xml(item.path) precessor = item.precessor while not precessor.type == "Context": precessor = precessor.precessor (root, ext) = os.path.splitext(precessor.name) if ext == ".cxt": cxt = fca.read_cxt(precessor.path) elif ext == ".txt": cxt = fca.read_txt(precessor.path) cs.context = cxt new_cs = fca.filter_concepts(cs, options["function"], options["mode"], options["opt"]) default_path = item.path[:-4] + "-filtered.xml" newpath = default_path i = 1 while (os.path.exists(newpath)): newpath = default_path[:-4] + "-{0}".format(i) + newpath[-4:] i += 1 fca.write_xml(newpath, new_cs) newpath = [newpath] else: newpath = [] dialog.Destroy() return newpath
def SaveConcepts(self, item): (root, ext) = os.path.splitext(item.name) if ext == ".cxt": cxt = uread_cxt(item.path) elif ext == ".txt": cxt = fca.read_txt(item.path) cl = fca.ConceptLattice(cxt) number_of_concepts = len(cl) default_path = "".join([item.path[:-3], "xml"]) newpath = default_path i = 1 while (os.path.exists(newpath)): newpath = default_path[:-4] + "-{0}".format(i) + newpath[-4:] i += 1 fca.write_xml(newpath, cl) dlg = wx.MessageDialog(None, str(number_of_concepts) +\ " concepts have been stored in " + newpath, "Done", wx.OK | wx.ICON_INFORMATION ) dlg.ShowModal() dlg.Destroy() return [newpath]
def __init__(self, item, model): self._item = item path = item.path self._model = model wx.grid.PyGridTableBase.__init__(self) (head, ext) = os.path.splitext(path) if ext == ".cxt": context = uread_cxt(path) elif ext == ".txt": context = fca.read_txt(path) self.path = path self.context = context