def includeFile(self): self.mainFrame.txtContent.SetFocus() dialog = wx.FileDialog(parent = self.mainFrame, message = "Include File", defaultDir = self.last_path, style = wx.OPEN | wx.FD_FILE_MUST_EXIST, wildcard = ULIEDIT_FILE_FILTER) if dialog.ShowModal() == wx.ID_OK: self.last_path = dialog.GetPath() filename = dialog.GetPath() self.last_path = os.path.dirname(self.last_path) content = self.file_manager.getContentFromFile(filename) encoding = uliedit_charset_helper.detect_encoding(filename) if encoding: content = content.decode(encoding) tmp = self.file_manager.getFileAtIndex(self.current_file_index) line_seperator = tmp["line_seperator"] self.mainFrame.txtContent.AddText(content) self.mainFrame.txtContent.ConvertEOLs(line_seperator) self.mainFrame.txtContent.SetFocus() self.updateStatusBar() return True else: wx.MessageDialog(None, u"Kann das Encoding nicht erkennen!", os.path.basename(filename), wx.OK | wx.ICON_WARNING).ShowModal() return False
def openFile(self, filename, readonly): filename = os.path.abspath(filename) encoding = uliedit_charset_helper.detect_encoding(filename) if encoding: """ wx.MessageDialog(None, encoding, "Encoding of " + os.path.basename(filename), wx.OK | wx.ICON_INFORMATION).ShowModal() """ if self.file_manager.isOpen(filename): wx.MessageDialog(None, u"This file is already open.", os.path.basename(filename), wx.OK | wx.ICON_WARNING, wildcard = ULIEDIT_FILE_FILTER).ShowModal() return False else: tmp = self.file_manager.addFile(filename, encoding, readonly) line_seperator = self.file_manager.getFileAtIndex(tmp)["line_seperator"] self.mainFrame.txtContent.SetEOLMode(line_seperator) self.mainFrame.txtContent.ConvertEOLs(line_seperator) self.setTitle(os.path.basename(filename), self.file_manager.getFileAtIndex(tmp)["readonly"] ) if tmp != None: self.current_file_index = copy.copy(tmp) content = self.file_manager.getContentByIndex(self.current_file_index) self.mainFrame.cbOpenFiles.Append(filename) self.mainFrame.cbOpenFiles.SetStringSelection(filename) try: self.mainFrame.txtContent.SetValue(content) except AttributeError: self.mainFrame.txtContent.SetReadOnly(False) self.mainFrame.txtContent.ClearAll() self.mainFrame.txtContent.SetText(content) self.mainFrame.txtContent.ConvertEOLs(self.file_manager.getFileAtIndex(tmp)["line_seperator"]) self.mainFrame.txtContent.SetEOLMode(self.file_manager.getFileAtIndex(tmp)["line_seperator"]) self.mainFrame.txtContent.EmptyUndoBuffer() self.mainFrame.txtContent.SetReadOnly(readonly) self.mainFrame.txtContent.SetFocus() self.file_manager.getFileAtIndex(tmp)["modified"] = False self.updateStatusBar() return True else: wx.MessageDialog(None, u"Kann das Encoding nicht erkennen!", os.path.basename(filename), wx.OK | wx.ICON_WARNING).ShowModal() return False