User Tools

Site Tools


Writing /var/lib/dokuwiki/data/meta/teaching/ie0117/proyectos/2013/ii/proyecto_gps_-_drivecr/gui_implementation.meta failed
teaching:ie0117:proyectos:2013:ii:proyecto_gps_-_drivecr:gui_implementation

DriveCR.py

In this archive the GUI is created and implemented. It must also include la corresponding classes to allow the communication between the client, server, and databases. It must also be able to display the map, coordinates and current position, along with the options and features the user will enjoy while using the app. When clicked, the buttons will perform instructions for sending or retrieving information, as required.

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'DriveCR.ui'
#
# Created: Tue Oct 29 21:11:21 2013
#      by: PyQt4 UI code generator 4.10.3
#
# WARNING! All changes made in this file will be lost!

import socket
import os
import DBmethods as dbm

from PyQt4 import QtCore, QtGui
from mapaOslo import LightMaps
from geoi import GeolocalizacionIP

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 10101)
print "socket created"
client.connect(server_address)
print "connection established"

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):

    def __init__(self):
        self.mapa = LightMaps()

    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(640, 507)
        MainWindow.setMinimumSize(QtCore.QSize(640, 507))
        MainWindow.setMaximumSize(QtCore.QSize(640, 507))
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.widgetInicio = QtGui.QWidget(self.centralwidget)
        self.widgetInicio.setGeometry(QtCore.QRect(0, 0, 640, 480))
        self.widgetInicio.setStyleSheet(_fromUtf8("background-color: rgb(72, 171, 37);"))
        self.widgetInicio.setObjectName(_fromUtf8("widgetInicio"))
        self.LogoG = QtGui.QLabel(self.widgetInicio)
        self.LogoG.setGeometry(QtCore.QRect(90, 200, 460, 120))
        self.LogoG.setStyleSheet(_fromUtf8("font: italic 100pt \"FreeSerif\";\n"
"color: rgb(255, 255, 255);"))
        self.LogoG.setObjectName(_fromUtf8("LogoG"))
        self.PinG = QtGui.QLabel(self.widgetInicio)
        self.PinG.setGeometry(QtCore.QRect(180, 120, 141, 121))
        self.PinG.setStyleSheet(_fromUtf8("image: url(:/images/iconos/1381308463_map_pin_fill.svg);"))
        self.PinG.setText(_fromUtf8(""))
        self.PinG.setObjectName(_fromUtf8("PinG"))
        self.sigInicioButton = QtGui.QPushButton(self.widgetInicio)
        self.sigInicioButton.setGeometry(QtCore.QRect(580, 20, 48, 48))
        self.sigInicioButton.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/Next.svg);"))
        self.sigInicioButton.setText(_fromUtf8(""))
        self.sigInicioButton.setObjectName(_fromUtf8("sigInicioButton"))
        self.sigInicioButton.clicked.connect(self.clicked_sigInicioButton)
        self.widgetSaludo = QtGui.QWidget(self.centralwidget)
        self.widgetSaludo.setGeometry(QtCore.QRect(0, 0, 640, 480))
        self.widgetSaludo.setStyleSheet(_fromUtf8("background-color: rgb(72, 171, 37);"))
        self.widgetSaludo.setObjectName(_fromUtf8("widgetSaludo"))
        self.label_10 = QtGui.QLabel(self.widgetSaludo)
        self.label_10.setGeometry(QtCore.QRect(170, 200, 251, 211))
        self.label_10.setStyleSheet(_fromUtf8("image: url(:/images/iconos/netalloycarlogo2.svg);"))
        self.label_10.setText(_fromUtf8(""))
        self.label_10.setObjectName(_fromUtf8("label_10"))
        self.label_11 = QtGui.QLabel(self.widgetSaludo)
        self.label_11.setGeometry(QtCore.QRect(80, 194, 301, 20))
        self.label_11.setStyleSheet(_fromUtf8("font: 75 16pt \"Caviar Dreams\";\n"
"color: rgb(255, 255, 255);"))
        self.label_11.setObjectName(_fromUtf8("label_11"))
        self.label_12 = QtGui.QLabel(self.widgetSaludo)
        self.label_12.setGeometry(QtCore.QRect(330, 50, 291, 211))
        self.label_12.setStyleSheet(_fromUtf8("image: url(:/images/iconos/Speech_bubble.svg);"))
        self.label_12.setText(_fromUtf8(""))
        self.label_12.setObjectName(_fromUtf8("label_12"))
        self.label_13 = QtGui.QLabel(self.widgetSaludo)
        self.label_13.setGeometry(QtCore.QRect(20, 160, 281, 31))
        self.label_13.setStyleSheet(_fromUtf8("font: 75 16pt \"Caviar Dreams\";\n"
"color: rgb(255, 255, 255);"))
        self.label_13.setObjectName(_fromUtf8("label_13"))
        self.label_22 = QtGui.QLabel(self.widgetSaludo)
        self.label_22.setGeometry(QtCore.QRect(420, 117, 171, 51))
        self.label_22.setStyleSheet(_fromUtf8("color: rgb(255, 255, 255);\n"
"font: 48pt \"Droid Sans [monotype]\";\n"
""))
        self.label_22.setObjectName(_fromUtf8("label_22"))
        self.atrSaludButton = QtGui.QPushButton(self.widgetSaludo)
        self.atrSaludButton.setGeometry(QtCore.QRect(10, 20, 48, 48))
        self.atrSaludButton.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/back.svg);"))
        self.atrSaludButton.setText(_fromUtf8(""))
        self.atrSaludButton.setObjectName(_fromUtf8("atrSaludButton"))
        self.atrSaludButton.clicked.connect(self.clicked_atrasSaludoButton)
        self.IniciaSeButton = QtGui.QPushButton(self.widgetSaludo)
        self.IniciaSeButton.setGeometry(QtCore.QRect(120, 390, 190, 29))
        self.IniciaSeButton.setStyleSheet(_fromUtf8("color: rgb(111, 132, 86);\n"
"background-color: rgb(218, 205, 205);\n"
"font: 75 11pt \"Bitstream Charter\";"))
        self.IniciaSeButton.setObjectName(_fromUtf8("IniciaSeButton"))
        self.IniciaSeButton.clicked.connect(self.clicked_iniciaSesionButton)
        self.creaUsuarButton = QtGui.QPushButton(self.widgetSaludo)
        self.creaUsuarButton.setGeometry(QtCore.QRect(330, 390, 190, 29))
        self.creaUsuarButton.setStyleSheet(_fromUtf8("color: rgb(111, 132, 86);\n"
"background-color: rgb(218, 205, 205);\n"
"font: 75 11pt \"Bitstream Charter\";"))
        self.creaUsuarButton.setObjectName(_fromUtf8("creaUsuarButton"))
        self.creaUsuarButton.clicked.connect(self.clicked_creaUsuarioButton)
        self.widgetCuenta = QtGui.QWidget(self.centralwidget)
        self.widgetCuenta.setGeometry(QtCore.QRect(0, 0, 640, 480))
        self.widgetCuenta.setStyleSheet(_fromUtf8("background-color: rgb(72, 171, 37);"))
        self.widgetCuenta.setObjectName(_fromUtf8("widgetCuenta"))
        self.label = QtGui.QLabel(self.widgetCuenta)
        self.label.setGeometry(QtCore.QRect(142, 188, 71, 31))
        self.label.setStyleSheet(_fromUtf8("font: 75 13pt \"Bitstream Charter\";\n"
"color: rgb(255, 255, 255);"))
        self.label.setObjectName(_fromUtf8("label"))
        self.label_2 = QtGui.QLabel(self.widgetCuenta)
        self.label_2.setGeometry(QtCore.QRect(142, 218, 81, 31))
        self.label_2.setStyleSheet(_fromUtf8("font: 75 13pt \"Bitstream Charter\";\n"
"color: rgb(255, 255, 255);"))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.label_3 = QtGui.QLabel(self.widgetCuenta)
        self.label_3.setGeometry(QtCore.QRect(142, 248, 91, 31))
        self.label_3.setStyleSheet(_fromUtf8("font: 75 13pt \"Bitstream Charter\";\n"
"color: rgb(255, 255, 255);"))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.label_4 = QtGui.QLabel(self.widgetCuenta)
        self.label_4.setGeometry(QtCore.QRect(142, 278, 187, 31))
        self.label_4.setStyleSheet(_fromUtf8("font: 75 13pt \"Bitstream Charter\";\n"
"color: rgb(255, 255, 255);"))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.label_5 = QtGui.QLabel(self.widgetCuenta)
        self.label_5.setGeometry(QtCore.QRect(142, 308, 187, 31))
        self.label_5.setStyleSheet(_fromUtf8("font: 75 13pt \"Bitstream Charter\";\n"
"color: rgb(255, 255, 255);"))
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.lineNombre = QtGui.QLineEdit(self.widgetCuenta)
        self.lineNombre.setGeometry(QtCore.QRect(330, 188, 171, 23))
        self.lineNombre.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.lineNombre.setObjectName(_fromUtf8("lineNombre"))
        self.lineUsuario = QtGui.QLineEdit(self.widgetCuenta)
        self.lineUsuario.setGeometry(QtCore.QRect(330, 218, 171, 23))
        self.lineUsuario.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.lineUsuario.setObjectName(_fromUtf8("lineUsuario"))
        self.lineContrasena = QtGui.QLineEdit(self.widgetCuenta)
        self.lineContrasena.setGeometry(QtCore.QRect(330, 248, 171, 23))
        self.lineContrasena.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.lineContrasena.setEchoMode(QtGui.QLineEdit.Password)
        self.lineContrasena.setObjectName(_fromUtf8("lineContrasena"))
        self.lineConfirmaContr = QtGui.QLineEdit(self.widgetCuenta)
        self.lineConfirmaContr.setGeometry(QtCore.QRect(330, 278, 171, 23))
        self.lineConfirmaContr.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.lineConfirmaContr.setEchoMode(QtGui.QLineEdit.Password)
        self.lineConfirmaContr.setObjectName(_fromUtf8("lineConfirmaContr"))
        self.lineCorreo = QtGui.QLineEdit(self.widgetCuenta)
        self.lineCorreo.setGeometry(QtCore.QRect(330, 308, 171, 23))
        self.lineCorreo.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.lineCorreo.setObjectName(_fromUtf8("lineCorreo"))
        self.label_14 = QtGui.QLabel(self.widgetCuenta)
        self.label_14.setGeometry(QtCore.QRect(20, 88, 141, 91))
        self.label_14.setStyleSheet(_fromUtf8("image: url(:/images/iconos/1381320670_87.svg);"))
        self.label_14.setText(_fromUtf8(""))
        self.label_14.setObjectName(_fromUtf8("label_14"))
        self.label_15 = QtGui.QLabel(self.widgetCuenta)
        self.label_15.setGeometry(QtCore.QRect(207, 98, 231, 81))
        self.label_15.setStyleSheet(_fromUtf8("font: italic 50pt \"FreeSerif\";\n"
"color: rgb(255, 255, 255);"))
        self.label_15.setObjectName(_fromUtf8("label_15"))
        self.label_16 = QtGui.QLabel(self.widgetCuenta)
        self.label_16.setGeometry(QtCore.QRect(263, 88, 51, 41))
        self.label_16.setStyleSheet(_fromUtf8("image: url(:/images/iconos/1381308463_map_pin_fill.svg);"))
        self.label_16.setText(_fromUtf8(""))
        self.label_16.setObjectName(_fromUtf8("label_16"))
        self.label_17 = QtGui.QLabel(self.widgetCuenta)
        self.label_17.setGeometry(QtCore.QRect(36, 360, 121, 21))
        self.label_17.setStyleSheet(_fromUtf8("font: 75 14pt \"Droid Sans\";\n"
"color: rgb(255, 255, 255);"))
        self.label_17.setObjectName(_fromUtf8("label_17"))
        self.horizontalLayoutWidget_2 = QtGui.QWidget(self.widgetCuenta)
        self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(90, 390, 461, 41))
        self.horizontalLayoutWidget_2.setObjectName(_fromUtf8("horizontalLayoutWidget_2"))
        self.horizontalLayout_2 = QtGui.QHBoxLayout(self.horizontalLayoutWidget_2)
        self.horizontalLayout_2.setMargin(0)
        self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
        self.label_23 = QtGui.QLabel(self.horizontalLayoutWidget_2)
        self.label_23.setStyleSheet(_fromUtf8("image: url(:/images/iconos/subtle-grunge-minimal-iconset/128px/4.png);"))
        self.label_23.setText(_fromUtf8(""))
        self.label_23.setObjectName(_fromUtf8("label_23"))
        self.horizontalLayout_2.addWidget(self.label_23)
        self.label_8 = QtGui.QLabel(self.horizontalLayoutWidget_2)
        self.label_8.setStyleSheet(_fromUtf8("image: url(:/images/iconos/subtle-grunge-minimal-iconset/128px/2.png);"))
        self.label_8.setText(_fromUtf8(""))
        self.label_8.setObjectName(_fromUtf8("label_8"))
        self.horizontalLayout_2.addWidget(self.label_8)
        self.label_9 = QtGui.QLabel(self.horizontalLayoutWidget_2)
        self.label_9.setStyleSheet(_fromUtf8("image: url(:/images/iconos/subtle-grunge-minimal-iconset/128px/25.png);"))
        self.label_9.setText(_fromUtf8(""))
        self.label_9.setObjectName(_fromUtf8("label_9"))
        self.horizontalLayout_2.addWidget(self.label_9)
        self.atrCuentaButton = QtGui.QPushButton(self.widgetCuenta)
        self.atrCuentaButton.setGeometry(QtCore.QRect(10, 20, 48, 48))
        self.atrCuentaButton.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/back.svg);"))
        self.atrCuentaButton.setText(_fromUtf8(""))
        self.atrCuentaButton.setObjectName(_fromUtf8("atrCuentaButton"))
        self.atrCuentaButton.clicked.connect(self.clicked_atrasCuentaButton)
        self.sigCuentaButton = QtGui.QPushButton(self.widgetCuenta)
        self.sigCuentaButton.setGeometry(QtCore.QRect(580, 20, 48, 48))
        self.sigCuentaButton.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/Next.svg);"))
        self.sigCuentaButton.setText(_fromUtf8(""))
        self.sigCuentaButton.setObjectName(_fromUtf8("sigCuentaButton"))
        self.sigCuentaButton.clicked.connect(self.clicked_sigCuentaButton)
        self.widgetLogin = QtGui.QWidget(self.centralwidget)
        self.widgetLogin.setGeometry(QtCore.QRect(0, 0, 640, 480))
        self.widgetLogin.setStyleSheet(_fromUtf8("background-color: rgb(72, 171, 37);"))
        self.widgetLogin.setObjectName(_fromUtf8("widgetLogin"))
        self.lineUsuaLogin = QtGui.QLineEdit(self.widgetLogin)
        self.lineUsuaLogin.setGeometry(QtCore.QRect(320, 266, 171, 23))
        self.lineUsuaLogin.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.lineUsuaLogin.setObjectName(_fromUtf8("lineUsuaLogin"))
        self.lineContLogin = QtGui.QLineEdit(self.widgetLogin)
        self.lineContLogin.setGeometry(QtCore.QRect(320, 323, 171, 23))
        self.lineContLogin.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.lineContLogin.setEchoMode(QtGui.QLineEdit.Password)
        self.lineContLogin.setObjectName(_fromUtf8("lineContLogin"))
        self.label_6 = QtGui.QLabel(self.widgetLogin)
        self.label_6.setGeometry(QtCore.QRect(170, 263, 81, 31))
        self.label_6.setStyleSheet(_fromUtf8("font: 75 13pt \"Bitstream Charter\";\n"
"color: rgb(255, 255, 255);"))
        self.label_6.setObjectName(_fromUtf8("label_6"))
        self.label_7 = QtGui.QLabel(self.widgetLogin)
        self.label_7.setGeometry(QtCore.QRect(170, 320, 91, 31))
        self.label_7.setStyleSheet(_fromUtf8("font: 75 13pt \"Bitstream Charter\";\n"
"color: rgb(255, 255, 255);"))
        self.label_7.setObjectName(_fromUtf8("label_7"))
        self.label_18 = QtGui.QLabel(self.widgetLogin)
        self.label_18.setGeometry(QtCore.QRect(20, 90, 141, 91))
        self.label_18.setStyleSheet(_fromUtf8("image: url(:/images/iconos/1381977216_04_In_alt.svg);"))
        self.label_18.setText(_fromUtf8(""))
        self.label_18.setObjectName(_fromUtf8("label_18"))
        self.label_19 = QtGui.QLabel(self.widgetLogin)
        self.label_19.setGeometry(QtCore.QRect(162, 93, 201, 31))
        self.label_19.setStyleSheet(_fromUtf8("color: rgb(255, 255, 255);\n"
"font: 75 16pt \"Caviar Dreams\";"))
        self.label_19.setObjectName(_fromUtf8("label_19"))
        self.label_20 = QtGui.QLabel(self.widgetLogin)
        self.label_20.setGeometry(QtCore.QRect(207, 158, 231, 81))
        self.label_20.setStyleSheet(_fromUtf8("font: italic 50pt \"FreeSerif\";\n"
"color: rgb(255, 255, 255);"))
        self.label_20.setObjectName(_fromUtf8("label_20"))
        self.label_21 = QtGui.QLabel(self.widgetLogin)
        self.label_21.setGeometry(QtCore.QRect(262, 150, 51, 41))
        self.label_21.setStyleSheet(_fromUtf8("image: url(:/images/iconos/1381308463_map_pin_fill.svg);"))
        self.label_21.setText(_fromUtf8(""))
        self.label_21.setObjectName(_fromUtf8("label_21"))
        self.atrLoginButton = QtGui.QPushButton(self.widgetLogin)
        self.atrLoginButton.setGeometry(QtCore.QRect(10, 20, 48, 48))
        self.atrLoginButton.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/back.svg);"))
        self.atrLoginButton.setText(_fromUtf8(""))
        self.atrLoginButton.setObjectName(_fromUtf8("atrLoginButton"))
        self.atrLoginButton.clicked.connect(self.clicked_atrasSesionButton)
        self.sigCuentaButton_2 = QtGui.QPushButton(self.widgetLogin)
        self.sigCuentaButton_2.setGeometry(QtCore.QRect(580, 20, 48, 48))
        self.sigCuentaButton_2.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/Next.svg);"))
        self.sigCuentaButton_2.setText(_fromUtf8(""))
        self.sigCuentaButton_2.setObjectName(_fromUtf8("sigCuentaButton_2"))
        self.sigCuentaButton_2.clicked.connect(self.clicked_sigSesionButton)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 25))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

