Changeset 6341 for misc/tools/plotcsv/plotcsv.py
- Timestamp:
- Feb 13, 2009, 5:16:00 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
misc/tools/plotcsv/plotcsv.py
r6338 r6341 15 15 import pylab 16 16 17 try: 18 import wx 19 except ImportError: 20 import tkinter_error 21 msg = ('Sorry, you have to install WxPython.\n' 22 'Get it from either:\n' 23 r' N:\georisk\downloads\event_selection, or' '\n' 24 ' [http://www.wxpython.org/download.php#binaries].') 25 tkinter_error.tkinter_error(msg) 26 print msg 27 sys.exit(1) 28 29 Imported_PyEmbeddedImage = True 30 try: 31 from wx.lib.embeddedimage import PyEmbeddedImage 32 except ImportError: 33 Imported_PyEmbeddedImage = False 34 35 36 # program name and version 37 APP_NAME = 'plotcsv' 38 APP_VERSION = '0.1' 39 40 # name of the configuration filename 41 # GUI values are saved in this file for next time 42 ConfigFilename = '%s.cfg' % APP_NAME 43 44 # GUI definitions 45 BUTTON_WIDTH = 100 46 BUTTON_HEIGHT = 30 47 48 MARGIN = 10 49 50 LAB_CTRL_OFFSET = 3 51 52 BOX_WIDTH = 400 53 BOX_HEIGHT = 360 54 BOX_CSV_WIDTH = 400 55 BOX_CSV_HEIGHT = 265 56 BOX_PLOT_WIDTH = 400 57 BOX_PLOT_HEIGHT = 90 58 59 TXT_CSVFILE_WIDTH = 390 60 TXT_CSVFILE_HEIGHT = 200 61 62 COLLAB_X_OFFSET = 20 63 64 CHBOX_HEIGHT = 30 65 CHBOX_WIDTH = 100 66 67 FORM_WIDTH = BOX_WIDTH + 15 68 FORM_HEIGHT = 405 69 70 START_YOFFSET = 7 71 OUT_TEXT_XOFFSET = 8 72 OUT_TEXT_YOFFSET = 11 73 OUTPUT_BOX_HEIGHT = 45 74 75 GEN_YOFFSET = 15 76 GEN_DELTAY = 15 77 GEN_LABELXOFFSET = 5 78 GEN_TEXTXOFFSET = BOX_WIDTH/2 + GEN_LABELXOFFSET + 10 79 80 TEXTLIST_WIDTH = BOX_WIDTH - 10 81 TEXTLIST_HEIGHT = 200 82 83 CTL_WIDTH = BOX_WIDTH / 2 84 CTL_HEIGHT = 22 85 86 DOUBLE_BUTTON_OFFSET = 8 87 88 COMBO_FUDGE = 2 89 90 # Copies of various parameters 91 Region = '' 92 GaugeNumber = '' 93 MinimumHeight = '' 94 MaximumHeight = '' 17 95 18 96 # Flag strings - keys in the 'options' dictionary … … 26 104 X_LABEL = 'x_label' 27 105 Y_LABEL = 'y_label' 106 107 108 ################################################################################ 109 # This code was generated by img2py.py 110 # Embed the ICON image here, so we don't need an external *.ico file. 111 ################################################################################ 112 113 if Imported_PyEmbeddedImage: 114 def getIcon(): 115 return PyEmbeddedImage( 116 "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAApxJ" 117 "REFUWIXtlr9O40AQh2edWwsKJFAarGtcRaElJWkoo4TGZegocqLME6TOC6CtaWjCFXRUfgJE" 118 "xStsiivuKiQ4ND8Kx/bu+k+cUKRhpC0ie+f7sjs7a0FEoB3GDyIiYDcOQgjydkI24lvgW2Bj" 119 "gctLolaLaG+P6OiI6PCQSIh89HpEy+VmOdE0lAKI1o8oArSuycMKAQegVQ9qDJeymUCdhGIF" 120 "yRLE1FzAhZ+dATc3wN0d8PiYg9z3XAkLbgl0u4DnAePxWvja5XXen0zK4RFHhoA5lNoabs4z" 121 "Uw4finDN2hAIw/xtKQGltoanMZut5k4U6K0IB2AIaJ0QVrQPT+LaU1vD0xg+2PDuSwJXCggC" 122 "UwAoSLyTxC9SpfAFLxBwAJ99THlavg1uwS0i0LHGcGiurHMKbucav0Uu8V9I/JsrK7FmjRM+" 123 "yRL77CPmuBbefUngxeNqCKR7HpDGPUWFmkjhEUf5v1qNkMNMoqzaNWtMJsU+kQmMx/bDq4HG" 124 "68CW0LdzC97iFtrctiSmPC2Fpzvc7yenvd9PfmcC+/s56/x8tedGTehjQnQvssSSJRQrxBwj" 125 "5LCwIi68KqwV8LykHz0/mxuuoa8GiBZ5YvnhQXFeF2USTeCWQFVo1oheBzn8jaCuPatZpRId" 126 "7sBnHyMeJXCtgaen2vNbK+AWnHwXUJNiYZZP1slylt1Sp6eZVKVAAc4S6u/c6hO1Em7JV1yV" 127 "pQKl8HTPnWZVKpH14PX3dUGgFm4ub5WEewvNZvZc54KxBBrB6ySmU+DgoHgPu2FIZAIbwask" 128 "zNHrrf9oCIxPMrO3N4LXSYQhEMeNpmcCKVywaA43JUYjwPeBTqcx3BIIOYTHHi74YjP4F4OI" 129 "IIgI9JOI2kS0JKI/m33TfzU+ASG0bvT61fpzAAAAAElFTkSuQmCC") 28 130 29 131 … … 132 234 133 235 134 ## 135 # @brief Help for the befuddled user. 136 def usage(): 137 print 'usage: %s <options> <filename>' % (ProgName) 138 print 'where <filename> is the path to the data file to plot' 139 print ' and <options> is zero or more of:' 140 print ' -x <datacol> where <datacol> is a column specifier,' 141 print ' -y <datacol> either a number or a header string' 142 print ' -v <range> force a range in Y axis values, of the form' 143 print ' <min>,<max>, eq, "-5,10"' 144 print ' -s <min,max> sets PNG output picture size' 145 sys.exit(10) 236 class MyFrame(wx.Frame): 237 def __init__(self, parent, id, title, pos=wx.DefaultPosition, 238 size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE): 239 # Make the frame 240 wx.Frame.__init__(self, parent, id, title, pos=(50, 50), 241 size=(FORM_WIDTH, FORM_HEIGHT), 242 style=(wx.DEFAULT_FRAME_STYLE & 243 ~ (wx.RESIZE_BOX | wx.MAXIMIZE_BOX | 244 wx.RESIZE_BORDER))) 245 246 p = self.panel = wx.Panel(self, -1) 247 248 if Imported_PyEmbeddedImage: 249 tsunami = getIcon() 250 icon = tsunami.GetIcon() 251 self.SetIcon(icon) 252 253 self.Center() 254 self.Show(True) 255 256 # start laying out controls 257 Y_OFFSET = START_YOFFSET 258 wx.StaticBox(p, -1, 'CSV files', (3, Y_OFFSET), 259 size=(BOX_CSV_WIDTH, BOX_CSV_HEIGHT)) 260 261 ## wx.StaticText(p, -1, 'Minimum wave height', 262 ## pos=(GEN_LABELXOFFSET, Y_OFFSET), 263 ## size=(CTL_WIDTH, CTL_HEIGHT), style=wx.ALIGN_RIGHT) 264 ## self.txtMinH = wx.TextCtrl(p, -1, size=(100, 20), 265 ## pos=(GEN_TEXTXOFFSET, Y_OFFSET)) 266 Y_OFFSET += GEN_DELTAY 267 268 ## self.lstGenerate = wx.ListCtrl(p, -1, pos=(8, Y_OFFSET), 269 ## size=(TEXTLIST_WIDTH,TEXTLIST_HEIGHT), 270 ## style=wx.LC_SINGLE_SEL) 271 ## self.txtCSVFiles = wx.TextCtrl(p, -1, 272 ## "Here is a looooooooooooooong line of text set in the control.\n\n" 273 ## "The quick brown fox jumped over the lazy dog...", 274 ## pos=(8, Y_OFFSET), size=(TXT_CSVFILE_WIDTH,TXT_CSVFILE_HEIGHT), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER) 275 self.txtCSVFiles = wx.ListBox(p, -1, pos=(8, Y_OFFSET), size=(TXT_CSVFILE_WIDTH,TXT_CSVFILE_HEIGHT)) 276 Y_OFFSET += TXT_CSVFILE_HEIGHT + MARGIN 277 x = FORM_WIDTH/2 - BUTTON_WIDTH - DOUBLE_BUTTON_OFFSET 278 self.btnAddCSVFile = wx.Button(p, label="Add", pos=(x, Y_OFFSET), 279 size=(100, BUTTON_HEIGHT)) 280 x = FORM_WIDTH/2 + DOUBLE_BUTTON_OFFSET 281 self.btnDelCSVFile = wx.Button(p, label="Delete", pos=(x, Y_OFFSET), 282 size=(100, BUTTON_HEIGHT)) 283 Y_OFFSET += BUTTON_HEIGHT + MARGIN 284 285 wx.StaticBox(p, -1, 'Plot details', (3, Y_OFFSET), 286 size=(BOX_PLOT_WIDTH, BOX_PLOT_HEIGHT)) 287 Y_OFFSET += GEN_DELTAY 288 wx.StaticText(p, -1, 'X-Column', 289 pos=(COLLAB_X_OFFSET, Y_OFFSET+LAB_CTRL_OFFSET), style=wx.ALIGN_LEFT) 290 self.cbXColHdr = wx.ComboBox(p, -1, pos=(COLLAB_X_OFFSET+50, Y_OFFSET), 291 size=(80, -1), style=wx.CB_DROPDOWN) 292 wx.StaticText(p, -1, 'Y-Column', 293 pos=(FORM_WIDTH/2+COLLAB_X_OFFSET, 294 Y_OFFSET+LAB_CTRL_OFFSET), style=wx.ALIGN_LEFT) 295 x = FORM_WIDTH/2 + COLLAB_X_OFFSET 296 self.cbYColHdr = wx.ComboBox(p, -1, pos=(x+50, Y_OFFSET), 297 size=(80, -1), style=wx.CB_DROPDOWN) 298 299 Y_OFFSET += BUTTON_HEIGHT + MARGIN 300 x = FORM_WIDTH/2 - BUTTON_WIDTH/2 301 self.btnPlote = wx.Button(p, label="Plot", pos=(x, Y_OFFSET), 302 size=(100, BUTTON_HEIGHT)) 303 304 305 306 307 308 ## wx.StaticText(p, -1, 'Maximum wave height', 309 ## pos=(GEN_LABELXOFFSET, Y_OFFSET), 310 ## size=(CTL_WIDTH, CTL_HEIGHT), style=wx.ALIGN_RIGHT) 311 ## self.chXColHdr = wx.Choice(p, -1, size=(CHBOX_WIDTH, CHBOX_HEIGHT), 312 ## pos=(10,Y_OFFSET)) 313 314 315 316 317 318 319 ## wx.StaticText(p, -1, 'Maximum wave height', 320 ## pos=(GEN_LABELXOFFSET, Y_OFFSET), 321 ## size=(CTL_WIDTH, CTL_HEIGHT), style=wx.ALIGN_RIGHT) 322 ## self.txtMaxH = wx.TextCtrl(p, -1, size=(100, 20), 323 ## pos=(GEN_TEXTXOFFSET, Y_OFFSET)) 324 ## Y_OFFSET += GEN_DELTAY 325 ## x = FORM_WIDTH/2 - BUTTON_WIDTH/2 326 ## self.btnGenerate = wx.Button(p, label="List", 327 ## pos=(x, Y_OFFSET), 328 ## size=(100, BUTTON_HEIGHT)) 329 ## Y_OFFSET += GEN_DELTAY + BUTTON_HEIGHT/2 330 ## 331 ## self.lstGenerate = wx.ListCtrl(p, -1, pos=(8, Y_OFFSET), 332 ## size=(TEXTLIST_WIDTH,TEXTLIST_HEIGHT), 333 ## style=wx.LC_REPORT|wx.LC_SINGLE_SEL) 334 ## 335 ## Y_OFFSET += TEXTLIST_HEIGHT + 20 336 ## self.Bind(wx.EVT_BUTTON, self.GenerateClick, self.btnGenerate) 337 ## self.lstGenerate.Bind(wx.EVT_LIST_ITEM_SELECTED, 338 ## self.OnItemSelected, self.lstGenerate) 339 ## 340 ## # start laying out get_multimux controls 341 ## wx.StaticBox(p, -1, 'multimux_grid', (3, Y_OFFSET), 342 ## size=(BOX_WIDTH, BOX2_HEIGHT)) 343 ## Y_OFFSET += 18 344 ## wx.StaticText(p, -1, 'Quake ID', pos=(GEN_LABELXOFFSET, Y_OFFSET), 345 ## size=(CTL_WIDTH, CTL_HEIGHT), style=wx.ALIGN_RIGHT) 346 ## self.txtQuakeID = wx.TextCtrl(p, -1, size=(100, 20), 347 ## pos=(GEN_TEXTXOFFSET, Y_OFFSET)) 348 ## Y_OFFSET += GEN_DELTAY 349 ## x = FORM_WIDTH/2 - BUTTON_WIDTH - DOUBLE_BUTTON_OFFSET 350 ## self.btnMultimux = wx.Button(p, label="Multimux", pos=(x, Y_OFFSET), 351 ## size=(100, BUTTON_HEIGHT)) 352 ## x = FORM_WIDTH/2 + DOUBLE_BUTTON_OFFSET 353 ## self.btnGrid = wx.Button(p, label="Grid", pos=(x, Y_OFFSET), 354 ## size=(100, BUTTON_HEIGHT)) 355 ## Y_OFFSET += GEN_DELTAY + BUTTON_HEIGHT/2 356 ## self.lstMultimux = wx.ListCtrl(p, -1, pos=(8, Y_OFFSET), 357 ## size=(TEXTLIST_WIDTH,TEXTLIST_HEIGHT), 358 ## style=wx.LC_REPORT|wx.LC_SINGLE_SEL) 359 ## Y_OFFSET += TEXTLIST_HEIGHT + 20 360 ## self.Bind(wx.EVT_BUTTON, self.MultimuxClick, self.btnMultimux) 361 ## self.Bind(wx.EVT_BUTTON, self.GridClick, self.btnGrid) 362 363 self.Bind(wx.EVT_CLOSE, self.doStateSave) 364 self.doStateRestore() 365 366 def doStateSave(self, event): 367 """ 368 Save state here. 369 """ 370 ## self.cfg['OutputDirectory'] = self.txtOutputDir.GetValue() 371 ## self.cfg['Region'] = self.cbRegion.GetValue() 372 ## self.cfg['GaugeNumber'] = self.txtTGN.GetValue() 373 ## self.cfg['MinimumHeight'] = self.txtMinH.GetValue() 374 ## self.cfg['MaximumHeight'] = self.txtMaxH.GetValue() 375 ## self.cfg.save() 376 377 event.Skip(True) 378 379 def doStateRestore(self): 380 """ 381 Restore state here - globals have been set and tested sane 382 """ 383 ## global Region, GaugeNumber, MinimumHeight, MaximumHeight 384 ## 385 ## cfg = Config(ConfigFilename) 386 ## output_dir = cfg['OutputDirectory'] 387 ## Region = cfg['Region'] 388 ## GaugeNumber = cfg['GaugeNumber'] 389 ## if GaugeNumber: 390 ## GaugeNumber = int(GaugeNumber) 391 ## MinimumHeight = cfg['MinimumHeight'] 392 ## if MinimumHeight: 393 ## MinimumHeight = float(MinimumHeight) 394 ## MaximumHeight = cfg['MaximumHeight'] 395 ## if MaximumHeight: 396 ## MaximumHeight = float(MaximumHeight) 397 ## 398 ## self.cfg = cfg 399 ## 400 ## region_name = None 401 ## for (name, dir) in Regions: 402 ## if name == Region: 403 ## region_name = name 404 ## if not region_name: 405 ## Region = '' 406 ## 407 ## if output_dir: 408 ## self.txtOutputDir.WriteText(output_dir) 409 ## self.cbRegion.SetStringSelection(Region) 410 ## if GaugeNumber: 411 ## self.txtTGN.WriteText(str(GaugeNumber)) 412 ## if MinimumHeight: 413 ## self.txtMinH.WriteText(str(MinimumHeight)) 414 ## if MaximumHeight: 415 ## self.txtMaxH.WriteText(str(MaximumHeight)) 416 417 def error(self, msg): 418 dlg = wx.MessageDialog(self, msg, 'Error', 419 wx.OK | wx.ICON_INFORMATION) 420 dlg.ShowModal() 421 dlg.Destroy() 422 423 424 ################################################################################ 425 # Code to do the GUI 426 ################################################################################ 146 427 147 428 if __name__ == '__main__': 148 # dictionary to convert option string to internal name 149 of_dict = { '-x': X_DATACOL, 150 '-y': Y_DATACOL, 151 '-s': SIZE, 152 '-v': Y_RANGE } 153 154 # set name of the program (for error reporting) 155 global ProgName 156 try: 157 ProgName = os.path.basename(sys.argv[0]) 158 except: 159 pass 160 161 # get options 162 opt_dict = {} 163 params = sys.argv[1:] 164 (opts, args) = getopt.gnu_getopt(params, 'x:y:s:v:') 165 if len(args) != 1: 166 usage() 167 for (o, v) in opts: 168 try: 169 opt_dict[of_dict[o]] = v.lower() 170 except: 171 usage() 172 173 # get name of data file 174 if len(args) != 1: 175 usage() 176 filename = args[0] 177 (filename_minus, _) = filename.split('.', 1) 178 179 # set default option values 180 opt_dict[X_DATACOL] = opt_dict.get(X_DATACOL, 0) 181 opt_dict[Y_DATACOL] = opt_dict.get(Y_DATACOL, 1) 182 opt_dict[SIZE] = opt_dict.get(SIZE, '800,600') 183 # opt_dict[X_RANGE] = opt_dict.get(X_RANGE, None) 184 opt_dict[Y_RANGE] = opt_dict.get(Y_RANGE, None) 185 opt_dict[FILENAME] = filename_minus 186 187 # plot the file 188 plot_file(args[0], opt_dict) 429 app = wx.App() 430 frame = MyFrame(None, -1, '%s %s' % (APP_NAME, APP_VERSION), 431 size=(FORM_WIDTH, FORM_HEIGHT)) 432 app.SetTopWindow(frame) 433 app.MainLoop() 434
Note: See TracChangeset
for help on using the changeset viewer.