import wx
import ws

class PreviewCommandPanel(wx.Panel):
    
    def __init__(self, parent, cmd):
        wx.Panel.__init__(self, parent)
        self.txt = ws.SmTextCtrl(self, -1, "", size=(-1,55),
                                   style=wx.TE_MULTILINE|wx.TE_READONLY)
        self.txt.SetFont(ws.SmFont(wx.MODERN, wx.NORMAL, wx.NORMAL))
        if wx.Platform == "__WXMAC__": self.txt.MacCheckSpelling(False)
        self.SetContent(cmd)
        self.sz = wx.FlexGridSizer(1,1)#(wx.VERTICAL)
        self.sz.Add(self.txt, flag=wx.EXPAND|wx.TOP, border=12)
        self.SetSizerAndFit(self.sz)
        self.sz.AddGrowableRow(0)
        self.sz.AddGrowableCol(0)
        self.sz.RecalcSizes()
        self.sz.Layout()
        self.sz.Fit(self)
        
    def SetContent(self, cmd):
        # Try to wrap the string so it looks nice in the text control
        # (FIXME: this makes cutting and pasting a pain)
        #cmd = cmd.replace("-", "_")

        if False:
            cmd = cmd.replace("-", "_")
            cmd = textwrap.fill(cmd, 100, subsequent_indent="    ",
                                   break_long_words=False)
            cmd = cmd.replace("_", "-")
        self.txt.SetValue(cmd)