import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from gui import GuiWidget
import socket
from grass import *
import os
import subprocess
import psycopg2
from datetime import datetime


clon = 0
clat = 0
item = 'LookAt'
head = '0'


filepath = str('/Users/sasha/Desktop/gps/')

a = [str('LookAt'),str('Camera')]
rasterlist = list_strings('rast')
vectorlist = list_strings('vect')
regionlist = list_strings('region')
grassenv = gisenv()
rasterpath = grassenv['GISDBASE']+str('/')+grassenv['LOCATION_NAME']+str('/')+grassenv['MAPSET']+str('/cellhd/')
vectorpath = grassenv['GISDBASE']+str('/')+grassenv['LOCATION_NAME']+str('/')+grassenv['MAPSET']+str('/vector/')

#try:
#	conn = psycopg2.connect("dbname='geoname' user='postgres' host='localhost' password='tiamo'");
#except:
#	print "I am unable to connect to the database"
#curs = conn.cursor()

user = ''
dbname = ''
host = ''
passwd = ''

Gtype = str('region')




class MyClass(QObject):
	
    def init(self):
        global slvallat
        global slvallon
        self.Value=0
        self.ZoomValue = 0
        self.w = GuiWidget()
        self.connect(self.w.exit, SIGNAL("clicked()"), qApp, SLOT("quit()"))
        self.raster = self.RasterList()
        self.vector = self.VectorList()
        self.region = self.RegionList()
        self.tl = self.TypeList()    
        self.w.InputRaster.addItems(self.raster)
        self.w.InputVector.addItems(self.vector)
        self.w.InputImage.addItems(self.raster)
        self.w.InputRegion.addItems(self.region)
        self.w.InputType.addItems(self.tl) 
        self.connect(self.w.GrassType, SIGNAL("currentIndexChanged(int)"),self.GetType)
        self.connect(self.w.ZoomSlider, SIGNAL("valueChanged(int)"), self.setValueZoomSpinBox)
        self.connect(self.w.ZoomSlider, SIGNAL("valueChanged(int)"), self.sendFunction)
        self.connect(self.w.ZoomSpinBox, SIGNAL("valueChanged(double)"), self.setValueZoomSlider)
        self.connect(self.w.ZoomSpinBox, SIGNAL("valueChanged(double)"), self.sendFunction)
        self.connect(self.w.ZoomSlider, SIGNAL("valueChanged()"), self.setValue)
        self.connect(self.w.ZoomSpinBox, SIGNAL("valueChanged()"), self.setValue)
        self.connect(self.w.RangeSlider, SIGNAL("valueChanged(int)"), self.setValueRangeSpinBox)
        self.connect(self.w.RangeSlider, SIGNAL("valueChanged(int)"), self.sendFunction)
        self.connect(self.w.RangeSpinBox, SIGNAL("valueChanged(double)"), self.setValueRangeSlider)
        self.connect(self.w.RangeSpinBox, SIGNAL("valueChanged(double)"), self.sendFunction)
        self.connect(self.w.RangeSlider, SIGNAL("valueChanged()"), self.setValue)
        self.connect(self.w.RangeSpinBox, SIGNAL("valueChanged()"), self.setValue)
        self.connect(self.w.RollSlider, SIGNAL("valueChanged(int)"), self.setValueRollSpinBox)
        self.connect(self.w.RollSlider, SIGNAL("valueChanged(int)"), self.sendFunction)
        self.connect(self.w.RollSpinBox, SIGNAL("valueChanged(double)"), self.setValueRollSlider)
        self.connect(self.w.RollSpinBox, SIGNAL("valueChanged(double)"), self.sendFunction)
        self.connect(self.w.RollSlider, SIGNAL("valueChanged()"), self.setValue)
        self.connect(self.w.RollSpinBox, SIGNAL("valueChanged()"), self.setValue)
        self.connect(self.w.PitchSlider, SIGNAL("valueChanged(int)"), self.setValuePitchSpinBox)
        self.connect(self.w.PitchSlider, SIGNAL("valueChanged(int)"), self.sendFunction)
        self.connect(self.w.PitchSpinBox, SIGNAL("valueChanged(double)"), self.setValuePitchSlider)
        self.connect(self.w.PitchSpinBox, SIGNAL("valueChanged(double)"), self.sendFunction)
        self.connect(self.w.PitchSlider, SIGNAL("valueChanged()"), self.setValue)
        self.connect(self.w.PitchSpinBox, SIGNAL("valueChanged()"), self.setValue)
        self.connect(self.w.HandlingSlider, SIGNAL("valueChanged(int)"), self.setValueHandlingSpinBox)
        self.connect(self.w.HandlingSlider, SIGNAL("valueChanged(int)"), self.sendFunction)
        self.connect(self.w.HandlingSpinBox, SIGNAL("valueChanged(double)"), self.setValueHandlingSlider)
        self.connect(self.w.HandlingSpinBox, SIGNAL("valueChanged(double)"), self.sendFunction)
        self.connect(self.w.HandlingSlider, SIGNAL("valueChanged()"), self.setValue)
        self.connect(self.w.HandlingSpinBox, SIGNAL("valueChanged()"), self.setValue)
        ##self.connect(self.w.SpeedSlider, SIGNAL("valueChanged(int)"), self.setValueSpeedSpinBox)
        self.connect(self.w.SpeedSpinBox, SIGNAL("valueChanged(double)"), self.setValueSpeedSpinBox)
        ##self.connect(self.w.SpeedSlider, SIGNAL("valueChanged()"), self.setValue)
        self.connect(self.w.SpeedSpinBox, SIGNAL("valueChanged()"), self.setValue)
        self.w.north.setAutoRepeat(True)
        self.w.northeast.setAutoRepeat(True)
        self.w.south.setAutoRepeat(True)
        self.w.east.setAutoRepeat(True)
        self.w.west.setAutoRepeat(True)
        self.w.southwest.setAutoRepeat(True)
        self.w.northwest.setAutoRepeat(True)
        self.w.southeast.setAutoRepeat(True)
        self.connect(self.w.north, SIGNAL("clicked()"),self.inclat)
        self.connect(self.w.northeast, SIGNAL("clicked()"),self.inclatlon)
        self.connect(self.w.south, SIGNAL("clicked()"),self.declat)
        self.connect(self.w.east, SIGNAL("clicked()"),self.inclon)
        self.connect(self.w.west, SIGNAL("clicked()"),self.declon)
        self.connect(self.w.southwest, SIGNAL("clicked()"),self.declatlon)
        self.connect(self.w.northwest, SIGNAL("clicked()"),self.inclatdeclon)
        self.connect(self.w.southeast, SIGNAL("clicked()"),self.declatinclon)
        self.connect(self.w.center, SIGNAL("clicked()"),self.setcenter)
        self.slvallon = self.setcenter()[0]
        self.slvallat = self.setcenter()[1]
        self.slstep = 1
        self.connect(self.w.Head, SIGNAL("currentIndexChanged(int)"),self.GetHead)
        self.connect(self.w.View, SIGNAL("currentIndexChanged(int)"),self.GetViewType)
        self.connect(self.w.State, SIGNAL("currentIndexChanged(int)"),self.GetState) 
        self.w.show()

    def setValueZoomSpinBox(self, z):
        self.ZoomValue = float(z)
        self.w.ZoomSpinBox.setRange(-100, 27536977)
        self.w.ZoomSpinBox.setSingleStep(1)
        self.w.ZoomSpinBox.setValue(self.ZoomValue)

    def setValueZoomSlider(self, z):
        self.ZoomValue = int(z)
        self.w.ZoomSlider.setMinimum(-100)
        self.w.ZoomSlider.setMaximum(27536977)
        self.w.ZoomSlider.setValue(self.ZoomValue)

    def setValueRangeSpinBox(self, r):
        self.RangeValue = float(r)
        self.w.RangeSpinBox.setRange(-100, 27536977)
        self.w.RangeSpinBox.setSingleStep(1)
        self.w.RangeSpinBox.setValue(self.RangeValue)

    def setValueRangeSlider(self, r):
        self.RangeValue = int(r)
        self.w.RangeSlider.setMinimum(-100)
        self.w.RangeSlider.setMaximum(27536977)
        self.w.RangeSlider.setValue(self.RangeValue)

    def setValueRollSpinBox(self, rl):
        self.RollValue = float(rl)
        self.w.RollSpinBox.setRange(-90, 90)
        self.w.RollSpinBox.setSingleStep(1)
        self.w.RollSpinBox.setValue(self.RollValue)

    def setValueRollSlider(self, rl):
        self.RollValue = int(rl)
        self.w.RollSlider.setMinimum(-90)
        self.w.RollSlider.setMaximum(90)
        self.w.RollSlider.setValue(self.RollValue)


    def setValuePitchSpinBox(self, p):
        self.PitchValue = float(p)
        self.w.PitchSpinBox.setRange(-90, 90)
        self.w.PitchSpinBox.setSingleStep(1)
        self.w.PitchSpinBox.setValue(self.PitchValue)

    def setValuePitchSlider(self, p):
        self.PitchValue = int(p)
        self.w.PitchSlider.setMinimum(-90)
        self.w.PitchSlider.setMaximum(90)
        self.w.PitchSlider.setValue(self.PitchValue)

    def setValueHandlingSpinBox(self, h):
        self.HandlingValue = float(h)
        self.w.HandlingSpinBox.setRange(-360, 360)
        self.w.HandlingSpinBox.setSingleStep(1)
        self.w.HandlingSpinBox.setValue(self.HandlingValue)

    def setValueHandlingSlider(self, h):
        self.HandlingValue = int(h)
        self.w.HandlingSlider.setMinimum(-360)
        self.w.HandlingSlider.setMaximum(360)
        self.w.HandlingSlider.setValue(self.HandlingValue)


    def setValueSpeedSpinBox(self, s):
        self.SpeedValue = float(s)
        self.w.SpeedSpinBox.setRange(0.01, 1)
        self.w.SpeedSpinBox.setSingleStep(0.01)
        self.w.SpeedSpinBox.setValue(self.SpeedValue)

    def GetHead(self,index):
        head = self.w.Head.itemText(index)
        print head
        if head == str('N'):
            head = str('0')
        if head == str('NE'):
            head = str('45') 
        if head == str('E'):
            head = str('90')
        if head == str('SE'):
            head = str('135')
        if head == str('S'):
            head = str('180')
        if head == str('SW'):
            head = str('-135')
        if head == str('W'):
            head = str('-90')
        if head == str('NW'):
            head = str('-45')
        if head == str('Auto'):
            head = str('angle')
        if head == str('Manual'):
            head = str('Manual')
        f = open(filepath+'HeadingMode', "w") 
        f.write(head)
        f.close


    def GetViewType(self,index):
        ViewT = self.w.View.itemText(index)
        print ViewT


    def GetState(self,index):
        State = self.w.State.itemText(index)
        print State
        f = open(filepath+'Run', "w")
        f.write(State)
        f.close


    def sendFunction(self):
        if self.w.Gps.isChecked():
            f = open(filepath+'Run', "w")
            f.write(str('start'))
            f.close
            f = open(filepath+'CameraSettings', "w")
            f.write(unicode(self.w.ZoomSlider.value())+str(" ")+unicode(self.w.HandlingSlider.value())+str(" ")+unicode(self.w.PitchSlider.value())+str(" ")+unicode(self.w.RollSlider.value())+str(" ")+unicode(self.w.RangeSlider.value())+str(" ")+item)
            f.close()
        else:
            f = open(filepath+'Run', "w")
            f.write(str('stop'))
            f.close
            R = open(filepath+'HeadingMode', "r")
            K = R.read()
            Y = K.rsplit(' ')
            T = len(Y)
            if T == 1:
                if str(Y[0]) == str('Manual'):
                    head = self.w.HandlingSlider.value()
                if str(Y[0]) != str('Manual'):
                    head = Y[0]
            ossimxml = '<Set target=":navigator" vref="wgs84"><%s><longitude>%s</longitude><latitude>%s</latitude><altitude>%s</altitude><heading>%s</heading><pitch>%s</pitch><roll>%s</roll><altitudeMode>absolute</altitudeMode><range>%s</range></%s></Set>' % (item, unicode(self.slvallon), unicode(self.slvallat), self.w.ZoomSlider.value(), head, self.w.PitchSlider.value() , self.w.RollSlider.value(),self.w.RangeSlider.value(), item)
            ossim = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            ossim.connect(("127.0.0.1", 7000))
            ossim.send(ossimxml)
            ossim.close()
            #print ossimxml
	    #print str("Lon")+str(" : ")+unicode(self.XtraslateLineEdit.text())
	    #print str("Lat")+str(" : ")+unicode(self.YtraslateLineEdit.text())
	    print str("altitude")+str(" : ")+str(self.w.ZoomSlider.value())
	    print str("headling")+str(" : ")+str(self.w.HandlingSlider.value())
	    print str("roll")+str(" : ")+str(self.w.PitchSlider.value())
	    print str("pitch")+str(" : ")+str(self.w.RollSlider.value())
	    print str("range")+str(" : ")+str(self.w.RangeSlider.value())
	    #print item
	    #print head

    def inclat(self):
        step = float(self.w.SpeedSpinBox.value())
        #step = step * 0.1
        self.slvallat += step
        print self.slvallat
        R = open(filepath+'HeadingMode', "r")
        K = R.read()
        Y = K.rsplit(' ')
        T = len(Y)
        if T == 1:
            if str(Y[0]) == str('Manual'):
                head = self.w.HandlingSlider.value()
            if str(Y[0]) != str('Manual'):
                head = Y[0]
        ossimxml = '<Set target=":navigator" vref="wgs84"><%s><longitude>%s</longitude><latitude>%s</latitude><altitude>%s</altitude><heading>%s</heading><pitch>%s</pitch><roll>%s</roll><altitudeMode>absolute</altitudeMode><range>%s</range></%s></Set>' % (item, unicode(self.slvallon), unicode(self.slvallat), self.w.ZoomSlider.value(), head, self.w.PitchSlider.value() , self.w.RollSlider.value(),self.w.RangeSlider.value(), item)
        ossim = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ossim.connect(("127.0.0.1", 7000))
        ossim.send(ossimxml)
        ossim.close()

    def declat(self):
        step = float(self.w.SpeedSpinBox.value())
        self.slvallat -= step
        print self.slvallat
        R = open(filepath+'HeadingMode', "r")
        K = R.read()
        Y = K.rsplit(' ')
        T = len(Y)
        if T == 1:
            if str(Y[0]) == str('Manual'):
                head = self.w.HandlingSlider.value()
            if str(Y[0]) != str('Manual'):
                head = Y[0]
        ossimxml = '<Set target=":navigator" vref="wgs84"><%s><longitude>%s</longitude><latitude>%s</latitude><altitude>%s</altitude><heading>%s</heading><pitch>%s</pitch><roll>%s</roll><altitudeMode>absolute</altitudeMode><range>%s</range></%s></Set>' % (item, unicode(self.slvallon), unicode(self.slvallat), self.w.ZoomSlider.value(), head, self.w.PitchSlider.value() , self.w.RollSlider.value(),self.w.RangeSlider.value(), item)
        ossim = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ossim.connect(("127.0.0.1", 7000))
        ossim.send(ossimxml)
        ossim.close()

    def inclon(self):
        step = float(self.w.SpeedSpinBox.value())
        self.slvallon += step
        print self.slvallon
        R = open(filepath+'HeadingMode', "r")
        K = R.read()
        Y = K.rsplit(' ')
        T = len(Y)
        if T == 1:
            if str(Y[0]) == str('Manual'):
                head = self.w.HandlingSlider.value()
            if str(Y[0]) != str('Manual'):
                head = Y[0]
        ossimxml = '<Set target=":navigator" vref="wgs84"><%s><longitude>%s</longitude><latitude>%s</latitude><altitude>%s</altitude><heading>%s</heading><pitch>%s</pitch><roll>%s</roll><altitudeMode>absolute</altitudeMode><range>%s</range></%s></Set>' % (item, unicode(self.slvallon), unicode(self.slvallat), self.w.ZoomSlider.value(), head, self.w.PitchSlider.value() , self.w.RollSlider.value(),self.w.RangeSlider.value(), item)
        ossim = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ossim.connect(("127.0.0.1", 7000))
        ossim.send(ossimxml)
        ossim.close()

    def declon(self):
        step = float(self.w.SpeedSpinBox.value())
        self.slvallon -= step
        print self.slvallon
        R = open(filepath+'HeadingMode', "r")
        K = R.read()
        Y = K.rsplit(' ')
        T = len(Y)
        if T == 1:
            if str(Y[0]) == str('Manual'):
                head = self.w.HandlingSlider.value()
            if str(Y[0]) != str('Manual'):
                head = Y[0]
        ossimxml = '<Set target=":navigator" vref="wgs84"><%s><longitude>%s</longitude><latitude>%s</latitude><altitude>%s</altitude><heading>%s</heading><pitch>%s</pitch><roll>%s</roll><altitudeMode>absolute</altitudeMode><range>%s</range></%s></Set>' % (item, unicode(self.slvallon), unicode(self.slvallat), self.w.ZoomSlider.value(), head, self.w.PitchSlider.value() , self.w.RollSlider.value(),self.w.RangeSlider.value(), item)
        ossim = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ossim.connect(("127.0.0.1", 7000))
        ossim.send(ossimxml)
        ossim.close()


    def inclatlon(self):
        step = float(self.w.SpeedSpinBox.value())
        #step = step * 0.1
        self.slvallat += step
        print self.slvallat
        self.slvallon += step
        print self.slvallon
        R = open(filepath+'HeadingMode', "r")
        K = R.read()
        Y = K.rsplit(' ')
        T = len(Y)
        if T == 1:
            if str(Y[0]) == str('Manual'):
                head = self.w.HandlingSlider.value()
            if str(Y[0]) != str('Manual'):
                head = Y[0]
        ossimxml = '<Set target=":navigator" vref="wgs84"><%s><longitude>%s</longitude><latitude>%s</latitude><altitude>%s</altitude><heading>%s</heading><pitch>%s</pitch><roll>%s</roll><altitudeMode>absolute</altitudeMode><range>%s</range></%s></Set>' % (item, unicode(self.slvallon), unicode(self.slvallat), self.w.ZoomSlider.value(), head, self.w.PitchSlider.value() , self.w.RollSlider.value(),self.w.RangeSlider.value(), item)
        ossim = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ossim.connect(("127.0.0.1", 7000))
        ossim.send(ossimxml)
        ossim.close()


    def declatlon(self):
        step = float(self.w.SpeedSpinBox.value())
        #step = step * 0.1
        self.slvallat -= step
        print self.slvallat
        self.slvallon -= step
        print self.slvallon
        R = open(filepath+'HeadingMode', "r")
        K = R.read()
        Y = K.rsplit(' ')
        T = len(Y)
        if T == 1:
            if str(Y[0]) == str('Manual'):
                head = self.w.HandlingSlider.value()
            if str(Y[0]) != str('Manual'):
                head = Y[0]
        ossimxml = '<Set target=":navigator" vref="wgs84"><%s><longitude>%s</longitude><latitude>%s</latitude><altitude>%s</altitude><heading>%s</heading><pitch>%s</pitch><roll>%s</roll><altitudeMode>absolute</altitudeMode><range>%s</range></%s></Set>' % (item, unicode(self.slvallon), unicode(self.slvallat), self.w.ZoomSlider.value(), head, self.w.PitchSlider.value() , self.w.RollSlider.value(),self.w.RangeSlider.value(), item)
        ossim = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ossim.connect(("127.0.0.1", 7000))
        ossim.send(ossimxml)
        ossim.close()

    def inclatdeclon(self):
        step = float(self.w.SpeedSpinBox.value())
        #step = step * 0.1
        self.slvallat += step
        print self.slvallat
        self.slvallon -= step
        print self.slvallon
        R = open(filepath+'HeadingMode', "r")
        K = R.read()
        Y = K.rsplit(' ')
        T = len(Y)
        if T == 1:
            if str(Y[0]) == str('Manual'):
                head = self.w.HandlingSlider.value()
            if str(Y[0]) != str('Manual'):
                head = Y[0]
        ossimxml = '<Set target=":navigator" vref="wgs84"><%s><longitude>%s</longitude><latitude>%s</latitude><altitude>%s</altitude><heading>%s</heading><pitch>%s</pitch><roll>%s</roll><altitudeMode>absolute</altitudeMode><range>%s</range></%s></Set>' % (item, unicode(self.slvallon), unicode(self.slvallat), self.w.ZoomSlider.value(), head, self.w.PitchSlider.value() , self.w.RollSlider.value(),self.w.RangeSlider.value(), item)
        ossim = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ossim.connect(("127.0.0.1", 7000))
        ossim.send(ossimxml)
        ossim.close()


    def declatinclon(self):
        step = float(self.w.SpeedSpinBox.value())
        #step = step * 0.1
        self.slvallat -= step
        print self.slvallat
        self.slvallon += step
        print self.slvallon
        R = open(filepath+'HeadingMode', "r")
        K = R.read()
        Y = K.rsplit(' ')
        T = len(Y)
        if T == 1:
            if str(Y[0]) == str('Manual'):
                head = self.w.HandlingSlider.value()
            if str(Y[0]) != str('Manual'):
                head = Y[0]
        ossimxml = '<Set target=":navigator" vref="wgs84"><%s><longitude>%s</longitude><latitude>%s</latitude><altitude>%s</altitude><heading>%s</heading><pitch>%s</pitch><roll>%s</roll><altitudeMode>absolute</altitudeMode><range>%s</range></%s></Set>' % (item, unicode(self.slvallon), unicode(self.slvallat), self.w.ZoomSlider.value(), head, self.w.PitchSlider.value() , self.w.RollSlider.value(),self.w.RangeSlider.value(), item)
        ossim = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        ossim.connect(("127.0.0.1", 7000))
        ossim.send(ossimxml)
        ossim.close()


    def setValue(self, v):
        self.Value = v

    def inc(self):
        self.Value += 1
        self.w.ZoomSlider.setValue(self.Value)
        self.w.ZoomSpinBox.setValue(self.Value)

    def dec(self):
        self.Value -= 1
        self.w.ZoomSlider.setValue(self.Value)
        self.w.ZoomSpinBox.setValue(self.Value)

    def setcenter(self):
        global centro
        global clon
        global clat
        clon = 0
        clat = 0
        #region = regionl()
        s = read_command("g.region", flags='l')
        region = parse_key_val(s,':')
        clon = region['center longitude']
        clat = region['center latitude']
        clon=str(clon)
        clat=str(clat)
        clon = clon.replace(':'," ")
        clat = clat.replace(':'," ")
        if clat[-1] == 'N':
            signlat = 1
        if clat[-1] == 'S':
            signlat = -1
        if clon[-1] == 'E':
           signlon = 1
        if clon[-1] == 'W':
            signlon = -1
        clat = clat[:-1] 
        clon = clon[:-1]
        clat = [float(i) for i in clat.split()]
        clon = [float(i) for i in clon.split()]
        clat = (clat[0]+(clat[1]/60)+clat[2]/3600) * float(signlat)
        clon = (clon[0]+(clon[1]/60)+clon[2]/3600) * float(signlon)
        slvallon = clon 
        slvallat = clat 
        centro = (clon,clat)
        return centro
        return clon
        return clat


    def VectorList(self):
        global vector
        v = list_strings('vect')
        vector = []
        for i in v:
            vname = i.split('@', 2)[0]
            vector.append(vname)
        return vector

    def RasterList(self):
        global raster
        r = list_strings('rast')
        raster = []
        for i in r:
            rname = i.split('@', 2)[0]
            raster.append(rname)
        return raster

    def RegionList(self):
        global region
        rg = list_strings('region')
        region = []
        for i in rg:
            rgname = i.split('@', 2)[0]
            region.append(rgname)
        return region

    def GetType(self,index):
        global Gtype
        Gtype = self.w.GrassType.itemText(index)
        print Gtype
        return Gtype

    def TypeList(self):
        global ListType
        if Gtype == str('region'):
            rg = list_strings('region')
            region = []
            for i in rg:
                rgname = i.split('@', 2)[0]
                region.append(rgname)
        return region

    def printstep(self):
        print self.w.SpeedSpinBox.value()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    p = MyClass()
    p.init()
    sys.exit(app.exec_())
