def OnFileRemove(self, event): """Removes a file from the current project.""" item = self.GetSelection() if item != self.root and self.GetItemText(item) not in files_categories.values(): self.Delete(item) self._project.delete_element(self.GetItemData(item).GetData()) project.save_project(self._project, self._project_dir)
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 OnTreeItemActivated(self, event, item=None): """Tree item was activated: try to open this file.""" if event: item = event.GetItem() if item != self.root and self.GetItemText(item) not in files_categories.values(): # load the current selected file # self.SetItemBold(item, 1) element = self.GetItemData(item).GetData() for i in range(self.nb.GetPageCount()): if element == self.nb.GetPage(i).element: self.nb.SetSelection(i) return if isinstance(element, fca.Scale): new_page = contextgrid.ContextGrid(self.nb) new_page.Show(False) new_page.SetTable(contextgrid.ContextTable(element)) self.nb.AddPage(new_page, element.name) self.nb.SetSelection(self.nb.GetPageIndex(new_page)) self._project.projectdirty = True elif isinstance(element, fca.Context): new_page = contextgrid.ContextGrid(self.nb) new_page.Show(False) new_page.SetTable(contextgrid.ContextTable(element)) self.nb.AddPage(new_page, element.name) self.nb.SetSelection(self.nb.GetPageIndex(new_page)) self._project.projectdirty = True elif isinstance(element, fca.ManyValuedContext): new_page = contextgrid.MVContextGrid(self.nb) new_page.Show(False) new_page.SetTable(contextgrid.MVContextTable(element)) self.nb.AddPage(new_page, element.name) self.nb.SetSelection(self.nb.GetPageIndex(new_page)) self._project.projectdirty = True elif isinstance(element, fca.ConceptSystem): new_page = conceptsystemgrid.ConceptSystemGrid(self.nb) new_page.Show(False) new_page.SetTable(conceptsystemgrid.ConceptSystemTable(element)) self.nb.AddPage(new_page, element.name) self.nb.SetSelection(self.nb.GetPageIndex(new_page)) self._project.projectdirty = True else: pass