##Codigo que no hace directo PyQt
#######################################################
    def clicked_sigInicioButton(self):
        self.widgetInicio.setVisible(False)
        self.widgetSaludo.setVisible(True)

    def clicked_atrasSaludoButton(self):
        self.widgetSaludo.setVisible(False)
        self.widgetInicio.setVisible(True)

    def clicked_iniciaSesionButton(self):
        self.widgetSaludo.setVisible(False)
        self.widgetLogin.setVisible(True)

    def clicked_creaUsuarioButton(self):
        self.widgetSaludo.setVisible(False)
        self.widgetCuenta.setVisible(True)

    def clicked_atrasSesionButton(self):
        self.widgetLogin.setVisible(False)
        self.widgetSaludo.setVisible(True)

    def clicked_sigSesionButton(self):
	self.widgetLogin.setVisible(False)        
        command = 'login'
	infoUsuario1 = ["","",""]	
        usuario = self.lineUsuaLogin.text()
        infoUsuario1[0] = usuario
        print usuario
        contrasena = self.lineContLogin.text()
        infoUsuario1[1]=contrasena
        info = reduce(lambda x,y: x+','+y, infoUsuario1)
        message = command+','+info
	client.send(message)
        a=client.recv(4096)
        print a
        print len(a)
        if len(a)==14:
            self.cargarMapa()
        else:
            print 'Usuario y/o contraseña invalida'


    def clicked_atrasCuentaButton(self):
        self.widgetCuenta.setVisible(False)
        self.widgetSaludo.setVisible(True)

    def clicked_sigCuentaButton(self):
	command = 'signup'
        infoUsuario = ["","","","",""]
        nombre = self.lineNombre.text()
        print nombre
        infoUsuario[0] = nombre
        usuario = self.lineUsuario.text()
        infoUsuario[1] = usuario
        contrasena = self.lineContrasena.text()
        confContrasena = self.lineConfirmaContr.text()
        infoUsuario[2]=confContrasena
        correo = self.lineCorreo.text()
        infoUsuario[3] = correo
        print infoUsuario[0],  infoUsuario[1], infoUsuario[2], infoUsuario[3]
        info = reduce(lambda x,y: x+','+y, infoUsuario)
        message = command+','+info
	client.send(message)
	print client.recv(100)
      
        
        if nombre=="" or usuario=="" or contrasena=="" or confContrasena=="" or correo=="":
            self.msgBox = QtGui.QMessageBox()
            self.msgBox.setText("Error: Ningun campo puede estar vacio")
            self.msgBox.addButton(QtGui.QPushButton('OK'), QtGui.QMessageBox.AcceptRole)
            self.msgBox.exec_();
        elif contrasena != confContrasena:
            self.msgBox = QtGui.QMessageBox()
            self.msgBox.setText("Error: Contrasenas no coinciden")
            self.msgBox.addButton(QtGui.QPushButton('OK'), QtGui.QMessageBox.AcceptRole)
            self.msgBox.exec_();
        elif len(contrasena) < 8:
            self.msgBox = QtGui.QMessageBox()
            self.msgBox.setText("Error: Contrasena debe tener como mínimo 8 caracteres")
            self.msgBox.addButton(QtGui.QPushButton('OK'), QtGui.QMessageBox.AcceptRole)
            self.msgBox.exec_();
        else:
            ##Ventana##
            self.msgBox = QtGui.QMessageBox()
            self.msgBox.setText('Usuario Registrado')
            self.msgBox.addButton(QtGui.QPushButton('OK'), QtGui.QMessageBox.AcceptRole)
            self.msgBox.exec_();
            print "Usuario creado"

            self.widgetCuenta.setVisible(False)
            self.widgetLogin.setVisible(True)
            return infoUsuario

    def clicked_UbicarButton(self):
        ##GeoData = GeolocalizacionIP()
        ##GeoData.cargarIP()
        ##coordenas = GeoData.getArregloCoord()
        self.mapa.setCenter(9.929330, -84.045500)
    
    def clicked_buttonMenu(self):
        self.widgetMenu.setVisible(True)

    def clicked_buttonInfo(self):
		self.widgetInformation.setVisible(True)
    
    def clicked_buttonInfoCerrar(self):
		self.widgetInformation.setVisible(False)
		   
    def clicked_buttonMenuCerrar(self):
		self.widgetMenu.setVisible(False)
	
	
    def cargarMapa(self):
        MainWindow.setCentralWidget(self.mapa)
        self.widgetEnMapa = QtGui.QWidget(self.mapa)
        self.widgetEnMapa.setGeometry(QtCore.QRect(0, 450, 641, 31))
        self.widgetEnMapa.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 144);"))
        self.widgetEnMapa.setObjectName(_fromUtf8("widgetEnMapa"))
        self.label_24 = QtGui.QLabel(self.widgetEnMapa)
        self.label_24.setGeometry(QtCore.QRect(0, 29, 640, 2))
        self.label_24.setStyleSheet(_fromUtf8("background-color: rgb(72, 171, 37);"))
        self.label_24.setText(_fromUtf8(""))
        self.label_24.setObjectName(_fromUtf8("label_24"))
        self.label_25 = QtGui.QLabel(self.widgetEnMapa)
        self.label_25.setGeometry(QtCore.QRect(0, 0, 2, 30))
        self.label_25.setStyleSheet(_fromUtf8("background-color: rgb(72, 171, 37);"))
        self.label_25.setText(_fromUtf8(""))
        self.label_25.setObjectName(_fromUtf8("label_25"))
        self.label_26 = QtGui.QLabel(self.widgetEnMapa)
        self.label_26.setGeometry(QtCore.QRect(0, 0, 640, 2))
        self.label_26.setStyleSheet(_fromUtf8("background-color: rgb(72, 171, 37);"))
        self.label_26.setText(_fromUtf8(""))
        self.label_26.setObjectName(_fromUtf8("label_26"))
        self.label_27 = QtGui.QLabel(self.widgetEnMapa)
        self.label_27.setGeometry(QtCore.QRect(638, 0, 2, 30))
        self.label_27.setStyleSheet(_fromUtf8("background-color: rgb(72, 171, 37);"))
        self.label_27.setText(_fromUtf8(""))
        self.label_27.setObjectName(_fromUtf8("label_27"))
        self.alertaButton = QtGui.QPushButton(self.widgetEnMapa)
        self.alertaButton.setGeometry(QtCore.QRect(96, 5, 17, 20))
        self.alertaButton.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/drivecr.svg);\n"
