| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | import json | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  | import random | 
					
						
							| 
									
										
										
										
											2023-11-02 19:17:25 +00:00
										 |  |  | import base | 
					
						
							|  |  |  | from base import log | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  | from PyQt6.QtCore import QObject, pyqtSlot | 
					
						
							| 
									
										
										
										
											2023-11-09 13:57:36 +00:00
										 |  |  | from core.messenger.broadcast import Broadcast | 
					
						
							|  |  |  | from core.registration.record import * | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  | class CallHandler(QObject): | 
					
						
							|  |  |  |     def __init__(self, sight): | 
					
						
							|  |  |  |         super().__init__() | 
					
						
							|  |  |  |         self.sight = sight | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot(str) | 
					
						
							| 
									
										
										
										
											2023-10-31 07:20:44 +00:00
										 |  |  |     def console(self, msg): | 
					
						
							| 
									
										
										
										
											2023-11-02 19:17:25 +00:00
										 |  |  |         log.console(msg) | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 13:57:36 +00:00
										 |  |  |     """@pyqtSlot(str, result=str)
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     def test2(self, t): | 
					
						
							| 
									
										
										
										
											2023-10-31 07:20:44 +00:00
										 |  |  |         print(t+"s") | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |         return t + "_return" | 
					
						
							| 
									
										
										
										
											2023-11-09 13:57:36 +00:00
										 |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot(result=str) | 
					
						
							|  |  |  |     def getDefaultTemplate(self): | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |         return base.data["default_template"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-30 19:43:35 +00:00
										 |  |  |     @pyqtSlot(result=int) | 
					
						
							|  |  |  |     def frameSupported(self): | 
					
						
							|  |  |  |         return base.frameSupported() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot(int) | 
					
						
							|  |  |  |     def setWidth(self, width): | 
					
						
							|  |  |  |         self.sight.resize(width, self.sight.height()); | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot(int) | 
					
						
							|  |  |  |     def setHeight(self, height): | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |         self.sight.resize(self.sight.width(), height); | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-02 19:17:25 +00:00
										 |  |  |     @pyqtSlot(int, int) | 
					
						
							|  |  |  |     def setSize(self, width, height): | 
					
						
							| 
									
										
										
										
											2023-11-09 13:57:36 +00:00
										 |  |  |         self.sight.resize(width, height); | 
					
						
							| 
									
										
										
										
											2023-11-02 19:17:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 13:57:36 +00:00
										 |  |  |     @pyqtSlot(int, int) | 
					
						
							| 
									
										
										
										
											2023-11-02 19:17:25 +00:00
										 |  |  |     def setPosition(self, x, y): | 
					
						
							| 
									
										
										
										
											2023-11-09 13:57:36 +00:00
										 |  |  |         self.sight.move(x, y) | 
					
						
							| 
									
										
										
										
											2023-11-02 19:17:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-27 13:14:49 +00:00
										 |  |  |     @pyqtSlot(result=str) | 
					
						
							|  |  |  |     def system(self): | 
					
						
							|  |  |  |         return base.data["platform"]["system"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |     @pyqtSlot(str, str, result=str) | 
					
						
							| 
									
										
										
										
											2023-10-27 13:14:49 +00:00
										 |  |  |     def create(self, id, page): | 
					
						
							|  |  |  |         new_id = base.sights.create(id, page) | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |         if new_id is not None: | 
					
						
							|  |  |  |             base.sights.show(new_id) | 
					
						
							| 
									
										
										
										
											2023-10-26 17:43:59 +00:00
										 |  |  |             """ The id will be added to its parent. When parent close will be its children closed as well """ | 
					
						
							|  |  |  |             self.sight.addChild(new_id) | 
					
						
							|  |  |  |             """ The child remember its parent. When the child is closed the parent will be know about that. """ | 
					
						
							|  |  |  |             base.sights.get(new_id).setParent(self.sight.getId()) | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |         return new_id; | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot(str, str, bool) | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |     def addData(self, key, value, is_global=False): | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |         if is_global: | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |             base.sights.addGlobalData(key, value) | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |             self.sight.addData(key, value) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot(str, bool, result=str) | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |     def getData(self, key, is_global=False): | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |         if is_global: | 
					
						
							|  |  |  |             return base.sights.getGlobalData(key) | 
					
						
							|  |  |  |         return self.sight.getData(key) | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot() | 
					
						
							|  |  |  |     def activeSight(self): | 
					
						
							|  |  |  |         if base.data["active_sight"] != self.sight.getId(): | 
					
						
							| 
									
										
										
										
											2023-11-09 13:57:36 +00:00
										 |  |  |             log.byCode("CLA1000E", "Active Sight is " + self.sight.getId()) | 
					
						
							| 
									
										
										
										
											2023-10-26 15:58:46 +00:00
										 |  |  |             base.data["active_sight"] = self.sight.getId() | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot() | 
					
						
							|  |  |  |     def close(self): | 
					
						
							|  |  |  |         base.sights.close(self.sight.getId()) | 
					
						
							| 
									
										
										
										
											2023-10-26 17:43:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot() | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |     def setMaximized(self): | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |         self.sight.showMaximized() | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |         self.sight.setLayoutContentMargins(0, 0, 0, 0)  # because there will be a transparented line as a border | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot() | 
					
						
							|  |  |  |     def setMinimize(self): | 
					
						
							|  |  |  |         self.sight.showMinimized() | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot() | 
					
						
							|  |  |  |     def restoreDown(self): | 
					
						
							|  |  |  |         self.sight.showNormal() | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |         self.sight.setLayoutContentMargins(1, 1, 1, | 
					
						
							|  |  |  |                                            1)  # because if it is no border then I get setgeometry warning what can't be set | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @pyqtSlot() | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     def setFullscreen(self): | 
					
						
							|  |  |  |         self.sight.showFullScreen() | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     """@pyqtSlot(result=str)
 | 
					
						
							|  |  |  |     def getTitle(self): | 
					
						
							|  |  |  |         return self.sight.getTitle();    | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot() | 
					
						
							|  |  |  |     def move(self): | 
					
						
							|  |  |  |         base.data["move"] = True | 
					
						
							| 
									
										
										
										
											2023-10-26 18:47:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot() | 
					
						
							|  |  |  |     def endmove(self): | 
					
						
							|  |  |  |         base.data["move"] = False | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |     @pyqtSlot() | 
					
						
							|  |  |  |     def resize(self): | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |         new_height = base.mousectrl.position[1] - self.sight.pos().y() | 
					
						
							|  |  |  |         new_width = base.mousectrl.position[0] - self.sight.pos().x() | 
					
						
							|  |  |  |         if (new_height < 250): | 
					
						
							| 
									
										
										
										
											2023-05-17 10:16:15 +00:00
										 |  |  |             new_height = 250 | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |         if (new_width < 250): | 
					
						
							|  |  |  |             new_width = 250 | 
					
						
							|  |  |  |         self.sight.resize(new_width, new_height) | 
					
						
							| 
									
										
										
										
											2023-10-26 18:47:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 13:57:36 +00:00
										 |  |  |     """@pyqtSlot(str, str, str)
 | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |     def message(self, label, sight_id_json, data): | 
					
						
							|  |  |  |         sight_list = json.loads(sight_id_json) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if len(sight_list) == 0: | 
					
						
							|  |  |  |             for sight in base.sights.getSights().values(): | 
					
						
							|  |  |  |                 sight.browser.page().runJavaScript("message('" + label + "', '"+data+"')", self.ready) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             for sight_id in sight_list: | 
					
						
							|  |  |  |                 if base.sights.checkKey(sight_id): | 
					
						
							| 
									
										
										
										
											2023-11-09 13:57:36 +00:00
										 |  |  |                     base.sights.get(sight_id).browser.page().runJavaScript("message('" + label + "', '"+data+"')", self.ready)"""
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @pyqtSlot(str, str) | 
					
						
							|  |  |  |     def register(self, type, referral_name): | 
					
						
							|  |  |  |         base.registrar.registry().register(type, referral_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @pyqtSlot(str, str, str, str) | 
					
						
							|  |  |  |     def dataReceiver(self, h_type, h_referral_data, d_json_data, receiver_array=None): | 
					
						
							|  |  |  |         if receiver_array is None: | 
					
						
							|  |  |  |             receiver_array = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if h_type == "message": | 
					
						
							|  |  |  |             r = Record(RecordHeader(h_type, h_referral_data, receiver_array), RecordData(d_json_data)) | 
					
						
							|  |  |  |             msg = Broadcast() | 
					
						
							|  |  |  |             msg.sendMessage(r) | 
					
						
							|  |  |  |         # base.sights.get("main").browser.page().runJavaScript("receiveData('" + type + "', '" + referral_data + "', '"+json_data+"')", self.ready) | 
					
						
							|  |  |  |         # print("RECEIVEEEE " + base.registrar.receiveData(type, referral_data, json_data)) | 
					
						
							| 
									
										
										
										
											2023-10-26 18:47:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def ready(self, returnValue): | 
					
						
							| 
									
										
										
										
											2023-10-27 08:58:33 +00:00
										 |  |  |         if returnValue is not None: | 
					
						
							|  |  |  |             print(returnValue) |