class MapApp(object): def __init__(self): pygame.init() pygame.display.set_caption('Map with cars') self.model = MapModel() self.view = MapView(self.model) self.control = MapControl(self.model) #test ----- # self.model.addCenter(["test", "1", "localhost", "1111"]) # self.model.addClient(["test", "1", "2", "4", "4"]) # self.model.cars[0][0].goto("1,2,4,4") def start_loop(self): clock = pygame.time.Clock() crashed = False while not crashed: #handle input crashed = self.control.checkEvents() self.model.update() #draw screen self.view.draw() #update pygame.display.update() clock.tick(60)
def __init__(self, parent=None): super().__init__(parent) self.mTile = None self.mMapDocument = None self.mMapScene = MapScene(self) self.mMapView = MapView(self, MapViewMode.NoStaticContents) self.mToolManager = ToolManager(self) self.mApplyingChanges = False self.mSynchronizing = False self.setObjectName("TileCollisionEditor") widget = QWidget(self) layout = QVBoxLayout(widget) layout.setSpacing(0) layout.setContentsMargins(5, 5, 5, 5) self.mMapView.setScene(self.mMapScene) self.mMapView.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.mMapView.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) rectangleObjectsTool = CreateRectangleObjectTool(self) ellipseObjectsTool = CreateEllipseObjectTool(self) polygonObjectsTool = CreatePolygonObjectTool(self) polylineObjectsTool = CreatePolylineObjectTool(self) toolBar = QToolBar(self) toolBar.setMovable(False) toolBar.setFloatable(False) toolBar.setContextMenuPolicy(Qt.ActionsContextMenu) self.mToolManager = ToolManager(self) toolBar.addAction( self.mToolManager.registerTool(ObjectSelectionTool(self))) toolBar.addAction(self.mToolManager.registerTool( EditPolygonTool(self))) toolBar.addAction(self.mToolManager.registerTool(rectangleObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(ellipseObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(polygonObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(polylineObjectsTool)) self.setCentralWidget(self.mMapView) self.addToolBar(toolBar) self.mMapScene.setSelectedTool(self.mToolManager.selectedTool()) self.mToolManager.selectedToolChanged.connect(self.setSelectedTool) zoomComboBox = QComboBox() self.statusBar().addPermanentWidget(zoomComboBox) zoomable = self.mMapView.zoomable() zoomable.connectToComboBox(zoomComboBox) undoShortcut = QShortcut(QKeySequence.Undo, self) redoShortcut = QShortcut(QKeySequence.Redo, self) cutShortcut = QShortcut(QKeySequence.Cut, self) copyShortcut = QShortcut(QKeySequence.Copy, self) pasteShortcut = QShortcut(QKeySequence.Paste, self) deleteShortcut = QShortcut(QKeySequence.Delete, self) deleteShortcut2 = QShortcut(QKeySequence.Back, self) undoShortcut.activated.connect(self.undo) redoShortcut.activated.connect(self.redo) cutShortcut.activated.connect(self.cut) copyShortcut.activated.connect(self.copy) pasteShortcut.activated.connect(self.paste) deleteShortcut.activated.connect(self.delete_) deleteShortcut2.activated.connect(self.delete_) self.retranslateUi() self.resize(300, 300) Utils.restoreGeometry(self)
def __init__(self): self.car = Vehicle() # Verify that the Vehicle object was created # print("Vehicle made!") # self.find_own_pos("1362060585", "1362060062") self.minute_warning = False self.second_warning = False self.meter_message = False self.map = MapView() self.text_to_speech = TextToSpeech()
class tela2(BoxLayout): lat = NumericProperty(0) lon = NumericProperty(0) map = MapView() layer = MarkerMapLayer() info = FloatLayout() def __init__(self, **kwargs): super(tela2, self).__init__(**kwargs) self.orientation = "vertical" gps.configure(on_location=self.on_location) gps.start() self.map = MapView(zoom=90, lat=self.lat, lon=self.lon) MapMarker(lon=self.lon, lat=self.lat, source="pessoa.png", on_press=self.on_press) self.add_widget(self.map) self.map.add_widget(self.layer) self.bind(lon=partial(self.tracking)) time.sleep(1) def tracking(self, *args): threading.Timer(5.0, self.tracking).start() self.layer.clear_widgets() self.layer.add_widget( MapMarker(lon=self.lon, lat=self.lat, source="pessoa.png", on_release=self.on_release, on_press=self.on_press)) self.map.center_on(self.lat, self.lon) def on_location(self, **kwargs): self.lat = kwargs['lat'] self.lon = kwargs['lon'] def on_press(self, *args): self.remove_widget(self.info) self.info.clear_widgets() lb1 = Label(text="Voce esta aqui", pos_hint={ "center_x": 0.5, "center_y": 0.5 }) self.info.add_widget(lb1) self.add_widget(self.info) def on_release(self, *args): self.remove_widget(self.info)
def __init__(self, **kwargs): super(tela2, self).__init__(**kwargs) self.orientation = "vertical" gps.configure(on_location=self.on_location) gps.start() self.map = MapView(zoom=90, lat=self.lat, lon=self.lon) MapMarker(lon=self.lon, lat=self.lat, source="pessoa.png", on_press=self.on_press) self.add_widget(self.map) self.map.add_widget(self.layer) self.bind(lon=partial(self.tracking)) time.sleep(1)
def test_init_simple_map(self): """ Makes sure we can initialize a simple MapView object. """ kwargs = {} mapview = MapView(**kwargs) self.assertEqual(len(mapview.children), 2)
def __init__(self, parent = None): super().__init__(parent) self.mTile = None self.mMapDocument = None self.mMapScene = MapScene(self) self.mMapView = MapView(self, MapViewMode.NoStaticContents) self.mToolManager = ToolManager(self) self.mApplyingChanges = False self.mSynchronizing = False self.setObjectName("TileCollisionEditor") widget = QWidget(self) layout = QVBoxLayout(widget) layout.setSpacing(0) layout.setContentsMargins(5, 5, 5, 5) self.mMapView.setScene(self.mMapScene) self.mMapView.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.mMapView.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) rectangleObjectsTool = CreateRectangleObjectTool(self) ellipseObjectsTool = CreateEllipseObjectTool(self) polygonObjectsTool = CreatePolygonObjectTool(self) polylineObjectsTool = CreatePolylineObjectTool(self) toolBar = QToolBar(self) toolBar.setMovable(False) toolBar.setFloatable(False) toolBar.setContextMenuPolicy(Qt.ActionsContextMenu) self.mToolManager = ToolManager(self) toolBar.addAction(self.mToolManager.registerTool(ObjectSelectionTool(self))) toolBar.addAction(self.mToolManager.registerTool(EditPolygonTool(self))) toolBar.addAction(self.mToolManager.registerTool(rectangleObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(ellipseObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(polygonObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(polylineObjectsTool)) self.setCentralWidget(self.mMapView) self.addToolBar(toolBar) self.mMapScene.setSelectedTool(self.mToolManager.selectedTool()) self.mToolManager.selectedToolChanged.connect(self.setSelectedTool) zoomComboBox = QComboBox() self.statusBar().addPermanentWidget(zoomComboBox) zoomable = self.mMapView.zoomable() zoomable.connectToComboBox(zoomComboBox) undoShortcut = QShortcut(QKeySequence.Undo, self) redoShortcut = QShortcut(QKeySequence.Redo, self) cutShortcut = QShortcut(QKeySequence.Cut, self) copyShortcut = QShortcut(QKeySequence.Copy, self) pasteShortcut = QShortcut(QKeySequence.Paste, self) deleteShortcut = QShortcut(QKeySequence.Delete, self) deleteShortcut2 = QShortcut(QKeySequence.Back, self) undoShortcut.activated.connect(self.undo) redoShortcut.activated.connect(self.redo) cutShortcut.activated.connect(self.cut) copyShortcut.activated.connect(self.copy) pasteShortcut.activated.connect(self.paste) deleteShortcut.activated.connect(self.delete_) deleteShortcut2.activated.connect(self.delete_) self.retranslateUi() self.resize(300, 300) Utils.restoreGeometry(self)
def addDocument(self, mapDocument): self.mDocuments.append(mapDocument) self.mUndoGroup.addStack(mapDocument.undoStack()) if (mapDocument.fileName() != ''): self.mFileSystemWatcher.addPath(mapDocument.fileName()) view = MapView() scene = MapScene(view) # scene is owned by the view container = MapViewContainer(view, self.mTabWidget) scene.setMapDocument(mapDocument) view.setScene(scene) documentIndex = self.mDocuments.size() - 1 self.mTabWidget.addTab(container, mapDocument.displayName()) self.mTabWidget.setTabToolTip(documentIndex, mapDocument.fileName()) mapDocument.fileNameChanged.connect(self.fileNameChanged) mapDocument.modifiedChanged.connect(self.updateDocumentTab) mapDocument.saved.connect(self.documentSaved) container.reload.connect(self.reloadRequested) self.switchToDocument(documentIndex) self.centerViewOn(0, 0)
def addDocument(self, mapDocument): self.mDocuments.append(mapDocument) self.mUndoGroup.addStack(mapDocument.undoStack()) if (mapDocument.fileName()!=''): self.mFileSystemWatcher.addPath(mapDocument.fileName()) view = MapView() scene = MapScene(view) # scene is owned by the view container = MapViewContainer(view, self.mTabWidget) scene.setMapDocument(mapDocument) view.setScene(scene) documentIndex = self.mDocuments.size() - 1 self.mTabWidget.addTab(container, mapDocument.displayName()) self.mTabWidget.setTabToolTip(documentIndex, mapDocument.fileName()) mapDocument.fileNameChanged.connect(self.fileNameChanged) mapDocument.modifiedChanged.connect(self.updateDocumentTab) mapDocument.saved.connect(self.documentSaved) container.reload.connect(self.reloadRequested) self.switchToDocument(documentIndex) self.centerViewOn(0, 0)
def newMapView(self, map): """ Creates a new map view """ mapview = MapView(map) self._mapviewlist.append(mapview) map_action = Action(unicode(map.getId())) action.activated.connect(cbwa(self.showMapView, mapview), sender=map_action, weak=False) self._mapgroup.addAction(map_action) self.showMapView(mapview) events.mapAdded.send(sender=self, map=map) return mapview
def initUI(self): centralWidget = QWidget() self.setCentralWidget(centralWidget) self.setWindowTitle(self._gameBoard.name) self.setWindowIcon( QIcon(os.path.join('./Pictures/', 'berserker_icon.png')) ) #Apparently this doens't work the same way on a mac. self.statusBar().showMessage('Ready!') vbox = QVBoxLayout() centralWidget.setLayout(vbox) self.gameStats = GameStats(self) self.mapView = MapView(self) self.bottomButtons = BottomButtons(self) vbox.addWidget(self.gameStats) vbox.addWidget(self.mapView) vbox.addWidget(self.bottomButtons) screen = QDesktopWidget().screenGeometry() self.setGeometry( (screen.width() - (self.gameboard.width - 1) * 20) / 2, (screen.height() - self.gameboard.height * 20 - 200) / 2, 500, 400) self.show()
def initUI(self): centralWidget = QWidget() self.setCentralWidget(centralWidget) self.setWindowTitle(self._gameBoard.name) self.setWindowIcon(QIcon(os.path.join('./Pictures/', 'berserker_icon.png'))) #Apparently this doens't work the same way on a mac. self.statusBar().showMessage('Ready!') vbox = QVBoxLayout() centralWidget.setLayout(vbox) self.gameStats = GameStats(self) self.mapView = MapView(self) self.bottomButtons = BottomButtons(self) vbox.addWidget(self.gameStats) vbox.addWidget(self.mapView) vbox.addWidget(self.bottomButtons) screen = QDesktopWidget().screenGeometry() self.setGeometry((screen.width() - (self.gameboard.width - 1) * 20) / 2, (screen.height() - self.gameboard.height * 20 - 200) / 2, 500, 400) self.show()
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(820, 627) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/icons/res/logo.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget) self.verticalLayout.setObjectName("verticalLayout") self.tabs = QtGui.QTabWidget(self.centralwidget) self.tabs.setTabShape(QtGui.QTabWidget.Rounded) self.tabs.setObjectName("tabs") self.tab_map = QtGui.QWidget() self.tab_map.setObjectName("tab_map") self.verticalLayout_2 = QtGui.QVBoxLayout(self.tab_map) self.verticalLayout_2.setObjectName("verticalLayout_2") self.splitter = QtGui.QSplitter(self.tab_map) self.splitter.setOrientation(QtCore.Qt.Vertical) self.splitter.setObjectName("splitter") self.graphicsViewMap = MapView(self.splitter) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(200) sizePolicy.setHeightForWidth(self.graphicsViewMap.sizePolicy().hasHeightForWidth()) self.graphicsViewMap.setSizePolicy(sizePolicy) self.graphicsViewMap.setMinimumSize(QtCore.QSize(0, 400)) self.graphicsViewMap.setObjectName("graphicsViewMap") self.verticalLayout_2.addWidget(self.splitter) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/icons/res/applications-internet.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tabs.addTab(self.tab_map, icon1, "") self.tab_events = QtGui.QWidget() self.tab_events.setObjectName("tab_events") self.verticalLayout_6 = QtGui.QVBoxLayout(self.tab_events) self.verticalLayout_6.setObjectName("verticalLayout_6") self.splitter_2 = QtGui.QSplitter(self.tab_events) self.splitter_2.setOrientation(QtCore.Qt.Vertical) self.splitter_2.setObjectName("splitter_2") self.groupBox = QtGui.QGroupBox(self.splitter_2) self.groupBox.setObjectName("groupBox") self.horizontalLayout_5 = QtGui.QHBoxLayout(self.groupBox) self.horizontalLayout_5.setSpacing(1) self.horizontalLayout_5.setMargin(1) self.horizontalLayout_5.setObjectName("horizontalLayout_5") self.tableHighPrio = QTableViewHighPrio(self.groupBox) self.tableHighPrio.setObjectName("tableHighPrio") self.horizontalLayout_5.addWidget(self.tableHighPrio) self.groupBox_2 = QtGui.QGroupBox(self.splitter_2) self.groupBox_2.setObjectName("groupBox_2") self.horizontalLayout_6 = QtGui.QHBoxLayout(self.groupBox_2) self.horizontalLayout_6.setSpacing(1) self.horizontalLayout_6.setMargin(1) self.horizontalLayout_6.setObjectName("horizontalLayout_6") self.tableLowPrio = QTableViewLowPrio(self.groupBox_2) self.tableLowPrio.setObjectName("tableLowPrio") self.horizontalLayout_6.addWidget(self.tableLowPrio) self.verticalLayout_6.addWidget(self.splitter_2) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/icons/res/application-vnd.oasis.opendocument.spreadsheet.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tabs.addTab(self.tab_events, icon2, "") self.tab_conf = QtGui.QWidget() self.tab_conf.setObjectName("tab_conf") self.verticalLayout_4 = QtGui.QVBoxLayout(self.tab_conf) self.verticalLayout_4.setObjectName("verticalLayout_4") self.toolBox_configuracion_comandos = QtGui.QToolBox(self.tab_conf) self.toolBox_configuracion_comandos.setFrameShape(QtGui.QFrame.StyledPanel) self.toolBox_configuracion_comandos.setFrameShadow(QtGui.QFrame.Raised) self.toolBox_configuracion_comandos.setObjectName("toolBox_configuracion_comandos") self.pageComs = QtGui.QWidget() self.pageComs.setGeometry(QtCore.QRect(0, 0, 786, 423)) self.pageComs.setObjectName("pageComs") self.verticalLayout_9 = QtGui.QVBoxLayout(self.pageComs) self.verticalLayout_9.setObjectName("verticalLayout_9") self.verticalLayout_8 = QtGui.QVBoxLayout() self.verticalLayout_8.setObjectName("verticalLayout_8") self.label_2 = QtGui.QLabel(self.pageComs) self.label_2.setAlignment(QtCore.Qt.AlignCenter) self.label_2.setObjectName("label_2") self.verticalLayout_8.addWidget(self.label_2) self.horizontalLayout_4 = QtGui.QHBoxLayout() self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.label_6 = QtGui.QLabel(self.pageComs) self.label_6.setObjectName("label_6") self.horizontalLayout_4.addWidget(self.label_6) self.comboBox_concentrador = QComboBoxModelQuery(self.pageComs) self.comboBox_concentrador.setObjectName("comboBox_concentrador") self.horizontalLayout_4.addWidget(self.comboBox_concentrador) self.label_4 = QtGui.QLabel(self.pageComs) self.label_4.setObjectName("label_4") self.horizontalLayout_4.addWidget(self.label_4) self.comboPgmZona = QtGui.QComboBox(self.pageComs) self.comboPgmZona.setObjectName("comboPgmZona") self.horizontalLayout_4.addWidget(self.comboPgmZona) self.label_5 = QtGui.QLabel(self.pageComs) self.label_5.setObjectName("label_5") self.horizontalLayout_4.addWidget(self.label_5) self.comboPgmUc = QtGui.QComboBox(self.pageComs) self.comboPgmUc.setObjectName("comboPgmUc") self.horizontalLayout_4.addWidget(self.comboPgmUc) spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_4.addItem(spacerItem) self.pushButton_prog_manual = QtGui.QPushButton(self.pageComs) self.pushButton_prog_manual.setObjectName("pushButton_prog_manual") self.horizontalLayout_4.addWidget(self.pushButton_prog_manual) self.pushButton_prog_auto = QtGui.QPushButton(self.pageComs) self.pushButton_prog_auto.setObjectName("pushButton_prog_auto") self.horizontalLayout_4.addWidget(self.pushButton_prog_auto) self.verticalLayout_8.addLayout(self.horizontalLayout_4) spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_8.addItem(spacerItem1) self.verticalLayout_9.addLayout(self.verticalLayout_8) self.toolBox_configuracion_comandos.addItem(self.pageComs, "") self.pageCOs = QtGui.QWidget() self.pageCOs.setGeometry(QtCore.QRect(0, 0, 786, 423)) self.pageCOs.setObjectName("pageCOs") self.verticalLayout_5 = QtGui.QVBoxLayout(self.pageCOs) self.verticalLayout_5.setObjectName("verticalLayout_5") self.verticalLayout_7 = QtGui.QVBoxLayout() self.verticalLayout_7.setSpacing(2) self.verticalLayout_7.setObjectName("verticalLayout_7") self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.label = QtGui.QLabel(self.pageCOs) self.label.setObjectName("label") self.horizontalLayout_3.addWidget(self.label) spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem2) self.pushAddCO = QtGui.QPushButton(self.pageCOs) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/icons/res/list-add.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.pushAddCO.setIcon(icon3) self.pushAddCO.setObjectName("pushAddCO") self.horizontalLayout_3.addWidget(self.pushAddCO) self.verticalLayout_7.addLayout(self.horizontalLayout_3) self.tableCO = QTableCO(self.pageCOs) self.tableCO.setObjectName("tableCO") self.verticalLayout_7.addWidget(self.tableCO) self.horizontalLayout_2 = QtGui.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.label_3 = QtGui.QLabel(self.pageCOs) self.label_3.setObjectName("label_3") self.horizontalLayout_2.addWidget(self.label_3) spacerItem3 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_2.addItem(spacerItem3) self.toolAddUC = QtGui.QToolButton(self.pageCOs) self.toolAddUC.setObjectName("toolAddUC") self.horizontalLayout_2.addWidget(self.toolAddUC) self.verticalLayout_7.addLayout(self.horizontalLayout_2) self.tableUC = QTableUC(self.pageCOs) self.tableUC.setObjectName("tableUC") self.verticalLayout_7.addWidget(self.tableUC) self.verticalLayout_5.addLayout(self.verticalLayout_7) self.toolBox_configuracion_comandos.addItem(self.pageCOs, "") self.verticalLayout_4.addWidget(self.toolBox_configuracion_comandos) icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(":/icons/res/configure.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tabs.addTab(self.tab_conf, icon4, "") self.verticalLayout.addWidget(self.tabs) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 820, 24)) self.menubar.setObjectName("menubar") self.menuSCADA = QtGui.QMenu(self.menubar) self.menuSCADA.setObjectName("menuSCADA") self.menuOptions = QtGui.QMenu(self.menubar) self.menuOptions.setObjectName("menuOptions") self.menuBarra_de_herramientas = QtGui.QMenu(self.menuOptions) self.menuBarra_de_herramientas.setObjectName("menuBarra_de_herramientas") self.menuHelp = QtGui.QMenu(self.menubar) self.menuHelp.setObjectName("menuHelp") self.menuAdmin = QtGui.QMenu(self.menubar) self.menuAdmin.setObjectName("menuAdmin") MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.scadaToolbar = QtGui.QToolBar(MainWindow) self.scadaToolbar.setIconSize(QtCore.QSize(32, 32)) self.scadaToolbar.setObjectName("scadaToolbar") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.scadaToolbar) self.toolBar_mapa = QtGui.QToolBar(MainWindow) self.toolBar_mapa.setIconSize(QtCore.QSize(32, 32)) self.toolBar_mapa.setObjectName("toolBar_mapa") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_mapa) self.toolBar_mapa_visor = QtGui.QToolBar(MainWindow) self.toolBar_mapa_visor.setIconSize(QtCore.QSize(32, 32)) self.toolBar_mapa_visor.setObjectName("toolBar_mapa_visor") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_mapa_visor) self.toolBar_debug = QtGui.QToolBar(MainWindow) self.toolBar_debug.setIconSize(QtCore.QSize(32, 32)) self.toolBar_debug.setObjectName("toolBar_debug") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_debug) self.toolBar_impresion = QtGui.QToolBar(MainWindow) self.toolBar_impresion.setIconSize(QtCore.QSize(32, 32)) self.toolBar_impresion.setObjectName("toolBar_impresion") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_impresion) self.actionAbout = QtGui.QAction(MainWindow) self.actionAbout.setObjectName("actionAbout") self.actionAbout_Qt = QtGui.QAction(MainWindow) self.actionAbout_Qt.setObjectName("actionAbout_Qt") self.actionQuit = QtGui.QAction(MainWindow) self.actionQuit.setObjectName("actionQuit") self.actionStart = QtGui.QAction(MainWindow) self.actionStart.setCheckable(True) icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap(":/icons/res/player-time.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionStart.setIcon(icon5) self.actionStart.setObjectName("actionStart") self.actionStop = QtGui.QAction(MainWindow) icon6 = QtGui.QIcon() icon6.addPixmap(QtGui.QPixmap(":/icons/res/process-stop.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionStop.setIcon(icon6) self.actionStop.setObjectName("actionStop") self.actionSCADA_Config = QtGui.QAction(MainWindow) self.actionSCADA_Config.setIcon(icon4) self.actionSCADA_Config.setObjectName("actionSCADA_Config") self.actionLogs = QtGui.QAction(MainWindow) self.actionLogs.setObjectName("actionLogs") self.actionMapa = QtGui.QAction(MainWindow) icon7 = QtGui.QIcon() icon7.addPixmap(QtGui.QPixmap(":/icons/res/applications-accessories.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionMapa.setIcon(icon7) self.actionMapa.setObjectName("actionMapa") self.actionEdici_n_Esquina = QtGui.QAction(MainWindow) self.actionEdici_n_Esquina.setObjectName("actionEdici_n_Esquina") self.actionUsuario = QtGui.QAction(MainWindow) self.actionUsuario.setObjectName("actionUsuario") self.actionDBUrl = QtGui.QAction(MainWindow) self.actionDBUrl.setObjectName("actionDBUrl") self.actionScada = QtGui.QAction(MainWindow) self.actionScada.setCheckable(True) self.actionScada.setChecked(True) self.actionScada.setObjectName("actionScada") self.actionIO = QtGui.QAction(MainWindow) self.actionIO.setCheckable(True) icon8 = QtGui.QIcon() icon8.addPixmap(QtGui.QPixmap(":/icons/res/strigi.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionIO.setIcon(icon8) self.actionIO.setObjectName("actionIO") self.actionLimpiar_Eventos = QtGui.QAction(MainWindow) icon9 = QtGui.QIcon() icon9.addPixmap(QtGui.QPixmap(":/icons/res/draw-eraser.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionLimpiar_Eventos.setIcon(icon9) self.actionLimpiar_Eventos.setObjectName("actionLimpiar_Eventos") self.actionImprimir = QtGui.QAction(MainWindow) icon10 = QtGui.QIcon() icon10.addPixmap(QtGui.QPixmap(":/icons/res/printer.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionImprimir.setIcon(icon10) self.actionImprimir.setObjectName("actionImprimir") self.menuSCADA.addAction(self.actionUsuario) self.menuSCADA.addAction(self.actionStart) self.menuSCADA.addAction(self.actionStop) self.menuSCADA.addAction(self.actionQuit) self.menuBarra_de_herramientas.addAction(self.actionScada) self.menuOptions.addAction(self.actionSCADA_Config) self.menuOptions.addAction(self.actionLogs) self.menuOptions.addAction(self.actionDBUrl) self.menuOptions.addAction(self.menuBarra_de_herramientas.menuAction()) self.menuHelp.addAction(self.actionAbout) self.menuHelp.addAction(self.actionAbout_Qt) self.menuAdmin.addAction(self.actionMapa) self.menubar.addAction(self.menuSCADA.menuAction()) self.menubar.addAction(self.menuAdmin.menuAction()) self.menubar.addAction(self.menuOptions.menuAction()) self.menubar.addAction(self.menuHelp.menuAction()) self.scadaToolbar.addAction(self.actionStart) self.scadaToolbar.addAction(self.actionStop) self.toolBar_mapa.addAction(self.actionMapa) self.toolBar_debug.addAction(self.actionIO) self.toolBar_debug.addAction(self.actionLimpiar_Eventos) self.toolBar_debug.addAction(self.actionSCADA_Config) self.toolBar_impresion.addAction(self.actionImprimir) self.retranslateUi(MainWindow) self.tabs.setCurrentIndex(2) self.toolBox_configuracion_comandos.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(MainWindow)
class TileCollisionEditor(QMainWindow): closed = pyqtSignal() def __init__(self, parent = None): super().__init__(parent) self.mTile = None self.mMapDocument = None self.mMapScene = MapScene(self) self.mMapView = MapView(self, MapViewMode.NoStaticContents) self.mToolManager = ToolManager(self) self.mApplyingChanges = False self.mSynchronizing = False self.setObjectName("TileCollisionEditor") widget = QWidget(self) layout = QVBoxLayout(widget) layout.setSpacing(0) layout.setContentsMargins(5, 5, 5, 5) self.mMapView.setScene(self.mMapScene) self.mMapView.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.mMapView.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) rectangleObjectsTool = CreateRectangleObjectTool(self) ellipseObjectsTool = CreateEllipseObjectTool(self) polygonObjectsTool = CreatePolygonObjectTool(self) polylineObjectsTool = CreatePolylineObjectTool(self) toolBar = QToolBar(self) toolBar.setMovable(False) toolBar.setFloatable(False) toolBar.setContextMenuPolicy(Qt.ActionsContextMenu) self.mToolManager = ToolManager(self) toolBar.addAction(self.mToolManager.registerTool(ObjectSelectionTool(self))) toolBar.addAction(self.mToolManager.registerTool(EditPolygonTool(self))) toolBar.addAction(self.mToolManager.registerTool(rectangleObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(ellipseObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(polygonObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(polylineObjectsTool)) self.setCentralWidget(self.mMapView) self.addToolBar(toolBar) self.mMapScene.setSelectedTool(self.mToolManager.selectedTool()) self.mToolManager.selectedToolChanged.connect(self.setSelectedTool) zoomComboBox = QComboBox() self.statusBar().addPermanentWidget(zoomComboBox) zoomable = self.mMapView.zoomable() zoomable.connectToComboBox(zoomComboBox) undoShortcut = QShortcut(QKeySequence.Undo, self) redoShortcut = QShortcut(QKeySequence.Redo, self) cutShortcut = QShortcut(QKeySequence.Cut, self) copyShortcut = QShortcut(QKeySequence.Copy, self) pasteShortcut = QShortcut(QKeySequence.Paste, self) deleteShortcut = QShortcut(QKeySequence.Delete, self) deleteShortcut2 = QShortcut(QKeySequence.Back, self) undoShortcut.activated.connect(self.undo) redoShortcut.activated.connect(self.redo) cutShortcut.activated.connect(self.cut) copyShortcut.activated.connect(self.copy) pasteShortcut.activated.connect(self.paste) deleteShortcut.activated.connect(self.delete_) deleteShortcut2.activated.connect(self.delete_) self.retranslateUi() self.resize(300, 300) Utils.restoreGeometry(self) def __del__(self): self.setTile(None) def setMapDocument(self, mapDocument): if (self.mMapDocument): self.mMapDocument.disconnect() self.mMapDocument = mapDocument if (self.mMapDocument): self.mMapDocument.tileObjectGroupChanged.connect(self.tileObjectGroupChanged) self.mMapDocument.tilesetFileNameChanged.connect(self.tilesetFileNameChanged) self.mMapDocument.currentObjectChanged.connect(self.currentObjectChanged) def writeSettings(self): Utils.saveGeometry(self) def setTile(self, tile): if type(tile)==list: tile = tile[0] if (self.mTile == tile): return self.mTile = tile self.mMapScene.disableSelectedTool() previousDocument = self.mMapScene.mapDocument() if (tile): self.mMapView.setEnabled(not self.mTile.tileset().isExternal()) map = Map(Map.Orientation.Orthogonal, 1, 1, tile.width(), tile.height()) map.addTileset(tile.sharedTileset()) tileLayer = TileLayer(QString(), 0, 0, 1, 1) tileLayer.setCell(0, 0, Cell(tile)) map.addLayer(tileLayer) objectGroup = None if (tile.objectGroup()): objectGroup = tile.objectGroup().clone() else: objectGroup = ObjectGroup() objectGroup.setDrawOrder(ObjectGroup.DrawOrder.IndexOrder) map.addLayer(objectGroup) mapDocument = MapDocument(map) self.mMapScene.setMapDocument(mapDocument) self.mToolManager.setMapDocument(mapDocument) mapDocument.setCurrentLayerIndex(1) self.mMapScene.enableSelectedTool() mapDocument.undoStack().indexChanged.connect(self.applyChanges) else: self.mMapView.setEnabled(False) self.mMapScene.setMapDocument(None) self.mToolManager.setMapDocument(None) if (previousDocument): previousDocument.undoStack().disconnect() del previousDocument def closeEvent(self, event): super().closeEvent(event) if (event.isAccepted()): self.closed.emit() def changeEvent(self, e): super().changeEvent(e) x = e.type() if x==QEvent.LanguageChange: self.retranslateUi() else: pass def setSelectedTool(self, tool): if type(tool)==list: tool = tool[0] self.mMapScene.disableSelectedTool() self.mMapScene.setSelectedTool(tool) self.mMapScene.enableSelectedTool() def applyChanges(self): if (self.mSynchronizing): return dummyDocument = self.mMapScene.mapDocument() objectGroup = dummyDocument.map().layerAt(1) clonedGroup = objectGroup.clone() undoStack = self.mMapDocument.undoStack() self.mApplyingChanges = True undoStack.push(ChangeTileObjectGroup(self.mMapDocument, self.mTile, clonedGroup)) self.mApplyingChanges = False def tileObjectGroupChanged(self, tile): if (self.mTile != tile): return if (self.mApplyingChanges): return self.mSynchronizing = True dummyDocument = self.mMapScene.mapDocument() layerModel = dummyDocument.layerModel() dummyDocument.undoStack().clear() layerModel.takeLayerAt(1).close() objectGroup = None if (tile.objectGroup()): objectGroup = tile.objectGroup().clone() else: objectGroup = ObjectGroup() objectGroup.setDrawOrder(ObjectGroup.DrawOrder.IndexOrder) layerModel.insertLayer(1, objectGroup) dummyDocument.setCurrentLayerIndex(1) self.mSynchronizing = False def currentObjectChanged(self, object): if type(object)==list and len(object)>0: object = object[0] # If a tile object is selected, edit the collision shapes for that tile if object and object.typeId() == Object.MapObjectType: cell = object.cell() if cell.tile: self.setTile(cell.tile) def tilesetFileNameChanged(self, tileset): if (self.mTile and self.mTile.tileset() == tileset): self.mMapView.setEnabled(not tileset.isExternal()) def undo(self): if (self.mMapDocument): self.mMapDocument.undoStack().undo() def redo(self): if (self.mMapDocument): self.mMapDocument.undoStack().redo() def cut(self): if (not self.mTile): return self.copy() self.delete_(Operation.Cut) def copy(self): if (not self.mTile): return dummyDocument = self.mMapScene.mapDocument() ClipboardManager.instance().copySelection(dummyDocument) def paste(self): if (not self.mTile): return clipboardManager = ClipboardManager.instance() map = clipboardManager.map() if (not map): return # We can currently only handle maps with a single layer if (map.layerCount() != 1): return layer = map.layerAt(0) objectGroup = layer.asObjectGroup() if objectGroup: dummyDocument = self.mMapScene.mapDocument() clipboardManager.pasteObjectGroup(objectGroup, dummyDocument, self.mMapView, ClipboardManager.NoTileObjects) def delete_(self, operation = Operation.Delete): if (not self.mTile): return dummyDocument = self.mMapScene.mapDocument() selectedObjects = dummyDocument.selectedObjects() if (selectedObjects.isEmpty()): return undoStack = dummyDocument.undoStack() if Operation.Delete: _x = self.tr("Delete") else: _x = self.tr("Cut") undoStack.beginMacro(operation == _x) for mapObject in selectedObjects: undoStack.push(RemoveMapObject(dummyDocument, mapObject)) undoStack.endMacro() def retranslateUi(self): self.setWindowTitle(self.tr("Tile Collision Editor"))
class UserInterface(QMainWindow): def __init__(self, parent): super().__init__(parent) self._gameBoard = GameBoard() self._parent = parent self._gameover = False self._isTowerSelected = False self._isTowerHovered = False self._towerBeingHovered = None self._selectedTower = None self._waveFinishTime = 0 self._gameSpeed = self._parent.speed self._timePassed = 0 self.timer = QBasicTimer() self._gameBoard.readMapData(os.path.join('./Maps/', self._parent.map)) self.timer.start(self._gameSpeed, self) self.initUI() def initUI(self): centralWidget = QWidget() self.setCentralWidget(centralWidget) self.setWindowTitle(self._gameBoard.name) self.setWindowIcon(QIcon(os.path.join('./Pictures/', 'berserker_icon.png'))) #Apparently this doens't work the same way on a mac. self.statusBar().showMessage('Ready!') vbox = QVBoxLayout() centralWidget.setLayout(vbox) self.gameStats = GameStats(self) self.mapView = MapView(self) self.bottomButtons = BottomButtons(self) vbox.addWidget(self.gameStats) vbox.addWidget(self.mapView) vbox.addWidget(self.bottomButtons) screen = QDesktopWidget().screenGeometry() self.setGeometry((screen.width() - (self.gameboard.width - 1) * 20) / 2, (screen.height() - self.gameboard.height * 20 - 200) / 2, 500, 400) self.show() def getGameboard(self): return self._gameBoard def getIsTowerSelected(self): return self._isTowerSelected def setIsTowerSelected(self, boolean): self._isTowerSelected = boolean def getSelectedTower(self): return self._selectedTower def setSelectedTower(self, towerType): self._selectedTower = towerType def getIsTowerBeingHovered(self): return self._isTowerHovered def setIsTowerBeingHovered(self, boolean, tower): self._isTowerHovered = boolean self._towerBeingHovered = tower def getTowerBeingHovered(self): return self._towerBeingHovered def getGameStats(self): return self.gameStats def getTimePassed(self): return self._timePassed def setWaveFinishTime(self, value): self._waveFinishTime = value def getGameOver(self): return self._gameover def timerEvent(self, event): # The time passed attribute helps with setting the enemy appearance interval and tower firerate. self._timePassed += 1 self.mapView.summonEnemy() self.mapView.moveEnemies() self.mapView.checkShooting() self.mapView.moveProjectiles() self.mapView.update() def loseGame(self): self.bottomButtons.clockTimer.stop() self.timer.stop() self.statusBar().showMessage('Game has ended. You lost.') self._gameover = True self.popUp = QFrame() self.popUp.setGeometry(500, 500, 100, 100) vbox = QVBoxLayout() youLost = QLabel() youLost.setPixmap(QPixmap(os.path.join('./Pictures/', "game_over.png"))) vbox.addWidget(youLost) done = QPushButton("Done") vbox.addWidget(done) self.popUp.setLayout(vbox) self.popUp.move(self.mapToGlobal(QPoint(0,0)).x() + self.gameboard.width*blockSize / 2 - 130, self.mapToGlobal(QPoint(0,0)).y() + self.gameboard.height*blockSize / 2) self.popUp.show() done.clicked.connect(self.backToMainMenu) def winGame(self): self.bottomButtons.clockTimer.stop() self.timer.stop() self.statusBar().showMessage('Game has ended. You won.') self._gameover = True self.popUp = QFrame() self.popUp.setGeometry(500, 500, 100, 100) vbox = QVBoxLayout() youLost = QLabel() youLost.setPixmap(QPixmap(os.path.join('./Pictures/', "victory.png"))) vbox.addWidget(youLost) done = QPushButton("Done") vbox.addWidget(done) self.popUp.setLayout(vbox) self.popUp.move(self.mapToGlobal(QPoint(0,0)).x() + self.gameboard.width*blockSize / 2 - 130, self.mapToGlobal(QPoint(0,0)).y() + self.gameboard.height*blockSize / 2) self.popUp.show() done.clicked.connect(self.backToMainMenu) def backToMainMenu(self): self._parent.show() self.popUp.deleteLater() self.deleteLater() def getGameSpeed(self): return self._gameSpeed def setGameSpeed(self, value): self._gameSpeed = value def getWaveFinishTime(self): return self._waveFinishTime def getTimer(self): return self.timer isTowerSelected = property(getIsTowerSelected, setIsTowerSelected) selectedTower = property(getSelectedTower, setSelectedTower) isTowerHovered = property(getIsTowerBeingHovered) towerBeingHovered = property(getTowerBeingHovered) gamestats = property(getGameStats) gameboard = property(getGameboard) timePassed = property(getTimePassed) gameover = property(getGameOver) gameSpeed = property(getGameSpeed, setGameSpeed) waveFinishTime = property(getWaveFinishTime, setWaveFinishTime)
class tela3(BoxLayout): lat = NumericProperty(0) lon = NumericProperty(0) info = FloatLayout() layer = MarkerMapLayer() map = MapView() layer = MarkerMapLayer() def __init__(self, **kwargs): super(tela3, self).__init__(**kwargs) self.orientation = "vertical" gps.configure(on_location=self.on_location) gps.start() self.map = MapView(zoom=90, lat=self.lat, lon=self.lon) MapMarker(lon=self.lon, lat=self.lat, source="bus.png", on_release=self.on_release1) self.add_widget(self.map) self.map.add_widget(self.layer) self.bind(lon=partial(self.tracking)) time.sleep(1) def tracking(self, *args): threading.Timer(5.0, self.tracking).start() self.layer.clear_widgets() self.layer.add_widget( MapMarker(lon=self.lon, lat=self.lat, source="bus.png", on_release=self.on_release1)) self.map.center_on(self.lat, self.lon) def on_location(self, **kwargs): self.lat = kwargs['lat'] self.lon = kwargs['lon'] def on_release(self, *args): self.remove_widget(self.info) def on_release1(self, *args): self.remove_widget(self.info) self.info.clear_widgets() lb1 = Label(text="Onibus linha: ", pos_hint={ "center_x": 0.38, "center_y": 0.4 }) lb2 = Label(text="Numero de passageiros:", pos_hint={ "center_x": 0.27, "center_y": 0.5 }) lb3 = Label(text="Opcao cadeirante:", pos_hint={ "center_x": 0.33, "center_y": 0.6 }) lb4 = Label(text="Transito:", pos_hint={ "center_x": 0.41, "center_y": 0.7 }) e1 = TextInput(size_hint=(0.2, 0.05), pos_hint={ "center_x": 0.6, "center_y": 0.4 }) e2 = TextInput(size_hint=(0.2, 0.05), pos_hint={ "center_x": 0.6, "center_y": 0.5 }) e3 = TextInput(size_hint=(0.2, 0.05), pos_hint={ "center_x": 0.6, "center_y": 0.6 }) e4 = TextInput(size_hint=(0.2, 0.05), pos_hint={ "center_x": 0.6, "center_y": 0.7 }) bt1 = Button(text="Confirmar", size_hint=(0.2, 0.1), pos_hint={ "center_x": 0.5, "center_y": 0.2 }, on_release=self.on_release) self.info.add_widget(lb1) self.info.add_widget(lb2) self.info.add_widget(lb3) self.info.add_widget(lb4) self.info.add_widget(e1) self.info.add_widget(e2) self.info.add_widget(e3) self.info.add_widget(e4) self.info.add_widget(bt1) self.add_widget(self.info, "TOP")
from kivy.base import runTouchApp import sys if __name__ == '__main__' and __package__ is None: from os import sys, path sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) from mapview import MapView from mapview.geojson import GeoJsonMapLayer if len(sys.argv) > 1: source = sys.argv[1] else: source = "https://storage.googleapis.com/maps-devrel/google.json" view = MapView() layer = GeoJsonMapLayer(source=source) view.add_layer(layer) runTouchApp(view)
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(820, 627) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/icons/res/logo.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget) self.verticalLayout.setObjectName("verticalLayout") self.tabs = QtGui.QTabWidget(self.centralwidget) self.tabs.setTabShape(QtGui.QTabWidget.Rounded) self.tabs.setObjectName("tabs") self.tab_map = QtGui.QWidget() self.tab_map.setObjectName("tab_map") self.verticalLayout_2 = QtGui.QVBoxLayout(self.tab_map) self.verticalLayout_2.setObjectName("verticalLayout_2") self.splitter = QtGui.QSplitter(self.tab_map) self.splitter.setOrientation(QtCore.Qt.Vertical) self.splitter.setObjectName("splitter") self.graphicsViewMap = MapView(self.splitter) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(200) sizePolicy.setHeightForWidth(self.graphicsViewMap.sizePolicy().hasHeightForWidth()) self.graphicsViewMap.setSizePolicy(sizePolicy) self.graphicsViewMap.setMinimumSize(QtCore.QSize(0, 400)) self.graphicsViewMap.setObjectName("graphicsViewMap") self.verticalLayout_2.addWidget(self.splitter) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/icons/res/applications-internet.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tabs.addTab(self.tab_map, icon1, "") self.tab_events = QtGui.QWidget() self.tab_events.setObjectName("tab_events") self.verticalLayout_6 = QtGui.QVBoxLayout(self.tab_events) self.verticalLayout_6.setObjectName("verticalLayout_6") self.splitter_2 = QtGui.QSplitter(self.tab_events) self.splitter_2.setOrientation(QtCore.Qt.Vertical) self.splitter_2.setObjectName("splitter_2") self.groupBox = QtGui.QGroupBox(self.splitter_2) self.groupBox.setObjectName("groupBox") self.horizontalLayout_5 = QtGui.QHBoxLayout(self.groupBox) self.horizontalLayout_5.setSpacing(1) self.horizontalLayout_5.setMargin(1) self.horizontalLayout_5.setObjectName("horizontalLayout_5") self.tableHighPrio = QTableViewHighPrio(self.groupBox) self.tableHighPrio.setObjectName("tableHighPrio") self.horizontalLayout_5.addWidget(self.tableHighPrio) self.groupBox_2 = QtGui.QGroupBox(self.splitter_2) self.groupBox_2.setObjectName("groupBox_2") self.horizontalLayout_6 = QtGui.QHBoxLayout(self.groupBox_2) self.horizontalLayout_6.setSpacing(1) self.horizontalLayout_6.setMargin(1) self.horizontalLayout_6.setObjectName("horizontalLayout_6") self.tableLowPrio = QTableViewLowPrio(self.groupBox_2) self.tableLowPrio.setObjectName("tableLowPrio") self.horizontalLayout_6.addWidget(self.tableLowPrio) self.verticalLayout_6.addWidget(self.splitter_2) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/icons/res/application-vnd.oasis.opendocument.spreadsheet.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tabs.addTab(self.tab_events, icon2, "") self.tab_conf = QtGui.QWidget() self.tab_conf.setObjectName("tab_conf") self.verticalLayout_4 = QtGui.QVBoxLayout(self.tab_conf) self.verticalLayout_4.setObjectName("verticalLayout_4") self.toolBox_configuracion_comandos = QtGui.QToolBox(self.tab_conf) self.toolBox_configuracion_comandos.setFrameShape(QtGui.QFrame.StyledPanel) self.toolBox_configuracion_comandos.setFrameShadow(QtGui.QFrame.Raised) self.toolBox_configuracion_comandos.setObjectName("toolBox_configuracion_comandos") self.pageComs = QtGui.QWidget() self.pageComs.setGeometry(QtCore.QRect(0, 0, 786, 423)) self.pageComs.setObjectName("pageComs") self.verticalLayout_9 = QtGui.QVBoxLayout(self.pageComs) self.verticalLayout_9.setObjectName("verticalLayout_9") self.verticalLayout_8 = QtGui.QVBoxLayout() self.verticalLayout_8.setObjectName("verticalLayout_8") self.label_2 = QtGui.QLabel(self.pageComs) self.label_2.setAlignment(QtCore.Qt.AlignCenter) self.label_2.setObjectName("label_2") self.verticalLayout_8.addWidget(self.label_2) self.horizontalLayout_4 = QtGui.QHBoxLayout() self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.label_6 = QtGui.QLabel(self.pageComs) self.label_6.setObjectName("label_6") self.horizontalLayout_4.addWidget(self.label_6) self.comboBox_concentrador = QComboBoxModelQuery(self.pageComs) self.comboBox_concentrador.setObjectName("comboBox_concentrador") self.horizontalLayout_4.addWidget(self.comboBox_concentrador) self.label_4 = QtGui.QLabel(self.pageComs) self.label_4.setObjectName("label_4") self.horizontalLayout_4.addWidget(self.label_4) self.comboPgmZona = QtGui.QComboBox(self.pageComs) self.comboPgmZona.setObjectName("comboPgmZona") self.horizontalLayout_4.addWidget(self.comboPgmZona) self.label_5 = QtGui.QLabel(self.pageComs) self.label_5.setObjectName("label_5") self.horizontalLayout_4.addWidget(self.label_5) self.comboPgmUc = QtGui.QComboBox(self.pageComs) self.comboPgmUc.setObjectName("comboPgmUc") self.horizontalLayout_4.addWidget(self.comboPgmUc) spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_4.addItem(spacerItem) self.pushButton_prog_manual = QtGui.QPushButton(self.pageComs) self.pushButton_prog_manual.setObjectName("pushButton_prog_manual") self.horizontalLayout_4.addWidget(self.pushButton_prog_manual) self.pushButton_prog_auto = QtGui.QPushButton(self.pageComs) self.pushButton_prog_auto.setObjectName("pushButton_prog_auto") self.horizontalLayout_4.addWidget(self.pushButton_prog_auto) self.verticalLayout_8.addLayout(self.horizontalLayout_4) spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_8.addItem(spacerItem1) self.verticalLayout_9.addLayout(self.verticalLayout_8) self.toolBox_configuracion_comandos.addItem(self.pageComs, "") self.pageCOs = QtGui.QWidget() self.pageCOs.setGeometry(QtCore.QRect(0, 0, 786, 423)) self.pageCOs.setObjectName("pageCOs") self.verticalLayout_5 = QtGui.QVBoxLayout(self.pageCOs) self.verticalLayout_5.setObjectName("verticalLayout_5") self.verticalLayout_7 = QtGui.QVBoxLayout() self.verticalLayout_7.setSpacing(2) self.verticalLayout_7.setObjectName("verticalLayout_7") self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.label = QtGui.QLabel(self.pageCOs) self.label.setObjectName("label") self.horizontalLayout_3.addWidget(self.label) spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem2) self.pushAddCO = QtGui.QPushButton(self.pageCOs) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/icons/res/list-add.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.pushAddCO.setIcon(icon3) self.pushAddCO.setObjectName("pushAddCO") self.horizontalLayout_3.addWidget(self.pushAddCO) self.verticalLayout_7.addLayout(self.horizontalLayout_3) self.tableCO = QTableCO(self.pageCOs) self.tableCO.setObjectName("tableCO") self.verticalLayout_7.addWidget(self.tableCO) self.horizontalLayout_2 = QtGui.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.label_3 = QtGui.QLabel(self.pageCOs) self.label_3.setObjectName("label_3") self.horizontalLayout_2.addWidget(self.label_3) spacerItem3 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_2.addItem(spacerItem3) self.toolAddUC = QtGui.QToolButton(self.pageCOs) self.toolAddUC.setObjectName("toolAddUC") self.horizontalLayout_2.addWidget(self.toolAddUC) self.verticalLayout_7.addLayout(self.horizontalLayout_2) self.tableUC = QTableUC(self.pageCOs) self.tableUC.setObjectName("tableUC") self.verticalLayout_7.addWidget(self.tableUC) self.verticalLayout_5.addLayout(self.verticalLayout_7) self.toolBox_configuracion_comandos.addItem(self.pageCOs, "") self.verticalLayout_4.addWidget(self.toolBox_configuracion_comandos) icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(":/icons/res/configure.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tabs.addTab(self.tab_conf, icon4, "") self.verticalLayout.addWidget(self.tabs) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 820, 24)) self.menubar.setObjectName("menubar") self.menuSCADA = QtGui.QMenu(self.menubar) self.menuSCADA.setObjectName("menuSCADA") self.menuOptions = QtGui.QMenu(self.menubar) self.menuOptions.setObjectName("menuOptions") self.menuBarra_de_herramientas = QtGui.QMenu(self.menuOptions) self.menuBarra_de_herramientas.setObjectName("menuBarra_de_herramientas") self.menuHelp = QtGui.QMenu(self.menubar) self.menuHelp.setObjectName("menuHelp") self.menuAdmin = QtGui.QMenu(self.menubar) self.menuAdmin.setObjectName("menuAdmin") MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.scadaToolbar = QtGui.QToolBar(MainWindow) self.scadaToolbar.setIconSize(QtCore.QSize(32, 32)) self.scadaToolbar.setObjectName("scadaToolbar") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.scadaToolbar) self.toolBar_mapa = QtGui.QToolBar(MainWindow) self.toolBar_mapa.setIconSize(QtCore.QSize(32, 32)) self.toolBar_mapa.setObjectName("toolBar_mapa") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_mapa) self.toolBar_mapa_visor = QtGui.QToolBar(MainWindow) self.toolBar_mapa_visor.setIconSize(QtCore.QSize(32, 32)) self.toolBar_mapa_visor.setObjectName("toolBar_mapa_visor") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_mapa_visor) self.toolBar_debug = QtGui.QToolBar(MainWindow) self.toolBar_debug.setIconSize(QtCore.QSize(32, 32)) self.toolBar_debug.setObjectName("toolBar_debug") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_debug) self.toolBar_impresion = QtGui.QToolBar(MainWindow) self.toolBar_impresion.setIconSize(QtCore.QSize(32, 32)) self.toolBar_impresion.setObjectName("toolBar_impresion") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_impresion) self.actionAbout = QtGui.QAction(MainWindow) self.actionAbout.setObjectName("actionAbout") self.actionAbout_Qt = QtGui.QAction(MainWindow) self.actionAbout_Qt.setObjectName("actionAbout_Qt") self.actionQuit = QtGui.QAction(MainWindow) self.actionQuit.setObjectName("actionQuit") self.actionStart = QtGui.QAction(MainWindow) self.actionStart.setCheckable(True) icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap(":/icons/res/player-time.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionStart.setIcon(icon5) self.actionStart.setObjectName("actionStart") self.actionStop = QtGui.QAction(MainWindow) icon6 = QtGui.QIcon() icon6.addPixmap(QtGui.QPixmap(":/icons/res/process-stop.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionStop.setIcon(icon6) self.actionStop.setObjectName("actionStop") self.actionSCADA_Config = QtGui.QAction(MainWindow) self.actionSCADA_Config.setIcon(icon4) self.actionSCADA_Config.setObjectName("actionSCADA_Config") self.actionLogs = QtGui.QAction(MainWindow) self.actionLogs.setObjectName("actionLogs") self.actionMapa = QtGui.QAction(MainWindow) icon7 = QtGui.QIcon() icon7.addPixmap(QtGui.QPixmap(":/icons/res/applications-accessories.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionMapa.setIcon(icon7) self.actionMapa.setObjectName("actionMapa") self.actionEdici_n_Esquina = QtGui.QAction(MainWindow) self.actionEdici_n_Esquina.setObjectName("actionEdici_n_Esquina") self.actionUsuario = QtGui.QAction(MainWindow) self.actionUsuario.setObjectName("actionUsuario") self.actionDBUrl = QtGui.QAction(MainWindow) self.actionDBUrl.setObjectName("actionDBUrl") self.actionScada = QtGui.QAction(MainWindow) self.actionScada.setCheckable(True) self.actionScada.setChecked(True) self.actionScada.setObjectName("actionScada") self.actionIO = QtGui.QAction(MainWindow) self.actionIO.setCheckable(True) icon8 = QtGui.QIcon() icon8.addPixmap(QtGui.QPixmap(":/icons/res/strigi.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionIO.setIcon(icon8) self.actionIO.setObjectName("actionIO") self.actionLimpiar_Eventos = QtGui.QAction(MainWindow) icon9 = QtGui.QIcon() icon9.addPixmap(QtGui.QPixmap(":/icons/res/draw-eraser.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionLimpiar_Eventos.setIcon(icon9) self.actionLimpiar_Eventos.setObjectName("actionLimpiar_Eventos") self.actionImprimir = QtGui.QAction(MainWindow) icon10 = QtGui.QIcon() icon10.addPixmap(QtGui.QPixmap(":/icons/res/printer.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionImprimir.setIcon(icon10) self.actionImprimir.setObjectName("actionImprimir") self.menuSCADA.addAction(self.actionUsuario) self.menuSCADA.addAction(self.actionStart) self.menuSCADA.addAction(self.actionStop) self.menuSCADA.addAction(self.actionQuit) self.menuBarra_de_herramientas.addAction(self.actionScada) self.menuOptions.addAction(self.actionSCADA_Config) self.menuOptions.addAction(self.actionLogs) self.menuOptions.addAction(self.actionDBUrl) self.menuOptions.addAction(self.menuBarra_de_herramientas.menuAction()) self.menuHelp.addAction(self.actionAbout) self.menuHelp.addAction(self.actionAbout_Qt) self.menuAdmin.addAction(self.actionMapa) self.menubar.addAction(self.menuSCADA.menuAction()) self.menubar.addAction(self.menuAdmin.menuAction()) self.menubar.addAction(self.menuOptions.menuAction()) self.menubar.addAction(self.menuHelp.menuAction()) self.scadaToolbar.addAction(self.actionStart) self.scadaToolbar.addAction(self.actionStop) self.toolBar_mapa.addAction(self.actionMapa) self.toolBar_debug.addAction(self.actionIO) self.toolBar_debug.addAction(self.actionLimpiar_Eventos) self.toolBar_debug.addAction(self.actionSCADA_Config) self.toolBar_impresion.addAction(self.actionImprimir) self.retranslateUi(MainWindow) self.tabs.setCurrentIndex(2) self.toolBox_configuracion_comandos.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Semforización", None, QtGui.QApplication.UnicodeUTF8)) self.tabs.setTabText(self.tabs.indexOf(self.tab_map), QtGui.QApplication.translate("MainWindow", "&Mapa", None, QtGui.QApplication.UnicodeUTF8)) self.groupBox.setTitle(QtGui.QApplication.translate("MainWindow", "Eventos de muy alta prioridad y alta prioridad", None, QtGui.QApplication.UnicodeUTF8)) self.groupBox_2.setTitle(QtGui.QApplication.translate("MainWindow", "Eventos de baja prioridad y muy baja prioridad", None, QtGui.QApplication.UnicodeUTF8)) self.tabs.setTabText(self.tabs.indexOf(self.tab_events), QtGui.QApplication.translate("MainWindow", "&Eventos", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'DejaVu Sans\'; font-size:8pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Cambio de programa</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) self.label_6.setText(QtGui.QApplication.translate("MainWindow", "Concentrador", None, QtGui.QApplication.UnicodeUTF8)) self.label_4.setText(QtGui.QApplication.translate("MainWindow", "Zona:", None, QtGui.QApplication.UnicodeUTF8)) self.label_5.setText(QtGui.QApplication.translate("MainWindow", "UC:", None, QtGui.QApplication.UnicodeUTF8)) self.pushButton_prog_manual.setText(QtGui.QApplication.translate("MainWindow", "Programa Manual", None, QtGui.QApplication.UnicodeUTF8)) self.pushButton_prog_auto.setText(QtGui.QApplication.translate("MainWindow", "Programa automático", None, QtGui.QApplication.UnicodeUTF8)) self.toolBox_configuracion_comandos.setItemText(self.toolBox_configuracion_comandos.indexOf(self.pageComs), QtGui.QApplication.translate("MainWindow", "C&omandos", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'DejaVu Sans\'; font-size:8pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Concentradores</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) self.label_3.setText(QtGui.QApplication.translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'DejaVu Sans\'; font-size:8pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Unidades de Control</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) self.toolAddUC.setText(QtGui.QApplication.translate("MainWindow", "...", None, QtGui.QApplication.UnicodeUTF8)) self.toolBox_configuracion_comandos.setItemText(self.toolBox_configuracion_comandos.indexOf(self.pageCOs), QtGui.QApplication.translate("MainWindow", "Concentradores y &Unidades de Control", None, QtGui.QApplication.UnicodeUTF8)) self.tabs.setTabText(self.tabs.indexOf(self.tab_conf), QtGui.QApplication.translate("MainWindow", "&Configuracion", None, QtGui.QApplication.UnicodeUTF8)) self.menuSCADA.setTitle(QtGui.QApplication.translate("MainWindow", "&SCADA", None, QtGui.QApplication.UnicodeUTF8)) self.menuOptions.setTitle(QtGui.QApplication.translate("MainWindow", "&Herramientas", None, QtGui.QApplication.UnicodeUTF8)) self.menuBarra_de_herramientas.setTitle(QtGui.QApplication.translate("MainWindow", "Barra de herramientas", None, QtGui.QApplication.UnicodeUTF8)) self.menuHelp.setTitle(QtGui.QApplication.translate("MainWindow", "A&yuda", None, QtGui.QApplication.UnicodeUTF8)) self.menuAdmin.setTitle(QtGui.QApplication.translate("MainWindow", "&Administración", None, QtGui.QApplication.UnicodeUTF8)) self.scadaToolbar.setWindowTitle(QtGui.QApplication.translate("MainWindow", "SCADA", None, QtGui.QApplication.UnicodeUTF8)) self.toolBar_mapa.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Edición de mapa", None, QtGui.QApplication.UnicodeUTF8)) self.toolBar_mapa_visor.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Visor de mapa", None, QtGui.QApplication.UnicodeUTF8)) self.toolBar_debug.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Debug", None, QtGui.QApplication.UnicodeUTF8)) self.toolBar_impresion.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Impresión", None, QtGui.QApplication.UnicodeUTF8)) self.actionAbout.setText(QtGui.QApplication.translate("MainWindow", "Sobre...", None, QtGui.QApplication.UnicodeUTF8)) self.actionAbout_Qt.setText(QtGui.QApplication.translate("MainWindow", "Sobre Qt...", None, QtGui.QApplication.UnicodeUTF8)) self.actionQuit.setText(QtGui.QApplication.translate("MainWindow", "Quit", None, QtGui.QApplication.UnicodeUTF8)) self.actionStart.setText(QtGui.QApplication.translate("MainWindow", "Start", None, QtGui.QApplication.UnicodeUTF8)) self.actionStart.setStatusTip(QtGui.QApplication.translate("MainWindow", "Inicia el motor scada", None, QtGui.QApplication.UnicodeUTF8)) self.actionStop.setText(QtGui.QApplication.translate("MainWindow", "Stop", None, QtGui.QApplication.UnicodeUTF8)) self.actionSCADA_Config.setText(QtGui.QApplication.translate("MainWindow", "SCADA Config", None, QtGui.QApplication.UnicodeUTF8)) self.actionLogs.setText(QtGui.QApplication.translate("MainWindow", "Logs", None, QtGui.QApplication.UnicodeUTF8)) self.actionMapa.setText(QtGui.QApplication.translate("MainWindow", "Edición Mapa", None, QtGui.QApplication.UnicodeUTF8)) self.actionEdici_n_Esquina.setText(QtGui.QApplication.translate("MainWindow", "Edición Esquina", None, QtGui.QApplication.UnicodeUTF8)) self.actionUsuario.setText(QtGui.QApplication.translate("MainWindow", "Cambio de usuario", None, QtGui.QApplication.UnicodeUTF8)) self.actionDBUrl.setText(QtGui.QApplication.translate("MainWindow", "Mostrar RFC1783 DB URL", None, QtGui.QApplication.UnicodeUTF8)) self.actionScada.setText(QtGui.QApplication.translate("MainWindow", "Scada", None, QtGui.QApplication.UnicodeUTF8)) self.actionIO.setText(QtGui.QApplication.translate("MainWindow", "DebugIO", None, QtGui.QApplication.UnicodeUTF8)) self.actionLimpiar_Eventos.setText(QtGui.QApplication.translate("MainWindow", "Limpiar Eventos", None, QtGui.QApplication.UnicodeUTF8)) self.actionImprimir.setText(QtGui.QApplication.translate("MainWindow", "Imprimir", None, QtGui.QApplication.UnicodeUTF8))
def __init__(self): pygame.init() pygame.display.set_caption('Map with cars') self.model = MapModel() self.view = MapView(self.model) self.control = MapControl(self.model)
source = sys.argv[1] options = {} layer = GeoJsonMapLayer(source=source) # try to auto center the map on the source lon, lat = layer.center options["lon"] = lon options["lat"] = lat min_lon, max_lon, min_lat, max_lat = layer.bounds radius = haversine(min_lon, min_lat, max_lon, max_lat) zoom = get_zoom_for_radius(radius, lat) options["zoom"] = zoom view = MapView(**options) view.add_layer(layer) marker_layer = ClusteredMarkerLayer( cluster_radius=200 ) view.add_layer(marker_layer) # create marker if they exists count = 0 def create_marker(feature): global count geometry = feature["geometry"] if geometry["type"] != "Point":
source = sys.argv[1] options = {} layer = GeoJsonMapLayer(source=source) # try to auto center the map on the source lon, lat = layer.center options["lon"] = lon options["lat"] = lat min_lon, max_lon, min_lat, max_lat = layer.bounds radius = haversine(min_lon, min_lat, max_lon, max_lat) zoom = get_zoom_for_radius(radius) options["zoom"] = zoom view = MapView(**options) view.add_layer(layer) marker_layer = ClusteredMarkerLayer( cluster_radius=200 ) view.add_layer(marker_layer) # create marker if they exists count = 0 def create_marker(feature): global count geometry = feature["geometry"] if geometry["type"] != "Point":
import sys from kivy.base import runTouchApp if __name__ == '__main__' and __package__ is None: from os import sys, path sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) from mapview import MapView, MapSource kwargs = {} if len(sys.argv) > 1: kwargs["map_source"] = MapSource(url=sys.argv[1], attribution="") runTouchApp(MapView(**kwargs))
# coding=utf-8 """ This example demonstrate how to use the MBTilesMapSource provider. It supports v1.1 version of .mbtiles of Mapbox. See more at http://mbtiles.org/ It currently require a Kivy version that can load data from a buffer. This is not the case on every platform at 1.8.1, but we're going to fix it. """ import sys from kivy.base import runTouchApp if __name__ == '__main__' and __package__ is None: from os import sys, path sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) from mapview import MapView from mapview.mbtsource import MBTilesMapSource source = MBTilesMapSource("wc.mbtiles") #sys.argv[1]) runTouchApp( MapView(map_source=source, lat=source.default_lat, lon=source.default_lon, zoom=10))
class ProcessData: def __init__(self): self.car = Vehicle() # Verify that the Vehicle object was created # print("Vehicle made!") # self.find_own_pos("1362060585", "1362060062") self.minute_warning = False self.second_warning = False self.meter_message = False self.map = MapView() self.text_to_speech = TextToSpeech() def notify(self, ambulance_position_history): '''Called by receiver to notify the car about new ambulance position''' print('process_data notified') car_pos = self.find_own_pos(ambulance_position_history[0]['timestamp'], ambulance_position_history[1]['timestamp']) if car_pos is not None: if 2 == len(car_pos): if car_pos[0] is not None and car_pos[1] is not None: print(" ") # TODO: Handle edge case when first message arrive # Plot coordinates to map, updates everytime new data arrives. Run in Safari self.map.plot_coordinates(car_pos[1]['longitude'], car_pos[1]['latitude'], 'bs') self.map.plot_coordinates( ambulance_position_history[1]['longitude'], ambulance_position_history[1]['latitude'], 'rs') message = self.pick_message(car_pos[1], car_pos[0], ambulance_position_history[1], ambulance_position_history[0]) self.text_to_speech.play(message) self.map.show_map() time.sleep(0.75) def find_own_pos(self, first_timestamp, second_timestamp): '''Use timestamps from ambulance data to get car data''' relevant_pos = [] old_car = None new_car = None for position in self.car.position_history: #print(str(position['timestamp'])[:10]) if str(position['timestamp'])[:10] == str(first_timestamp + 300)[:10]: relevant_pos.append(position) if str(position['timestamp'])[:10] == str(second_timestamp + 300)[:10]: relevant_pos.append(position) if len(relevant_pos) > 1: old_car = relevant_pos.pop() new_car = relevant_pos.pop() return new_car, old_car # if first_car_pos is not None and second_car_pos is not None: # self.car.position_history.clear() # Clear old data points # self.car.position_history.append(first_car_pos) # self.car.position_history.append(second_car_pos) def pick_message(self, new_car, old_car, new_ambu, old_ambu): '''Checks if the current data is relevant, and returns a integer for each case Keyword arguments: new_car -- A tuple containing the cars current position old_car -- A tuple containing the cars previous position new_ambu -- A tuple containing the ambulance current position old_ambu -- A tuple containing the ambulance previous position returns 0 if the situation is not relevant 1 if the ambulance is less than 20 sec behind 2 if the ambulance is less than 2 minutes behind 3 if the ambulance just passed the car and is less than 50 meters ahead ''' new_car_pos = (new_car['latitude'], new_car['longitude']) new_car_time = new_car['timestamp'] old_car_pos = (old_car['latitude'], old_car['longitude']) old_car_time = old_car['timestamp'] car_speed = Calculator.speed(new_car_pos[1], new_car_pos[0], old_car_pos[1], old_car_pos[0], (new_car_time - old_car_time)) print("Car time" + str(new_car_time - old_car_time)) print("Car speed: " + str(car_speed)) new_ambu_pos = (new_ambu['latitude'], new_ambu['longitude']) new_ambu_time = new_car['timestamp'] old_ambu_pos = (old_ambu['latitude'], old_ambu['longitude']) old_ambu_time = old_car['timestamp'] ambu_speed = Calculator.speed(new_ambu_pos[1], new_ambu_pos[0], old_ambu_pos[1], old_ambu_pos[0], (new_ambu_time - old_ambu_time)) print("Ambu speed: " + str(ambu_speed)) car_dir = self._find_direction(new_car_pos, old_car_pos) ambu_dir = self._find_direction(new_ambu_pos, old_ambu_pos) distance_km = Calculator.gps_to_kmeters(new_car_pos[1], new_car_pos[0], new_ambu_pos[1], new_ambu_pos[0]) print("Distance is : " + str(distance_km)) if not self._is_relevant(new_car_pos, car_speed, old_car_pos, new_ambu_pos, ambu_speed, old_ambu_pos): #0.05km is 50 meters. if distance_km < 0.05\ and car_dir.name == ambu_dir.name: if not self.meter_message: self.meter_message = True self.minute_warning = False self.second_warning = False return 3 else: return 0 return 0 time_to_intersection = Calculator.time_to_intersection( distance_km, ambu_speed, car_speed) print('The vehicles are: ' + str(distance_km) + ' kms Appart. Time to intersect: ' + str(time_to_intersection)) #time to intersection is less than 20 sec, 1/3 of a minute if time_to_intersection <= (1 / 3): if not self.second_warning: self.second_warning = True return 1 return 0 if time_to_intersection <= 2: if not self.minute_warning: self.minute_warning = True self.meter_message = False return 2 return 0 def _is_relevant(self, new_car_pos, car_speed, old_car_pos, new_ambu_pos, ambu_speed, old_ambu_pos): '''Takes in the car and the ambulances current and previous postition. Returns whether the car should be notified or not, as a boolean Keyword arguments: new_car_pos -- A tuple containing the cars current position latitude first, longitude second car_speed -- A float containing the cars current speed old_car_pos -- A tuple containing the cars previous position latitude first, longitude second new_ambu_pos -- A tuple containing the ambulance current position latitude first, longitude second ambu_speed -- A float containing the ambulances current speed old_ambu_pos -- A tuple containing the ambulance previous position latitude first, longitude second ''' car_dir = self._find_direction(old_car_pos, new_car_pos) ambu_dir = self._find_direction(old_ambu_pos, new_ambu_pos) if ambu_speed <= 0: return False if car_dir != ambu_dir: print('Car not going the same direction as ambu') return False if not self._ambu_behind(new_car_pos, new_ambu_pos, car_dir): print('Ambulance not behind car') return False distance_km = Calculator.gps_to_kmeters(float(new_car_pos[1]), float(new_car_pos[0]), float(new_ambu_pos[1]), float(new_ambu_pos[0])) time_to_intersection = Calculator.time_to_intersection( distance_km, ambu_speed, car_speed) print('The vehicles are: ' + str(distance_km) + ' kms apart. Time to intersect: ' + str(time_to_intersection)) if time_to_intersection == 0: return False if time_to_intersection > 2: print('Ambulance is too far behind: ' + str(time_to_intersection)) return False return True def _find_direction(self, data1, data2): '''Find direction for vehicle, returns Direction enum Keyword arguments: data1 -- tuple with latitude and longitude from newest data data2 -- tuple with latitude and longitude from oldest data ''' lat_change = float(data2[0]) - float(data1[0]) long_change = float(data2[1]) - float(data1[1]) if lat_change == 0 and long_change == 0: return Direction.standing_still if fabs(lat_change) > fabs(long_change): if lat_change > 0: return Direction.north return Direction.south if long_change > 0: return Direction.east return Direction.west def _ambu_behind(self, car_pos, ambu_pos, direction): '''Decide if the ambu is in front of, or behind the car Keyword arguments: car_pos -- tuple with latitude and longitude from newest data of car ambu_pos -- tuple with latitude and longitude from newest data of ambu direction -- Direction of the two vehicles. Must be the same after comparing in is_relevant ''' if direction.name == 'north': return car_pos[0] > ambu_pos[0] if direction.name == 'south': return car_pos[0] < ambu_pos[0] if direction.name == 'east': return car_pos[1] > ambu_pos[1] if direction.name == 'west': return car_pos[1] < ambu_pos[1] return True
class ProcessData: def __init__(self): self.car = Vehicle() # Verify that the Vehicle object was created # print("Vehicle made!") # self.find_own_pos("1362060585", "1362060062") self.minute_warning = False self.second_warning = False self.meter_message = False self.map = MapView() self.text_to_speech = TextToSpeech() def notify(self, ambulance_position_history): '''Called by receiver to notify the car about new ambulance position''' print('process_data notified') car_pos = self.find_own_pos(ambulance_position_history[0]['timestamp'], ambulance_position_history[1]['timestamp']) if car_pos is not None: if 2 == len(car_pos): if car_pos[0] is not None and car_pos[1] is not None: print(" ") # TODO: Handle edge case when first message arrive # Plot coordinates to map, updates everytime new data arrives. Run in Safari self.map.plot_coordinates(car_pos[1]['longitude'], car_pos[1]['latitude'], 'bs') self.map.plot_coordinates(ambulance_position_history[1]['longitude'], ambulance_position_history[1]['latitude'], 'rs') message = self.pick_message(car_pos[1], car_pos[0], ambulance_position_history[1], ambulance_position_history[0]) self.text_to_speech.play(message) self.map.show_map() time.sleep(0.75) def find_own_pos(self, first_timestamp, second_timestamp): '''Use timestamps from ambulance data to get car data''' relevant_pos = [] old_car = None new_car = None for position in self.car.position_history: #print(str(position['timestamp'])[:10]) if str(position['timestamp'])[:10] == str(first_timestamp+300)[:10]: relevant_pos.append(position) if str(position['timestamp'])[:10] == str(second_timestamp + 300)[:10]: relevant_pos.append(position) if len(relevant_pos) > 1: old_car = relevant_pos.pop() new_car = relevant_pos.pop() return new_car, old_car # if first_car_pos is not None and second_car_pos is not None: # self.car.position_history.clear() # Clear old data points # self.car.position_history.append(first_car_pos) # self.car.position_history.append(second_car_pos) def pick_message(self, new_car, old_car, new_ambu, old_ambu): '''Checks if the current data is relevant, and returns a integer for each case Keyword arguments: new_car -- A tuple containing the cars current position old_car -- A tuple containing the cars previous position new_ambu -- A tuple containing the ambulance current position old_ambu -- A tuple containing the ambulance previous position returns 0 if the situation is not relevant 1 if the ambulance is less than 20 sec behind 2 if the ambulance is less than 2 minutes behind 3 if the ambulance just passed the car and is less than 50 meters ahead ''' new_car_pos = (new_car['latitude'], new_car['longitude']) new_car_time = new_car['timestamp'] old_car_pos = (old_car['latitude'], old_car['longitude']) old_car_time = old_car['timestamp'] car_speed = Calculator.speed(new_car_pos[1], new_car_pos[0], old_car_pos[1], old_car_pos[0], (new_car_time - old_car_time)) print("Car time" + str(new_car_time-old_car_time)) print("Car speed: " + str(car_speed)) new_ambu_pos = (new_ambu['latitude'], new_ambu['longitude']) new_ambu_time = new_car['timestamp'] old_ambu_pos = (old_ambu['latitude'], old_ambu['longitude']) old_ambu_time = old_car['timestamp'] ambu_speed = Calculator.speed(new_ambu_pos[1], new_ambu_pos[0], old_ambu_pos[1], old_ambu_pos[0], (new_ambu_time - old_ambu_time )) print("Ambu speed: " + str(ambu_speed)) car_dir = self._find_direction(new_car_pos, old_car_pos) ambu_dir = self._find_direction(new_ambu_pos, old_ambu_pos) distance_km = Calculator.gps_to_kmeters(new_car_pos[1], new_car_pos[0], new_ambu_pos[1], new_ambu_pos[0]) print("Distance is : " + str(distance_km )) if not self._is_relevant(new_car_pos, car_speed, old_car_pos, new_ambu_pos, ambu_speed, old_ambu_pos): #0.05km is 50 meters. if distance_km < 0.05\ and car_dir.name == ambu_dir.name: if not self.meter_message: self.meter_message = True self.minute_warning = False self.second_warning = False return 3 else: return 0 return 0 time_to_intersection = Calculator.time_to_intersection( distance_km, ambu_speed, car_speed) print ('The vehicles are: ' + str(distance_km) + ' kms Appart. Time to intersect: ' + str(time_to_intersection)) #time to intersection is less than 20 sec, 1/3 of a minute if time_to_intersection <= (1/3): if not self.second_warning: self.second_warning = True return 1 return 0 if time_to_intersection <= 2: if not self.minute_warning: self.minute_warning = True self.meter_message = False return 2 return 0 def _is_relevant(self, new_car_pos, car_speed, old_car_pos, new_ambu_pos, ambu_speed, old_ambu_pos): '''Takes in the car and the ambulances current and previous postition. Returns whether the car should be notified or not, as a boolean Keyword arguments: new_car_pos -- A tuple containing the cars current position latitude first, longitude second car_speed -- A float containing the cars current speed old_car_pos -- A tuple containing the cars previous position latitude first, longitude second new_ambu_pos -- A tuple containing the ambulance current position latitude first, longitude second ambu_speed -- A float containing the ambulances current speed old_ambu_pos -- A tuple containing the ambulance previous position latitude first, longitude second ''' car_dir = self._find_direction(old_car_pos, new_car_pos) ambu_dir = self._find_direction(old_ambu_pos, new_ambu_pos) if ambu_speed <= 0: return False if car_dir != ambu_dir: print('Car not going the same direction as ambu') return False if not self._ambu_behind(new_car_pos, new_ambu_pos, car_dir): print ('Ambulance not behind car') return False distance_km = Calculator.gps_to_kmeters(float(new_car_pos[1]), float(new_car_pos[0]), float(new_ambu_pos[1]), float(new_ambu_pos[0])) time_to_intersection = Calculator.time_to_intersection( distance_km, ambu_speed, car_speed) print ('The vehicles are: ' + str(distance_km) + ' kms apart. Time to intersect: ' + str(time_to_intersection)) if time_to_intersection == 0: return False if time_to_intersection > 2: print('Ambulance is too far behind: ' + str(time_to_intersection)) return False return True def _find_direction(self, data1, data2): '''Find direction for vehicle, returns Direction enum Keyword arguments: data1 -- tuple with latitude and longitude from newest data data2 -- tuple with latitude and longitude from oldest data ''' lat_change = float(data2[0]) - float(data1[0]) long_change = float(data2[1]) - float(data1[1]) if lat_change == 0 and long_change == 0: return Direction.standing_still if fabs(lat_change) > fabs(long_change): if lat_change > 0: return Direction.north return Direction.south if long_change > 0: return Direction.east return Direction.west def _ambu_behind(self, car_pos, ambu_pos, direction): '''Decide if the ambu is in front of, or behind the car Keyword arguments: car_pos -- tuple with latitude and longitude from newest data of car ambu_pos -- tuple with latitude and longitude from newest data of ambu direction -- Direction of the two vehicles. Must be the same after comparing in is_relevant ''' if direction.name == 'north': return car_pos[0] > ambu_pos[0] if direction.name == 'south': return car_pos[0] < ambu_pos[0] if direction.name == 'east': return car_pos[1] > ambu_pos[1] if direction.name == 'west': return car_pos[1] < ambu_pos[1] return True
def build(self): self.container = FloatLayout() #Контейнер программы self.dots_obj = [] self.google_map = MapView( zoom=15, lat=55.122850, lon=37.947274 ) # Координаты lat и lon - примерные координаты Михнево #60px x 60px height x 0.9 center on 121 px btn_down = Image(source="source_img/button_down2.png", pos_hint={ 'top': 0.6, 'right': 0.6 }, size_hint=(.2, .2)) #Создание экземпляра карты и помещение на нее курсора fl = FloatLayout() fl.add_widget(self.google_map) fl.add_widget(btn_down) self.container.add_widget(fl) #Создание кнопок Добавления и удаления меток и помещение их на основной экран приложения button_bl = BoxLayout(orientation="horizontal", size_hint_y=.10) button_bl.add_widget( Button(text="Добавить экипаж", size=(100, 50), on_press=self.add_gps_dot)) #Кнопка добавления метки button_bl.add_widget( Button(text="Здесь чисто", size=(100, 50), on_press=self.remove_gps_dot)) self.container.add_widget(button_bl) #self.container.add_widget(Button(size_hint = (.3,.1), pos_hint = {'top': 1, 'right': 1}, text = 'Обновить', on_press=self.build)) self.update_gps_dots_list() #Обновление списка меток на карте #Проверка включен ли модуль рекламы if self.check_marketplace() == '1': #Модуль с рекламой self.market_place = FloatLayout() pic_source = 'http://dps.mybland.xyz/marketplace_source/' + str( random.randint(1, 3)) + '.jpg' market_place_source = AsyncImage(source=pic_source) market_place_close = Button(pos_hint={ 'top': 0.98, 'right': 0.98 }, text='X', size_hint=(.07, .06), on_press=self.close_market_place) self.market_place.add_widget(market_place_source) self.market_place.add_widget(market_place_close) self.container.add_widget(self.market_place) #Проверка версии продукта, в случае несовпадения вылезает баннер на все окно программы if self.check_version() != __version__: self.container.add_widget( Button( size_hint=(1, 1), text= 'Обновите приложение по ссылке \n http://dps.mybland.xyz/index.html', on_press=self.update_app)) return self.container
class TileCollisionEditor(QMainWindow): closed = pyqtSignal() def __init__(self, parent=None): super().__init__(parent) self.mTile = None self.mMapDocument = None self.mMapScene = MapScene(self) self.mMapView = MapView(self, MapViewMode.NoStaticContents) self.mToolManager = ToolManager(self) self.mApplyingChanges = False self.mSynchronizing = False self.setObjectName("TileCollisionEditor") widget = QWidget(self) layout = QVBoxLayout(widget) layout.setSpacing(0) layout.setContentsMargins(5, 5, 5, 5) self.mMapView.setScene(self.mMapScene) self.mMapView.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.mMapView.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) rectangleObjectsTool = CreateRectangleObjectTool(self) ellipseObjectsTool = CreateEllipseObjectTool(self) polygonObjectsTool = CreatePolygonObjectTool(self) polylineObjectsTool = CreatePolylineObjectTool(self) toolBar = QToolBar(self) toolBar.setMovable(False) toolBar.setFloatable(False) toolBar.setContextMenuPolicy(Qt.ActionsContextMenu) self.mToolManager = ToolManager(self) toolBar.addAction( self.mToolManager.registerTool(ObjectSelectionTool(self))) toolBar.addAction(self.mToolManager.registerTool( EditPolygonTool(self))) toolBar.addAction(self.mToolManager.registerTool(rectangleObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(ellipseObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(polygonObjectsTool)) toolBar.addAction(self.mToolManager.registerTool(polylineObjectsTool)) self.setCentralWidget(self.mMapView) self.addToolBar(toolBar) self.mMapScene.setSelectedTool(self.mToolManager.selectedTool()) self.mToolManager.selectedToolChanged.connect(self.setSelectedTool) zoomComboBox = QComboBox() self.statusBar().addPermanentWidget(zoomComboBox) zoomable = self.mMapView.zoomable() zoomable.connectToComboBox(zoomComboBox) undoShortcut = QShortcut(QKeySequence.Undo, self) redoShortcut = QShortcut(QKeySequence.Redo, self) cutShortcut = QShortcut(QKeySequence.Cut, self) copyShortcut = QShortcut(QKeySequence.Copy, self) pasteShortcut = QShortcut(QKeySequence.Paste, self) deleteShortcut = QShortcut(QKeySequence.Delete, self) deleteShortcut2 = QShortcut(QKeySequence.Back, self) undoShortcut.activated.connect(self.undo) redoShortcut.activated.connect(self.redo) cutShortcut.activated.connect(self.cut) copyShortcut.activated.connect(self.copy) pasteShortcut.activated.connect(self.paste) deleteShortcut.activated.connect(self.delete_) deleteShortcut2.activated.connect(self.delete_) self.retranslateUi() self.resize(300, 300) Utils.restoreGeometry(self) def __del__(self): self.setTile(None) def setMapDocument(self, mapDocument): if (self.mMapDocument): self.mMapDocument.disconnect() self.mMapDocument = mapDocument if (self.mMapDocument): self.mMapDocument.tileObjectGroupChanged.connect( self.tileObjectGroupChanged) self.mMapDocument.tilesetFileNameChanged.connect( self.tilesetFileNameChanged) self.mMapDocument.currentObjectChanged.connect( self.currentObjectChanged) def writeSettings(self): Utils.saveGeometry(self) def setTile(self, tile): if type(tile) == list: tile = tile[0] if (self.mTile == tile): return self.mTile = tile self.mMapScene.disableSelectedTool() previousDocument = self.mMapScene.mapDocument() if (tile): self.mMapView.setEnabled(not self.mTile.tileset().isExternal()) map = Map(Map.Orientation.Orthogonal, 1, 1, tile.width(), tile.height()) map.addTileset(tile.sharedTileset()) tileLayer = TileLayer(QString(), 0, 0, 1, 1) tileLayer.setCell(0, 0, Cell(tile)) map.addLayer(tileLayer) objectGroup = None if (tile.objectGroup()): objectGroup = tile.objectGroup().clone() else: objectGroup = ObjectGroup() objectGroup.setDrawOrder(ObjectGroup.DrawOrder.IndexOrder) map.addLayer(objectGroup) mapDocument = MapDocument(map) self.mMapScene.setMapDocument(mapDocument) self.mToolManager.setMapDocument(mapDocument) mapDocument.setCurrentLayerIndex(1) self.mMapScene.enableSelectedTool() mapDocument.undoStack().indexChanged.connect(self.applyChanges) else: self.mMapView.setEnabled(False) self.mMapScene.setMapDocument(None) self.mToolManager.setMapDocument(None) if (previousDocument): previousDocument.undoStack().disconnect() del previousDocument def closeEvent(self, event): super().closeEvent(event) if (event.isAccepted()): self.closed.emit() def changeEvent(self, e): super().changeEvent(e) x = e.type() if x == QEvent.LanguageChange: self.retranslateUi() else: pass def setSelectedTool(self, tool): if type(tool) == list: tool = tool[0] self.mMapScene.disableSelectedTool() self.mMapScene.setSelectedTool(tool) self.mMapScene.enableSelectedTool() def applyChanges(self): if (self.mSynchronizing): return dummyDocument = self.mMapScene.mapDocument() objectGroup = dummyDocument.map().layerAt(1) clonedGroup = objectGroup.clone() undoStack = self.mMapDocument.undoStack() self.mApplyingChanges = True undoStack.push( ChangeTileObjectGroup(self.mMapDocument, self.mTile, clonedGroup)) self.mApplyingChanges = False def tileObjectGroupChanged(self, tile): if (self.mTile != tile): return if (self.mApplyingChanges): return self.mSynchronizing = True dummyDocument = self.mMapScene.mapDocument() layerModel = dummyDocument.layerModel() dummyDocument.undoStack().clear() layerModel.takeLayerAt(1).close() objectGroup = None if (tile.objectGroup()): objectGroup = tile.objectGroup().clone() else: objectGroup = ObjectGroup() objectGroup.setDrawOrder(ObjectGroup.DrawOrder.IndexOrder) layerModel.insertLayer(1, objectGroup) dummyDocument.setCurrentLayerIndex(1) self.mSynchronizing = False def currentObjectChanged(self, object): if type(object) == list and len(object) > 0: object = object[0] # If a tile object is selected, edit the collision shapes for that tile if object and object.typeId() == Object.MapObjectType: cell = object.cell() if cell.tile: self.setTile(cell.tile) def tilesetFileNameChanged(self, tileset): if (self.mTile and self.mTile.tileset() == tileset): self.mMapView.setEnabled(not tileset.isExternal()) def undo(self): if (self.mMapDocument): self.mMapDocument.undoStack().undo() def redo(self): if (self.mMapDocument): self.mMapDocument.undoStack().redo() def cut(self): if (not self.mTile): return self.copy() self.delete_(Operation.Cut) def copy(self): if (not self.mTile): return dummyDocument = self.mMapScene.mapDocument() ClipboardManager.instance().copySelection(dummyDocument) def paste(self): if (not self.mTile): return clipboardManager = ClipboardManager.instance() map = clipboardManager.map() if (not map): return # We can currently only handle maps with a single layer if (map.layerCount() != 1): return layer = map.layerAt(0) objectGroup = layer.asObjectGroup() if objectGroup: dummyDocument = self.mMapScene.mapDocument() clipboardManager.pasteObjectGroup(objectGroup, dummyDocument, self.mMapView, ClipboardManager.NoTileObjects) def delete_(self, operation=Operation.Delete): if (not self.mTile): return dummyDocument = self.mMapScene.mapDocument() selectedObjects = dummyDocument.selectedObjects() if (selectedObjects.isEmpty()): return undoStack = dummyDocument.undoStack() if Operation.Delete: _x = self.tr("Delete") else: _x = self.tr("Cut") undoStack.beginMacro(operation == _x) for mapObject in selectedObjects: undoStack.push(RemoveMapObject(dummyDocument, mapObject)) undoStack.endMacro() def retranslateUi(self): self.setWindowTitle(self.tr("Tile Collision Editor"))
class UserInterface(QMainWindow): def __init__(self, parent): super().__init__(parent) self._gameBoard = GameBoard() self._parent = parent self._gameover = False self._isTowerSelected = False self._isTowerHovered = False self._towerBeingHovered = None self._selectedTower = None self._waveFinishTime = 0 self._gameSpeed = self._parent.speed self._timePassed = 0 self.timer = QBasicTimer() self._gameBoard.readMapData(os.path.join('./Maps/', self._parent.map)) self.timer.start(self._gameSpeed, self) self.initUI() def initUI(self): centralWidget = QWidget() self.setCentralWidget(centralWidget) self.setWindowTitle(self._gameBoard.name) self.setWindowIcon( QIcon(os.path.join('./Pictures/', 'berserker_icon.png')) ) #Apparently this doens't work the same way on a mac. self.statusBar().showMessage('Ready!') vbox = QVBoxLayout() centralWidget.setLayout(vbox) self.gameStats = GameStats(self) self.mapView = MapView(self) self.bottomButtons = BottomButtons(self) vbox.addWidget(self.gameStats) vbox.addWidget(self.mapView) vbox.addWidget(self.bottomButtons) screen = QDesktopWidget().screenGeometry() self.setGeometry( (screen.width() - (self.gameboard.width - 1) * 20) / 2, (screen.height() - self.gameboard.height * 20 - 200) / 2, 500, 400) self.show() def getGameboard(self): return self._gameBoard def getIsTowerSelected(self): return self._isTowerSelected def setIsTowerSelected(self, boolean): self._isTowerSelected = boolean def getSelectedTower(self): return self._selectedTower def setSelectedTower(self, towerType): self._selectedTower = towerType def getIsTowerBeingHovered(self): return self._isTowerHovered def setIsTowerBeingHovered(self, boolean, tower): self._isTowerHovered = boolean self._towerBeingHovered = tower def getTowerBeingHovered(self): return self._towerBeingHovered def getGameStats(self): return self.gameStats def getTimePassed(self): return self._timePassed def setWaveFinishTime(self, value): self._waveFinishTime = value def getGameOver(self): return self._gameover def timerEvent(self, event): # The time passed attribute helps with setting the enemy appearance interval and tower firerate. self._timePassed += 1 self.mapView.summonEnemy() self.mapView.moveEnemies() self.mapView.checkShooting() self.mapView.moveProjectiles() self.mapView.update() def loseGame(self): self.bottomButtons.clockTimer.stop() self.timer.stop() self.statusBar().showMessage('Game has ended. You lost.') self._gameover = True self.popUp = QFrame() self.popUp.setGeometry(500, 500, 100, 100) vbox = QVBoxLayout() youLost = QLabel() youLost.setPixmap(QPixmap(os.path.join('./Pictures/', "game_over.png"))) vbox.addWidget(youLost) done = QPushButton("Done") vbox.addWidget(done) self.popUp.setLayout(vbox) self.popUp.move( self.mapToGlobal(QPoint(0, 0)).x() + self.gameboard.width * blockSize / 2 - 130, self.mapToGlobal(QPoint(0, 0)).y() + self.gameboard.height * blockSize / 2) self.popUp.show() done.clicked.connect(self.backToMainMenu) def winGame(self): self.bottomButtons.clockTimer.stop() self.timer.stop() self.statusBar().showMessage('Game has ended. You won.') self._gameover = True self.popUp = QFrame() self.popUp.setGeometry(500, 500, 100, 100) vbox = QVBoxLayout() youLost = QLabel() youLost.setPixmap(QPixmap(os.path.join('./Pictures/', "victory.png"))) vbox.addWidget(youLost) done = QPushButton("Done") vbox.addWidget(done) self.popUp.setLayout(vbox) self.popUp.move( self.mapToGlobal(QPoint(0, 0)).x() + self.gameboard.width * blockSize / 2 - 130, self.mapToGlobal(QPoint(0, 0)).y() + self.gameboard.height * blockSize / 2) self.popUp.show() done.clicked.connect(self.backToMainMenu) def backToMainMenu(self): self._parent.show() self.popUp.deleteLater() self.deleteLater() def getGameSpeed(self): return self._gameSpeed def setGameSpeed(self, value): self._gameSpeed = value def getWaveFinishTime(self): return self._waveFinishTime def getTimer(self): return self.timer isTowerSelected = property(getIsTowerSelected, setIsTowerSelected) selectedTower = property(getSelectedTower, setSelectedTower) isTowerHovered = property(getIsTowerBeingHovered) towerBeingHovered = property(getTowerBeingHovered) gamestats = property(getGameStats) gameboard = property(getGameboard) timePassed = property(getTimePassed) gameover = property(getGameOver) gameSpeed = property(getGameSpeed, setGameSpeed) waveFinishTime = property(getWaveFinishTime, setWaveFinishTime)