#!/usr/bin/env python # Edit Column Options # Copyright 2004 by Brian C. Christensen # This file is part of GanttPV. # # GanttPV is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # GanttPV is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GanttPV; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 040715 - first version of this script # 040902 - added edit for column label # 050912 - Alex - get the column list from GanttReport def hint(s): try: Data.Hint("%s: %s" % (scriptname, s)) except AttributeError: self.SetStatusText(s) def UpdateColumn(self): sel = self.Report.GetSelectedCols() # current selection if not sel: hint("Select a column first.") return columns = self.Report.table.columns s = sel[0] cid = columns[s] sel_cids = [columns[s] for s in sel] if sel_cids.count(cid) != len(sel_cids): hint("Select only one column.") return c = Data.Database['ReportColumn'][cid] ctid = self.Report.table.ctypes[s] ct = Data.Database['ColumnType'][ctid] if ct.get('AccessType') == 's': periods = c.get('Periods') or 1 dlg = wx.TextEntryDialog(None, 'Enter new number of periods', 'Edit Column Periods', str(periods)) if dlg.ShowModal() == wx.ID_OK: try: newvalue = int(dlg.GetValue()) except ValueError: pass else: if newvalue < 1: newvalue = 1 if newvalue != periods: change = {'Table': 'ReportColumn', 'ID': cid, 'Periods': newvalue} Data.Update(change) Data.SetUndo('Edit Column Periods') dlg.Destroy() else: # allow edit of column label # should allow two rows -- do this later ctype = ct.get('Label') or ct.get('Name') or "-" default = ctype.replace("\n", r"\n") msg = 'Defaults to column type: "' + default + '"\nUse ' + r'"\n"' + " to separate lines." label = c.get('Label') or "" oldvalue = label.replace("\n", r"\n") or default dlg = wx.TextEntryDialog(None, msg, 'Edit Column Label', oldvalue) dlg.SetValue(oldvalue) if dlg.ShowModal() == wx.ID_OK: newvalue = dlg.GetValue().replace(r"\n", "\n") if newvalue != label: change = {'Table': 'ReportColumn', 'ID': cid, 'Label': newvalue} Data.Update(change) Data.SetUndo('Edit Column Label') dlg.Destroy() UpdateColumn(self)