"background-color: rgb(183, 232, 144);"))
        self.alertaButton.setText(_fromUtf8(""))
        self.alertaButton.clicked.connect(self.clicked_buttonMenu)
        self.alertaButton.setObjectName(_fromUtf8("alertaButton"))
        self.ubicarButton = QtGui.QPushButton(self.widgetEnMapa)
        self.ubicarButton.setGeometry(QtCore.QRect(310, 5, 20, 20))
        self.ubicarButton.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/LocationArrow.svg);\n"
"background-color: rgb(183, 232, 144);"))
        self.ubicarButton.setText(_fromUtf8(""))
        self.ubicarButton.clicked.connect(self.clicked_UbicarButton)
        self.ubicarButton.setObjectName(_fromUtf8("ubicarButton"))
        self.ajustesButton = QtGui.QPushButton(self.widgetEnMapa)
        self.ajustesButton.setGeometry(QtCore.QRect(523, 5, 20, 20))
        self.ajustesButton.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/settings.svg);\n"
"background-color: rgb(183, 232, 144);"))
        self.ajustesButton.setText(_fromUtf8(""))
        self.ajustesButton.clicked.connect(self.clicked_buttonInfo)
        self.ajustesButton.setObjectName(_fromUtf8("ajustesButton"))
        
        self.widgetMenu = QtGui.QWidget(self.mapa)
        self.widgetMenu.setGeometry(QtCore.QRect(0, 0, 214, 450))
        self.widgetMenu.setStyleSheet(_fromUtf8("background-color: rgb(66, 66, 66);"))
        self.widgetMenu.setObjectName(_fromUtf8("widgetMenu"))
        self.l11 = QtGui.QLabel(self.widgetMenu)
        self.l11.setGeometry(QtCore.QRect(0, 75, 214, 1))
        self.l11.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.l11.setText(_fromUtf8(""))
        self.l11.setObjectName(_fromUtf8("l11"))
        self.l5 = QtGui.QLabel(self.widgetMenu)
        self.l5.setGeometry(QtCore.QRect(0, 128, 214, 1))
        self.l5.setStyleSheet(_fromUtf8("\n"
"background-color: rgb(183, 232, 149);"))
        self.l5.setText(_fromUtf8(""))
        self.l5.setObjectName(_fromUtf8("l5"))
        self.l6 = QtGui.QLabel(self.widgetMenu)
        self.l6.setGeometry(QtCore.QRect(0, 181, 214, 1))
        self.l6.setStyleSheet(_fromUtf8("\n"
"background-color: rgb(183, 232, 149);"))
        self.l6.setText(_fromUtf8(""))
        self.l6.setObjectName(_fromUtf8("l6"))
        self.l7 = QtGui.QLabel(self.widgetMenu)
        self.l7.setGeometry(QtCore.QRect(0, 234, 214, 1))
        self.l7.setStyleSheet(_fromUtf8("\n"
"background-color: rgb(183, 232, 149);"))
        self.l7.setText(_fromUtf8(""))
        self.l7.setObjectName(_fromUtf8("l7"))
        self.l8 = QtGui.QLabel(self.widgetMenu)
        self.l8.setGeometry(QtCore.QRect(0, 287, 214, 1))
        self.l8.setStyleSheet(_fromUtf8("\n"
"background-color: rgb(183, 232, 149);"))
        self.l8.setText(_fromUtf8(""))
        self.l8.setObjectName(_fromUtf8("l8"))
        self.l9 = QtGui.QLabel(self.widgetMenu)
        self.l9.setGeometry(QtCore.QRect(0, 340, 214, 1))
        self.l9.setStyleSheet(_fromUtf8("\n"
"background-color: rgb(183, 232, 149);"))
        self.l9.setText(_fromUtf8(""))
        self.l9.setObjectName(_fromUtf8("l9"))
        self.l10 = QtGui.QLabel(self.widgetMenu)
        self.l10.setGeometry(QtCore.QRect(0, 393, 214, 1))
        self.l10.setStyleSheet(_fromUtf8("\n"
"background-color: rgb(183, 232, 149);"))
        self.l10.setText(_fromUtf8(""))
        self.l10.setObjectName(_fromUtf8("l10"))
        self.laMenu = QtGui.QLabel(self.widgetMenu)
        self.laMenu.setGeometry(QtCore.QRect(60, 20, 91, 31))
        self.laMenu.setStyleSheet(_fromUtf8("color: rgb(255, 255, 255);\n"
"font: 75 24pt \"URW Bookman L\";"))
        self.laMenu.setObjectName(_fromUtf8("laMenu"))
        self.labelNav = QtGui.QLabel(self.widgetMenu)
        self.labelNav.setGeometry(QtCore.QRect(15, 85, 32, 32))
        self.labelNav.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/1386661906_93.svg);"))
        self.labelNav.setText(_fromUtf8(""))
        self.labelNav.setObjectName(_fromUtf8("labelNav"))
        self.labelCarro = QtGui.QLabel(self.widgetMenu)
        self.labelCarro.setGeometry(QtCore.QRect(15, 144, 32, 32))
        self.labelCarro.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/1386661925_13.svg);"))
        self.labelCarro.setText(_fromUtf8(""))
        self.labelCarro.setObjectName(_fromUtf8("labelCarro"))
        self.labelPolice = QtGui.QLabel(self.widgetMenu)
        self.labelPolice.setGeometry(QtCore.QRect(15, 194, 32, 32))
        self.labelPolice.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/Users-Policeman-icon.png);"))
        self.labelPolice.setText(_fromUtf8(""))
        self.labelPolice.setObjectName(_fromUtf8("labelPolice"))
        self.labelCono = QtGui.QLabel(self.widgetMenu)
        self.labelCono.setGeometry(QtCore.QRect(15, 244, 32, 32))
        self.labelCono.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/1386677804_101.png);"))
        self.labelCono.setText(_fromUtf8(""))
        self.labelCono.setObjectName(_fromUtf8("labelCono"))
        self.labelCierre = QtGui.QLabel(self.widgetMenu)
        self.labelCierre.setGeometry(QtCore.QRect(15, 300, 32, 32))
        self.labelCierre.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/1386678134_icon-close-circled.png);"))
        self.labelCierre.setText(_fromUtf8(""))
        self.labelCierre.setObjectName(_fromUtf8("labelCierre"))
        self.labelAcciden = QtGui.QLabel(self.widgetMenu)
        self.labelAcciden.setGeometry(QtCore.QRect(15, 350, 32, 32))
        self.labelAcciden.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/choque.svg);"))
        self.labelAcciden.setObjectName(_fromUtf8("labelAcciden"))
        self.buttonNavegar = QtGui.QPushButton(self.widgetMenu)
        self.buttonNavegar.setGeometry(QtCore.QRect(66, 90, 89, 27))
        self.buttonNavegar.setStyleSheet(_fromUtf8("color: rgb(0, 0, 0);\n"
"background-color: rgb(183, 232, 149);"))
        self.buttonNavegar.setObjectName(_fromUtf8("buttonNavegar"))
        self.buttonTrafic = QtGui.QPushButton(self.widgetMenu)
        self.buttonTrafic.setGeometry(QtCore.QRect(66, 143, 89, 27))
        self.buttonTrafic.setStyleSheet(_fromUtf8("color: rgb(0, 0, 0);\n"
"background-color: rgb(183, 232, 149);"))
        self.buttonTrafic.setObjectName(_fromUtf8("buttonTrafic"))
        self.buttonPolice = QtGui.QPushButton(self.widgetMenu)
        self.buttonPolice.setGeometry(QtCore.QRect(66, 194, 89, 27))
        self.buttonPolice.setStyleSheet(_fromUtf8("color: rgb(0, 0, 0);\n"
"background-color: rgb(183, 232, 149);"))
        self.buttonPolice.setObjectName(_fromUtf8("buttonPolice"))
        self.buttonPeligro = QtGui.QPushButton(self.widgetMenu)
        self.buttonPeligro.setGeometry(QtCore.QRect(66, 250, 89, 27))
        self.buttonPeligro.setStyleSheet(_fromUtf8("color: rgb(0, 0, 0);\n"
"background-color: rgb(183, 232, 149);"))
        self.buttonPeligro.setObjectName(_fromUtf8("buttonPeligro"))
        self.buttonCierres = QtGui.QPushButton(self.widgetMenu)
        self.buttonCierres.setGeometry(QtCore.QRect(66, 300, 89, 27))
        self.buttonCierres.setStyleSheet(_fromUtf8("color: rgb(0, 0, 0);\n"
"background-color: rgb(183, 232, 149);"))
        self.buttonCierres.setObjectName(_fromUtf8("buttonCierres"))
        self.buttonAccide = QtGui.QPushButton(self.widgetMenu)
        self.buttonAccide.setGeometry(QtCore.QRect(66, 353, 89, 27))
        self.buttonAccide.setStyleSheet(_fromUtf8("color: rgb(0, 0, 0);\n"
"background-color: rgb(183, 232, 149);\n"
""))
        self.buttonAccide.setObjectName(_fromUtf8("buttonAccide"))
        
        self.Cerrar1Button = QtGui.QPushButton(self.widgetMenu)
        self.Cerrar1Button.setGeometry(QtCore.QRect(90, 410, 32, 32))
        self.Cerrar1Button.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/1386715210_icon-close-round.svg);"))
        self.Cerrar1Button.setText(_fromUtf8(""))
        self.Cerrar1Button.clicked.connect(self.clicked_buttonMenuCerrar)
        self.Cerrar1Button.setObjectName(_fromUtf8("Cerrar1Button"))
        
        self.widgetMenu.setVisible(False)
        self.widgetInformation = QtGui.QWidget(self.mapa)
        self.widgetInformation.setGeometry(QtCore.QRect(426, 0, 214, 450))
        self.widgetInformation.setStyleSheet(_fromUtf8("background-color: rgba( 66, 66, 66);"))
        self.widgetInformation.setObjectName(_fromUtf8("widgetInformation"))
        self.l1 = QtGui.QLabel(self.widgetInformation)
        self.l1.setGeometry(QtCore.QRect(0, 75, 214, 1))
        self.l1.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.l1.setText(_fromUtf8(""))
        self.l1.setObjectName(_fromUtf8("l1"))
        self.l2 = QtGui.QLabel(self.widgetInformation)
        self.l2.setGeometry(QtCore.QRect(0, 128, 214, 1))
        self.l2.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.l2.setText(_fromUtf8(""))
        self.l2.setObjectName(_fromUtf8("l2"))
        self.l4 = QtGui.QLabel(self.widgetInformation)
        self.l4.setGeometry(QtCore.QRect(0, 234, 214, 1))
        self.l4.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.l4.setText(_fromUtf8(""))
        self.l4.setObjectName(_fromUtf8("l4"))
        self.l3 = QtGui.QLabel(self.widgetInformation)
        self.l3.setGeometry(QtCore.QRect(0, 181, 214, 1))
        self.l3.setStyleSheet(_fromUtf8("background-color: rgb(183, 232, 149);"))
        self.l3.setText(_fromUtf8(""))
        self.l3.setObjectName(_fromUtf8("l3"))
        self.buttonAmigos = QtGui.QPushButton(self.widgetInformation)
        self.buttonAmigos.setGeometry(QtCore.QRect(66, 143, 89, 27))
        self.buttonAmigos.setStyleSheet(_fromUtf8("color: rgb(0, 0, 0);\n"
"background-color: rgb(183, 232, 149);"))
        self.buttonAmigos.setObjectName(_fromUtf8("buttonAmigos"))
        self.buttonPerfil = QtGui.QPushButton(self.widgetInformation)
        self.buttonPerfil.setGeometry(QtCore.QRect(66, 90, 89, 27))
        self.buttonPerfil.setStyleSheet(_fromUtf8("color: rgb(0, 0, 0);\n"
"background-color: rgb(183, 232, 149);"))
        self.buttonPerfil.setObjectName(_fromUtf8("buttonPerfil"))
        self.buttonAjustes = QtGui.QPushButton(self.widgetInformation)
        self.buttonAjustes.setGeometry(QtCore.QRect(66, 194, 89, 27))
        self.buttonAjustes.setStyleSheet(_fromUtf8("color: rgb(0, 0, 0);\n"
"background-color: rgb(183, 232, 149);"))
        self.buttonAjustes.setObjectName(_fromUtf8("buttonAjustes"))
        self.labelPerfil = QtGui.QLabel(self.widgetInformation)
        self.labelPerfil.setGeometry(QtCore.QRect(10, 85, 32, 32))
        self.labelPerfil.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/1386662467_group.png);"))
        self.labelPerfil.setText(_fromUtf8(""))
        self.labelPerfil.setObjectName(_fromUtf8("labelPerfil"))
        self.labelAmigos = QtGui.QLabel(self.widgetInformation)
        self.labelAmigos.setGeometry(QtCore.QRect(10, 144, 32, 32))
        self.labelAmigos.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/1386661911_88.svg);"))
        self.labelAmigos.setText(_fromUtf8(""))
        self.labelAmigos.setObjectName(_fromUtf8("labelAmigos"))
        self.labelSett = QtGui.QLabel(self.widgetInformation)
        self.labelSett.setGeometry(QtCore.QRect(10, 194, 32, 32))
        self.labelSett.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/1386661975_Black_Settings.png);"))
        self.labelSett.setText(_fromUtf8(""))
        self.labelSett.setObjectName(_fromUtf8("labelSett"))
        self.labelnfo = QtGui.QLabel(self.widgetInformation)
        self.labelnfo.setGeometry(QtCore.QRect(15, 20, 191, 31))
        self.labelnfo.setStyleSheet(_fromUtf8("color: rgb(255, 255, 255);\n"
"font: 75 24pt \"URW Bookman L\";"))
        self.labelnfo.setObjectName(_fromUtf8("labelnfo"))
        
        self.Cerrar2Button = QtGui.QPushButton(self.widgetInformation)
        self.Cerrar2Button.setGeometry(QtCore.QRect(90, 410, 32, 32))
        self.Cerrar2Button.setStyleSheet(_fromUtf8("border-image: url(:/images/iconos/1386715210_icon-close-round.svg);"))
        self.Cerrar2Button.setText(_fromUtf8(""))
        self.Cerrar2Button.clicked.connect(self.clicked_buttonInfoCerrar)
        self.Cerrar2Button.setObjectName(_fromUtf8("Cerrar2Button"))
        
        
        self.widgetInformation.setVisible(False)
        self.laMenu.setText(_translate("MainWindow", "Menú", None))
        self.labelAcciden.setText(_translate("MainWindow", "TextLabel", None))
        self.buttonNavegar.setText(_translate("MainWindow", "Navegar", None))
        self.buttonTrafic.setText(_translate("MainWindow", "Tráfico", None))
        self.buttonPolice.setText(_translate("MainWindow", "Policía", None))
        self.buttonPeligro.setText(_translate("MainWindow", "Peligro", None))
        self.buttonCierres.setText(_translate("MainWindow", "Cierres", None))
        self.buttonAccide.setText(_translate("MainWindow", "Accidente", None))
        self.buttonAmigos.setText(_translate("MainWindow", "Amigos", None))
        self.buttonPerfil.setText(_translate("MainWindow", "Mi Perfil", None))
        self.buttonAjustes.setText(_translate("MainWindow", "Ajustes", None))
        self.labelnfo.setText(_translate("MainWindow", "Información", None))
         
        

