#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Tue Jun 17 16:13:04 2008

import wx, replath.preferences

# begin wxGlade: extracode
# end wxGlade

class MyDialog(wx.Dialog):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyDialog.__init__
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
        wx.Dialog.__init__(self, *args, **kwds)
        self.notebook_1_pane_2 = PreferencesPanel(self, -1)

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyDialog.__set_properties
        self.SetTitle("dialog_1")
        self.SetSize((748, 745))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyDialog.__do_layout
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_2.Add(self.notebook_1_pane_2, 0, wx.ADJUST_MINSIZE, 0)
        self.SetSizer(sizer_2)
        self.Layout()
        # end wxGlade

# end of class MyDialog


class PreferencesPanel(wx.Panel):
    def __init__(self, *args, **kwds):
        # begin wxGlade: PreferencesPanel.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.sizer_5_staticbox = wx.StaticBox(self, -1, "Serial Port :")
        self.sizer_4_staticbox = wx.StaticBox(self, -1, "Cartesian :")
        self.label_4 = wx.StaticText(self, -1, "Steps per mm : ")
        self.label_2 = wx.StaticText(self, -1, "X :")
        self.text_stepPermmX = wx.TextCtrl(self, -1, "")
        self.label_3 = wx.StaticText(self, -1, "Y :")
        self.text_stepPermmY = wx.TextCtrl(self, -1, "")
        self.label_10 = wx.StaticText(self, -1, "Z :")
        self.text_stepPermmZ = wx.TextCtrl(self, -1, "")
        self.label_5 = wx.StaticText(self, -1, "Print area limit (steps) : ")
        self.label_6 = wx.StaticText(self, -1, "X :")
        self.text_limitX = wx.TextCtrl(self, -1, "")
        self.label_7 = wx.StaticText(self, -1, "Y :")
        self.text_limitY = wx.TextCtrl(self, -1, "")
        self.checkbox_enableLimit = wx.CheckBox(self, -1, "Enable")
        self.label_13 = wx.StaticText(self, -1, "Torque (%) :")
        self.text_torque = wx.TextCtrl(self, -1, "")
        self.label_12 = wx.StaticText(self, -1, "Move speed (0-255) :")
        self.text_speed = wx.TextCtrl(self, -1, "")
        self.label_1 = wx.StaticText(self, -1, "Serial Port :")
        self.text_serialPort = wx.TextCtrl(self, -1, "")
        self.label_8 = wx.StaticText(self, -1, "Baud Rate :")
        self.text_baudRate = wx.TextCtrl(self, -1, "")
        self.label_9 = wx.StaticText(self, -1, "Timeout :")
        self.text_timeout = wx.TextCtrl(self, -1, "")

        self.__set_properties()
        self.__do_layout()
        # end wxGlade
        
        
        self.prefHandler = replath.preferences.PreferenceHandler(self,  "output_reprap.conf")
        
        # Default preferences
        self.pref_stepsPerMillimeterX, self.pref_stepsPerMillimeterY, self.pref_stepsPerMillimeterZ = 30, 30, 30
        self.pref_limitX, self.pref_limitY = 0, 0
        self.pref_enableLimit = False
        self.pref_torque = 65
        self.pref_speed = 180
        self.pref_serialPort = 0
        self.pref_baudRate = 19200
        self.pref_timeout = 60
        
        #self.prefHandler.save() #temp
        self.prefHandler.load()
        self.setPrefValues()

    def __set_properties(self):
        # begin wxGlade: PreferencesPanel.__set_properties
        pass
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: PreferencesPanel.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_5 = wx.StaticBoxSizer(self.sizer_5_staticbox, wx.VERTICAL)
        grid_sizer_2 = wx.FlexGridSizer(3, 3, 4, 0)
        sizer_4 = wx.StaticBoxSizer(self.sizer_4_staticbox, wx.VERTICAL)
        grid_sizer_3 = wx.FlexGridSizer(5, 3, 0, 0)
        grid_sizer_1 = wx.FlexGridSizer(2, 13, 4, 0)
        grid_sizer_1.Add(self.label_4, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.label_2, 0, wx.ALIGN_RIGHT|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.text_stepPermmX, 0, wx.EXPAND, 0)
        grid_sizer_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.label_3, 0, wx.ALIGN_RIGHT|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.text_stepPermmY, 0, wx.EXPAND, 0)
        grid_sizer_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.label_10, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.text_stepPermmZ, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.label_5, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.label_6, 0, wx.ALIGN_RIGHT|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.text_limitX, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.label_7, 0, wx.ALIGN_RIGHT|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.text_limitY, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.checkbox_enableLimit, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.AddGrowableCol(0)
        grid_sizer_1.AddGrowableCol(4)
        grid_sizer_1.AddGrowableCol(12)
        sizer_4.Add(grid_sizer_1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 10)
        grid_sizer_3.Add(self.label_13, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_3.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_3.Add(self.text_torque, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_3.Add(self.label_12, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_3.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_3.Add(self.text_speed, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_3.AddGrowableCol(2)
        sizer_4.Add(grid_sizer_3, 0, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 10)
        sizer_1.Add(sizer_4, 0, wx.ALL|wx.EXPAND, 10)
        grid_sizer_2.Add(self.label_1, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add(self.text_serialPort, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add(self.label_8, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add(self.text_baudRate, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add(self.label_9, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add((10, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add(self.text_timeout, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.AddGrowableCol(2)
        sizer_5.Add(grid_sizer_2, 1, wx.ALL|wx.EXPAND, 10)
        sizer_1.Add(sizer_5, 0, wx.ALL|wx.EXPAND, 10)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        # end wxGlade
    
        # Set values of frame control
    def setPrefValues(self):
        self.text_stepPermmX.SetValue( str(self.pref_stepsPerMillimeterX) )
        self.text_stepPermmY.SetValue( str(self.pref_stepsPerMillimeterY) )
        self.text_stepPermmZ.SetValue( str(self.pref_stepsPerMillimeterZ) )
        self.text_limitX.SetValue( str(self.pref_limitX) )
        self.text_limitY.SetValue( str(self.pref_limitY) )
        #self.text_limitZ.SetValue( str(self.pref_limitZ) )
        self.checkbox_enableLimit.SetValue( self.pref_enableLimit )
        self.text_torque.SetValue( str(self.pref_torque) )
        self.text_speed.SetValue( str(self.pref_speed) )
        self.text_serialPort.SetValue( str(self.pref_serialPort) )
        self.text_baudRate.SetValue( str(self.pref_baudRate) )
        self.text_timeout.SetValue( str(self.pref_timeout) )

    def savePrefValues(self):
        self.pref_stepsPerMillimeterX = int( self.text_stepPermmX.GetValue() )
        self.pref_stepsPerMillimeterY = int( self.text_stepPermmY.GetValue() )
        self.pref_stepsPerMillimeterZ = int( self.text_stepPermmZ.GetValue() )
        self.pref_limitX = int( self.text_limitX.GetValue() )
        self.pref_limitY = int( self.text_limitY.GetValue() )
        #self.pref_limitZ = int( self.text_limitZ.GetValue() )
        self.pref_enableLimit = self.checkbox_enableLimit.GetValue()
        self.pref_torque = int( self.text_torque.GetValue() )
        self.pref_speed = int( self.text_speed.GetValue() )
        self.pref_serialPort = int( self.text_serialPort.GetValue() )
        self.pref_baudRate = int( self.text_baudRate.GetValue() )
        self.pref_timeout = int( self.text_timeout.GetValue() )
        self.prefHandler.save()


# end of class PreferencesPanel


