#!/usr/bin/python2.2
#^--- change the above line to point to your installation of Python
# $Id: //guest/mitch_stuart/perforce/utils/delta/p4DirSpecQualDialog.py#2 $
import string
from wxPython.wx import *
from wxPython.lib.rcsizer import RowColSizer
import p4Util
import pyUtil
import wxUtil
DATE_SPEC_MAXCHARS = len("YYYY/MM/DD:hh:mm:ss")
class p4DirSpecQualDialog(wxDialog):
def __init__(self, dirPath, parent, id, title="Select Qualifier for Dirspec",
pos=wxDefaultPosition, size=wxSize(300, 300),
style=wxDEFAULT_DIALOG_STYLE):
wxDialog.__init__(self, parent, id, title, pos, size, style)
self.labelsLoaded = False
self.labelsLoadedPath = ""
self.dirPath = dirPath
self.radioTypeLabel = wxRadioButton(self, -1, "Label", style=wxRB_GROUP)
self.comboLabel = LabelComboBox(self, -1,
style=wxCB_DROPDOWN | wxCB_READONLY,
size=(self.GetCharWidth() * 40, -1))
self.radioTypeDate = wxRadioButton(self, -1, "Date")
self.textDate = wxTextCtrl(self, -1,
size=wxSize(self.GetCharWidth() * DATE_SPEC_MAXCHARS, -1))
self.textDate.SetMaxLength(DATE_SPEC_MAXCHARS)
self.radioTypeHead = wxRadioButton(self, -1, "Head")
self.radioTypeHave = wxRadioButton(self, -1, "Have")
self.typeRadios = [self.radioTypeLabel, self.radioTypeDate,
self.radioTypeHead, self.radioTypeHave]
self.okButton = wxButton(self, wxID_OK, " OK ")
self.okButton.SetDefault()
self.cancelButton = wxButton(self, wxID_CANCEL, " Cancel ")
sizer = RowColSizer()
row = 0
row += 1
sizer.Add(wxStaticText(self, -1, "Dirspec: "), pos=(row, 1))
sizer.AddSpacer(4, -1, pos=(row, 2))
sizer.Add(wxStaticText(self, -1, self.dirPath), pos=(row, 3))
sizer.AddSpacer(10, -1, pos=(row, 4))
row += 1
sizer.Add(self.radioTypeLabel, pos=(row, 1))
sizer.Add(self.comboLabel, pos=(row, 3), flag=wxBOTTOM, border=8)
row += 1
sizer.Add(self.radioTypeDate, pos=(row, 1))
sizer.Add(self.textDate, pos=(row, 3))
row += 1
sizer.Add(wxStaticText(self, -1, "(YYYY/MM/DD or YYYY/MM/DD:hh:mm:ss)"),
pos=(row, 3))
row += 1
sizer.Add(self.radioTypeHead, pos=(row, 1))
sizer.Add(wxStaticText(self, -1, "(latest version in depot)"),
pos=(row, 3))
row += 1
sizer.Add(self.radioTypeHave, pos=(row, 1))
sizer.Add(wxStaticText(self, -1, "(latest version on this client)"),
pos=(row, 3))
row += 1
sizer.AddSpacer(-1, 10, pos=(row, 1))
row += 1
buttonSizer = wxBoxSizer(wxHORIZONTAL)
buttonSizer.AddMany([self.okButton, self.cancelButton])
sizer.Add(buttonSizer, pos=(row, 1), colspan=4, flag=wxALIGN_CENTER)
row += 1
sizer.AddSpacer(0, 10, pos=(row, 1))
self.SetSizer(sizer)
sizer.Fit(self)
self.Center()
EVT_COMBOBOX(self, self.comboLabel.GetId(), self.onLabelSelected)
EVT_TEXT(self, self.textDate.GetId(), self.onDateFieldModified)
def loadComboLabels(self):
# Load labels if
# (a) we have not loaded them yet
# or
# (b) the path has changed since we loaded them (i.e., if this
# dialog instance is reused with a different path)
if not self.labelsLoaded or self.labelsLoadedPath != self.dirPath:
try:
wxBeginBusyCursor()
labelList = self.getLabels(self.dirPath)
for label in labelList:
self.comboLabel.Append(label)
#if len(labelList) > 0:
# self.comboLabel.SetSelection(0)
self.labelsLoaded = True
self.labelsLoadedPath = self.dirPath
finally:
wxEndBusyCursor()
def onLabelSelected(self, evt):
wxUtil.checkOneRadio(self.typeRadios, self.radioTypeLabel)
def onDateFieldModified(self, evt):
wxUtil.checkOneRadio(self.typeRadios, self.radioTypeDate)
def getLabels(self, dirPath):
labelDict = p4Util.execP4Marshal("labels " + dirPath)
labels = []
for labelEntry in labelDict:
labels.append(labelEntry["label"])
# Sort, ignoring case
labels.sort(pyUtil.cmpIgnoreCase)
return labels
def getQualifier(self):
if self.radioTypeLabel.GetValue():
return "@" + self.comboLabel.GetValue()
elif self.radioTypeDate.GetValue():
return "@" + self.textDate.GetValue()
elif self.radioTypeHave.GetValue():
return "#have"
else:
# Either self.radioTypeHead is selected, or no radio is selected
return ""
class LabelComboBox(wxComboBox):
# http://groups.google.com/groups?
#q=wxpython+wxcombobox+event&hl=en&lr=&ie=UTF-8&oe=UTF-8&
#selm=mailman.1000833187.26514.wx-users%40lists.wxwindows.org&rnum=3
def __init__(self, *_args, **_kwargs):
apply(wxComboBox.__init__, (self,) + _args, _kwargs)
EVT_SET_FOCUS(self, self.onSetFocus)
def onSetFocus (self, event):
self.GetParent().loadComboLabels()
event.Skip()
class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(None, -1, "Test")
frame.Show(true)
self.SetTopWindow(frame)
dialog = p4DirSpecQualDialog(gDirPath, frame, -1)
dialog.ShowModal()
return true
def main():
app = MyApp(0)
app.MainLoop()
if __name__ == '__main__':
gDirPath = "//depot/..."
main()