######################################################


    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.LogoG.setText(_translate("MainWindow", "DriveCR", None))
        self.label_11.setText(_translate("MainWindow", "de nuestra red de usuarios!", None))
        self.label_13.setText(_translate("MainWindow", "Gracias por formar parte", None))
        self.label_22.setText(_translate("MainWindow", "Hola!", None))
        self.IniciaSeButton.setText(_translate("MainWindow", "Iniciar Sesión", None))
        self.creaUsuarButton.setText(_translate("MainWindow", "Crear Usuario", None))
        self.label.setText(_translate("MainWindow", "Nombre:", None))
        self.label_2.setText(_translate("MainWindow", "Usuario:", None))
        self.label_3.setText(_translate("MainWindow", "Contraseña:", None))
        self.label_4.setText(_translate("MainWindow", "Confirmar Contraseña:", None))
        self.label_5.setText(_translate("MainWindow", "Correo Electrónico:", None))
        self.label_15.setText(_translate("MainWindow", "DriveCR", None))
        self.label_17.setText(_translate("MainWindow", "Ingresar con:", None))
        self.label_6.setText(_translate("MainWindow", "Usuario:", None))
        self.label_7.setText(_translate("MainWindow", "Contraseña:", None))
        self.label_19.setText(_translate("MainWindow", "Iniciar sesión en:", None))
        self.label_20.setText(_translate("MainWindow", "DriveCR", None))
        
        
        
        
      

