jit imports

This commit is contained in:
leo 2022-05-23 21:51:58 +02:00
parent c3d70b4c76
commit c5339f95e9
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
4 changed files with 112 additions and 87 deletions

7
Car.py
View File

@ -1,10 +1,13 @@
import sumolib
from math import dist, ceil, sqrt, log, cos, sin, atan2, pi
from random import randint, uniform
from PySide6.QtGui import QPainter, QColor
from PySide6.QtCore import QPointF, Signal, QObject, Qt
from itertools import islice
import time
import globalImport
def pysideImports():
globalImport("PySide6.QtGui", ["QPainter", "QColor"])
globalImport("PySide6.QtCore", ["QPointF", "Signal", "QObject", "Qt"])
class updateSignals(QObject):
updateDisp = Signal(tuple)

View File

@ -1,13 +1,16 @@
import sumolib
from Car import Car
from Flow import Flow
from carInfo import Ui_carInfo
from varEdit import Ui_varEdit
from PySide6.QtWidgets import QWidget, QLabel, QToolBox
from PySide6.QtCore import Qt, Slot, Signal, QThread
from PySide6.QtCharts import QChart, QSplineSeries, QLineSeries
from PySide6.QtGui import QColor
from math import ceil, dist
import globalImport
def pysideImports():
globalImport("carInfo", "Ui_carInfo")
globalImport("varEdit", "Ui_varEdit")
globalImport("PySide6.QtWidgets", ["QWidget, QLabel, QToolBox"])
globalImport("PySide6.QtCore", ["Qt", "Slot", "Signal", "QThread"])
globalImport("PySide6.QtCharts", ["QChart", "QSplineSeries", "QLineSeries"])
globalImport("PySide6.QtGui", ["QColor"])
class carInfo(QWidget):
def __init__(self,parent):
@ -116,6 +119,8 @@ class CarController:
self.vroomEnable=True
def addParent(self, mainWindow):
pysideImports()
self.infoWidget=mainWindow.findChild(QToolBox, "carInfos")
varWidget = mainWindow.ui.constEdit

13
Map.py
View File

@ -3,8 +3,16 @@
# mais si on se decide à utiliser notre propre format dans le futur ça facilitera la transition
import sumolib
from PySide6.QtGui import QPainter, QPolygonF
from PySide6.QtCore import Qt, QPointF, QThread
import globalImport
imported = False
def pysideImports():
if imported:
return
globalImport("PySide6.QtGui", ["QPainter", "QPolygonF"])
globalImport("PySide6.QtCore", ["Qt", "QPointF", "QThread"])
imported = True
def safeCall(func):
def inner(*args, **kwargs):
@ -29,6 +37,7 @@ class Map:
@safeCall
def draw(self, painter):
pysideImports()
for edge in self.net.getEdges():
color=Qt.white
if(edge.getFunction()=="internal"):

8
globalImport.py Normal file
View File

@ -0,0 +1,8 @@
def globalImport(namespace, childrens=None):
if childrens is None:
globals()[namespace] = __import__(namespace)
elif isinstance(childrens, str):
globals()[namespace] = __import__(f"{namespace}.{childrens}")
else:
for c in childrens:
globals()[c] = __import__(f"{namespace}.{c}")