Commit fff4bb56 authored by Nils Cedric Holle's avatar Nils Cedric Holle

Remove module switchers

parent 896cf3d5
import os
from puzzlestream.backend.signal import PSSignal
from puzzlestream.ui.codeeditor import PSCodeEdit
from puzzlestream.ui.fileexplorer import PSFileExplorer
from pyqode.python.backend import server
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
translate = QCoreApplication.translate
class PSEditorWidget(QWidget):
def __init__(self, parent: QObject = None):
super().__init__(parent)
self.__layout = QVBoxLayout()
self.__layout = QGridLayout()
self.__layout.setContentsMargins(0, 0, 0, 0)
self.__layout.setSpacing(0)
self.setLayout(self.__layout)
......@@ -22,14 +25,43 @@ class PSEditorWidget(QWidget):
self.editorFilePathLabel = QLabel(self.editorHeader)
self.editorFilePathLabel.setObjectName("editorFilePathLabel")
self.editorHeaderLayout.addWidget(self.editorFilePathLabel)
self.moduleSwitcher = QComboBox(self.editorHeader)
self.moduleSwitcher.setObjectName("moduleSwitcher")
self.moduleSwitcher.setSizePolicy(QSizePolicy.Minimum,
QSizePolicy.Maximum)
self.editorHeaderLayout.addWidget(self.moduleSwitcher)
self.__layout.addWidget(self.editorHeader)
self.__layout.addWidget(self.editorHeader, 0, 1)
# file explorer stuff
self.__fileExplorer = PSFileExplorer(self)
self.__fileExplorer.openFileSignal.connect(self.__openFile)
self.__layout.addWidget(self.__fileExplorer, 1, 0, 2, 1)
self.__moduleFileOpened = PSSignal()
self.editor = PSCodeEdit(server.__file__)
self.__layout.addWidget(self.editor)
self.__layout.addWidget(self.editor, 1, 1)
self.currentIndexChangedConnected = False
self.currentModule = None
self.__modules = []
@property
def fileExplorer(self):
return self.__fileExplorer
@property
def moduleFileOpened(self):
return self.__moduleFileOpened
def setModules(self, modules: list):
self.__modules = modules
def __openFile(self, path: str):
self.editor.file.open(path)
self.currentModule = None
for m in self.__modules:
if os.path.normpath(path) == os.path.normpath(m.filePath):
self.__currentModule = m
break
if self.__currentModule is not None:
self.editorFilePathLabel.setText(
m.filePath + " - " +
translate("Status", self.__currentModule.status))
self.moduleFileOpened.emit(m)
else:
self.editorFilePathLabel.setText("")
self.__disableEditorControlElements()
......@@ -34,7 +34,6 @@ from puzzlestream.ui.about import PSAboutWindow
from puzzlestream.ui.codeeditor import PSCodeEdit
from puzzlestream.ui.dataview import PSDataView
from puzzlestream.ui.editorwidget import PSEditorWidget
from puzzlestream.ui.fileexplorer import PSFileExplorer
from puzzlestream.ui.gittab import PSGitTab
from puzzlestream.ui.graphicsview import PSGraphicsView
from puzzlestream.ui.manager import PSManager
......@@ -76,6 +75,7 @@ class PSMainWindow(QMainWindow):
w = self.__newEditorWidget()
self.__editorWidgets = [w]
self.__editors = [w.editor]
w.moduleFileOpened.connect(self.__updateActiveModule)
self.horizontalSplitter.insertWidget(0, w)
self.btnOpenCloseSecondEditor = QPushButton(self)
self.btnOpenCloseSecondEditor.setText("+")
......@@ -103,9 +103,6 @@ class PSMainWindow(QMainWindow):
self.__editorWidgets.append(w)
self.__editors.append(w.editor)
# module switcher
self.__connectSwitcher()
# welcome screen
self.__welcomeLabel = QLabel(self)
font = QFont()
......@@ -371,11 +368,6 @@ class PSMainWindow(QMainWindow):
self.mainTabWidget.addTab(self.helpToolBar, "Help")
self.gridLayout.addWidget(self.mainTabWidget, 0, 0, 1, 2)
# file explorer stuff
self.__fileExplorer = PSFileExplorer(self)
self.__fileExplorer.openFileSignal.connect(self.__openFile)
self.gridLayout.addWidget(self.__fileExplorer, 1, 0)
self.cornerToolBar = QToolBar(self)
self.cornerToolBar.setObjectName("cornerToolBar")
self.mainTabWidget.setCornerWidget(self.cornerToolBar)
......@@ -639,9 +631,7 @@ class PSMainWindow(QMainWindow):
self.horizontalSplitter.insertWidget(2, w)
i = self.horizontalSplitter.indexOf(
self.verticalSplitter)
self.__updateModuleSwitchers()
self.__updateEditorModule(self.__activeModule, 1)
self.__connectSwitcher(1)
self.btnOpenCloseSecondEditor.setText("-")
self.btnOpenCloseSecondEditor.pressed.disconnect()
self.btnOpenCloseSecondEditor.setToolTip(
......@@ -839,60 +829,16 @@ class PSMainWindow(QMainWindow):
self.__rightWidget.updatePuzzleItem(module)
def __updateEditorModule(self, module: PSModule, i: int = 0):
self.__disconnectSwitcher(i)
if not os.path.exists(module.filePath):
module.createModuleScript()
self.__updateEditorModuleList()
self.__editors[i].file.open(module.filePath)
self.__editorWidgets[i].editorFilePathLabel.setText(
module.filePath + " - " + translate("Status", module.status))
self.__editorWidgets[i].moduleSwitcher.setCurrentText(
module.name)
self.__connectSwitcher(i)
self.__enableEditorControlElements()
def __connectSwitcher(self, i: int = 0):
e = self.__editorWidgets[i]
if not e.currentIndexChangedConnected:
e.moduleSwitcher.currentIndexChanged.connect(
lambda index: self.__moduleSwitcherIndexChanged(i, index))
e.currentIndexChangedConnected = True
def __disconnectSwitcher(self, i: int = 0):
e = self.__editorWidgets[i]
if e.currentIndexChangedConnected:
e.moduleSwitcher.currentIndexChanged.disconnect()
e.currentIndexChangedConnected = False
def __updateModuleSwitchers(self):
for i in range(len(self.__editorWidgets)):
switcher = self.__editorWidgets[i].moduleSwitcher
oldText = switcher.currentText()
self.__disconnectSwitcher(i)
switcher.clear()
names = sorted(
[m.name for m in self.__manager.scene.modules.values()])
switcher.addItems(names)
if oldText in names:
switcher.setCurrentText(oldText)
self.__connectSwitcher(i)
def __enableEditorControlElements(self):
for e in [self.btnRunPauseActive, self.btnStopActive]:
e.setEnabled(True)
def __disableEditorControlElements(self):
for e in [self.btnRunPauseActive, self.btnStopActive]:
e.setEnabled(False)
def __moduleSwitcherIndexChanged(self, switcherIndex: int, index: int):
for m in self.__manager.scene.modules.values():
if m.name == self.__editorWidgets[switcherIndex
].moduleSwitcher.currentText():
if switcherIndex == 0:
self.__updateActiveModule(m)
else:
self.__updateEditorModule(m, switcherIndex)
break
def __updateEditorModuleList(self):
for e in self.__editorWidgets:
e.setModules(self.__manager.scene.modules.values())
def __runPauseActiveModule(self, stopHere: bool = False):
if self.__activeModule is not None:
......@@ -914,7 +860,6 @@ class PSMainWindow(QMainWindow):
self.__activeModule.stop()
def __nameChanged(self, module: PSModule):
self.__updateModuleSwitchers()
if module == self.__activeModule:
self.__updateActiveModule(module)
......@@ -1409,7 +1354,8 @@ class PSMainWindow(QMainWindow):
self.__manager.load(path, silent=start)
self.setWindowTitle("Puzzlestream - " + path)
self.__resetUI(path)
self.__fileExplorer.setPath(path)
for e in self.__editorWidgets:
e.fileExplorer.setPath(path)
elif not start:
msg = QMessageBox(self)
msg.setText(
......@@ -1422,7 +1368,6 @@ class PSMainWindow(QMainWindow):
self.__openProject()
self.__updateProjectLoadedStatus()
self.__updateModuleSwitchers()
self.__gitTab.setRepo(self.__manager.repo)
if self.__btnPuzzleLock.isChecked() != self.__manager.puzzleLocked:
self.__btnPuzzleLock.click()
......@@ -1476,7 +1421,6 @@ class PSMainWindow(QMainWindow):
)
)
self.__btnAddStatusAction.setVisible(True)
self.__updateModuleSwitchers()
def __newExtModule(self):
self.__disableAddActions()
......@@ -1490,7 +1434,6 @@ class PSMainWindow(QMainWindow):
)
)
self.__btnAddStatusAction.setVisible(True)
self.__updateModuleSwitchers()
def __newIntModuleFromTemplate(self, templatePath: str):
self.__disableAddActions()
......@@ -1504,7 +1447,6 @@ class PSMainWindow(QMainWindow):
)
)
self.__btnAddStatusAction.setVisible(True)
self.__updateModuleSwitchers()
def __newPipe(self):
self.__disableAddActions()
......@@ -1552,9 +1494,6 @@ class PSMainWindow(QMainWindow):
self.__manager.save()
self.__gitTab.reload()
if isinstance(item, PSModule):
self.__updateModuleSwitchers()
def __itemDeleted(self, item: PSPuzzleItem):
if item == self.__activeModule:
self.__welcomeLabel.setText(self.__projectOpenText)
......@@ -1563,9 +1502,6 @@ class PSMainWindow(QMainWindow):
self.horizontalSplitter.setStretchFactor(0, 0)
self.__resetActiveModule()
if isinstance(item, PSModule):
self.__updateModuleSwitchers()
self.__manager.save()
self.__gitTab.reload()
......@@ -1732,27 +1668,3 @@ class PSMainWindow(QMainWindow):
"\">here</a> for update instructions."
)
)
"""
===========================================================================
Update check stuff
"""
def __openFile(self, path: str):
self.__editors[0].file.open(path)
module = None
for m in self.__manager.scene.modules.values():
print(os.path.normpath(path), os.path.normpath(m.filePath))
if os.path.normpath(path) == os.path.normpath(m.filePath):
module = m
break
if module is not None:
self.__editorWidgets[0].editorFilePathLabel.setText(
m.filePath + " - " + translate("Status", m.status))
self.__editorWidgets[0].moduleSwitcher.setCurrentText(
m.name)
self.__enableEditorControlElements()
else:
self.__editorWidgets[0].editorFilePathLabel.setText("")
self.__editorWidgets[0].moduleSwitcher.setCurrentText("")
self.__disableEditorControlElements()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment