goutput.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. """Return GRASS command thread"""
  34. return gcmd.CommandThread(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. time.sleep(.1) # wait for stdout
  335. if event.aborted:
  336. # Thread aborted (using our convention of None return)
  337. self.WriteLog(_('Please note that the data are left in incosistent stage '
  338. 'and can be corrupted'), self.cmd_output.StyleWarning)
  339. self.WriteCmdLog(_('Command aborted'),
  340. pid=self.cmdThread.requestId)
  341. else:
  342. try:
  343. # Process results here
  344. self.WriteCmdLog(_('Command finished (%d sec)') % (time.time() - event.time),
  345. pid=event.pid)
  346. except KeyError:
  347. # stopped deamon
  348. pass
  349. self.console_progressbar.SetValue(0) # reset progress bar on '0%'
  350. self.cmd_output_timer.Stop()
  351. # updated command dialog
  352. if hasattr(self.parent.parent, "btn_run"):
  353. dialog = self.parent.parent
  354. if hasattr(self.parent.parent, "btn_abort"):
  355. dialog.btn_abort.Enable(False)
  356. if hasattr(self.parent.parent, "btn_cancel"):
  357. dialog.btn_cancel.Enable(True)
  358. if hasattr(self.parent.parent, "btn_clipboard"):
  359. dialog.btn_clipboard.Enable(True)
  360. if hasattr(self.parent.parent, "btn_help"):
  361. dialog.btn_help.Enable(True)
  362. dialog.btn_run.Enable(True)
  363. if dialog.get_dcmd is None and \
  364. dialog.closebox.IsChecked():
  365. time.sleep(1)
  366. dialog.Close()
  367. event.Skip()
  368. def OnProcessPendingOutputWindowEvents(self, event):
  369. self.ProcessPendingEvents()
  370. class GMStdout:
  371. """GMConsole standard output
  372. Based on FrameOutErr.py
  373. Name: FrameOutErr.py
  374. Purpose: Redirecting stdout / stderr
  375. Author: Jean-Michel Fauth, Switzerland
  376. Copyright: (c) 2005-2007 Jean-Michel Fauth
  377. Licence: GPL
  378. """
  379. def __init__(self, parent):
  380. self.parent = parent # GMConsole
  381. def write(self, s):
  382. if len(s) == 0 or s == '\n':
  383. return
  384. s = s.replace('\n', os.linesep)
  385. for line in s.split(os.linesep):
  386. if len(line) == 0:
  387. continue
  388. evt = wxCmdOutput(text=line + os.linesep,
  389. type='')
  390. wx.PostEvent(self.parent.cmd_output, evt)
  391. class GMStderr:
  392. """GMConsole standard error output
  393. Based on FrameOutErr.py
  394. Name: FrameOutErr.py
  395. Purpose: Redirecting stdout / stderr
  396. Author: Jean-Michel Fauth, Switzerland
  397. Copyright: (c) 2005-2007 Jean-Michel Fauth
  398. Licence: GPL
  399. """
  400. def __init__(self, parent):
  401. self.parent = parent # GMConsole
  402. self.type = ''
  403. self.message = ''
  404. self.printMessage = False
  405. def write(self, s):
  406. s = s.replace('\n', os.linesep)
  407. # remove/replace escape sequences '\b' or '\r' from stream
  408. s = s.replace('\b', '').replace('\r', '%s' % os.linesep)
  409. progressValue = -1
  410. for line in s.split(os.linesep):
  411. if len(line) == 0:
  412. continue
  413. if 'GRASS_INFO_PERCENT' in line:
  414. value = int(line.rsplit(':', 1)[1].strip())
  415. if value >= 0 and value < 100:
  416. progressValue = value
  417. else:
  418. progressValue = 0
  419. elif 'GRASS_INFO_MESSAGE' in line:
  420. self.type = 'message'
  421. self.message = line.split(':', 1)[1].strip()
  422. elif 'GRASS_INFO_WARNING' in line:
  423. self.type = 'warning'
  424. self.message = line.split(':', 1)[1].strip()
  425. elif 'GRASS_INFO_ERROR' in line:
  426. self.type = 'error'
  427. self.message = line.split(':', 1)[1].strip()
  428. elif 'GRASS_INFO_END' in line:
  429. self.printMessage = True
  430. elif self.type == '':
  431. if len(line) == 0:
  432. continue
  433. evt = wxCmdOutput(text=line,
  434. type='')
  435. wx.PostEvent(self.parent.cmd_output, evt)
  436. elif len(line) > 0:
  437. self.message += line.strip() + os.linesep
  438. if self.printMessage and len(self.message) > 0:
  439. evt = wxCmdOutput(text=self.message,
  440. type=self.type)
  441. wx.PostEvent(self.parent.cmd_output, evt)
  442. self.type = ''
  443. self.message = ''
  444. self.printMessage = False
  445. # update progress message
  446. if progressValue > -1:
  447. # self.gmgauge.SetValue(progressValue)
  448. evt = wxCmdProgress(value=progressValue)
  449. wx.PostEvent(self.parent.console_progressbar, evt)
  450. class GMStc(wx.stc.StyledTextCtrl):
  451. """Styled GMConsole
  452. Based on FrameOutErr.py
  453. Name: FrameOutErr.py
  454. Purpose: Redirecting stdout / stderr
  455. Author: Jean-Michel Fauth, Switzerland
  456. Copyright: (c) 2005-2007 Jean-Michel Fauth
  457. Licence: GPL
  458. """
  459. def __init__(self, parent, id, margin=False, wrap=None):
  460. wx.stc.StyledTextCtrl.__init__(self, parent, id)
  461. self.parent = parent
  462. self.wrap = wrap
  463. #
  464. # styles
  465. #
  466. self.StyleDefault = 0
  467. self.StyleDefaultSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
  468. self.StyleCommand = 1
  469. self.StyleCommandSpec = "face:Courier New,size:10,fore:#000000,back:#bcbcbc"
  470. self.StyleOutput = 2
  471. self.StyleOutputSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
  472. # fatal error
  473. self.StyleError = 3
  474. self.StyleErrorSpec = "face:Courier New,size:10,fore:#7F0000,back:#FFFFFF"
  475. # warning
  476. self.StyleWarning = 4
  477. self.StyleWarningSpec = "face:Courier New,size:10,fore:#0000FF,back:#FFFFFF"
  478. # message
  479. self.StyleMessage = 5
  480. self.StyleMessageSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
  481. # unknown
  482. self.StyleUnknown = 6
  483. self.StyleUnknownSpec = "face:Courier New,size:10,fore:#7F0000,back:#FFFFFF"
  484. # default and clear => init
  485. self.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, self.StyleDefaultSpec)
  486. self.StyleClearAll()
  487. self.StyleSetSpec(self.StyleCommand, self.StyleCommandSpec)
  488. self.StyleSetSpec(self.StyleOutput, self.StyleOutputSpec)
  489. self.StyleSetSpec(self.StyleError, self.StyleErrorSpec)
  490. self.StyleSetSpec(self.StyleWarning, self.StyleWarningSpec)
  491. self.StyleSetSpec(self.StyleMessage, self.StyleMessageSpec)
  492. self.StyleSetSpec(self.StyleUnknown, self.StyleUnknownSpec)
  493. #
  494. # line margins
  495. #
  496. # TODO print number only from cmdlog
  497. self.SetMarginWidth(1, 0)
  498. self.SetMarginWidth(2, 0)
  499. if margin:
  500. self.SetMarginType(0, wx.stc.STC_MARGIN_NUMBER)
  501. self.SetMarginWidth(0, 30)
  502. else:
  503. self.SetMarginWidth(0, 0)
  504. #
  505. # miscellaneous
  506. #
  507. self.SetViewWhiteSpace(False)
  508. self.SetTabWidth(4)
  509. self.SetUseTabs(False)
  510. self.UsePopUp(True)
  511. self.SetSelBackground(True, "#FFFF00")
  512. self.SetUseHorizontalScrollBar(True)
  513. #
  514. # bindins
  515. #
  516. self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
  517. def OnDestroy(self, evt):
  518. """The clipboard contents can be preserved after
  519. the app has exited"""
  520. wx.TheClipboard.Flush()
  521. evt.Skip()
  522. def AddTextWrapped(self, txt, wrap=None):
  523. """Add string to text area.
  524. String is wrapped and linesep is also added to the end
  525. of the string"""
  526. if wrap is None and self.wrap:
  527. wrap = self.wrap
  528. if wrap is not None:
  529. txt = textwrap.fill(txt, wrap) + os.linesep
  530. else:
  531. txt += os.linesep
  532. self.AddText(txt)
  533. def SetWrap(self, wrap):
  534. """Set wrapping value
  535. @param wrap wrapping value
  536. @return current wrapping value
  537. """
  538. if wrap > 0:
  539. self.wrap = wrap
  540. return self.wrap