├── requerimientos.txt ├── README.md ├── HerramientasCartecianas.py ├── main.py ├── QtReloj.py └── LICENSE /requerimientos.txt: -------------------------------------------------------------------------------- 1 | click==8.0.1 2 | colorama==0.4.4 3 | PyQt5==5.15.4 4 | pyqt5-plugins==5.15.4.2.2 5 | PyQt5-Qt5==5.15.2 6 | PyQt5-sip==12.9.0 7 | python-dotenv==0.19.0 8 | pytz==2021.1 9 | qt5-applications==5.15.2.2.2 10 | qt5-tools==5.15.2.1.2 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/HerramientasCartecianas.py:
--------------------------------------------------------------------------------
1 | from math import degrees,radians,sin,atan
2 |
3 | def longitudDe_LaRecta (punto_1 :list, punto_2 :list):
4 | # _________________________
5 | # /(X2 - X1)^2 + (Y2 - Y1)^2
6 | return (((punto_2[0] - punto_1[0])**2) + ((punto_2[1] - punto_1[1])**2))**.5
7 |
8 |
9 |
10 | def AngulosDe_LaRecta(punto_1 :list, punto_2 :list):
11 | # (Y2 - Y1) _1 _.-`| (X1,Y1) a<
12 | # m = --------- tan (m) m _.-` _|
13 | # (X2 - X1) (X2,Y2) a< _.-`______|_|
14 | m = (punto_2[1] - punto_1[1])/(punto_2[0] - punto_1[0])
15 | angulos = dict()
16 | angulos['X1,0'] = abs(degrees(atan(m)))
17 | angulos['0,Y2'] = 90 - angulos['X1,0']
18 | return angulos
19 |
20 |
21 |
22 |
23 | def coordenadasCirculares(CoorDel_centro: list, RADIO ,NumDe_DivicionesDel_Circulo = 0, unidadesDe_Desplazamiento = 0, sentido =''):
24 | x_centro = CoorDel_centro[0]
25 | y_centro = CoorDel_centro[1]
26 | x = y = 0
27 |
28 | try:
29 | unidadDe_DivicionDel_Circulo = 360 / NumDe_DivicionesDel_Circulo
30 | except ZeroDivisionError:
31 | return {'x': x_centro, 'y': y_centro}
32 |
33 | if sentido == 'horario':
34 | y = 90 - ((unidadDe_DivicionDel_Circulo * unidadesDe_Desplazamiento) + unidadDe_DivicionDel_Circulo)
35 | x = 90 - abs(y)
36 | elif sentido == 'antihorario':
37 | x = - ((unidadDe_DivicionDel_Circulo * unidadesDe_Desplazamiento) + unidadDe_DivicionDel_Circulo)
38 | y = 90 - abs(x)
39 | else: # sentido Radial
40 | x = 90 - (unidadDe_DivicionDel_Circulo * unidadesDe_Desplazamiento)
41 | y = 90 - abs(x)
42 |
43 | carteciano_x = (sin(radians(x)) * RADIO)
44 | carteciano_y = (sin(radians(y)) * RADIO)
45 | return {'x' : x_centro + carteciano_x, 'y' : y_centro - carteciano_y}
46 |
47 | # x1+ -->
48 | # y1+ +- - - - - |- - - - - - +
49 | # | | . . 12. . |
50 | # v | 11 | 1 |
51 | #[oX +, oY -]__/ [-x, +y ] | 10 | 2 | [+x ,+y ] \__ [oX +, oY -]
52 | # \ [+x1,+y1] |. | [oX,oY] . | [+x1,+y1] /
53 | # ------------|9---------|/---------3 |-----------
54 | # |. | . |
55 | # | 8 | 4 |
56 | #[oX +, oY -]__/ [-x, +y ] | 7 | 5 | [+x, -y ] \__ [oX +, oY -]
57 | # \ [+x1,+y1] | . . 6 . . | [+x1,+y1] /
58 | # +- - - - - |- - - - - - +
59 | # |
60 |
61 |
62 |
63 | if __name__ == '__main__':
64 | XD = coordenadasCirculares([100,100], 100,12,2,'horario')
65 | print(XD)
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | import pytz
2 | from PyQt5 import QtWidgets,QtCore,QtGui
3 | from PyQt5.QtWidgets import QApplication,\
4 | QWidget,\
5 | QPushButton,\
6 | QVBoxLayout,\
7 | QHBoxLayout,\
8 | QButtonGroup,\
9 | QLabel
10 |
11 | from datetime import datetime
12 | import time
13 | from QtReloj import QReloj
14 |
15 | class ventanaPrincipal(QWidget):
16 | def __init__(self):
17 | super(QWidget,self).__init__()
18 | self.porpiedades_internas()
19 | self.iniciador()
20 | self.estilo()
21 | self.estructura()
22 | self.conexiones()
23 | self.ActualizarFechaHora()
24 | self.ARRANCAR()
25 |
26 | def porpiedades_internas(self):
27 | self.setMaximumSize(250,250)
28 |
29 | def iniciador(self):
30 | self.boton_local = QPushButton('Local')
31 | self.boton_Mexico = QPushButton('Cd Mexico')
32 | self.boton_EU = QPushButton('New York')
33 | self.boton_Japon = QPushButton('Tokio')
34 |
35 | self.grupoDe_Botones = QButtonGroup()
36 | self.grupoDe_Botones.addButton(self.boton_local,0)
37 | self.grupoDe_Botones.addButton(self.boton_Mexico,1)
38 | self.grupoDe_Botones.addButton(self.boton_EU,2)
39 | self.grupoDe_Botones.addButton(self.boton_Japon,3)
40 |
41 | self.reloj = QReloj()
42 | self.meridiano = QLabel('AM')
43 | self.sec = self.min = self.hr = 0
44 | self.dia = self.mes = self.anyo = 0
45 |
46 | self.Tiempo = QtCore.QTimer()
47 |
48 | self.Pais_seleccionado = 0
49 | self.Pais = ('Local','Mexico : CDMX', 'EU : Nueva_York','Japon : Tokio')
50 |
51 | self.etiqueta = QLabel('Reloj')
52 |
53 | def estilo(self):
54 | self.setStyleSheet('background-color:#10002b;')
55 | paleta = QtGui.QPalette()
56 | paleta.setColor(QtGui.QPalette.WindowText,QtGui.QColor('#9bf6ff'))
57 | paleta.setColor(QtGui.QPalette.ButtonText,QtGui.QColor('#9bf6ff'))
58 | self.etiqueta.setPalette(paleta)
59 | self.meridiano.setPalette(paleta)
60 | self.meridiano.setAlignment(QtCore.Qt.AlignCenter)
61 | self.boton_EU.setPalette(paleta)
62 | self.boton_EU.setFlat(True)
63 | self.boton_Mexico.setPalette(paleta)
64 | self.boton_Mexico.setFlat(True)
65 | self.boton_Japon.setPalette(paleta)
66 | self.boton_Japon.setFlat(True)
67 | self.boton_local.setPalette(paleta)
68 | self.boton_local.setFlat(True)
69 |
70 | def estructura(self):
71 | h1 = QHBoxLayout()
72 | h1.addWidget(self.etiqueta)
73 | h1.addWidget(self.meridiano)
74 |
75 | div_reloj = QHBoxLayout()
76 | div_reloj.addWidget(self.reloj)
77 | div_botones = QHBoxLayout()
78 | div_botones.addWidget(self.boton_local)
79 | div_botones.addWidget(self.boton_Mexico)
80 | div_botones.addWidget(self.boton_EU)
81 | div_botones.addWidget(self.boton_Japon)
82 |
83 | self.CUERPO = QVBoxLayout(self)
84 | self.CUERPO.addLayout(h1)
85 | self.CUERPO.addLayout(div_reloj)
86 | self.CUERPO.addLayout(div_botones)
87 |
88 | def conexiones(self):
89 | self.grupoDe_Botones.buttonClicked[int].connect(self.__push__)
90 | self.reloj.CambioDeFecha.connect(self.ActualizarFechaHora)
91 | self.Tiempo.timeout.connect(self.reloj.CorrerTiempo)
92 | self.reloj.CambioMeridiano.connect(self.meridiano.setText)
93 |
94 | def ARRANCAR(self):
95 | self.Tiempo.start(1000)
96 |
97 | def __push__(self,Pais_elegido):
98 | self.Pais_seleccionado = Pais_elegido
99 | self.ActualizarFechaHora()
100 |
101 |
102 | def ActualizarFechaHora(self):
103 | ubicacion_actual = self.Pais[self.Pais_seleccionado]
104 | zonaHoraria = None
105 | if ubicacion_actual == 'Mexico : CDMX':
106 | zonaHoraria = pytz.timezone('America/Mexico_City')
107 | elif ubicacion_actual == 'EU : Nueva_York':
108 | zonaHoraria = pytz.timezone('America/New_York')
109 | elif ubicacion_actual == 'Japon : Tokio':
110 | zonaHoraria = pytz.timezone('Asia/Tokyo')
111 | fecha_y_hora = datetime.now(zonaHoraria)
112 | self.hr = fecha_y_hora.hour
113 | self.min = fecha_y_hora.minute
114 | self.sec = int(fecha_y_hora.second)
115 | self.dia = fecha_y_hora.date().day
116 | self.mes = fecha_y_hora.date().month
117 | self.anyo = fecha_y_hora.date().year
118 | self.__actualizarCalendario__()
119 |
120 | self.__actualizarReloj__()
121 |
122 | def __actualizarReloj__(self):
123 | self.reloj.ActualizarHoraCompleta(self.hr, self.min, self.sec)
124 | def __actualizarCalendario__(self):
125 | self.etiqueta.setText(f'{self.dia}/{self.mes}/{self.anyo} : Pais {self.Pais[self.Pais_seleccionado]}')
126 |
127 |
128 |
129 | if __name__ == '__main__':
130 | import sys
131 | app = QApplication(sys.argv)
132 | v = ventanaPrincipal()
133 | v.show()
134 | sys.exit(app.exec_())
--------------------------------------------------------------------------------
/QtReloj.py:
--------------------------------------------------------------------------------
1 | from PyQt5 import QtWidgets,QtGui,QtCore
2 | from PyQt5.QtGui import QPixmap,QPainter
3 | from PyQt5.QtCore import QRectF,QPointF
4 | from HerramientasCartecianas import coordenadasCirculares
5 |
6 | class QReloj(QtWidgets.QWidget):
7 |
8 | CambioDeFecha = QtCore.pyqtSignal(bool)
9 | CambioMeridiano = QtCore.pyqtSignal(str)
10 |
11 | def __init__(self):
12 | super(QtWidgets.QWidget, self).__init__()
13 | self.propiedades_internas()
14 | self.iniciador()
15 |
16 |
17 | def propiedades_internas(self):
18 | self.setMinimumSize(200,200)
19 |
20 |
21 | def Pixmap_verifiacacion(self):
22 | self.lienzo = QPixmap(self.rect().size())
23 | return self.lienzo.isNull()
24 |
25 |
26 | def iniciador(self):
27 | self.lienzo = None
28 | self.CENTRO = None
29 | self.longitudMaxVentana = 0
30 | self.longitudMinVentana = 0
31 |
32 | self.sec = self.min = 59
33 | self.hr = 11
34 | self.hr_24 = 11
35 |
36 |
37 | self.__AbortarMision__ = self.Pixmap_verifiacacion()
38 |
39 |
40 | def __centro(self):
41 | centro_x = self.size().width() / 2
42 | centro_y = self.size().height() / 2
43 | if centro_x > centro_y:
44 | self.longitudMaxVentana = self.size().width()
45 | self.longitudMinVentana = self.size().height()
46 | else:
47 | self.longitudMaxVentana = self.size().height()
48 | self.longitudMinVentana = self.size().width()
49 | return (centro_x,centro_y)
50 |
51 |
52 | def paintEvent(self,event):
53 | # inicio para dibujar todo el programa
54 | self.__iniciar__()
55 |
56 | def __iniciar__(self):
57 | if self.__AbortarMision__:
58 | return
59 | self.CENTRO = self.__centro()
60 | #color del fondo
61 | self.lienzo.fill(QtGui.QColor('#10002b'))
62 | #crear linezo
63 | Pintar = QPainter(self)
64 | Pintar.drawPixmap(0,0,self.lienzo)
65 | self.DibujarContenido(Pintar)
66 |
67 |
68 | def DibujarContenido(self,Pintar):
69 | Pintar.setRenderHint(QPainter.Antialiasing,True)
70 | self._dibujarContornoReloj(Pintar)
71 | self._dibujarManesilla(Pintar,self.longitudMinVentana *.35,self.sec,60,2,'#fdffb6')
72 | self._dibujarManesilla(Pintar,self.longitudMinVentana *.30,self.min,60,5,'#9bf6ff')
73 | self._dibujarManesilla(Pintar,self.longitudMinVentana *.20,self.hr,12,7,'#ffc09f')
74 |
75 |
76 | def resizeEvent(self, event):
77 | #redibujar en caso de redimencionarse la ventana
78 | self.__resetear__()
79 |
80 | def __resetear__(self):
81 | if self.__AbortarMision__:
82 | return
83 | del self.lienzo
84 | self.lienzo = None
85 | self.__AbortarMision__ = self.Pixmap_verifiacacion()
86 | self.__Recalcular__ = True
87 |
88 |
89 | def __Centra_dimencion(self,Tam_Reloj):
90 | tam_x = self.size().width()
91 | tam_y = self.size().height()
92 | return QRectF((tam_x - Tam_Reloj)/2, (tam_y - Tam_Reloj)/2,Tam_Reloj,Tam_Reloj)
93 |
94 |
95 | def _dibujarContornoReloj(self,Pintar):
96 | Pen = QtGui.QPen()
97 | Pen.setWidth(3)
98 | Pen.setColor(QtGui.QColor('#7400b8'))
99 | Pintar.setPen(Pen)
100 | Pintar.drawEllipse(self.__Centra_dimencion(self.longitudMinVentana - 20))
101 | self.__minutero_y_segundero(Pintar)
102 |
103 |
104 | def __minutero_y_segundero(self,Pintar):
105 | Pen = Pintar.pen()
106 | Pen.setColor(QtGui.QColor('#ffadad'))
107 | Pintar.setPen(Pen)
108 |
109 | for i in range(60):
110 | p1 = coordenadasCirculares(self.CENTRO,self.longitudMinVentana*.45, 60,i)
111 | p2 = coordenadasCirculares(self.CENTRO,self.longitudMinVentana*.44, 60,i)
112 | Pintar.drawLine(QPointF(p1['x'],p1['y']),QPointF(p2['x'],p2['y']))
113 |
114 | Pen.setColor(QtGui.QColor('#9bf6ff'))
115 | Pintar.setPen(Pen)
116 | for i in range(12):
117 | p1 = coordenadasCirculares(self.CENTRO,self.longitudMinVentana*.45, 12,i)
118 | p2 = coordenadasCirculares(self.CENTRO,self.longitudMinVentana*.40, 12,i)
119 | p3 = coordenadasCirculares(self.CENTRO,self.longitudMinVentana*.35, 12,i,'horario')
120 | Pintar.drawLine(QPointF(p1['x'],p1['y']),QPointF(p2['x'],p2['y']))
121 | Pintar.drawText(QPointF(p3['x'] - 3,p3['y'] + 3),str(i + 1))
122 |
123 |
124 | def _dibujarManesilla(self,Pintar,longitud,unidad_de_tiempo,ciclos,grosor = 1,color='#000000'):
125 | Pen = Pintar.pen()
126 | Pen.setWidth(grosor)
127 | Pen.setCapStyle(QtCore.Qt.RoundCap)
128 | Pen.setColor(QtGui.QColor(color))
129 | Pintar.setPen(Pen)
130 | XY = coordenadasCirculares(self.CENTRO,longitud,ciclos,unidad_de_tiempo,'horario')
131 | coor_XY = QPointF(XY['x'],XY['y'])
132 | Pintar.drawLine(QPointF(self.CENTRO[0],self.CENTRO[1]),coor_XY)
133 |
134 | def CorrerTiempo(self):
135 | self.ActualizarSec(self.sec + 2)
136 |
137 | def ActualizarSec(self,sec):
138 | self.sec = sec - 1
139 | if self.sec > 59:
140 | self.sec = 0
141 | self.ActualizarMin(self.min + 2)
142 | else:
143 | self.update()
144 |
145 | def ActualizarMin(self,min):
146 | self.min = min - 1
147 | if self.min > 59:
148 | self.min = 0
149 | self.ActualizarHr(self.hr + 2)
150 | else:
151 | self.update()
152 |
153 | def ActualizarHr(self,hr):
154 | self.hr_24 = hr - 1
155 | if self.hr_24 > 23:
156 | self.hr_24 = 0
157 | self.CambioDeFecha.emit(True)
158 | self.CambioMeridiano.emit('AM')
159 | if self.hr_24 > 11 :
160 | self.hr = self.hr_24 - 12
161 | self.CambioMeridiano.emit('PM')
162 | else:
163 | self.hr = self.hr_24
164 | self.update()
165 |
166 | def ActualizarHoraCompleta(self,Hr,Min,Sec):
167 | self.hr_24 = Hr - 1
168 | if self.hr_24 > 11:
169 | self.hr = self.hr_24 - 12
170 | self.CambioMeridiano.emit('PM')
171 | else:
172 | self.hr = self.hr_24
173 | self.CambioMeridiano.emit('AM')
174 | self.min = Min - 1
175 | self.sec = int(Sec) - 1
176 | self.update()
177 |
178 |
179 |
180 |
181 |
182 | if __name__ == '__main__':
183 | import sys
184 | from PyQt5.QtWidgets import QApplication
185 |
186 | app = QApplication(sys.argv)
187 | v = QReloj()
188 | v.ActualizarHoraCompleta(12,17,37)
189 | v.show()
190 | sys.exit(app.exec_())
191 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.