]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/tool/UICommon.py
   1 #---------------------------------------------------------------------------- 
   3 # Purpose:      Shared UI stuff 
   9 # Copyright:    (c) 2005 ActiveGrid, Inc. 
  10 # License:      wxWindows License 
  11 #---------------------------------------------------------------------------- 
  19 def CreateDirectoryControl( parent
, fileLabel
, dirLabel
, fileExtension
, startingName
="", startingDirectory
=""): 
  21     nameControl 
= wx
.TextCtrl(parent
, -1, startingName
, size
=(-1,-1)) 
  22     nameLabelText 
= wx
.StaticText(parent
, -1, fileLabel
) 
  23     dirLabelText 
= wx
.StaticText(parent
, -1, dirLabel
) 
  24     dirControl 
= wx
.TextCtrl(parent
, -1, startingDirectory
, size
=(-1,-1)) 
  25     dirControl
.SetToolTipString(startingDirectory
) 
  26     button 
= wx
.Button(parent
, -1, _("Browse..."), size
=(60,-1)) 
  28     def OnFindDirClick(event
):  
  30         nameCtrlValue 
= nameControl
.GetValue() 
  32             root
, ext 
= os
.path
.splitext( nameCtrlValue 
) 
  33             if ext 
== '.' + fileExtension
: 
  36                 name 
= _("%s.%s") % (nameCtrlValue
, fileExtension
) 
  37         path 
= wx
.FileSelector(_("Choose a filename and directory"), 
  40                        wildcard
=_("*.%s") % fileExtension 
, 
  45             dir, filename 
= os
.path
.split(path
) 
  46             dirControl
.SetValue(dir) 
  47             dirControl
.SetToolTipString(dir) 
  48             nameControl
.SetValue(filename
) 
  50     parent
.Bind(wx
.EVT_BUTTON
, OnFindDirClick
, button
) 
  52     def Validate(allowOverwriteOnPrompt
=False): 
  53         if nameControl
.GetValue() == "": 
  54             wx
.MessageBox(_("Please provide a filename."), _("Provide a Filename"))             
  56         if nameControl
.GetValue().find(' ') != -1: 
  57             wx
.MessageBox(_("Please provide a filename that does not contains spaces."), _("Spaces in Filename"))             
  59         filePath 
= os
.path
.join(dirControl
.GetValue(), MakeNameEndInExtension(nameControl
.GetValue(), "." + fileExtension
)) 
  60         if os
.path
.exists(filePath
): 
  61             if allowOverwriteOnPrompt
: 
  62                 res 
= wx
.MessageBox(_("That file already exists. Would you like to overwrite it."), "File Exists", style
=wx
.YES_NO|wx
.NO_DEFAULT
) 
  63                 return (res 
== wx
.YES
)   
  65                 wx
.MessageBox(_("That file already exists. Please choose a different name."), "File Exists") 
  69     flexGridSizer 
= wx
.FlexGridSizer(cols 
= 3, vgap 
= HALF_SPACE
, hgap 
= HALF_SPACE
) 
  70     flexGridSizer
.AddGrowableCol(1,1) 
  71     flexGridSizer
.Add(nameLabelText
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT|wx
.TOP|wx
.RIGHT
, HALF_SPACE
) 
  72     flexGridSizer
.Add(nameControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
) 
  73     flexGridSizer
.Add(button
, flag
=wx
.ALIGN_RIGHT|wx
.LEFT
, border
=HALF_SPACE
) 
  75     flexGridSizer
.Add(dirLabelText
, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT|wx
.TOP|wx
.RIGHT
, border
=HALF_SPACE
) 
  76     flexGridSizer
.Add(dirControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
, border
=HALF_SPACE
) 
  77     flexGridSizer
.Add(wx
.StaticText(parent
, -1, ""), 0) 
  78     return nameControl
, dirControl
, flexGridSizer
, Validate
 
  80 def AddFilesToCurrentProject(paths
, save
=False): 
  81     projectService 
= wx
.GetApp().GetService(ProjectEditor
.ProjectService
) 
  83         projectDocument 
= projectService
.GetCurrentProject() 
  85             files 
= projectDocument
.GetFiles() 
  90                 projectDocument
.GetCommandProcessor().Submit(ProjectEditor
.ProjectAddFilesCommand(projectDocument
, paths
)) 
  91                 projectDocument
.GetFirstView().DoSelectFiles([paths
[0]]) 
  93                     projectDocument
.OnSaveDocument(projectDocument
.GetFilename()) 
  95 def MakeNameEndInExtension(name
, extension
): 
  98     root
, ext 
= os
.path
.splitext(name
) 
 102         return name 
+ extension
 
 105 def PluralName(name
): 
 108     if name
.endswith('us'): 
 109         return name
[0:-2] + 'ii' 
 110     elif name
.endswith('s'): 
 112     elif name
.endswith('y'): 
 113         return name
[0:-1] + 'ies'