def OpenDocument(self): if self.openFileDialog.ShowDialog() != WinForms.DialogResult.OK: return filename = self.openFileDialog.FileName stream = File.OpenRead(filename) buff = System.Array.CreateInstance(System.Byte, 1024) buff.Initialize() data = [] read = 1 while read > 0: read, _ = stream.Read(buff, 0, 1024) temp = Encoding.ASCII.GetString(buff, 0, read) data.append(temp) data = ''.join(data) stream.Close() filename = self.filename = filename.lower() if filename.endswith('.rtf'): self.richTextBox.Rtf = data self.doctype = 2 else: self.richTextBox.Text = data self.doctype = 1 self.Text = 'Python Wordpad - %s' % filename self.richTextBox.Select(0, 0)
def __init__(self, xamlPath): stream = File.OpenRead(xamlPath) try: self.Root = XamlReader.Load(stream) except SystemError, e: print 'Error parsing xaml file: {0}'.format(xamlPath) #print str(e) raise e
def __init__(self): stream = File.OpenRead( "wpfFromXAML2.xaml") #r'D:\git\ipy\ch9_wpf\wpfFromXAML.xaml' #stream = File.OpenRead(r'D:\git\ipy\ch9_wpf\wpfFromXAML2.xaml') #r'D:\git\ipy\ch9_wpf\wpfFromXAML.xaml' # create WPF object from xaml self.Root = XamlReader.Load(stream) self.button = self.Root.FindName('button') self.stackPanel = self.Root.FindName('stackPanel') self.button.Click += self.on_click self.button.Click += self.button_Click
def add_image(self): """Добавляем картинку.""" self.button.LargeImage = BitmapImage() stream = File.OpenRead(self.image) self.button.LargeImage.BeginInit() self.button.LargeImage.CacheOption = BitmapCacheOption.OnLoad self.button.LargeImage.StreamSource = stream self.button.LargeImage.DecodePixelHeight = 32 self.button.LargeImage.DecodePixelWidth = 32 self.button.LargeImage.EndInit() self.button.LargeImage.Freeze() stream.Close() stream.Dispose() stream = File.OpenRead(self.image) self.button.Image = BitmapImage() self.button.Image.BeginInit() self.button.Image.CacheOption = BitmapCacheOption.OnLoad self.button.Image.StreamSource = stream self.button.Image.DecodePixelHeight = 16 self.button.Image.DecodePixelWidth = 16 self.button.Image.EndInit() self.button.LargeImage.Freeze() stream.Close() stream.Dispose()
def __read(self): try: filestream = File.OpenRead(self.file_location) xml = XmlReader.Create(filestream) if self.progress: self.progress.filestream = filestream except IOError as e: raise e else: if xml.IsStartElement('osm'): self.__readOsmEntities(xml) else: print('Osm file is not valid. No <osm> element found.\n') finally: if File.Exists(self.file_location): xml.Close() filestream.Close()
def __init__(self): stream = File.OpenRead(fileName) self.Root = XamlReader.Load(stream) self.button = self.Root.FindName('button') self.stackPanel = self.Root.FindName('stackPanel') self.button.Click += self.onClick