##############################################
        self.widgetInicio.setVisible(True)
        self.widgetSaludo.setVisible(False)
        self.widgetCuenta.setVisible(False)
        self.widgetLogin.setVisible(False)
       
        ##self.widgetEnMapa.setVisible(False)
##############################################

import resources_rc

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

map.py

This class is in charge of displaying the map on the screen by downloading the map, rendering the images, zoom, positioning, tiles, and more information required. It is acoplated to the GUI to display a map of our current location and navigate to the desired destination, in the desired or recommended route.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

'''
*****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Copyright (C) 2010 Mitja Kleider <mitja@kleider.name>
**
** This file may be used under the terms of the GNU General Public
** License version 3.0 as published by the Free Software Foundation
** Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
*****************************************************************************
'''

from PyQt4 import QtCore, QtGui, QtNetwork
import math
import sys

import sys
import threading, time
from threading import Thread

HOLD_TIME = 701
MAX_MAGNIFIER = 229
tdim = 256

MIN_ZOOM = 2
MAX_ZOOM = 18

def qHash(point):
    '''Qt doesn't implement a qHash() for QPoint.'''
    return (point.x(),point.y())

def tileForCoordinate(lat, lng, zoom):
    zn = 1 << zoom    # 2**zoom
    tx = (lng+180.0)/360.0
    ty = (1.0 - math.log(math.tan(lat*math.pi/180.0) + 1.0/math.cos(lat*math.pi/180.0)) / math.pi) / 2.0
    return QtCore.QPointF(tx*zn, ty*zn)

def longitudeFromTile(tx, zoom):
    zn = 1 << zoom
    lat = tx / zn * 360.0 - 180.0
    return lat

def latitudeFromTile(ty, zoom):
    zn = 1 << zoom
    n = math.pi - 2 * math.pi * ty / zn
    lng = 180.0 / math.pi * math.atan(0.5 * (math.exp(n) - math.exp(-n)))
    return lng

class SlippyMap(QtCore.QObject):
    updated = QtCore.pyqtSignal(QtCore.QRect)

    def __init__(self, parent=None, width=400, height=300, zoom=15, latitude=59.9138204, longitude=10.7386413):
        QtCore.QObject.__init__(self)
        self.width = width
        self.height = height
        self.zoom = zoom
        self.latitude = latitude
        self.longitude = longitude

        self.m_emptyTile = QtGui.QPixmap(tdim, tdim)
        self.m_emptyTile.fill(QtCore.Qt.lightGray)

        self.m_manager = QtNetwork.QNetworkAccessManager()
        cache = QtNetwork.QNetworkDiskCache()
        cache.setCacheDirectory(QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.CacheLocation))
        self.m_manager.setCache(cache)
        self.m_manager.finished.connect(self.handleNetworkData)

        self.m_url = QtCore.QUrl()
        self.m_offset = QtCore.QPoint()
        self.m_tilesRect = QtCore.QRect()
        self.m_tilePixmaps = {}

    def invalidate(self, emitSignal=True):
        if self.width <= 0 or self.height <= 0:
            return

        ct = tileForCoordinate(self.latitude, self.longitude, self.zoom)
        tx = ct.x()
        ty = ct.y()

        # top left corner of the center tile
        xp = int(self.width / 2 - (tx - math.floor(tx)) * tdim)
        yp = int(self.height / 2 - (ty - math.floor(ty)) * tdim)

        # first tile vertical and horizontal
        xa = (xp + tdim -1) / tdim
        ya = (yp + tdim -1) / tdim
        xs = tx - xa
        ys = ty - ya

        # offset for top-left tile
        self.m_offset = QtCore.QPoint(xp - xa * tdim, yp - ya * tdim)

        # last tile vertical and horizontal
        xe = tx + (self.width - xp -1) / tdim
        ye = ty + (self.height - yp -1) / tdim

        # build a rect
        self.m_tilesRect = QtCore.QRect(xs, ys, xe - xs + 1, ye - ys + 1)

        if self.m_url.isEmpty():
            self.download()

        if emitSignal:
            self.updated.emit(QtCore.QRect(0, 0, self.width, self.height))

    def render(self, painter, rect):
        mx = 0
        my = 0
        center = tileForCoordinate(self.latitude, self.longitude, self.zoom)
        cx = math.floor(center.x());
        cy = math.floor(center.y());

        for x in xrange(self.m_tilesRect.width()+1):
            for y in xrange(self.m_tilesRect.height()+1):
                tp = QtCore.QPoint(x + self.m_tilesRect.left(), y + self.m_tilesRect.top())
                box = self.tileRect(tp)
                if tp.x() == cx and tp.y() == cy:
                    mx = box.x();
                    my = box.y();
                    latdiff = QtCore.qAbs(tp.x() - center.x());
                    lngdiff = QtCore.qAbs(tp.y() - center.y());

                if rect.intersects(box):
                    if qHash(tp) in self.m_tilePixmaps:
                        painter.drawPixmap(box, self.m_tilePixmaps[qHash(tp)])
                    else:
                        painter.drawPixmap(box, self.m_emptyTile)
                if mx != 0 and my != 0:
                    marker = QtGui.QIcon("marker.svg")
                    painter.drawPixmap((mx+(latdiff*256.0)), (my+(lngdiff*256.0)), marker.pixmap(16,16))

    def pan(self, delta):
        dx = QtCore.QPointF(delta) / tdim
        center = tileForCoordinate(self.latitude, self.longitude, self.zoom) - dx
        self.latitude = latitudeFromTile(center.y(), self.zoom)
        self.longitude = longitudeFromTile(center.x(), self.zoom)
        self.invalidate()

    def zoomTo(self, zoomlevel):
        self.zoom = zoomlevel
        self.invalidate(False)

    def zoomIn(self):
        if self.zoom < MAX_ZOOM:
            self.zoomTo(self.zoom+1)

    def zoomOut(self):
        if self.zoom > MIN_ZOOM:
            self.zoomTo(self.zoom-1)

    def handleNetworkData(self, reply):
        img = QtGui.QImage()
        tp = reply.request().attribute(QtNetwork.QNetworkRequest.User).toPoint()
        url = reply.url()

        ## debug: check if reply was cached
        #fromCache = reply.attribute(QtNetwork.QNetworkRequest.SourceIsFromCacheAttribute).toBool()

        if not reply.error():
            if not img.load(reply, ""):
                img = QtGui.QImage()
        reply.deleteLater()
        if img.isNull():
            self.m_tilePixmaps[qHash(tp)] = self.m_emptyTile
        else:
            self.m_tilePixmaps[qHash(tp)] = QtGui.QPixmap.fromImage(img)
        self.updated.emit(self.tileRect(tp))

        self.download()

    def download(self):
        try:
            for x in xrange(self.m_tilesRect.width()+1):
                for y in xrange(self.m_tilesRect.height()+1):
                    tp = self.m_tilesRect.topLeft() + QtCore.QPoint(x, y)
                    if not qHash(tp) in self.m_tilePixmaps:
                        raise StopIteration()

            self.m_url = QtCore.QUrl()
            # purge unused spaces
            bound = self.m_tilesRect.adjusted(-2, -2, 2, 2)
            for hash in self.m_tilePixmaps.keys():
                if not bound.contains(QtCore.QPoint(hash[0],hash[1])):
                    del self.m_tilePixmaps[hash]

        except StopIteration:
            path = QtCore.QString("http://tile.openstreetmap.org/%1/%2/%3.png")
            self.m_url = QtCore.QUrl(path.arg(self.zoom).arg(tp.x()).arg(tp.y()))
            request = QtNetwork.QNetworkRequest()
            request.setUrl(self.m_url)
            request.setRawHeader("User-Agent", "(PyQt) LightMaps 1.0")
            request.setAttribute(QtNetwork.QNetworkRequest.User, QtCore.QVariant(tp))
            self.m_manager.get(request)

    def tileRect(self, tp):
        t = tp - self.m_tilesRect.topLeft()
        x = t.x() * tdim + self.m_offset.x()
        y = t.y() * tdim + self.m_offset.y()
        return QtCore.QRect(x, y, tdim, tdim)


