1

I am trying to create a command terminal like window..I have used the following code..Problem is that it set the command prompt as ">>>" that is editable.

I want window with fixed ">>>" with cursor waiting for command...now the issue is that user can easily delete ">>>" as it is a simple text..

Is it any way to fixed this par of text in we.textctrl or in any other control.

class MyFrame(wx.Frame):

def __init__(self, parent, title):
       wx.Frame.__init__(self, parent, title=title, size=(400,400))
       self.SetPosition(wx.Point(0,0))                           
       self.cmdArea = wx.TextCtrl(self, style=wx.TE_MULTILINE)          
       self.cmdArea.SetValue(">>>")                
       self.Show(True)
user2764578
  • 61
  • 3
  • 10

2 Answers2

-1

Capture the backspace event and then check if the preceding characters are ">>>". If so ignore the event.

anderspitman
  • 9,230
  • 10
  • 40
  • 61
  • ...And what if the user types more than two `>` in a row? I'm going to take a stab in the dark here and say the OP doesn't want to infuriate the user for no good reason. – Parthian Shot Aug 04 '14 at 18:59
  • Obviously not a complete solution, but it gets him pointed toward one. Creating logic to detect >>> at the beginning of a line isn't that hard. Regular expressions is one way. – anderspitman Aug 04 '14 at 19:02
  • can you please help me with example – user2764578 Aug 04 '14 at 19:25
  • `Creating logic to detect >>> at the beginning of a line isn't that hard. Regular expressions is one way.` My issue with your answer is more fundamental; it's agnostic as to whether or not the input was generated by a program within the shell, or the shell itself, or the user. If multiline strings are allowed, which any decent shell should be able to handle, your solution still has drawbacks. Basically, you're suggesting a dumb terminal implementation, which [can lead to some pretty insidious issues](http://www.jwz.org/gruntle/ctrlh.html). – Parthian Shot Aug 04 '14 at 19:32
  • Sounds like you're familiar enough with this domain to provide a more complete and usable answer. – anderspitman Aug 04 '14 at 19:37
  • While flattering, I'm unfamiliar with wxwidgets. And I feel like the best answer will depend somewhat on the underlying tools. Besides which, I'm not sure what the canonical answer might be (I've only ever written small shells), so I'll fade into the shadows for now. – Parthian Shot Aug 04 '14 at 19:46
-1

If you google for "terminal widget for wxwindows", you should find this one.

It doesn't come with Python bindings, though. So you'll have to roll your own.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94