]>
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 if not os
.path
.exists(dirControl
.GetValue()):
60 wx
.MessageBox(_("That directory does not exist. Please choose an existing directory."), _("Provide a Valid Directory"))
63 filePath
= os
.path
.join(dirControl
.GetValue(), MakeNameEndInExtension(nameControl
.GetValue(), "." + fileExtension
))
64 if os
.path
.exists(filePath
):
65 if allowOverwriteOnPrompt
:
66 res
= wx
.MessageBox(_("That file already exists. Would you like to overwrite it."), "File Exists", style
=wx
.YES_NO|wx
.NO_DEFAULT
)
67 return (res
== wx
.YES
)
69 wx
.MessageBox(_("That file already exists. Please choose a different name."), "File Exists")
73 flexGridSizer
= wx
.FlexGridSizer(cols
= 3, vgap
= HALF_SPACE
, hgap
= HALF_SPACE
)
74 flexGridSizer
.AddGrowableCol(1,1)
75 flexGridSizer
.Add(nameLabelText
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT|wx
.TOP|wx
.RIGHT
, HALF_SPACE
)
76 flexGridSizer
.Add(nameControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
)
77 flexGridSizer
.Add(button
, flag
=wx
.ALIGN_RIGHT|wx
.LEFT
, border
=HALF_SPACE
)
79 flexGridSizer
.Add(dirLabelText
, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT|wx
.TOP|wx
.RIGHT
, border
=HALF_SPACE
)
80 flexGridSizer
.Add(dirControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
, border
=HALF_SPACE
)
81 flexGridSizer
.Add(wx
.StaticText(parent
, -1, ""), 0)
82 return nameControl
, dirControl
, flexGridSizer
, Validate
84 def AddFilesToCurrentProject(paths
, save
=False):
85 projectService
= wx
.GetApp().GetService(ProjectEditor
.ProjectService
)
87 projectDocument
= projectService
.GetCurrentProject()
89 files
= projectDocument
.GetFiles()
94 projectDocument
.GetCommandProcessor().Submit(ProjectEditor
.ProjectAddFilesCommand(projectDocument
, paths
))
95 projectDocument
.GetFirstView().DoSelectFiles([paths
[0]])
97 projectDocument
.OnSaveDocument(projectDocument
.GetFilename())
99 def MakeNameEndInExtension(name
, extension
):
102 root
, ext
= os
.path
.splitext(name
)
106 return name
+ extension
109 def PluralName(name
):
112 if name
.endswith('us'):
113 return name
[0:-2] + 'ii'
114 elif name
.endswith('s'):
116 elif name
.endswith('y'):
117 return name
[0:-1] + 'ies'