Advertisement
Guest User

editor4.py

a guest
Jan 31st, 2012
2,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. import wx
  2. import os
  3.  
  4. class Window(wx.Frame):
  5.  
  6.     def __init__(self, parent, title):
  7.         wx.Frame.__init__(self, parent, title = title, size = (300,250))
  8.         self.control = wx.TextCtrl(self, style = wx.TE_MULTILINE)
  9.         self.Show(True)
  10.  
  11.         menu = wx.Menu()
  12.         openItem = menu.Append(wx.ID_OPEN, "Open", "Push the button to open the file")
  13.         aboutItem = menu.Append(wx.ID_ABOUT,"About","Push the button to get an information about this application")
  14.         exitItem = menu.Append(wx.ID_EXIT,"Exit","Push the button to leave this application")
  15.         bar = wx.MenuBar()
  16.         bar.Append(menu,"File")
  17.         self.SetMenuBar(bar)
  18.         self.Bind(wx.EVT_MENU, self.OnOpen, openItem)
  19.         self.Bind(wx.EVT_MENU, self.OnAbout, aboutItem)
  20.         self.Bind(wx.EVT_MENU, self.OnExit, exitItem)
  21.  
  22.     def OnOpen(self, e):
  23.         self.dirname = " "
  24.         openDlg = wx.FileDialog(self, "Choose a file to open", self.dirname, " ", "*.*", wx.OPEN)
  25.         if openDlg.ShowModal() == wx.ID_OK:
  26.                 self.filename = openDlg.GetFilename()
  27.                 self.dirname = openDlg.GetDirectory()
  28.                 f = open(os.path.join(self.dirname,self.filename), "r")
  29.                 self.control.SetValue(f.read())
  30.                 f.close()
  31.                 wnd.SetTitle(self.filename + " - pyNote")
  32.  
  33.     def OnAbout(self, e):
  34.         aboutDlg = wx.MessageDialog(self, "This is a mini editor keeping your text","About pyNote", wx.OK)
  35.         aboutDlg.ShowModal()
  36.        
  37.     def OnExit(self, e):
  38.         self.control.SetValue("Close me, please! :(")
  39.  
  40. app = wx.App()
  41. wnd = Window(None, "pyNote")
  42. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement