MainWindow
1# MainWindow.py 2 3from PySide6.QtWidgets import QMainWindow, QGraphicsScene, QGraphicsView, QMenu, QFileDialog, QDockWidget 4from PySide6.QtGui import QAction, QPixmap, QPainter 5from PySide6.QtCore import Qt, QTimer, QPointF 6from MapView import MapView 7import file_operations 8from CustomGraphicsView import CustomGraphicsView 9from ExecCommandDialog import ExecCommandDialog # Import the new dialog 10 11class MainWindow(QMainWindow): 12 def __init__(self): 13 super().__init__() 14 self.scene = CustomGraphicsScene() 15 self.view = CustomGraphicsView(self.scene, self) # Pass MainWindow reference to CustomGraphicsView 16 self.setCentralWidget(self.view) 17 self.create_dock_widgets() 18 self.create_actions_and_menus() 19 20 def create_actions_and_menus(self): 21 actions = { 22 "File": { 23 "New": self.new, 24 "Save": self.save, 25 "Load": self.load, 26 }, 27 "Tools": { 28 "Map View": self.toggle_map_view, 29 "Exec Command": self.exec_command, 30 } 31 } 32 33 self.menu_bar = self.menuBar() 34 self.actions = {} 35 36 for menu_name, actions_dict in actions.items(): 37 menu = self.menu_bar.addMenu(menu_name) 38 for action_name, method in actions_dict.items(): 39 action = QAction(action_name, self) 40 action.triggered.connect(method) 41 self.actions[action_name.lower().replace(" ", "_") + "_action"] = action 42 menu.addAction(action) 43 44 def create_dock_widgets(self): 45 self.map_view = MapView() 46 self.dock_widget = QDockWidget("Map View", self) 47 self.dock_widget.setWidget(self.map_view) 48 self.dock_widget.setFloating(True) 49 50 # Move the dock widget to the bottom-left corner of the screen 51 screen_geometry = self.screen().geometry() 52 screen_height = screen_geometry.height() 53 self.dock_widget.move(0, screen_height - 200) 54 self.addDockWidget(Qt.BottomDockWidgetArea, self.dock_widget) 55 56 def new(self): 57 self.scene.clear() # Clears all items from the scene 58 self.scene.node_counter = 1 # Reset the node counter 59 self.view.update_map_view() # Refresh the view 60 61 def save(self): 62 file_operations.save(self.scene) 63 64 def load(self): 65 self.new() 66 file_operations.load(self.scene) 67 self.view.update_map_view() # Refresh the view after loading 68 69 def exec_command(self): 70 self.exec_command_dialog = ExecCommandDialog(self) 71 self.exec_command_dialog.show() 72 73 def toggle_map_view(self): 74 is_visible = self.dock_widget.isVisible() 75 self.dock_widget.setVisible(not is_visible) 76 77 78class CustomGraphicsScene(QGraphicsScene): 79 def __init__(self): 80 super().__init__() 81 self.node_counter = 1 # Initialize the counter
class
MainWindow(PySide6.QtWidgets.QMainWindow):
12class MainWindow(QMainWindow): 13 def __init__(self): 14 super().__init__() 15 self.scene = CustomGraphicsScene() 16 self.view = CustomGraphicsView(self.scene, self) # Pass MainWindow reference to CustomGraphicsView 17 self.setCentralWidget(self.view) 18 self.create_dock_widgets() 19 self.create_actions_and_menus() 20 21 def create_actions_and_menus(self): 22 actions = { 23 "File": { 24 "New": self.new, 25 "Save": self.save, 26 "Load": self.load, 27 }, 28 "Tools": { 29 "Map View": self.toggle_map_view, 30 "Exec Command": self.exec_command, 31 } 32 } 33 34 self.menu_bar = self.menuBar() 35 self.actions = {} 36 37 for menu_name, actions_dict in actions.items(): 38 menu = self.menu_bar.addMenu(menu_name) 39 for action_name, method in actions_dict.items(): 40 action = QAction(action_name, self) 41 action.triggered.connect(method) 42 self.actions[action_name.lower().replace(" ", "_") + "_action"] = action 43 menu.addAction(action) 44 45 def create_dock_widgets(self): 46 self.map_view = MapView() 47 self.dock_widget = QDockWidget("Map View", self) 48 self.dock_widget.setWidget(self.map_view) 49 self.dock_widget.setFloating(True) 50 51 # Move the dock widget to the bottom-left corner of the screen 52 screen_geometry = self.screen().geometry() 53 screen_height = screen_geometry.height() 54 self.dock_widget.move(0, screen_height - 200) 55 self.addDockWidget(Qt.BottomDockWidgetArea, self.dock_widget) 56 57 def new(self): 58 self.scene.clear() # Clears all items from the scene 59 self.scene.node_counter = 1 # Reset the node counter 60 self.view.update_map_view() # Refresh the view 61 62 def save(self): 63 file_operations.save(self.scene) 64 65 def load(self): 66 self.new() 67 file_operations.load(self.scene) 68 self.view.update_map_view() # Refresh the view after loading 69 70 def exec_command(self): 71 self.exec_command_dialog = ExecCommandDialog(self) 72 self.exec_command_dialog.show() 73 74 def toggle_map_view(self): 75 is_visible = self.dock_widget.isVisible() 76 self.dock_widget.setVisible(not is_visible)
QMainWindow(self, parent: Optional[PySide6.QtWidgets.QWidget] = None, flags: PySide6.QtCore.Qt.WindowType = Default(Qt.WindowFlags)) -> None
def
create_dock_widgets(self):
45 def create_dock_widgets(self): 46 self.map_view = MapView() 47 self.dock_widget = QDockWidget("Map View", self) 48 self.dock_widget.setWidget(self.map_view) 49 self.dock_widget.setFloating(True) 50 51 # Move the dock widget to the bottom-left corner of the screen 52 screen_geometry = self.screen().geometry() 53 screen_height = screen_geometry.height() 54 self.dock_widget.move(0, screen_height - 200) 55 self.addDockWidget(Qt.BottomDockWidgetArea, self.dock_widget)
Inherited Members
- PySide6.QtWidgets.QMainWindow
- addDockWidget
- addToolBar
- addToolBarBreak
- centralWidget
- contextMenuEvent
- corner
- createPopupMenu
- dockOptions
- dockWidgetArea
- documentMode
- event
- iconSize
- insertToolBar
- insertToolBarBreak
- isAnimated
- isDockNestingEnabled
- isSeparator
- removeDockWidget
- removeToolBar
- removeToolBarBreak
- resizeDocks
- restoreDockWidget
- restoreState
- saveState
- setAnimated
- setCentralWidget
- setCorner
- setDockNestingEnabled
- setDockOptions
- setDocumentMode
- setIconSize
- setMenuBar
- setMenuWidget
- setStatusBar
- setTabPosition
- setTabShape
- setToolButtonStyle
- setUnifiedTitleAndToolBarOnMac
- splitDockWidget
- statusBar
- tabPosition
- tabShape
- tabifiedDockWidgets
- tabifyDockWidget
- takeCentralWidget
- toolBarArea
- toolBarBreak
- toolButtonStyle
- unifiedTitleAndToolBarOnMac
- DockOption
- iconSizeChanged
- toolButtonStyleChanged
- tabifiedDockWidgetActivated
- PySide6.QtWidgets.QWidget
- acceptDrops
- accessibleDescription
- accessibleName
- actionEvent
- actions
- activateWindow
- addAction
- addActions
- adjustSize
- autoFillBackground
- backgroundRole
- backingStore
- baseSize
- changeEvent
- childAt
- childrenRect
- childrenRegion
- clearFocus
- clearMask
- close
- closeEvent
- contentsMargins
- contentsRect
- contextMenuPolicy
- create
- createWinId
- createWindowContainer
- cursor
- destroy
- devType
- dragEnterEvent
- dragLeaveEvent
- dragMoveEvent
- dropEvent
- effectiveWinId
- ensurePolished
- enterEvent
- find
- focusInEvent
- focusNextChild
- focusNextPrevChild
- focusOutEvent
- focusPolicy
- focusPreviousChild
- focusProxy
- focusWidget
- font
- fontInfo
- fontMetrics
- foregroundRole
- frameGeometry
- frameSize
- geometry
- grab
- grabGesture
- grabKeyboard
- grabMouse
- grabShortcut
- graphicsEffect
- graphicsProxyWidget
- hasFocus
- hasHeightForWidth
- hasMouseTracking
- hasTabletTracking
- height
- heightForWidth
- hide
- hideEvent
- initPainter
- inputMethodEvent
- inputMethodHints
- inputMethodQuery
- insertAction
- insertActions
- internalWinId
- isActiveWindow
- isAncestorOf
- isEnabled
- isEnabledTo
- isFullScreen
- isHidden
- isLeftToRight
- isMaximized
- isMinimized
- isModal
- isRightToLeft
- isTopLevel
- isVisible
- isVisibleTo
- isWindow
- isWindowModified
- keyPressEvent
- keyReleaseEvent
- keyboardGrabber
- layout
- layoutDirection
- leaveEvent
- locale
- lower
- mapFrom
- mapFromGlobal
- mapFromParent
- mapTo
- mapToGlobal
- mapToParent
- mask
- maximumHeight
- maximumSize
- maximumWidth
- metric
- minimumHeight
- minimumSize
- minimumSizeHint
- minimumWidth
- mouseDoubleClickEvent
- mouseGrabber
- mouseMoveEvent
- mousePressEvent
- mouseReleaseEvent
- move
- moveEvent
- nativeEvent
- nativeParentWidget
- nextInFocusChain
- normalGeometry
- overrideWindowFlags
- overrideWindowState
- paintEngine
- paintEvent
- palette
- parentWidget
- pos
- previousInFocusChain
- raise_
- rect
- redirected
- releaseKeyboard
- releaseMouse
- releaseShortcut
- removeAction
- render
- repaint
- resize
- resizeEvent
- restoreGeometry
- saveGeometry
- screen
- scroll
- setAcceptDrops
- setAccessibleDescription
- setAccessibleName
- setAttribute
- setAutoFillBackground
- setBackgroundRole
- setBaseSize
- setContentsMargins
- setContextMenuPolicy
- setCursor
- setDisabled
- setEnabled
- setFixedHeight
- setFixedSize
- setFixedWidth
- setFocus
- setFocusPolicy
- setFocusProxy
- setFont
- setForegroundRole
- setGeometry
- setGraphicsEffect
- setHidden
- setInputMethodHints
- setLayout
- setLayoutDirection
- setLocale
- setMask
- setMaximumHeight
- setMaximumSize
- setMaximumWidth
- setMinimumHeight
- setMinimumSize
- setMinimumWidth
- setMouseTracking
- setPalette
- setParent
- setScreen
- setShortcutAutoRepeat
- setShortcutEnabled
- setSizeIncrement
- setSizePolicy
- setStatusTip
- setStyle
- setStyleSheet
- setTabOrder
- setTabletTracking
- setToolTip
- setToolTipDuration
- setUpdatesEnabled
- setVisible
- setWhatsThis
- setWindowFilePath
- setWindowFlag
- setWindowFlags
- setWindowIcon
- setWindowIconText
- setWindowModality
- setWindowModified
- setWindowOpacity
- setWindowRole
- setWindowState
- setWindowTitle
- show
- showEvent
- showFullScreen
- showMaximized
- showMinimized
- showNormal
- size
- sizeHint
- sizeIncrement
- sizePolicy
- stackUnder
- statusTip
- style
- styleSheet
- tabletEvent
- testAttribute
- toolTip
- toolTipDuration
- topLevelWidget
- underMouse
- ungrabGesture
- unsetCursor
- unsetLayoutDirection
- unsetLocale
- update
- updateGeometry
- updateMicroFocus
- updatesEnabled
- visibleRegion
- whatsThis
- wheelEvent
- width
- winId
- window
- windowFilePath
- windowFlags
- windowHandle
- windowIcon
- windowIconText
- windowModality
- windowOpacity
- windowRole
- windowState
- windowTitle
- windowType
- x
- y
- RenderFlag
- windowTitleChanged
- windowIconChanged
- windowIconTextChanged
- customContextMenuRequested
- PySide6.QtCore.QObject
- blockSignals
- childEvent
- children
- connect
- connectNotify
- customEvent
- deleteLater
- disconnect
- disconnectNotify
- dumpObjectInfo
- dumpObjectTree
- dynamicPropertyNames
- emit
- eventFilter
- findChild
- findChildren
- inherits
- installEventFilter
- isQuickItemType
- isSignalConnected
- isWidgetType
- isWindowType
- killTimer
- metaObject
- moveToThread
- objectName
- parent
- property
- receivers
- removeEventFilter
- sender
- senderSignalIndex
- setObjectName
- setProperty
- signalsBlocked
- startTimer
- thread
- timerEvent
- tr
- destroyed
- objectNameChanged
- PySide6.QtGui.QPaintDevice
- colorCount
- depth
- devicePixelRatio
- devicePixelRatioF
- devicePixelRatioFScale
- heightMM
- logicalDpiX
- logicalDpiY
- paintingActive
- physicalDpiX
- physicalDpiY
- widthMM
- painters
- PaintDeviceMetric
class
CustomGraphicsScene(PySide6.QtWidgets.QGraphicsScene):
79class CustomGraphicsScene(QGraphicsScene): 80 def __init__(self): 81 super().__init__() 82 self.node_counter = 1 # Initialize the counter
QGraphicsScene(self, parent: Optional[PySide6.QtCore.QObject] = None) -> None QGraphicsScene(self, sceneRect: Union[PySide6.QtCore.QRectF, PySide6.QtCore.QRect], parent: Optional[PySide6.QtCore.QObject] = None) -> None QGraphicsScene(self, x: float, y: float, width: float, height: float, parent: Optional[PySide6.QtCore.QObject] = None) -> None
Inherited Members
- PySide6.QtWidgets.QGraphicsScene
- activePanel
- activeWindow
- addEllipse
- addItem
- addLine
- addPath
- addPixmap
- addPolygon
- addRect
- addSimpleText
- addText
- addWidget
- advance
- backgroundBrush
- bspTreeDepth
- clear
- clearFocus
- clearSelection
- collidingItems
- contextMenuEvent
- createItemGroup
- destroyItemGroup
- dragEnterEvent
- dragLeaveEvent
- dragMoveEvent
- drawBackground
- drawForeground
- dropEvent
- event
- eventFilter
- focusInEvent
- focusItem
- focusNextPrevChild
- focusOnTouch
- focusOutEvent
- font
- foregroundBrush
- hasFocus
- height
- helpEvent
- inputMethodEvent
- inputMethodQuery
- invalidate
- isActive
- itemAt
- itemIndexMethod
- items
- itemsBoundingRect
- keyPressEvent
- keyReleaseEvent
- minimumRenderSize
- mouseDoubleClickEvent
- mouseGrabberItem
- mouseMoveEvent
- mousePressEvent
- mouseReleaseEvent
- palette
- removeItem
- render
- sceneRect
- selectedItems
- selectionArea
- sendEvent
- setActivePanel
- setActiveWindow
- setBackgroundBrush
- setBspTreeDepth
- setFocus
- setFocusItem
- setFocusOnTouch
- setFont
- setForegroundBrush
- setItemIndexMethod
- setMinimumRenderSize
- setPalette
- setSceneRect
- setSelectionArea
- setStickyFocus
- setStyle
- stickyFocus
- style
- update
- views
- wheelEvent
- width
- ItemIndexMethod
- SceneLayer
- changed
- sceneRectChanged
- selectionChanged
- focusItemChanged
- PySide6.QtCore.QObject
- blockSignals
- childEvent
- children
- connect
- connectNotify
- customEvent
- deleteLater
- disconnect
- disconnectNotify
- dumpObjectInfo
- dumpObjectTree
- dynamicPropertyNames
- emit
- findChild
- findChildren
- inherits
- installEventFilter
- isQuickItemType
- isSignalConnected
- isWidgetType
- isWindowType
- killTimer
- metaObject
- moveToThread
- objectName
- parent
- property
- receivers
- removeEventFilter
- sender
- senderSignalIndex
- setObjectName
- setParent
- setProperty
- signalsBlocked
- startTimer
- thread
- timerEvent
- tr
- destroyed
- objectNameChanged