#!/usr/bin/python2.7
# -*- coding: utf-8 -*-

import os
import subprocess
from math import sqrt,ceil
from Tkinter import *
from tkMessageBox import *

class MaineClaine:
	def __init__(self):
        	self.window = Tk()
        	self.window.title("Комитет сельских дел. Главная счетная экспедиция")
        	self.window.resizable(1, 1)
        	self.workspace =  Frame(self.window,width=300,height=500, relief=FLAT)
        	self.workspace.grid(row=0, column=0)
        	lab = Label(self.workspace, text="МНК-аппроксимация", font="Courier 12 bold")
        	lab.grid(row=0, column=0, sticky="ewns")
        	self.btn = Button(self.workspace, text="Пуск")
        	self.btn["command"] = self.run
        	self.btn.grid(row=1, column=0)
        	lab = Label(self.workspace, text="	Линейные системы. Метод простых итераций", font="Courier 12 bold")
        	lab.grid(row=0, column=1, sticky="ewns")
        	self.btnp = Button(self.workspace, text="Пуск")
        	self.btnp["command"] = self.runp
        	self.btnp.grid(row=1, column=1)

        	lab = Label(self.workspace, text="Транспортная задача", font="Courier 12 bold")
        	lab.grid(row=3, column=0, sticky="ewns")
        	self.btnt = Button(self.workspace, text="Пуск")
        	self.btnt["command"] = self.runt
        	self.btnt.grid(row=4, column=0)
       	        lab = Label(self.workspace, text="Симплекс-метод", font="Courier 12 bold")
        	lab.grid(row=3, column=1, sticky="ewns")
        	self.btns = Button(self.workspace, text="Пуск")
        	self.btns["command"] = self.runs
        	self.btns.grid(row=4, column=1)

        	lab = Label(self.workspace, text="Вычисление погрешностей", font="Courier 12 bold")
        	lab.grid(row=5, column=0, sticky="ewns")
        	self.btno = Button(self.workspace, text="Пуск")
        	self.btno["command"] = self.runo
        	self.btno.grid(row=6, column=0)
       	        lab = Label(self.workspace, text="Выбор оптимальных стратегий", font="Courier 12 bold")
        	lab.grid(row=5, column=1, sticky="ewns")
        	self.btng = Button(self.workspace, text="Пуск")
        	self.btng["command"] = self.rung
        	self.btng.grid(row=6, column=1)

        	lab = Label(self.workspace, text="Вычисление интегралов(консоль)", font="Courier 12 bold")
        	lab.grid(row=7, column=0, sticky="ewns")
        	self.btni = Button(self.workspace, text="Пуск")
        	self.btni["command"] = self.runi
        	self.btni.grid(row=8, column=0)
       	        lab = Label(self.workspace, text="Решение нелинейных уравнений(консоль)", font="Courier 12 bold")
        	lab.grid(row=7, column=1, sticky="ewns")
        	self.btnu = Button(self.workspace, text="Пуск")
        	self.btnu["command"] = self.runu
        	self.btnu.grid(row=8, column=1)

       	        lab = Label(self.workspace, text="Метод Гаусса(интерактив)", font="Courier 12 bold")
        	lab.grid(row=9, column=0, sticky="ewns")
        	self.btngs = Button(self.workspace, text="Пуск")
        	self.btngs["command"] = self.rungs
        	self.btngs.grid(row=10, column=0)

       	        lab = Label(self.workspace, text="Решение нелинейных уравнений. Вычисление интегралов. Метод Эйлера", font="Courier 12 bold")
        	lab.grid(row=9, column=1, sticky="ewns")
        	self.btnc = Button(self.workspace, text="Запуск приложения с графическим интерфейсом")
        	self.btnc["command"] = self.runc
        	self.btnc.grid(row=10, column=1)

		lab = Label(self.workspace, text="Описание лабораторных работ ", font="Courier 12 bold")
        	lab.grid(row=11, column=1, sticky="ewns")
        	self.btndoc = Button(self.workspace, text="Нажми и читай с удовольствием")
        	self.btndoc["command"] = self.rundoc
        	self.btndoc.grid(row=12, column=1)

		lab = Label(self.workspace, text="Матричные вычисления", font="Courier 12 bold")
        	lab.grid(row=11, column=0, sticky="ewns")
        	self.btnpy = Button(self.workspace, text="Пуск")
        	self.btnpy["command"] = self.runpy
        	self.btnpy.grid(row=12, column=0)

        	self.window.mainloop()

	def run(self):
		PIPE = subprocess.PIPE
		cmd = 'python ~/kombain/mnk.py'
		p = subprocess.Popen(cmd, shell = True)
		p.wait() 
	def runpy(self):
		PIPE = subprocess.PIPE
		cmd = 'cd ~/kombain && python'
		p = subprocess.Popen(cmd, shell = True)
		p.wait() 
	def runp(self):
		PIPE = subprocess.PIPE
		cmd = 'python ~/kombain/simple_iter.py'
		p = subprocess.Popen(cmd, shell = True)
		p.wait() 
	def runt(self):
		PIPE = subprocess.PIPE
		cmd = 'python ~/kombain/opt.py'
		p = subprocess.Popen(cmd, shell = True)
		p.wait()
	def runs(self):
		PIPE = subprocess.PIPE
		tmp=os.getcwd()
		if tmp.split('/')[-1]=='kombain':
			cmd = 'gnome-open file://'+tmp+'/Simplex.html'
		else:	
			cmd = 'gnome-open file://'+tmp+'/kombain/Simplex.html'
		p = subprocess.Popen(cmd, shell = True)
		p.wait() 
	def rundoc(self):
		PIPE = subprocess.PIPE
		tmp=os.getcwd()
		if tmp.split('/')[-1]=='kombain':
			cmd = 'gnome-open file://'+tmp+'/pisk.html'
		else:	
			cmd = 'gnome-open file://'+tmp+'/kombain/pisk.html'
		p = subprocess.Popen(cmd, shell = True)
		p.wait() 
	def runo(self):
		PIPE = subprocess.PIPE
		tmp=os.getcwd()
		if tmp.split('/')[-1]=='kombain':
			cmd = 'gnome-open file://'+tmp+'/Calc_Error.htm'
		else:	
			cmd = 'gnome-open file://'+tmp+'/kombain/Calc_Error.htm'
		p = subprocess.Popen(cmd, shell = True)
		p.wait() 
	def rung(self):
		PIPE = subprocess.PIPE
		tmp=os.getcwd()
		if tmp.split('/')[-1]=='kombain':
			cmd = 'gnome-open file://'+tmp+'/games.htm'
		else:	
			cmd = 'gnome-open file://'+tmp+'/kombain/games.htm'
		p = subprocess.Popen(cmd, shell = True)
		p.wait() 
	def runi(self):
		PIPE = subprocess.PIPE
		cmd = '~/kombain/su'
		p = subprocess.Popen(cmd, shell = True)
		p.wait()
	def runu(self):
		PIPE = subprocess.PIPE
		cmd = '~/kombain/eq'
		p = subprocess.Popen(cmd, shell = True)
		p.wait()
	def runc(self):
		PIPE = subprocess.PIPE
		cmd = 'cd ~/kombain/ && java ru.cdml.mobimath.Maine'
		p = subprocess.Popen(cmd, shell = True)
		p.wait()
	def rungs(self):
		PIPE = subprocess.PIPE
		tmp=os.getcwd()
		if tmp.split('/')[-1]=='kombain':
			cmd = 'gnome-open file://'+tmp+'/Gauss.htm'
		else:	
			cmd = 'gnome-open file://'+tmp+'/kombain/Gauss.htm'
		p = subprocess.Popen(cmd, shell = True)
		p.wait()

MaineClaine()


