

#----------------------------------------------------------------
# Title           : ClockPuncher3_debug.py
# Description     : Clock Punch program for contractors.
# Author          : Michael Stover
# Date            : 2015-05-21
# Version         : 3.0.3
# Usage           : python ClockPuncher3_debug.py
# Notes           :
# Python_version  : 2.7.5
#----------------------------------------------------------------

import sys
import os
import wx
import wx.lib.platebtn as PB
import wx.lib.agw.flatmenu as FM


class CustomFrame(wx.Frame):
    def __init__(self, parent, *arg, **kw):
        super(CustomFrame, self).__init__(parent, *arg, **kw)
        self.Bind(wx.EVT_MOTION, self.OnMouseMove)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

    def OnPaint(self, event):
        evtObj = event.GetEventObject()
        evtObjBG = evtObj.GetBackgroundColour()

        dc = wx.PaintDC(evtObj)
        dc = wx.GCDC(dc)
        w, h = self.GetSizeTuple()
        r = 10
        dc.SetPen( wx.Pen("#000000",3) )
        dc.SetBrush( wx.Brush(evtObjBG))
        dc.DrawRectangle( 0,0,w,h )

    def OnMouseMove(self, event):
        """implement dragging"""
        if not event.Dragging():
            self._dragPos = None
            return
        #self.CaptureMouse()
        if not self._dragPos:
            self._dragPos = event.GetPosition()
        else:
            pos = event.GetPosition()
            displacement = self._dragPos - pos
            self.SetPosition( self.GetPosition() - displacement )
        #self.ReleaseMouse()
        event.Skip()


class CustomPB(PB.PlateButton):
    def __init__(self, parent, *arg, **kw):
        super(CustomPB, self).__init__(parent, *arg, **kw)
        self.SetBackgroundColour(wx.WHITE)


class MainFrame(CustomFrame):
    def __init__(self, parent=None, *arg, **kw):
        super(MainFrame, self).__init__(parent, *arg, **kw)

        self.OnInitWidgets()
        self.OnInitMenu()
        self.OnInitLayout()
        self.OnBindEvents()

    def OnInitMenu(self):
      #-----------------------------------------------------------------
      # FlatMenuBar
        self.menuBar = FM.FlatMenuBar(self._panel, wx.ID_ANY, 32, 5,
            options=FM.FM_OPT_IS_LCD)
        self.menuBar.SetBackgroundColour(wx.WHITE)
      # File Menu
        self.f_menu = FM.FlatMenu()
        self.f_menu.Append(
            wx.ID_CLOSE,
            '&Close\tCtrl+X',
            'Exit the program',
            None
            )
        self.menuBar.Append(self.f_menu, "&File")

      # Help Menu
        self.h_menu = FM.FlatMenu()

        self.h_menu.Append(
            wx.NewId(),
            '&About',
            '',
        )

        self.menuBar.Append(self.h_menu, '&Help')

    def OnInitWidgets(self):
        self._panel = wx.Panel(self)
        self._panel.SetBackgroundColour(wx.Colour(220,220,220,255))

        self._titleBox = wx.StaticText(
            self._panel, -1, 'Flat Demo',
            style=wx.NO_BORDER|wx.TE_CENTER
        )
        self._titleBox.SetBackgroundColour(wx.WHITE)

      #-----------------------------------------------------------------
      # Buttons and TextCtrls
        self.btnOne = CustomPB(
                                self._panel,
                                id=wx.NewId(),
                                label='Button 1',
                                style=wx.SIMPLE_BORDER,
                                size=(93,-1)
                                )

        self.btnTwo = CustomPB(
                                self._panel,
                                id=wx.NewId(),
                                label='Button 2',
                                style=wx.SIMPLE_BORDER,
                                size=(93,-1)
                                )

        self.btnThree = CustomPB(
                                self._panel,
                                id=wx.NewId(),
                                label='Button 3',
                                style=wx.SIMPLE_BORDER,
                                size=(93,-1)
                                )

        self.btnFour = CustomPB(
                                self._panel,
                                id=wx.NewId(),
                                label='Button 4',
                                style=wx.SIMPLE_BORDER,
                                size=(93,-1)
                                )

        self._mouseList = [self._panel, self._titleBox]

    def OnInitLayout(self):
        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        panelSizer = wx.BoxSizer(wx.VERTICAL)
        titleSizer = wx.BoxSizer(wx.HORIZONTAL)
        menuSizer = wx.BoxSizer(wx.HORIZONTAL)

        titleSizer.Add(self._titleBox, 1, wx.ALL|wx.EXPAND|wx.CENTER,1)

        menuSizer.Add(self.menuBar, 1, wx.EXPAND, 1)

        widgetSizer = wx.FlexGridSizer(rows=4, cols=1, vgap=1, hgap=2)
        widgetSizer.AddMany(
            [
                (self.btnOne,   1, wx.ALL|wx.EXPAND, 3),
                (self.btnTwo,   1, wx.ALL|wx.EXPAND, 3),
                (self.btnThree, 1, wx.ALL|wx.EXPAND, 3),
                (self.btnFour,  1, wx.ALL|wx.EXPAND, 3),
            ]
        )

        panelSizer.Add(titleSizer, 0, wx.ALL|wx.EXPAND, 2)
        panelSizer.Add(menuSizer, 0, wx.ALL|wx.EXPAND, 3)
        panelSizer.Add(widgetSizer, 3, wx.EXPAND,1)
        self._panel.SetSizer(panelSizer)

        mainSizer.Add(self._panel, 1, wx.ALL|wx.EXPAND, 2)
        self.SetSizerAndFit(mainSizer)
        self.SetPosition( (400,300) )
        self.Layout()

    def OnBindEvents(self):
        for _widget in self._mouseList:
            _widget.Bind(wx.EVT_MOTION, self.OnMouseMove)
        self.Bind(wx.EVT_MENU, self.OnClose, id = wx.ID_CLOSE)

    def OnClose(self, event):
        self.Close(force=True)


def RunApp():
    app = wx.App()
    frame = MainFrame(title='Flat Demo',
        style = ( wx.CLIP_CHILDREN | wx.NO_BORDER )
    )
    frame.Show()
    app.MainLoop()

if __name__ == '__main__':
    RunApp()