文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Common Dialogs

Common Dialogs

时间:2007-04-12  来源:wxPhoenix

  import wx
import wx.lib.wordwrap as wordwrap
import os
    class Frame(wx.Frame):
 def __init__(
  self, parent, id=-1, title='Common Dialogs', pos=wx.DefaultPosition,
  size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
  ):
  
  wx.Frame.__init__(self, parent, id, title, pos, size, style)
  
  Panel = wx.Panel(self, -1)
  MenuBar = wx.MenuBar()
  
  FileMenu = wx.Menu()
  MenuItem = FileMenu.Append(-1, 'Exit')
  self.Bind(wx.EVT_MENU, self.OnExit, MenuItem)
  MenuBar.Append(FileMenu, '&File')
  
  TestMenu = wx.Menu()
  MenuItem = TestMenu.Append(-1, 'AboutBox')
  self.Bind(wx.EVT_MENU, self.OnAboutBox, MenuItem)
  MenuItem = TestMenu.Append(-1, 'ColourDialog')
  self.Bind(wx.EVT_MENU, self.OnColourDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'DirDialog')
  self.Bind(wx.EVT_MENU, self.OnDirDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'FileDialog')
  self.Bind(wx.EVT_MENU, self.OnFileDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'FindReplaceDialog')
  self.Bind(wx.EVT_MENU, self.OnFindReplaceDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'FontDialog')
  self.Bind(wx.EVT_MENU, self.OnFontDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'MessageDialog')
  self.Bind(wx.EVT_MENU, self.OnMessageDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'MultiChoiceDialog')
  self.Bind(wx.EVT_MENU, self.OnMultiChoiceDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'PageSetupDialog')
  self.Bind(wx.EVT_MENU, self.OnPageSetupDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'PrintDialog')
  self.Bind(wx.EVT_MENU, self.OnPrintDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'ProgressDialog')
  self.Bind(wx.EVT_MENU, self.OnProgressDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'SingleChoiceDialog')
  self.Bind(wx.EVT_MENU, self.OnSingleChoiceDialog, MenuItem)
  MenuItem = TestMenu.Append(-1, 'TextEntryDialog')
  self.Bind(wx.EVT_MENU, self.OnTextEntryDialog, MenuItem)
  
  MenuBar.Append(TestMenu, '&Test')
  self.SetMenuBar(MenuBar)
  
  
 def OnExit(self, event):
  self.Close()
  
 def OnAboutBox(self, event):
  AboutInfo = wx.AboutDialogInfo()
  AboutInfo.Name = 'Common Dialogs'
  AboutInfo.Version = '2.8.0.1'
  AboutInfo.Copyright = '(C) 2007 Coders Everywhere'
  AboutInfo.Description = wordwrap.wordwrap(
   'This is demo of wxPython\'s Common Dialogs which I entitled '
   'ShowBox. You can apply them in the pratical development to '
   'move quickly.\n\n'
    'You can select Test-Menu to try Boxitem what ShowBox includes.',
    350, wx.ClientDC(self))
  AboutInfo.WebSite = ('http://www.wxpython.org', 'wxPython Home Page')
  AboutInfo.License = wordwrap.wordwrap('cool huh?  '*6, 500, wx.ClientDC(self))
  AboutInfo.Developers = ['Shaka LCF', 'wxPhoenix']
  AboutInfo.DocWriters = ['XiaoJun', 'AXiang', 'LaoGu']
  AboutInfo.Artists = ['XueGe', 'SinSin', 'XiaoYi', 'LaoKong']
  
  wx.AboutBox(AboutInfo)
  
  
 def OnColourDialog(self, event):
  ColorDlg = wx.ColourDialog(self)
  if ColorDlg.ShowModal() == wx.ID_OK:
   ColorData = ColorDlg.GetColourData()
   wx.MessageBox('Colour Tuple: %s' % str(ColorData.GetColour().Get()), 'Prompt')
  
  
 def OnDirDialog(self, event):
  DirDialog = wx.DirDialog(parent=self,
         message='Select a directory',
         defaultPath=os.getcwd(),
         style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)
        
  if DirDialog.ShowModal() == wx.ID_OK:
   wx.MessageBox('You selected: %s' % DirDialog.GetPath(), 'Prompt')
  
  
 def OnFileDialog(self, event):
  FileDialog = wx.FileDialog(parent=self,
           message='Choose a file',
           defaultDir=os.getcwd(),
           defaultFile='',
           wildcard='Python source(*.py)|*.py',
           style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
           )
  
  if FileDialog.ShowModal() == wx.ID_OK:
   PathList = FileDialog.GetPaths()
   Paths = ''
   for Path in PathList:
    Paths += Path + '\n'
   wx.MessageBox('You selected %d files:\n\n%s' % (len(PathList), Paths), 'Prompt')
             
     
 def OnFindReplaceDialog(self, event):
  pass
  
  
 def OnFontDialog(self, event):
  pass
  
  
 def OnMessageDialog(self, event):
  MessageDialog = wx.MessageDialog(self,
           'This is demo of Common Dialogs',
           'Prompt',
           wx.OK | wx.ICON_INFORMATION
           # wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
           )
          
  MessageDialog = MessageDialog.ShowModal()
  
  
 def OnMultiChoiceDialog(self, event):
  Languages = ['C', 'C++', 'Python', 'Java', 'C#', 'Perl', 'Ruby', 'PHP', 'JavaScript']
  MultiChoiceDialog = wx.MultiChoiceDialog(self,
             'Choose you favourite language(s)',
             'Popular Languages:',
             Languages)
            
  if MultiChoiceDialog.ShowModal() == wx.ID_OK:
   Indexs = MultiChoiceDialog.GetSelections()
   Choices = [Languages[index] for index in Indexs ]
   wx.MessageBox('Your favourite language(s):\n\n%s' % '\n'.join(Choices), 'Prompt')
 
  
 def OnPageSetupDialog(self, event):
  pass
  
  
 def OnPrintDialog(self, event):
  pass
  
  
 def OnProgressDialog(self, event):
  Max = 100
  ProgressDialog = wx.ProgressDialog(title='Execute Progress',
             message='Waiting...',
             maximum=Max,
             parent=self,
             style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL |
             wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME
             )
            
  Continue, Count= True, 0
  while Continue and Count < Max:
   Count += 1
   wx.MilliSleep(200)
   
   if Count >= Max / 2:
    Continue, Skip = ProgressDialog.Update(Count, 'Half-Time! A moment left!')
   else:
    Continue, Skip = ProgressDialog.Update(Count)
 
 
 def OnSingleChoiceDialog(self, event):
  SingleChoiceDialog = wx.SingleChoiceDialog(
        self, 'Languages', 'Choose you favourite language',
        ['C/C++', 'Python', 'Java', 'C#', 'Perl', 'PHP'],
        wx.CHOICEDLG_STYLE)
        
  if SingleChoiceDialog.ShowModal() == wx.ID_OK:
   wx.MessageBox('Your favourite language is %s' % SingleChoiceDialog.GetStringSelection(), 'Prompt')
  
  
 def OnTextEntryDialog(self, event):
  TextEntryDialog = wx.TextEntryDialog(parent=self,
            message='What is your favourite programming language?',
            caption='Enter some text',
            defaultValue='Python')
           
  if TextEntryDialog.ShowModal() == wx.ID_OK:
   wx.MessageBox('You enter: %s' % TextEntryDialog.GetValue(), 'Prompt')
  
  
def TestFrame():
 app = wx.PySimpleApp()
 frame = Frame(parent=None)
 frame.Centre()
 frame.Show()
 app.MainLoop()
 
if __name__ == '__main__':
 TestFrame()
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载