def __init__(self, parent=None): TrackView.__init__(self, parent) self.setScene(QGraphicsScene()) self._track = None handlers = {('init', 'sectors'): self._initTrack, ('init', 'weather'): self._setWeather, ('update', 'weather'): self._setWeather} OTPApplication.registerMsgHandlers(handlers)
def mousePressEvent(self, event): handled = False for item in self.items(event.pos()): if isinstance(item, PhysicalSector): sectId = item.sectorId() if sectId is not None: self.sectorClicked.emit(sectId) handled = True break if not handled: TrackView.mousePressEvent(self, event)
def __init__(self, parent=None): TrackView.__init__(self, parent) scene = QGraphicsScene() scene.setItemIndexMethod(QGraphicsScene.NoIndex) self.setScene(scene) self._cars = {} self._track = None self._timer = QTimer(self) self._timer.setInterval(40) self._timer.timeout.connect(self.scene().advance) handlers = {('init', 'cars_pos'): self._initCars, ('init', 'sectors'): self._initTrack, ('init', 'race_state'): self._setRaceState, ('update', 'cars_pos'): self._moveCars} OTPApplication.registerMsgHandlers(handlers)
def __init__(self, parent, **kwargs): wx.Panel.__init__(self, parent, -1, **kwargs) self.oldtime = time.time() self.viewbox = wx.WrapSizer() #car views global listcar for i, car in enumerate(listcar): c = CarView(self, listcar, i) self.viewbox.Add(c, 0, wx.ALL, 1) #track view c = TrackView(self, listcar) self.viewbox.Add(c, 0, wx.ALL, 1) self.SetAutoLayout(True) self.SetSizer(self.viewbox) #refresh and animation timer self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) self.timer.Start(1 / 60.)