class LightMaps(QtGui.QWidget):
    def __init__(self, parent=None, pressed=False, snapped=False, zoomed=False, invert=False):
        QtGui.QWidget.__init__(self)

        self.pressed = pressed
        self.snapped = snapped
        self.zoomed = zoomed
        self.invert = invert

        self.pressPos = QtCore.QPoint()
        self.dragPos = QtCore.QPoint()

        self.zoomPixmap = QtGui.QPixmap()
        self.maskPixmap = QtGui.QPixmap()

        self.tapTimer = QtCore.QBasicTimer()

        self.m_normalMap = SlippyMap(self)
        self.m_largeMap = SlippyMap(self)
        self.m_normalMap.updated.connect(self.updateMap)
        self.m_largeMap.updated.connect(self.update)

    def setCenter(self, lat, lng):
        self.m_normalMap.latitude = lat
        self.m_normalMap.longitude = lng
        self.m_normalMap.invalidate()
        self.m_largeMap.invalidate()

    def toggleNightMode(self):
        self.invert = not self.invert
        self.update()

    def updateMap(self, rect):
        self.update(rect)

    def activateZoom(self):
        if self.m_normalMap.zoom < MAX_ZOOM:
            self.zoomed = True
            self.tapTimer.stop()
            self.m_largeMap.zoom = self.m_normalMap.zoom + 1
            self.m_largeMap.width = self.m_normalMap.width * 2
            self.m_largeMap.height = self.m_normalMap.height * 2
            self.m_largeMap.latitude = self.m_normalMap.latitude
            self.m_largeMap.longitude = self.m_normalMap.longitude
            self.m_largeMap.invalidate()
            self.update()

    def resizeEvent(self, event):
        self.m_normalMap.width = self.width()
        self.m_normalMap.height = self.height()
        self.m_normalMap.invalidate()
        self.m_largeMap.width = self.m_normalMap.width * 2
        self.m_largeMap.height = self.m_normalMap.height * 2
        self.m_largeMap.invalidate()

    def paintEvent(self, event):
        p = QtGui.QPainter()
        p.begin(self)
        self.m_normalMap.render(p, event.rect())
        p.setPen(QtCore.Qt.black)
        p.drawText(self.rect(), QtCore.Qt.AlignBottom | QtCore.Qt.TextWordWrap, "Map data CCBYSA 2010 OpenStreetMap.org contributors")
        p.end()

        if self.zoomed:
            dim = min((self.width(), self.height()))
            magnifierSize = min((MAX_MAGNIFIER, dim * 2 / 3))
            radius = magnifierSize / 2
            ring = radius - 15
            box = QtCore.QSize(magnifierSize, magnifierSize)

            # reupdate our mask
            if self.maskPixmap.size() != box:
                self.maskPixmap = QtGui.QPixmap(box)
                self.maskPixmap.fill(QtCore.Qt.transparent)

                g = QtGui.QRadialGradient()
                g.setCenter(radius, radius)
                g.setFocalPoint(radius, radius)
                g.setRadius(radius)
                g.setColorAt(1.0, QtGui.QColor(255, 255, 255, 0))
                g.setColorAt(0.5, QtGui.QColor(128, 128, 128, 255))

                mask = QtGui.QPainter(self.maskPixmap)
                mask.setRenderHint(QtGui.QPainter.Antialiasing)
                mask.setCompositionMode(QtGui.QPainter.CompositionMode_Source)
                mask.setBrush(g)
                mask.setPen(QtCore.Qt.NoPen)
                mask.drawRect(self.maskPixmap.rect())
                mask.setBrush(QtGui.QColor(QtCore.Qt.transparent))
                mask.drawEllipse(g.center(), ring, ring)
                mask.end()

            center = self.dragPos - QtCore.QPoint(0, radius)
            center = center + QtCore.QPoint(0, radius / 2)
            corner = center - QtCore.QPoint(radius, radius)

            xy = center * 2 - QtCore.QPoint(radius, radius)

            # set the dimension to the magnified portion only
            if self.zoomPixmap.size() != box:
                self.zoomPixmap = QtGui.QPixmap(box)
                self.zoomPixmap.fill(QtCore.Qt.lightGray)
            p = QtGui.QPainter(self.zoomPixmap)
            p.translate(-xy)
            self.m_largeMap.render(p, QtCore.QRect(xy, box))
            p.end()

            clipPath = QtGui.QPainterPath()
            clipPath.addEllipse(QtCore.QPointF(center), ring, ring)

            p = QtGui.QPainter(self)
            p.setRenderHint(QtGui.QPainter.Antialiasing)
            p.setClipPath(clipPath)
            p.drawPixmap(corner, self.zoomPixmap)
            p.setClipping(False)
            p.drawPixmap(corner, self.maskPixmap)
            p.setPen(QtCore.Qt.gray)
            p.drawPath(clipPath)

        if self.invert:
            p = QtGui.QPainter(self)
            p.setCompositionMode(QtGui.QPainter.CompositionMode_Difference)
            p.fillRect(event.rect(), QtCore.Qt.white)
            p.end()

    def timerEvent(self, event):
        if not self.zoomed:
            self.activateZoom()
        self.update()

    def mousePressEvent(self, event):
        if event.buttons() == QtCore.Qt.LeftButton:
            self.pressed = self.snapped = True;
            self.pressPos = self.dragPos = event.pos()
            self.tapTimer.stop()
            self.tapTimer.start(HOLD_TIME, self)

    def mouseMoveEvent(self, event):
        if event.buttons():
            if not self.zoomed:
                if not self.pressed or not self.snapped:
                    delta = event.pos() - self.pressPos
                    self.pressPos = event.pos()
                    self.m_normalMap.pan(delta)
                else:
                    threshold = 10
                    delta = event.pos() - self.pressPos
                    if self.snapped:
                        self.snapped &= delta.x() < threshold
                        self.snapped &= delta.y() < threshold
                        self.snapped &= delta.x() > -threshold
                        self.snapped &= delta.y() > -threshold
                    if not self.snapped:
                        self.tapTimer.stop()
            else:
                self.dragPos = event.pos()
                self.update()

    def mouseReleaseEvent(self, event):
        self.zoomed = False
        self.update()

    def keyPressEvent(self, event):
        if not self.zoomed:
            if event.key() == QtCore.Qt.Key_Left:
                self.m_normalMap.pan(QtCore.QPoint(20, 0))
            elif event.key() == QtCore.Qt.Key_Right:
                self.m_normalMap.pan(QtCore.QPoint(-20, 0))
            elif event.key() == QtCore.Qt.Key_Up:
                self.m_normalMap.pan(QtCore.QPoint(0, 20))
            elif event.key() == QtCore.Qt.Key_Down:
                self.m_normalMap.pan(QtCore.QPoint(0, -20))
            elif event.key() == QtCore.Qt.Key_Z or event.key() == QtCore.Qt.Key_Select:
                self.dragPos = QtCore.QPoint(self.width() / 2, self.height() / 2)
                self.activateZoom()
            elif event.key() == QtCore.Qt.Key_Plus:
                self.m_normalMap.zoomIn()
            elif event.key() == QtCore.Qt.Key_Minus:
                self.m_normalMap.zoomOut()
        else:
            if event.key() == QtCore.Qt.Key_Z or event.key() == QtCore.Qt.Key_Select:
                self.zoomed = False
                self.update()
            else:
                delta = QtCore.QPoint(0, 0)
                if event.key() == QtCore.Qt.Key_Left:
                    delta = QtCore.QPoint(-15, 0)
                elif event.key() == QtCore.Qt.Key_Right:
                    delta = QtCore.QPoint(15, 0)
                elif event.key() == QtCore.Qt.Key_Up:
                    delta = QtCore.QPoint(0, -15)
                elif event.key() == QtCore.Qt.Key_Down:
                    delta = QtCore.QPoint(0, 15)
                if delta != QtCore.QPoint(0, 0):
                    self.dragPos += delta
                    self.update()

    def wheelEvent(self, event):
        if self.zoomed:
            self.zoomed = False
        if event.delta() > 0:
            self.m_normalMap.zoomIn()
        else:
            self.m_normalMap.zoomOut()



