#!/usr/bin/env python '''Quick Label''' # Copyright (c) 2006 Qualcomm # Miki Tebeka <mtebeka@qualcomm.com> from os import environ import sys from os.path import isfile, dirname, join import wx from wx.lib.intctrl import IntCtrl from wx.lib.dialogs import messageDialog from p4 import P4, P4Error from time import strftime from p4v_common import quick_label, fix_path, P4VAddin, gen_p4, make_error, \ optparser class QuickLabel(P4VAddin): '''GUI''' def __init__(self, p4, path): P4VAddin.__init__(self, "Quick Label") self.p4 = p4 sizer = wx.BoxSizer(wx.VERTICAL) gsizer = wx.FlexGridSizer(3, 2, 2) # Rows, cols, hgap # Depot Path: _____________ gsizer.Add(wx.StaticText(self, -1, "Depot Path:"), 0, wx.ALIGN_CENTER_VERTICAL|wx.WEST, 2) self._path = wx.TextCtrl(self, -1, size=(300, -1)) self._path.SetValue(path) gsizer.Add(self._path, 0, wx.EXPAND) # Label Name: ____________ gsizer.Add(wx.StaticText(self, -1, "Label Name:"), 0, wx.ALIGN_CENTER_VERTICAL|wx.WEST, 2) self._label = wx.TextCtrl(self, -1, size=(300, -1)) gsizer.Add(self._label, 0, wx.EXPAND) # Description: _________________- gsizer.Add(wx.StaticText(self, -1, "Description:"), 0, wx.ALIGN_TOP|wx.WEST, 2) self._desc = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE) self._desc.SetValue("Created by %s." % self.p4.user) gsizer.Add(self._desc, 1, wx.EXPAND) gsizer.AddGrowableCol(1) sizer.Add(gsizer, 0, wx.EXPAND) # o Latest Version o Changelist: _____ [...] hsizer = wx.BoxSizer(wx.HORIZONTAL) self._latest = wx.RadioButton(self, -1, "Latest Version", style=wx.RB_GROUP) self._latest.controls = [] sizer.Add(self._latest, 0, wx.WEST, 2) hsizer = wx.BoxSizer(wx.HORIZONTAL) self._change_rb = wx.RadioButton(self, -1, "Changelist") hsizer.Add(self._change_rb, 0, wx.ALIGN_CENTER|wx.WEST, 2) self._change = IntCtrl(self, -1) self._change.SetValue(1) hsizer.Add(self._change, 1, wx.EXPAND|wx.ALIGN_CENTER) b = wx.Button(self, -1, "...", style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.OnChangelists, b) hsizer.Add(b) self._change_rb.controls = [self._change, b] sizer.Add(hsizer, 1, wx.NORTH|wx.EXPAND, 5) self.Bind(wx.EVT_RADIOBUTTON, self.OnRadio) # Change selection disabled at start for ctrl in self._change_rb.controls: ctrl.Disable() self.radio_buttons = [self._change_rb, self._latest] # [Label] [Quit] sizer.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.NORTH|wx.SOUTH, 5) hsizer = wx.BoxSizer(wx.HORIZONTAL) b = wx.Button(self, -1, "Label") self.Bind(wx.EVT_BUTTON, self.OnLabel, b) hsizer.Add(b) # This is a "stock" button that will cause exit hsizer.Add(wx.Button(self, wx.ID_CANCEL, "Quit")) sizer.Add(hsizer) # Size window self.SetSizer(sizer) sizer.Fit(self) self.CenterOnScreen() # Label name is default input self._label.SetFocus() def label_exists(self, name): '''Check if label exits name - Label name to check ''' for label in self.p4.run_labels(): if label["label"] == name: return 1 return 0 def OnLabel(self, evt): '''Handle click on [Label]''' # Get input try: path = self.getval(self._path, "Depot Path") label = self.getval(self._label, "Label Name") desc = self.getval(self._desc, "Description") except ValueError, e: error("\"%s\" can't be empty" % e.args[0]) return if self.label_exists(label): error("Label `%s` already exists" % label) return path = fix_path(path) rev = "" if self._change_rb.GetValue(): rev = "%s" % self._change.GetValue() try: quick_label(self.p4, label, path, desc, rev) except P4Error, e: error(e.value) messageDialog(self, "Label %s created" % label, "Label Created", wx.OK|wx.ICON_INFORMATION) def OnChangelists(self, evt): '''Select changelist (click on [...]) handler''' path = self._path.GetValue().strip() if path: path = fix_path(path) # Get submitted changes in path changes = [] for change in self.p4.run_changes("-s", "submitted", path): changes.append(change["change"]) # Let user select one dlg = wx.SingleChoiceDialog(self, "Select changelist", "Changelists", changes) if dlg.ShowModal() == wx.ID_OK: self._change.SetValue(int(dlg.GetStringSelection())) dlg.Destroy() def OnRadio(self, evt): '''Radio button handler''' radio = evt.GetEventObject() # Disable other radio associated controls for rb in self.radio_buttons: if rb is radio: for ctrl in rb.controls: ctrl.Enable() else: for ctrl in rb.controls: ctrl.Disable() error = None def main(argv = None): global error if argv is None: import sys argv = sys.argv # Initialize wx (need to be first so that "error" will work) app = wx.PySimpleApp() error = make_error("QuickLabel Error") # Command line parsing parser = optparser("usage: %prog [options] PATH") opts, args = parser.parse_args(argv[1:]) if len(args) != 1: error(parser.get_usage()) raise SystemExit(parser.get_usage()) # Get arguments path = args[0] try: p4 = gen_p4(opts) except P4Error, e: error(e) raise SystemExit(1) # Main dlg = QuickLabel(p4, path) dlg.ShowModal() dlg.Destroy() if __name__ == "__main__": main()
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 5665 | Robert Cowham | Initial branch | ||
//guest/miki_tebeka/p4vaddins/main/quick-label.py | |||||
#3 | 5628 | Miki Tebeka | Initial support for P4V new XML settings file | ||
#2 | 5382 | Miki Tebeka |
* Start of UNIX - File format and #! * getvalue returns string (not unicode in some cases) |
||
#1 | 5280 | Miki Tebeka | Initial checkin of project |