def OnReturnTreeview(self, event=None): item = self.tree.focus() if self.tree.item(item, "text") == '': return elif self.tree.item(item, "text").startswith('>'): root = os.getcwd() sub = self.tree.item(item, "text").split()[1] dir = root + sub dir = self.checkPath(dir) try: os.chdir(dir) except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') self.selected = None self.refreshTree() self.parent.title(dir) elif '/' in self.tree.item(item, "text") or '\\' in self.tree.item( item, "text"): os.chdir('..') dir = self.checkPath(os.getcwd()) self.parent.title(dir) self.refreshTree() return 'break' else: file = self.tree.item(item, "text") dir = os.getcwd() dir = self.checkPath(dir) filename = dir + '/' + file self.tree.config(cursor="X_cursor") self.tree.bind('<Double-1>', self.ignore) try: self.notebookFrame.new() self.notebookFrame.open(filename) except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') filename = self.notebookFrame.textPad.filename = None self.notebookFrame.tabChanged() self.notebookFrame.textPad.focus() self.tree.config(cursor='') self.tree.update() self.parent.title(filename) # workaround # step 2 self.refreshTree() self.tree.update() self.tree.after(500, self.bindit) self.refreshTree()
def deleteFile(self): rootDir = self.checkPath(os.getcwd()) directory = None file = None size = None if self.selected: for idx in self.selected: try: text = self.tree.item(idx)['text'] except: self.selected = [] return if '/' in text or '\\' in text: directory = True else: file = True if file == True: filename = rootDir + '/' + text else: # directory if text.startswith('>'): dir = text.split()[-1] filename = rootDir + dir elif '/' in text or '\\' in text: filename = text else: return filename = self.checkPath(filename) dialog = MessageYesNoDialog(self, 'Delete', '\n\tDelete\n\n' + filename + ' ?\n\n') result = dialog.result if result == 1: if directory: try: shutil.rmtree(filename) self.refreshTree() except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') elif file: try: os.remove(filename) self.refreshTree() except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') self.parent.title('Done !')
def refresh_preferences(self): if MessageDialog( "BORIS", "Refresh will re-initialize all your preferences and close BORIS", [CANCEL, "Refresh preferences"]) == "Refresh preferences": self.flag_refresh = True self.accept()
def printer(self, event=None): # print file to html if not self.textPad: return if not self.textPad.filename: return text = self.textPad.get("1.0",'end-1c') filename = self.textPad.filename.split('/')[-1] kwList = keyword.kwlist output = "<head>" + filename + "</head>\n" output += "<body>\n" output += '<pre><code>\n' output += text + '\n' output += '</pre></code>\n' output += "</body>" fname = self.textPad.filename + "_.html" with open(fname, "w") as f: f.write(output) try: webbrowser.open(fname) except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') return self.filebrowserFrame.refreshTree()
def saveAs(self, event=None): dialog = SaveFileDialog(self, "Save as") filename = dialog.filename if not filename: return try: with open(filename, 'w') as f: text = self.textPad.get("1.0",'end-1c') f.write(text) except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') # update textPad self.textPad.filename = filename # update tab text file = self.textPad.filename.split('/')[-1] id = self.notebook.index(self.notebook.select()) self.notebook.tab(id, text=file) # generate tabChanged event (get new textPad, etc) self.tabChanged() self.filebrowserFrame.refreshTree()
def open(self, filename=None, event=None): if not filename: filename = filedialog.askopenfilename() if not filename: return try: # open file for reading with open(filename, 'r') as f: text = f.read() # update textPad self.textPad.delete('1.0', tk.END) self.textPad.insert("1.0", text) self.textPad.filename = filename self.textPad.tag_all_lines() except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') return # update tab text file = self.textPad.filename.split('/')[-1] id = self.notebook.index(self.notebook.select()) self.notebook.tab(id, text=file) # generate tabChanged event (get new textPad, etc) self.tabChanged() # update autocompleteList from codeeditor self.textPad.updateAutoCompleteList() self.filebrowserFrame.refreshTree()
def refresh_preferences(self): """ allow user to delete the config file (.boris) """ if MessageDialog( "BORIS", ("Refresh will re-initialize " "all your preferences and close BORIS"), [CANCEL, "Refresh preferences"]) == "Refresh preferences": self.flag_refresh = True self.accept()
def terminal(self, event=None): c = Configuration() # -> in configuration.py system = c.getSystem() terminalCommand = c.getTerminal(system) try: subprocess.call(terminalCommand, shell=True) except Exception as e: dialog = MessageDialog(self, 'Error', '\n' + str(e) + '\n') return
def pasteFile(self): if not self.sourceItem: self.parent.title('<No Selection>') return if not self.selected: currentDirectory = self.checkPath(os.getcwd()) self.destinationItem = currentDirectory if self.selected: try: for idx in self.selected: text = self.tree.item(idx)['text'] except Exception as e: #print('this') MessageDialog(self, 'Error', '\n' + str(e) + '\n') return currentDirectory = self.checkPath(os.getcwd()) if text.startswith('>'): dir = text.split()[1] self.destinationItem = currentDirectory + dir elif '/' in text or '\\' in text: self.destinationItem = currentDirectory else: self.destinationItem = currentDirectory + '/' + text #print('self.sourceItem:', self.sourceItem) #print('self.destinationItem:', self.destinationItem) if os.path.isfile(self.sourceItem): # Source == file if os.path.isdir(self.destinationItem): # Destination == directory destination = self.destinationItem try: shutil.copy2(self.sourceItem, destination) self.refreshTree() except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') return elif os.path.isfile(self.destinationItem): # Destination == file destination = os.path.dirname(self.destinationItem) try: shutil.copy2(self.sourceItem, destination) self.refreshTree() except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') return elif os.path.isdir(self.sourceItem): # Source == directory if os.path.isdir(self.destinationItem): # Destination == directory destination = self.destinationItem + '/' basename = self.sourceItem.split('/')[-1] destination = destination + basename destination = self.checkPath(destination) #print('destination:', destination) try: shutil.copytree(self.sourceItem, destination) self.refreshTree() except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') return elif os.path.isfile(self.destinationItem): # Destination == file destination = os.path.dirname(self.destinationItem) + '/' destination = self.checkPath(destination) basename = self.sourceItem.split('/')[-1] destination = destination + basename #print('destination:', destination) try: shutil.copytree(self.sourceItem, destination) self.refreshTree() except Exception as e: MessageDialog(self, 'Error', '\n' + str(e) + '\n') return self.selected = None self.sourceItem = None self.parent.title('Done !')