#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Sun Mar  1 15:35:59 2009

import wx

# begin wxGlade: extracode
# end wxGlade



class DisplayDialog(wx.Dialog):
    def __init__(self, output_window, *args, **kwds):
        # begin wxGlade: DisplayDialog.__init__
        self.parent = kwds['parent']
        del kwds['parent']
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE

	self.outputwin = output_window

        wx.Dialog.__init__(self, *args, **kwds)
        self.sizer_5_staticbox = wx.StaticBox(self, -1, "Color and Font")
        self.radio_box_crlf = wx.RadioBox(self, -1, "newline", choices=["CRLF", "CR", "LF"], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
        self.radio_box_echo = wx.RadioBox(self, -1, "echo", choices=["off", "on"], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
        self.radio_box_unprintable = wx.RadioBox(self, -1, "unprintable", choices=["off", "on"], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
        self.button_font = wx.Button(self, -1, "font")
        self.button_forecolor = wx.Button(self, -1, "foreColor")
        self.button_backcolor = wx.Button(self, -1, "backColor")
        self.button_cancel = wx.Button(self, wx.ID_CANCEL, "", style=wx.BU_RIGHT|wx.BU_BOTTOM)
        self.button_ok = wx.Button(self, wx.ID_OK, "", style=wx.BU_RIGHT|wx.BU_BOTTOM)
        
        self.backupSettings()
        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_RADIOBOX, self.onRadioBoxCrlf, self.radio_box_crlf)
        self.Bind(wx.EVT_RADIOBOX, self.onRadionBoxEcho, self.radio_box_echo)
        self.Bind(wx.EVT_RADIOBOX, self.onRadioBoxUnprintable, self.radio_box_unprintable)
        self.Bind(wx.EVT_BUTTON, self.onFont, self.button_font)
        self.Bind(wx.EVT_BUTTON, self.onForecolor, self.button_forecolor)
        self.Bind(wx.EVT_BUTTON, self.onBackcolor, self.button_backcolor)
        self.Bind(wx.EVT_BUTTON, self.onCancel, self.button_cancel)
        self.Bind(wx.EVT_BUTTON, self.onOk, self.button_ok)
        # end wxGlade
        
        
    def __set_properties(self):
        # begin wxGlade: DisplayDialog.__set_properties
        _icon = wx.EmptyIcon()

	path = self.outputwin.workingdir

        _icon.CopyFromBitmap(wx.Bitmap(path + "/../images/zulu_logo16x16.png", wx.BITMAP_TYPE_ANY))
        self.SetIcon(_icon)        
        self.SetTitle("display settings")
        #initialize depend on settings
        self.radio_box_crlf.SetSelection(self.preNewline)  
        self.radio_box_echo.SetSelection(self.preEcho)
        self.radio_box_unprintable.SetSelection(self.preUnprintable)
        self.button_font.SetMinSize((65, 32))
        self.button_forecolor.SetMinSize((65, 29))
        self.button_backcolor.SetMinSize((65, 32))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: DisplayDialog.__do_layout
        sizer_3 = wx.BoxSizer(wx.VERTICAL)
        sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_5 = wx.StaticBoxSizer(self.sizer_5_staticbox, wx.HORIZONTAL)
        sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_4.Add(self.radio_box_crlf, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, 10)
        sizer_4.Add(self.radio_box_echo, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, 10)
        sizer_4.Add(self.radio_box_unprintable, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, 10)
        sizer_3.Add(sizer_4, 0, wx.ALL|wx.EXPAND, 8)
        sizer_5.Add(self.button_font, 0, wx.ALL|wx.EXPAND, 2)
        sizer_5.Add(self.button_forecolor, 1, wx.ALL|wx.EXPAND, 2)
        sizer_5.Add(self.button_backcolor, 1, wx.ALL, 2)
        sizer_3.Add(sizer_5, 1, wx.EXPAND, 0)
        sizer_6.Add(self.button_cancel, 0, wx.LEFT|wx.ALIGN_BOTTOM, 8)
        sizer_6.Add(self.button_ok, 0, wx.LEFT|wx.ALIGN_BOTTOM, 60)
        sizer_3.Add(sizer_6, 1, wx.ALL|wx.EXPAND, 5)
        self.SetSizer(sizer_3)
        sizer_3.Fit(self)
        self.Layout()
        # end wxGlade
    
    def backupSettings(self):
        """backup settings:when click cancel, we can come back
        """
        self.preFont = self.parent.settings.font
        self.preForecolor = self.parent.settings.forecolor
        self.preBackcolor = self.parent.settings.backcolor
        self.preNewline = self.parent.settings.newline
        self.preEcho = self.parent.settings.echo
        self.preUnprintable = self.parent.settings.unprintable
        
    def onRadioBoxCrlf(self, event): # wxGlade: DisplayDialog.<event_handler>
        self.parent.settings.newline = self.radio_box_crlf.GetSelection()

    def onRadionBoxEcho(self, event): # wxGlade: DisplayDialog.<event_handler>
        self.parent.settings.echo = self.radio_box_echo.GetSelection()

    def onRadioBoxUnprintable(self, event): # wxGlade: DisplayDialog.<event_handler>
        self.parent.settings.unprintable = self.radio_box_unprintable.GetSelection()

    def onFont(self, event): # wxGlade: DisplayDialog.<event_handler>
        data = wx.FontData()
        data.EnableEffects(True)
        #data.SetColour(self.curClr)         # set colour
        if self.parent.settings.font is not None:
            data.SetInitialFont(self.parent.settings.font)
        dlg = wx.FontDialog(self, data)
        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetFontData()
            self.font = data.GetChosenFont()
            self.parent.settings.font = self.font
            self.parent.updateTextctrl()
        dlg.Destroy()

    def onForecolor(self, event): # wxGlade: DisplayDialog.<event_handler>
        dlg = wx.ColourDialog(self)
        dlg.GetColourData().SetChooseFull(True)
        dlg.GetColourData().SetColour(self.parent.settings.forecolor)
        if dlg.ShowModal() == wx.ID_OK:
            self.forecolor = dlg.GetColourData().GetColour().Get()
            self.parent.settings.forecolor = self.forecolor
            self.parent.updateTextctrl()
        dlg.Destroy()

    def onBackcolor(self, event): # wxGlade: DisplayDialog.<event_handler>
        dlg = wx.ColourDialog(self)
        dlg.GetColourData().SetChooseFull(True)
        dlg.GetColourData().SetColour(self.parent.settings.backcolor)
        if dlg.ShowModal() == wx.ID_OK:
            self.backcolor = dlg.GetColourData().GetColour().Get()
            self.parent.settings.backcolor = self.backcolor
            self.parent.updateTextctrl()
        dlg.Destroy()

    def onCancel(self, event): # wxGlade: DisplayDialog.<event_handler>
        self.parent.settings.font = self.preFont
        self.parent.settings.forecolor = self.preForecolor
        self.parent.settings.backcolor = self.preBackcolor
        self.parent.settings.newline = self.preNewline
        self.parent.settings.echo = self.preEcho
        self.parent.settings.unprintable = self.preUnprintable
        self.parent.updateTextctrl()
        self.Destroy()

    def onOk(self, event): # wxGlade: DisplayDialog.<event_handler>
        self.Destroy()

# end of class DisplayDialog


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    display_dialog = DisplayDialog(None, -1, "")
    app.SetTopWindow(display_dialog)
    display_dialog.Show()
    app.MainLoop()
