#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Mon Jul 21 19:56:38 2008

import wx, sys, os, reprap

# begin wxGlade: extracode
# end wxGlade


if sys.platform=="win32":
    # Windows (taking path of this script)
    iconPath = os.path.join( os.getcwd(), "graphics" )
else:
    # Linux
    iconPath = "/usr/share/reprap/icons/"

appIcon = os.path.join(iconPath, "reprap.png")


class AxiesPanel(wx.Panel):
    def __init__(self, *args, **kwds):
        # begin wxGlade: AxiesPanel.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.sizer_axies_staticbox = wx.StaticBox(self, -1, "Axies")
        self.label_1 = wx.StaticText(self, -1, "X:")
        self.slider_x = wx.Slider(self, -1, 0, 0, 10)
        self.gauge_x = wx.Gauge(self, -1, 10)
        self.button_home_x = wx.Button(self, wx.ID_HOME, "")
        self.checkbox_torque_x = wx.CheckBox(self, -1, "Torque")
        self.label_1_copy = wx.StaticText(self, -1, "Y:")
        self.slider_y = wx.Slider(self, -1, 0, 0, 10)
        self.gauge_y = wx.Gauge(self, -1, 10)
        self.button_home_y = wx.Button(self, wx.ID_HOME, "")
        self.checkbox_torque_y = wx.CheckBox(self, -1, "Torque")
        self.label_1_copy_1 = wx.StaticText(self, -1, "Z:")
        self.slider_z = wx.Slider(self, -1, 0, 0, 10)
        self.gauge_z = wx.Gauge(self, -1, 10)
        self.button_home_z = wx.Button(self, wx.ID_HOME, "")
        self.checkbox_torque_z = wx.CheckBox(self, -1, "Torque")

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

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

    def __do_layout(self):
        # begin wxGlade: AxiesPanel.__do_layout
        sizer_9 = wx.BoxSizer(wx.VERTICAL)
        sizer_axies = wx.StaticBoxSizer(self.sizer_axies_staticbox, wx.VERTICAL)
        sizer_10 = wx.BoxSizer(wx.VERTICAL)
        sizer_3_copy_1 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_4_copy_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_5_copy_1 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_3_copy = wx.BoxSizer(wx.HORIZONTAL)
        sizer_4_copy = wx.BoxSizer(wx.VERTICAL)
        sizer_5_copy = wx.BoxSizer(wx.HORIZONTAL)
        sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_4 = wx.BoxSizer(wx.VERTICAL)
        sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_3.Add(self.label_1, 0, wx.ADJUST_MINSIZE, 0)
        sizer_3.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        sizer_4.Add(self.slider_x, 0, wx.EXPAND|wx.FIXED_MINSIZE, 0)
        sizer_4.Add(self.gauge_x, 0, wx.EXPAND|wx.FIXED_MINSIZE, 0)
        sizer_5.Add(self.button_home_x, 1, wx.ADJUST_MINSIZE|wx.FIXED_MINSIZE, 0)
        sizer_5.Add(self.checkbox_torque_x, 1, wx.ADJUST_MINSIZE|wx.FIXED_MINSIZE, 0)
        sizer_4.Add(sizer_5, 1, wx.EXPAND, 0)
        sizer_3.Add(sizer_4, 1, wx.EXPAND, 0)
        sizer_10.Add(sizer_3, 0, wx.ALL|wx.EXPAND, 5)
        sizer_3_copy.Add(self.label_1_copy, 0, wx.ADJUST_MINSIZE, 0)
        sizer_3_copy.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        sizer_4_copy.Add(self.slider_y, 0, wx.EXPAND|wx.FIXED_MINSIZE, 0)
        sizer_4_copy.Add(self.gauge_y, 0, wx.EXPAND|wx.FIXED_MINSIZE, 0)
        sizer_5_copy.Add(self.button_home_y, 1, wx.ADJUST_MINSIZE|wx.FIXED_MINSIZE, 0)
        sizer_5_copy.Add(self.checkbox_torque_y, 1, wx.ADJUST_MINSIZE|wx.FIXED_MINSIZE, 0)
        sizer_4_copy.Add(sizer_5_copy, 1, wx.EXPAND, 0)
        sizer_3_copy.Add(sizer_4_copy, 1, wx.EXPAND, 0)
        sizer_10.Add(sizer_3_copy, 0, wx.ALL|wx.EXPAND, 5)
        sizer_3_copy_1.Add(self.label_1_copy_1, 0, wx.ADJUST_MINSIZE, 0)
        sizer_3_copy_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        sizer_4_copy_1.Add(self.slider_z, 0, wx.EXPAND|wx.FIXED_MINSIZE, 0)
        sizer_4_copy_1.Add(self.gauge_z, 0, wx.EXPAND|wx.FIXED_MINSIZE, 0)
        sizer_5_copy_1.Add(self.button_home_z, 1, wx.ADJUST_MINSIZE|wx.FIXED_MINSIZE, 0)
        sizer_5_copy_1.Add(self.checkbox_torque_z, 1, wx.ADJUST_MINSIZE|wx.FIXED_MINSIZE, 0)
        sizer_4_copy_1.Add(sizer_5_copy_1, 1, wx.EXPAND, 0)
        sizer_3_copy_1.Add(sizer_4_copy_1, 1, wx.EXPAND, 0)
        sizer_10.Add(sizer_3_copy_1, 0, wx.ALL|wx.EXPAND, 5)
        sizer_axies.Add(sizer_10, 1, wx.ALL|wx.EXPAND, 10)
        sizer_9.Add(sizer_axies, 1, wx.ALL|wx.EXPAND, 10)
        self.SetSizer(sizer_9)
        sizer_9.Fit(self)
        # end wxGlade

