]>
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 #----------------------------------------------------------------------------
17 import activegrid
.util
as utillib
20 def CreateDirectoryControl( parent
, fileLabel
, dirLabel
, fileExtension
, startingName
="", startingDirectory
=""):
22 nameControl
= wx
.TextCtrl(parent
, -1, startingName
, size
=(-1,-1))
23 nameLabelText
= wx
.StaticText(parent
, -1, fileLabel
)
24 dirLabelText
= wx
.StaticText(parent
, -1, dirLabel
)
25 dirControl
= wx
.TextCtrl(parent
, -1, startingDirectory
, size
=(-1,-1))
26 dirControl
.SetToolTipString(startingDirectory
)
27 button
= wx
.Button(parent
, -1, _("Browse..."), size
=(60,-1))
29 def OnFindDirClick(event
):
31 nameCtrlValue
= nameControl
.GetValue()
33 root
, ext
= os
.path
.splitext( nameCtrlValue
)
34 if ext
== '.' + fileExtension
:
37 name
= _("%s.%s") % (nameCtrlValue
, fileExtension
)
38 path
= wx
.FileSelector(_("Choose a filename and directory"),
41 wildcard
=_("*.%s") % fileExtension
,
46 dir, filename
= os
.path
.split(path
)
47 dirControl
.SetValue(dir)
48 dirControl
.SetToolTipString(dir)
49 nameControl
.SetValue(filename
)
51 parent
.Bind(wx
.EVT_BUTTON
, OnFindDirClick
, button
)
53 def Validate(allowOverwriteOnPrompt
=False):
54 if nameControl
.GetValue() == "":
55 wx
.MessageBox(_("Please provide a filename."), _("Provide a Filename"))
57 if nameControl
.GetValue().find(' ') != -1:
58 wx
.MessageBox(_("Please provide a filename that does not contains spaces."), _("Spaces in Filename"))
60 if not os
.path
.exists(dirControl
.GetValue()):
61 wx
.MessageBox(_("That directory does not exist. Please choose an existing directory."), _("Provide a Valid Directory"))
64 filePath
= os
.path
.join(dirControl
.GetValue(), MakeNameEndInExtension(nameControl
.GetValue(), "." + fileExtension
))
65 if os
.path
.exists(filePath
):
66 if allowOverwriteOnPrompt
:
67 res
= wx
.MessageBox(_("That file already exists. Would you like to overwrite it."), "File Exists", style
=wx
.YES_NO|wx
.NO_DEFAULT
)
68 return (res
== wx
.YES
)
70 wx
.MessageBox(_("That file already exists. Please choose a different name."), "File Exists")
74 flexGridSizer
= wx
.FlexGridSizer(cols
= 3, vgap
= HALF_SPACE
, hgap
= HALF_SPACE
)
75 flexGridSizer
.AddGrowableCol(1,1)
76 flexGridSizer
.Add(nameLabelText
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT|wx
.TOP|wx
.RIGHT
, HALF_SPACE
)
77 flexGridSizer
.Add(nameControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
)
78 flexGridSizer
.Add(button
, flag
=wx
.ALIGN_RIGHT|wx
.LEFT
, border
=HALF_SPACE
)
80 flexGridSizer
.Add(dirLabelText
, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT|wx
.TOP|wx
.RIGHT
, border
=HALF_SPACE
)
81 flexGridSizer
.Add(dirControl
, 2, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.EXPAND
, border
=HALF_SPACE
)
82 flexGridSizer
.Add(wx
.StaticText(parent
, -1, ""), 0)
83 return nameControl
, dirControl
, flexGridSizer
, Validate
85 def AddFilesToCurrentProject(paths
, save
=False):
86 projectService
= wx
.GetApp().GetService(ProjectEditor
.ProjectService
)
88 projectDocument
= projectService
.GetCurrentProject()
90 files
= projectDocument
.GetFiles()
95 projectDocument
.GetCommandProcessor().Submit(ProjectEditor
.ProjectAddFilesCommand(projectDocument
, paths
))
96 projectDocument
.GetFirstView().DoSelectFiles([paths
[0]])
98 projectDocument
.OnSaveDocument(projectDocument
.GetFilename())
100 def MakeNameEndInExtension(name
, extension
):
103 root
, ext
= os
.path
.splitext(name
)
107 return name
+ extension
110 def PluralName(name
):
113 if name
.endswith('us'):
114 return name
[0:-2] + 'ii'
115 elif name
.endswith('s'):
117 elif name
.endswith('y'):
118 return name
[0:-1] + 'ies'
122 def GetPythonExecPath():
123 pythonExecPath
= wx
.ConfigBase_Get().Read("ActiveGridPythonLocation")
124 if not pythonExecPath
:
125 pythonExecPath
= utillib
.pythonExecPath
126 return pythonExecPath