class MapZoom(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.map = LightMaps(self)
        self.setCentralWidget(self.map)

        #self.setCentralWidget(self.map)
        self.map.setFocus()

        osloAction = QtGui.QAction("&Oslo", self)
        berlinAction = QtGui.QAction("&Berlin", self)
        jakartaAction = QtGui.QAction("&Jakarta", self)
        nightModeAction = QtGui.QAction("&Night Mode", self)
        nightModeAction.setCheckable(True)
        nightModeAction.setChecked(False)
        osmAction = QtGui.QAction("&About OpenStreetMap", self)
        osloAction.triggered.connect(self.chooseOslo)
        berlinAction.triggered.connect(self.chooseBerlin)
        jakartaAction.triggered.connect(self.chooseJakarta)
        nightModeAction.triggered.connect(self.map.toggleNightMode)
        osmAction.triggered.connect(self.aboutOsm)

        menu = self.menuBar().addMenu("&Options")
        menu.addAction(osloAction)
        menu.addAction(berlinAction)
        menu.addAction(jakartaAction)
        menu.addSeparator()
        menu.addAction(nightModeAction)
        menu.addAction(osmAction)

    def chooseOslo(self):
        self.map.setCenter(59.9138204, 10.7387413)

    def chooseBerlin(self):
        self.map.setCenter(52.52958999943302, 13.383053541183472)

    def chooseJakarta(self):
        self.map.setCenter(-6.211544, 106.845172)

    def aboutOsm(self):
        QtGui.QDesktopServices.openUrl(QtCore.QUrl("http://www.openstreetmap.org"))

class hilo(threading.Thread):
	def __init__(self, mapa): 
		threading.Thread.__init__(self)
		self.mapa = mapa
		
	def run(self):
		archi=open('ruta.txt','r')
		linea=archi.readline()
		while linea!="":
			lista=linea.split()
			print lista[0]
			print lista[1]
			self.mapa.setCenter(float(lista[0]), float(lista[1]))
			time.sleep(0.2)
			linea=archi.readline()
		archi.close()


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    app.setApplicationName("LightMaps")

    w = MapZoom()
    w.setWindowTitle("OpenStreetMap")

    if False:
        w.showMaximized()
    else:
        w.resize(600, 450)
        w.show()

    sys.exit(app.exec_())

Return to previous page

teaching/ie0117/proyectos/2013/ii/proyecto_gps_-_drivecr/gui_implementation.txt · Last modified: 2022/09/20 00:08 (external edit)