# end of class AxiesPanel


class MovePanel(wx.Panel):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MovePanel.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.sizer_buttonMove_staticbox = wx.StaticBox(self, -1, "X-Y Move")
        self.button_up = wx.BitmapButton(self, -1, (wx.Bitmap( os.path.join(iconPath, 'go-up.png'))))
        self.button_left = wx.BitmapButton(self, -1, (wx.Bitmap( os.path.join(iconPath, 'go-previous.png'))))
        self.button_right = wx.BitmapButton(self, -1, (wx.Bitmap( os.path.join(iconPath, 'go-next.png'))))
        self.button_down = wx.BitmapButton(self, -1, (wx.Bitmap( os.path.join(iconPath, 'go-down.png'))))
        self.label_2 = wx.StaticText(self, -1, "Speed :")
        self.slider_speed = wx.Slider(self, -1, 0, 0, 255, style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_LABELS)
        self.label_2_copy = wx.StaticText(self, -1, "Steps :")
        self.slider_steps = wx.Slider(self, -1, 0, 0, 1000, style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_LABELS)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.onClickUp, self.button_up)
        self.Bind(wx.EVT_BUTTON, self.onClickLeft, self.button_left)
        self.Bind(wx.EVT_BUTTON, self.onClickRight, self.button_right)
        self.Bind(wx.EVT_BUTTON, self.onClickDown, self.button_down)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MovePanel.__set_properties
        self.button_up.SetSize(self.button_up.GetBestSize())
        self.button_left.SetSize(self.button_left.GetBestSize())
        self.button_right.SetSize(self.button_right.GetBestSize())
        self.button_down.SetSize(self.button_down.GetBestSize())
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MovePanel.__do_layout
        sizer_8 = wx.BoxSizer(wx.VERTICAL)
        sizer_buttonMove = wx.StaticBoxSizer(self.sizer_buttonMove_staticbox, wx.VERTICAL)
        sizer_8_copy = wx.BoxSizer(wx.VERTICAL)
        grid_sizer_2 = wx.FlexGridSizer(2, 2, 10, 10)
        grid_sizer_1 = wx.GridSizer(4, 3, 0, 0)
        grid_sizer_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.button_up, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.button_left, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.button_right, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.button_down, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        sizer_8_copy.Add(grid_sizer_1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 30)
        grid_sizer_2.Add(self.label_2, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add(self.slider_speed, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add(self.label_2_copy, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.Add(self.slider_steps, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_2.AddGrowableCol(1)
        sizer_8_copy.Add(grid_sizer_2, 0, wx.EXPAND, 0)
        sizer_buttonMove.Add(sizer_8_copy, 1, wx.ALL|wx.EXPAND, 10)
        sizer_8.Add(sizer_buttonMove, 1, wx.ALL|wx.EXPAND, 10)
        self.SetSizer(sizer_8)
        sizer_8.Fit(self)
        # end wxGlade


    def onClickUp(self, event): # wxGlade: MovePanel.<event_handler>
        x, y, z = reprap.cartesian.getPos()
        reprap.cartesian.seek( ( None, y + int( self.slider_steps.GetValue() ), None ), waitArrival = True, speed = int( self.slider_speed.GetValue() ) )
    
    def onClickLeft(self, event): # wxGlade: MovePanel.<event_handler>
        x, y, z = reprap.cartesian.getPos()
        reprap.cartesian.seek( ( x - int( self.slider_steps.GetValue() ), None, None ), waitArrival = True, speed = int( self.slider_speed.GetValue() ) )
    
    def onClickRight(self, event): # wxGlade: MovePanel.<event_handler>
        x, y, z = reprap.cartesian.getPos()
        reprap.cartesian.seek( ( x + int( self.slider_steps.GetValue() ), None, None ), waitArrival = True, speed = int( self.slider_speed.GetValue() ) )
    
    def onClickDown(self, event): # wxGlade: MovePanel.<event_handler>
        x, y, z = reprap.cartesian.getPos()
        reprap.cartesian.seek( ( None, y - int( self.slider_steps.GetValue() ), None ), waitArrival = True, speed = int( self.slider_speed.GetValue() ) )

# end of class MovePanel


class MainControlFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MainControlFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.panel_main = wx.Panel(self, -1)
        
        # Tool Bar
        self.frame_main_toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL|wx.TB_TEXT|wx.TB_NOICONS)
        self.SetToolBar(self.frame_main_toolbar)
        self.frame_main_toolbar.AddLabelTool(100, "Home Reset", wx.NullBitmap, wx.NullBitmap, wx.ITEM_NORMAL, "", "")
        self.frame_main_toolbar.AddLabelTool(101, "Torque", wx.NullBitmap, wx.NullBitmap, wx.ITEM_CHECK, "", "")
        # Tool Bar end
        self.panel_axies = AxiesPanel(self.panel_main, -1)
        self.panel_move = MovePanel(self.panel_main, -1)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_TOOL, self.onClickHomeResetAll, id=100)
        self.Bind(wx.EVT_TOOL, self.onTorqueAllToggle, id=101)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MainControlFrame.__set_properties
        self.SetTitle("RepRap Control")
        self.frame_main_toolbar.Realize()
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MainControlFrame.__do_layout
        sizer_main = wx.BoxSizer(wx.VERTICAL)
        sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_1.Add(self.panel_axies, 1, wx.EXPAND, 0)
        sizer_1.Add(self.panel_move, 1, wx.EXPAND, 0)
        self.panel_main.SetSizer(sizer_1)
        sizer_main.Add(self.panel_main, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_main)
        sizer_main.Fit(self)
        self.Layout()
        # end wxGlade


    def onTorqueAllToggle(self, event): # wxGlade: MainControlFrame.<event_handler>
        print "Event handler `onTorqueAllToggle' not implemented!"
        event.Skip()

    def onClickHomeResetAll(self, event): # wxGlade: MainControlFrame.<event_handler>
        reprap.cartesian.homeReset(waitArrival = True)
        reprap.cartesian.free()

# end of class MainControlFrame



