#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.6.8 on Tue Apr 21 15:01:06 2015
#


import wx
import subprocess
import threading
import time

# begin wxGlade: dependencies
import gettext
# end wxGlade

# begin wxGlade: extracode
# end wxGlade

class StartThread(threading.Thread):
  def __init__(self,ref):
        threading.Thread.__init__(self)
        self.ref = ref
  
  def run(self):
    # fetch a binary file
	subprocess.call(["sudo","apachectl","start"])
	
class StopThread(threading.Thread):
  def __init__(self,ref):
        threading.Thread.__init__(self)
        self.ref = ref
  
  def run(self):
    # fetch a binary file
	subprocess.call(["sudo","apachectl","stop"])

class RestartThread(threading.Thread):
  def __init__(self,ref):
        threading.Thread.__init__(self)
        self.ref = ref
  
  def run(self):
    # fetch a binary file
	time.sleep(5)
	subprocess.call(["sudo","apachectl","restart"])
		
class DownloadThread(threading.Thread):
  def __init__(self,ref):
        threading.Thread.__init__(self)
        self.ref = ref
  
  def run(self):
    # fetch a binary file
	pass

class UploadThread(threading.Thread):
  def __init__(self,ref):
        threading.Thread.__init__(self)
        self.ref = ref
  
  def run(self):
    # fetch a binary file
	pass


class MyFrame1(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame1.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.label_1 = wx.StaticText(self, wx.ID_ANY, _("Swerver"), style=wx.ALIGN_CENTRE)
        self.startButton = wx.Button(self, wx.ID_ANY, _("Start"))
        self.label_5 = wx.StaticText(self, wx.ID_ANY, _("\nServer Status\n"), style=wx.ALIGN_CENTRE)
        self.stopButton = wx.Button(self, wx.ID_ANY, _("Stop"))
        self.statusText = wx.StaticText(self, wx.ID_ANY, _("\nStatus\n"), style=wx.ALIGN_CENTRE)
        self.restartButton = wx.Button(self, wx.ID_ANY, _("Restart"))
        self.goButton = wx.Button(self, wx.ID_ANY, _("Go to Server"))
        self.uploadButton = wx.Button(self, wx.ID_ANY, _("Upload"))

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

    def __set_properties(self):
        # begin wxGlade: MyFrame1.__set_properties
        self.SetTitle(_("frame_2"))
        self.SetSize((459, 411))
        self.label_1.SetFont(wx.Font(15, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_5.SetFont(wx.Font(15, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.statusText.SetFont(wx.Font(13, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame1.__do_layout
        sizer_2 = wx.BoxSizer(wx.VERTICAL)
        grid_sizer_1 = wx.GridSizer(3, 2, 0, 0)
        sizer_2.Add(self.label_1, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 10)
        grid_sizer_1.Add(self.startButton, 0, wx.ALL | wx.EXPAND, 10)
        grid_sizer_1.Add(self.label_5, 0, wx.ALL | wx.EXPAND, 10)
        grid_sizer_1.Add(self.stopButton, 0, wx.ALL | wx.EXPAND, 10)
        grid_sizer_1.Add(self.statusText, 0, wx.ALL | wx.EXPAND, 10)
        grid_sizer_1.Add(self.restartButton, 0, wx.ALL | wx.EXPAND, 10)
        grid_sizer_1.Add(self.goButton, 0, wx.ALL | wx.EXPAND, 10)
        sizer_2.Add(grid_sizer_1, 1, wx.EXPAND, 0)
        sizer_2.Add(self.uploadButton, 0, wx.ALL | wx.EXPAND, 10)
        self.SetSizer(sizer_2)
        self.Layout()
        # end wxGlade

# end of class MyFrame1

class MyFrame2(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame2.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.label_4 = wx.StaticText(self, wx.ID_ANY, _("Welcome to Swerver!"), style=wx.ALIGN_CENTRE)
        self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("/home/michael/Pictures/Tire.jpg", wx.BITMAP_TYPE_ANY))
        self.initButton = wx.Button(self, wx.ID_ANY, _("Start Swerver"))

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

    def __set_properties(self):
        # begin wxGlade: MyFrame2.__set_properties
        self.SetTitle(_("frame_3"))
        self.SetSize((482, 443))
        self.label_4.SetFont(wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.bitmap_1.SetMinSize((462, 311))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame2.__do_layout
        sizer_3 = wx.BoxSizer(wx.VERTICAL)
        sizer_3.Add(self.label_4, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 10)
        sizer_3.Add(self.bitmap_1, 0, wx.ALL | wx.EXPAND, 10)
        sizer_3.Add(self.initButton, 0, wx.ALL | wx.EXPAND, 10)
        self.SetSizer(sizer_3)
        self.Layout()
        # end wxGlade
    
    def startButton(self,event):
        self.statusText.SetLabel("Start")
        startthread = StartThread(self)
        startthread.start()
        self.statusText.SetLabel("Running")

    def stopButton(self,event):
      #subprocess.call(["sudo","apachectl","stop"])
	    stopthread = StopThread(self)
            stopthread.start()
	    self.statusText.SetLabel("Stopped")

    def restartButton(self,event):
        #subprocess.call(["sudo","apachectl","restart"])
	    self.statusText.SetLabel("Stopped")	
	    restartthread = RestartThread(self)
            restartthread.start()
	    self.statusText.SetLabel("Runn")	

    def uploadButton(self,event):
        pass
    def goButton(self,event):
        pass
   

# end of class MyFrame2
if __name__ == "__main__":
    gettext.install("app") # replace with the appropriate catalog name

    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    mainwindow = (None, wx.ID_ANY, "")
    app.SetTopWindow(mainwindow)
    mainwindow.Show()
    app.MainLoop()
