goutput.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. """
  2. @package goutput
  3. @brief Command output log widget
  4. Classes:
  5. - GMConsole
  6. - GMStc
  7. - GMStdout
  8. - GMStderr
  9. (C) 2007-2008 by the GRASS Development Team
  10. This program is free software under the GNU General Public
  11. License (>=v2). Read the file COPYING that comes with GRASS
  12. for details.
  13. @author Michael Barton (Arizona State University)
  14. @author Martin Landa <landa.martin gmail.com>
  15. """
  16. import os
  17. import sys
  18. import textwrap
  19. import time
  20. import threading
  21. import Queue
  22. import wx
  23. import wx.stc
  24. from wx.lib.newevent import NewEvent
  25. import globalvar
  26. import gcmd
  27. from debug import Debug as Debug
  28. wxCmdOutput, EVT_CMD_OUTPUT = NewEvent()
  29. wxCmdProgress, EVT_CMD_PROGRESS = NewEvent()
  30. wxCmdDone, EVT_CMD_DONE = NewEvent()
  31. wxCmdAbort, EVT_CMD_ABORT = NewEvent()
  32. def GrassCmd(cmd, stdout, stderr):
  33. """Run GRASS command on background"""
  34. return gcmd.RunCommand(cmd=cmd,
  35. stdout=stdout, stderr=stderr)
  36. class CmdThread(threading.Thread):
  37. """Thread for GRASS commands"""
  38. requestId = 0
  39. def __init__(self, parent, requestQ, resultQ, **kwds):
  40. threading.Thread.__init__(self, **kwds)
  41. self.setDaemon(True)
  42. self.parent = parent # GMConsole
  43. self.requestQ = requestQ
  44. self.resultQ = resultQ
  45. self.start()
  46. def RunCmd(self, callable, *args, **kwds):
  47. CmdThread.requestId += 1
  48. self.requestTime = time.time()
  49. self.requestCmd = None
  50. self.requestQ.put((CmdThread.requestId, callable, args, kwds))
  51. return CmdThread.requestId
  52. def run(self):
  53. while True:
  54. requestId, callable, args, kwds = self.requestQ.get()
  55. self.requestCmd = callable(*args, **kwds)
  56. self.resultQ.put((requestId, self.requestCmd.run()))
  57. event = wxCmdDone(aborted=self.requestCmd.aborted,
  58. time=self.requestTime,
  59. pid=requestId)
  60. wx.PostEvent(self.parent, event)
  61. def abort(self):
  62. self.requestCmd.abort()
  63. class GMConsole(wx.Panel):
  64. """
  65. Create and manage output console for commands entered on the
  66. GIS Manager command line.
  67. """
  68. def __init__(self, parent, id=wx.ID_ANY, margin=False, pageid=0,
  69. pos=wx.DefaultPosition, size=wx.DefaultSize,
  70. style=wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE):
  71. wx.Panel.__init__(self, parent, id, pos, size, style)
  72. # initialize variables
  73. self.Map = None
  74. self.parent = parent # GMFrame
  75. self.lineWidth = 80
  76. self.pageid = pageid
  77. #
  78. # create queues
  79. #
  80. self.requestQ = Queue.Queue()
  81. self.resultQ = Queue.Queue()
  82. #
  83. # progress bar
  84. #
  85. self.console_progressbar = wx.Gauge(parent=self, id=wx.ID_ANY,
  86. range=100, pos=(110, 50), size=(-1, 25),
  87. style=wx.GA_HORIZONTAL)
  88. self.console_progressbar.Bind(EVT_CMD_PROGRESS, self.OnCmdProgress)
  89. #
  90. # text control for command output
  91. #
  92. self.cmd_output = GMStc(parent=self, id=wx.ID_ANY, margin=margin,
  93. wrap=None)
  94. self.cmd_output_timer = wx.Timer(self.cmd_output, id=wx.ID_ANY)
  95. self.cmd_output.Bind(EVT_CMD_OUTPUT, self.OnCmdOutput)
  96. self.cmd_output.Bind(wx.EVT_TIMER, self.OnProcessPendingOutputWindowEvents)
  97. self.Bind(EVT_CMD_DONE, self.OnCmdDone)
  98. #
  99. # stream redirection
  100. #
  101. self.cmd_stdout = GMStdout(self)
  102. self.cmd_stderr = GMStderr(self)
  103. #
  104. # thread
  105. #
  106. self.cmdThread = CmdThread(self, self.requestQ, self.resultQ)
  107. #
  108. # buttons
  109. #
  110. self.console_clear = wx.Button(parent=self, id=wx.ID_CLEAR)
  111. self.console_save = wx.Button(parent=self, id=wx.ID_SAVE)
  112. self.Bind(wx.EVT_BUTTON, self.ClearHistory, self.console_clear)
  113. self.Bind(wx.EVT_BUTTON, self.SaveHistory, self.console_save)
  114. self.Bind(EVT_CMD_ABORT, self.OnCmdAbort)
  115. self.__layout()
  116. def __layout(self):
  117. """Do layout"""
  118. boxsizer1 = wx.BoxSizer(wx.VERTICAL)
  119. gridsizer1 = wx.GridSizer(rows=1, cols=2, vgap=0, hgap=0)
  120. boxsizer1.Add(item=self.cmd_output, proportion=1,
  121. flag=wx.EXPAND | wx.ADJUST_MINSIZE, border=0)
  122. gridsizer1.Add(item=self.console_clear, proportion=0,
  123. flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, border=0)
  124. gridsizer1.Add(item=self.console_save, proportion=0,
  125. flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, border=0)
  126. boxsizer1.Add(item=gridsizer1, proportion=0,
  127. flag=wx.EXPAND | wx.ALIGN_CENTRE_VERTICAL | wx.TOP | wx.BOTTOM,
  128. border=5)
  129. boxsizer1.Add(item=self.console_progressbar, proportion=0,
  130. flag=wx.EXPAND | wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
  131. boxsizer1.Fit(self)
  132. boxsizer1.SetSizeHints(self)
  133. # layout
  134. self.SetAutoLayout(True)
  135. self.SetSizer(boxsizer1)
  136. def Redirect(self):
  137. """Redirect stderr
  138. @return True redirected
  139. @return False failed
  140. """
  141. if Debug.get_level() == 0:
  142. # don't redirect when debugging is enabled
  143. #sys.stdout = self.cmd_stdout
  144. #sys.stderr = self.cmd_stderr
  145. pass
  146. return True
  147. return False
  148. def WriteLog(self, line, style=None, wrap=None):
  149. """Generic method for writing log message in
  150. given style
  151. @param line text line
  152. @param style text style (see GMStc)
  153. @param stdout write to stdout or stderr
  154. """
  155. if not style:
  156. style = self.cmd_output.StyleDefault
  157. self.cmd_output.GotoPos(self.cmd_output.GetLength())
  158. p1 = self.cmd_output.GetCurrentPos()
  159. # fill space
  160. if len(line) < self.lineWidth:
  161. diff = 80 - len(line)
  162. line += diff * ' '
  163. self.cmd_output.AddTextWrapped(line, wrap=wrap) # adds os.linesep
  164. p2 = self.cmd_output.GetCurrentPos()
  165. self.cmd_output.StartStyling(p1, 0xff)
  166. self.cmd_output.SetStyling(p2 - p1, style)
  167. self.cmd_output.EnsureCaretVisible()
  168. def WriteCmdLog(self, line, pid=None):
  169. """Write out line in selected style"""
  170. if pid:
  171. line = '(' + str(pid) + ') ' + line
  172. self.WriteLog(line, self.cmd_output.StyleCommand)
  173. def RunCmd(self, command):
  174. """
  175. Run in GUI GRASS (or other) commands typed into
  176. console command text widget, and send stdout output to output
  177. text widget.
  178. Command is transformed into a list for processing.
  179. TODO: Display commands (*.d) are captured and
  180. processed separately by mapdisp.py. Display commands are
  181. rendered in map display widget that currently has
  182. the focus (as indicted by mdidx).
  183. """
  184. # map display window available ?
  185. try:
  186. curr_disp = self.parent.curr_page.maptree.mapdisplay
  187. self.Map = curr_disp.GetRender()
  188. except:
  189. curr_disp = None
  190. if not self.requestQ.empty():
  191. # only one running command enabled (per GMConsole instance)
  192. busy = wx.BusyInfo(message=_("Unable to run the command, another command is running..."),
  193. parent=self)
  194. wx.Yield()
  195. time.sleep(3)
  196. busy.Destroy()
  197. return None
  198. # command given as a string ?
  199. try:
  200. cmdlist = command.strip().split(' ')
  201. except:
  202. cmdlist = command
  203. if cmdlist[0] in globalvar.grassCmd['all']:
  204. # send GRASS command without arguments to GUI command interface
  205. # except display commands (they are handled differently)
  206. if cmdlist[0][0:2] == "d.":
  207. #
  208. # display GRASS commands
  209. #
  210. try:
  211. layertype = {'d.rast' : 'raster',
  212. 'd.rgb' : 'rgb',
  213. 'd.his' : 'his',
  214. 'd.shaded' : 'shaded',
  215. 'd.legend' : 'rastleg',
  216. 'd.rast.arrow' : 'rastarrow',
  217. 'd.rast.num' : 'rastnum',
  218. 'd.vect' : 'vector',
  219. 'd.vect.thematic': 'thememap',
  220. 'd.vect.chart' : 'themechart',
  221. 'd.grid' : 'grid',
  222. 'd.geodesic' : 'geodesic',
  223. 'd.rhumbline' : 'rhumb',
  224. 'd.labels' : 'labels'}[cmdlist[0]]
  225. except KeyError:
  226. wx.MessageBox(message=_("Command '%s' not yet implemented.") % cmdlist[0])
  227. return None
  228. # add layer into layer tree
  229. self.parent.curr_page.maptree.AddLayer(ltype=layertype,
  230. lcmd=cmdlist)
  231. else:
  232. #
  233. # other GRASS commands (r|v|g|...)
  234. #
  235. if hasattr(self.parent, "curr_page"):
  236. # change notebook page only for Layer Manager
  237. if self.parent.notebook.GetSelection() != 1:
  238. self.parent.notebook.SetSelection(1)
  239. # activate computational region (set with g.region)
  240. # for all non-display commands.
  241. tmpreg = os.getenv("GRASS_REGION")
  242. os.unsetenv("GRASS_REGION")
  243. if len(cmdlist) == 1:
  244. import menuform
  245. # process GRASS command without argument
  246. menuform.GUI().ParseCommand(cmdlist, parentframe=self)
  247. else:
  248. # process GRASS command with argument
  249. cmdPID = self.cmdThread.requestId + 1
  250. self.WriteCmdLog('%s' % ' '.join(cmdlist), pid=cmdPID)
  251. self.cmdThread.RunCmd(GrassCmd,
  252. cmdlist, self.cmd_stdout, self.cmd_stderr)
  253. self.cmd_output_timer.Start(50)
  254. return None
  255. # deactivate computational region and return to display settings
  256. if tmpreg:
  257. os.environ["GRASS_REGION"] = tmpreg
  258. else:
  259. # Send any other command to the shell. Send output to
  260. # console output window
  261. if hasattr(self.parent, "curr_page"):
  262. # change notebook page only for Layer Manager
  263. if self.parent.notebook.GetSelection() != 1:
  264. self.parent.notebook.SetSelection(1)
  265. # if command is not a GRASS command, treat it like a shell command
  266. try:
  267. generalCmd = gcmd.Command(cmdlist,
  268. stdout=self.cmd_stdout,
  269. stderr=self.cmd_stderr)
  270. except gcmd.CmdError, e:
  271. print >> sys.stderr, e
  272. return None
  273. def ClearHistory(self, event):
  274. """Clear history of commands"""
  275. self.cmd_output.ClearAll()
  276. self.console_progressbar.SetValue(0)
  277. def SaveHistory(self, event):
  278. """Save history of commands"""
  279. self.history = self.cmd_output.GetSelectedText()
  280. if self.history == '':
  281. self.history = self.cmd_output.GetText()
  282. # add newline if needed
  283. if len(self.history) > 0 and self.history[-1] != os.linesep:
  284. self.history += os.linesep
  285. wildcard = "Text file (*.txt)|*.txt"
  286. dlg = wx.FileDialog(
  287. self, message=_("Save file as..."), defaultDir=os.getcwd(),
  288. defaultFile="grass_cmd_history.txt", wildcard=wildcard,
  289. style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
  290. # Show the dialog and retrieve the user response. If it is the OK response,
  291. # process the data.
  292. if dlg.ShowModal() == wx.ID_OK:
  293. path = dlg.GetPath()
  294. output = open(path, "w")
  295. output.write(self.history)
  296. output.close()
  297. dlg.Destroy()
  298. def GetCmd(self):
  299. """Get running command or None"""
  300. return self.requestQ.get()
  301. def OnCmdOutput(self, event):
  302. """Print command output"""
  303. message = event.text
  304. type = event.type
  305. # message prefix
  306. if type == 'warning':
  307. messege = 'WARNING: ' + message
  308. elif type == 'error':
  309. message = 'ERROR: ' + message
  310. p1 = self.cmd_output.GetCurrentPos()
  311. if os.linesep not in message:
  312. self.cmd_output.AddTextWrapped(message, wrap=60)
  313. else:
  314. self.cmd_output.AppendText(message)
  315. p2 = self.cmd_output.GetCurrentPos()
  316. self.cmd_output.StartStyling(p1, 0xff)
  317. if type == 'error':
  318. self.cmd_output.SetStyling(p2 - p1 + 1, self.cmd_output.StyleError)
  319. elif type == 'warning':
  320. self.cmd_output.SetStyling(p2 - p1 + 1, self.cmd_output.StyleWarning)
  321. elif type == 'message':
  322. self.cmd_output.SetStyling(p2 - p1 + 1, self.cmd_output.StyleMessage)
  323. else: # unknown
  324. self.cmd_output.SetStyling(p2 - p1 + 1, self.cmd_output.StyleUnknown)
  325. self.cmd_output.EnsureCaretVisible()
  326. def OnCmdProgress(self, event):
  327. """Update progress message info"""
  328. self.console_progressbar.SetValue(event.value)
  329. def OnCmdAbort(self, event):
  330. """Abort running command"""
  331. self.cmdThread.abort()
  332. def OnCmdDone(self, event):
  333. """Command done (or aborted)"""
  334. if event.aborted:
  335. # Thread aborted (using our convention of None return)
  336. self.WriteLog(_('Please note that the data are left in incosistent stage '
  337. 'and can be corrupted'), self.cmd_output.StyleWarning)
  338. self.WriteCmdLog(_('Command aborted'),
  339. pid=self.cmdThread.requestId)
  340. else:
  341. try:
  342. # Process results here
  343. self.WriteCmdLog(_('Command finished (%d sec)') % (time.time() - event.time),
  344. pid=event.pid)
  345. except KeyError:
  346. # stopped deamon
  347. pass
  348. self.console_progressbar.SetValue(0) # reset progress bar on '0%'
  349. self.cmd_output_timer.Stop()
  350. # updated command dialog
  351. if hasattr(self.parent.parent, "btn_run"):
  352. dialog = self.parent.parent
  353. if hasattr(self.parent.parent, "btn_abort"):
  354. dialog.btn_abort.Enable(False)
  355. if hasattr(self.parent.parent, "btn_cancel"):
  356. dialog.btn_cancel.Enable(True)
  357. if hasattr(self.parent.parent, "btn_clipboard"):
  358. dialog.btn_clipboard.Enable(True)
  359. if hasattr(self.parent.parent, "btn_help"):
  360. dialog.btn_help.Enable(True)
  361. dialog.btn_run.Enable(True)
  362. if dialog.get_dcmd is None and \
  363. dialog.closebox.IsChecked():
  364. time.sleep(1)
  365. dialog.Close()
  366. event.Skip()
  367. def OnProcessPendingOutputWindowEvents(self, event):
  368. self.ProcessPendingEvents()
  369. class GMStdout:
  370. """GMConsole standard output
  371. Based on FrameOutErr.py
  372. Name: FrameOutErr.py
  373. Purpose: Redirecting stdout / stderr
  374. Author: Jean-Michel Fauth, Switzerland
  375. Copyright: (c) 2005-2007 Jean-Michel Fauth
  376. Licence: GPL
  377. """
  378. def __init__(self, parent):
  379. self.parent = parent # GMConsole
  380. def write(self, s):
  381. if len(s) == 0 or s == '\n':
  382. return
  383. s = s.replace('\n', os.linesep)
  384. for line in s.split(os.linesep):
  385. evt = wxCmdOutput(text=line + os.linesep,
  386. type='')
  387. wx.PostEvent(self.parent.cmd_output, evt)
  388. class GMStderr:
  389. """GMConsole standard error output
  390. Based on FrameOutErr.py
  391. Name: FrameOutErr.py
  392. Purpose: Redirecting stdout / stderr
  393. Author: Jean-Michel Fauth, Switzerland
  394. Copyright: (c) 2005-2007 Jean-Michel Fauth
  395. Licence: GPL
  396. """
  397. def __init__(self, parent):
  398. self.parent = parent # GMConsole
  399. self.type = ''
  400. self.message = ''
  401. self.printMessage = False
  402. def write(self, s):
  403. s = s.replace('\n', os.linesep)
  404. # remove/replace escape sequences '\b' or '\r' from stream
  405. s = s.replace('\b', '').replace('\r', '%s' % os.linesep)
  406. progressValue = -1
  407. for line in s.split(os.linesep):
  408. if len(line) == 0:
  409. continue
  410. if 'GRASS_INFO_PERCENT' in line:
  411. value = int(line.rsplit(':', 1)[1].strip())
  412. if value >= 0 and value < 100:
  413. progressValue = value
  414. else:
  415. progressValue = 0
  416. elif 'GRASS_INFO_MESSAGE' in line:
  417. self.type = 'message'
  418. self.message = line.split(':', 1)[1].strip()
  419. elif 'GRASS_INFO_WARNING' in line:
  420. self.type = 'warning'
  421. self.message = line.split(':', 1)[1].strip()
  422. elif 'GRASS_INFO_ERROR' in line:
  423. self.type = 'error'
  424. self.message = line.split(':', 1)[1].strip()
  425. elif 'GRASS_INFO_END' in line:
  426. self.printMessage = True
  427. elif not self.type:
  428. if len(line) > 0:
  429. continue
  430. evt = wxCmdOutput(text=line,
  431. type='')
  432. wx.PostEvent(self.parent.cmd_output, evt)
  433. elif len(line) > 0:
  434. self.message += line.strip() + os.linesep
  435. if self.printMessage and len(self.message) > 0:
  436. evt = wxCmdOutput(text=self.message,
  437. type=self.type)
  438. wx.PostEvent(self.parent.cmd_output, evt)
  439. self.type = ''
  440. self.message = ''
  441. self.printMessage = False
  442. # update progress message
  443. if progressValue > -1:
  444. # self.gmgauge.SetValue(progressValue)
  445. evt = wxCmdProgress(value=progressValue)
  446. wx.PostEvent(self.parent.console_progressbar, evt)
  447. class GMStc(wx.stc.StyledTextCtrl):
  448. """Styled GMConsole
  449. Based on FrameOutErr.py
  450. Name: FrameOutErr.py
  451. Purpose: Redirecting stdout / stderr
  452. Author: Jean-Michel Fauth, Switzerland
  453. Copyright: (c) 2005-2007 Jean-Michel Fauth
  454. Licence: GPL
  455. """
  456. def __init__(self, parent, id, margin=False, wrap=None):
  457. wx.stc.StyledTextCtrl.__init__(self, parent, id)
  458. self.parent = parent
  459. self.wrap = wrap
  460. #
  461. # styles
  462. #
  463. self.StyleDefault = 0
  464. self.StyleDefaultSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
  465. self.StyleCommand = 1
  466. self.StyleCommandSpec = "face:Courier New,size:10,fore:#000000,back:#bcbcbc"
  467. self.StyleOutput = 2
  468. self.StyleOutputSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
  469. # fatal error
  470. self.StyleError = 3
  471. self.StyleErrorSpec = "face:Courier New,size:10,fore:#7F0000,back:#FFFFFF"
  472. # warning
  473. self.StyleWarning = 4
  474. self.StyleWarningSpec = "face:Courier New,size:10,fore:#0000FF,back:#FFFFFF"
  475. # message
  476. self.StyleMessage = 5
  477. self.StyleMessageSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
  478. # unknown
  479. self.StyleUnknown = 6
  480. self.StyleUnknownSpec = "face:Courier New,size:10,fore:#7F0000,back:#FFFFFF"
  481. # default and clear => init
  482. self.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, self.StyleDefaultSpec)
  483. self.StyleClearAll()
  484. self.StyleSetSpec(self.StyleCommand, self.StyleCommandSpec)
  485. self.StyleSetSpec(self.StyleOutput, self.StyleOutputSpec)
  486. self.StyleSetSpec(self.StyleError, self.StyleErrorSpec)
  487. self.StyleSetSpec(self.StyleWarning, self.StyleWarningSpec)
  488. self.StyleSetSpec(self.StyleMessage, self.StyleMessageSpec)
  489. self.StyleSetSpec(self.StyleUnknown, self.StyleUnknownSpec)
  490. #
  491. # line margins
  492. #
  493. # TODO print number only from cmdlog
  494. self.SetMarginWidth(1, 0)
  495. self.SetMarginWidth(2, 0)
  496. if margin:
  497. self.SetMarginType(0, wx.stc.STC_MARGIN_NUMBER)
  498. self.SetMarginWidth(0, 30)
  499. else:
  500. self.SetMarginWidth(0, 0)
  501. #
  502. # miscellaneous
  503. #
  504. self.SetViewWhiteSpace(False)
  505. self.SetTabWidth(4)
  506. self.SetUseTabs(False)
  507. self.UsePopUp(True)
  508. self.SetSelBackground(True, "#FFFF00")
  509. self.SetUseHorizontalScrollBar(True)
  510. #
  511. # bindins
  512. #
  513. self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
  514. def OnDestroy(self, evt):
  515. """The clipboard contents can be preserved after
  516. the app has exited"""
  517. wx.TheClipboard.Flush()
  518. evt.Skip()
  519. def AddTextWrapped(self, txt, wrap=None):
  520. """Add string to text area.
  521. String is wrapped and linesep is also added to the end
  522. of the string"""
  523. if wrap is None and self.wrap:
  524. wrap = self.wrap
  525. if wrap is not None:
  526. txt = textwrap.fill(txt, wrap) + os.linesep
  527. else:
  528. txt += os.linesep
  529. self.AddText(txt)
  530. def SetWrap(self, wrap):
  531. """Set wrapping value
  532. @param wrap wrapping value
  533. @return current wrapping value
  534. """
  535. if wrap > 0:
  536. self.wrap = wrap
  537. return self.wrap