Ver código fonte

converted main tabs to stacked widget

Bachir Soussi Chiadmi 7 anos atrás
pai
commit
096ffa069e
3 arquivos alterados com 70 adições e 40 exclusões
  1. 62 32
      app.py
  2. 2 2
      classes/content.py
  3. 6 6
      classes/view.py

+ 62 - 32
app.py

@@ -14,7 +14,7 @@ import sys, os, shutil, tempfile
 from PyQt5 import QtCore
 from PyQt5 import QtCore
 from PyQt5.QtCore import QCoreApplication, QUrl, pyqtSlot, QSettings
 from PyQt5.QtCore import QCoreApplication, QUrl, pyqtSlot, QSettings
 from PyQt5.QtGui import QIcon, QKeySequence, QFont, QSyntaxHighlighter
 from PyQt5.QtGui import QIcon, QKeySequence, QFont, QSyntaxHighlighter
-from PyQt5.QtWidgets import QMainWindow, QAction, QWidget, QApplication, QShortcut, QGridLayout, QLabel, QTabWidget, QHBoxLayout, QVBoxLayout, QSplitter, QSplitterHandle, QPlainTextEdit, QInputDialog, QLineEdit, QFileDialog, QMessageBox, QPushButton
+from PyQt5.QtWidgets import QMainWindow, QAction, QWidget, QApplication, QShortcut, QGridLayout, QLabel, QTabWidget, QStackedWidget, QHBoxLayout, QVBoxLayout, QSplitter, QSplitterHandle, QPlainTextEdit, QInputDialog, QLineEdit, QFileDialog, QMessageBox, QPushButton
 # from PyQt5.QtNetwork import QNetworkProxyFactory, QNetworkRequest
 # from PyQt5.QtNetwork import QNetworkProxyFactory, QNetworkRequest
 from PyQt5.QtWebKit import QWebSettings
 from PyQt5.QtWebKit import QWebSettings
 from PyQt5.QtWebKitWidgets import QWebPage, QWebView, QWebInspector
 from PyQt5.QtWebKitWidgets import QWebPage, QWebView, QWebInspector
@@ -66,7 +66,7 @@ class Core():
       settings.setValue('mainwindow/size', self.mainwindow.size())
       settings.setValue('mainwindow/size', self.mainwindow.size())
       settings.setValue('mainwindow/pos', self.mainwindow.pos())
       settings.setValue('mainwindow/pos', self.mainwindow.pos())
       # TODO: save splitters pos
       # TODO: save splitters pos
-      
+
    def initnewproject(self, cwd = None):
    def initnewproject(self, cwd = None):
       if cwd == None :
       if cwd == None :
          cwd = self.cwd
          cwd = self.cwd
@@ -108,7 +108,7 @@ class MainWindow(QMainWindow):
 
 
       self.initMenuBar()
       self.initMenuBar()
 
 
-      self.initTabs()
+      self.initMainStack()
       # self.shortcut = QShortcut(QKeySequence("Ctrl+Q"), self)
       # self.shortcut = QShortcut(QKeySequence("Ctrl+Q"), self)
       # self.shortcut.activated.connect(self.quit)
       # self.shortcut.activated.connect(self.quit)
 
 
@@ -137,13 +137,33 @@ class MainWindow(QMainWindow):
       quit.setShortcut("Ctrl+q")
       quit.setShortcut("Ctrl+q")
       file.addAction(quit)
       file.addAction(quit)
 
 
-      file.triggered[QAction].connect(self.processtrigger)
+      file.triggered[QAction].connect(self.onfilemenutrigger)
 
 
+      # edit menu
       edit = bar.addMenu("Edit")
       edit = bar.addMenu("Edit")
       edit.addAction("copy")
       edit.addAction("copy")
       edit.addAction("paste")
       edit.addAction("paste")
+      edit.addAction("preferences")
+
+      # view menu
+      view = bar.addMenu("&View")
+
+      designview = QAction("&Design",self)
+      designview.setShortcut("F1")
+      view.addAction(designview)
+
+      contentview = QAction("&Content",self)
+      contentview.setShortcut("F2")
+      view.addAction(contentview)
+
+      versionview = QAction("&Version",self)
+      versionview.setShortcut("F3")
+      view.addAction(versionview)
 
 
-   def processtrigger(self, q):
+      view.triggered[QAction].connect(self.onviewmenutrigger)
+
+
+   def onfilemenutrigger(self, q):
       print(q.text()+" is triggered")
       print(q.text()+" is triggered")
       if q.text() == "&New Project":
       if q.text() == "&New Project":
          self.newprojectdialogue()
          self.newprojectdialogue()
@@ -195,34 +215,44 @@ class MainWindow(QMainWindow):
       else:
       else:
          self.core.quit()
          self.core.quit()
 
 
-   def initTabs(self):
-      self.tabwidget = QTabWidget()
+   def onviewmenutrigger(self, q):
+      print(q.text()+" is triggered")
+      if q.text() == "&Design":
+         self.mainstack.setCurrentIndex(0)
+      elif q.text() == "&Content":
+         self.mainstack.setCurrentIndex(1)
+      elif q.text() == "&Version":
+         self.mainstack.setCurrentIndex(2)
+
+
+   def initMainStack(self):
+      self.mainstack = QStackedWidget()
       # self.tabwidget.setContentsMargins(0,0,0,0)
       # self.tabwidget.setContentsMargins(0,0,0,0)
-      self.tabwidget.setStyleSheet("""
-         QTabWidget::pane {
-            border:0px solid inherted;
-            margin:0px;
-            padding:0px;
-            }
-         QTabBar::tab {
-            padding: 4px;
-            font-size:12px;
-         }
-         QTabBar::tab:selected {
-            font-weight:bold;
-         }
-        """)
-
-      self.viewtab = view.ViewTab(self.core)
-      self.contenttab = content.ContentTab(self.core)
-      self.versiontab = QLabel("Version (git).")
-
-
-      self.tabwidget.addTab(self.viewtab, "View")
-      self.tabwidget.addTab(self.contenttab, "Content")
-      self.tabwidget.addTab(self.versiontab, "Version")
-
-      self.setCentralWidget(self.tabwidget)
+      # self.tabwidget.setStyleSheet("""
+      #    QTabWidget::pane {
+      #       border:0px solid inherted;
+      #       margin:0px;
+      #       padding:0px;
+      #       }
+      #    QTabBar::tab {
+      #       padding: 4px;
+      #       font-size:12px;
+      #    }
+      #    QTabBar::tab:selected {
+      #       font-weight:bold;
+      #    }
+      #   """)
+
+      self.viewstack = view.ViewStack(self.core)
+      self.contentstack = content.ContentStack(self.core)
+      self.versionstack = QLabel("Version (git).")
+
+
+      self.mainstack.addWidget(self.viewstack)
+      self.mainstack.addWidget(self.contentstack)
+      self.mainstack.addWidget(self.versionstack)
+
+      self.setCentralWidget(self.mainstack)
 
 
 
 
 def main():
 def main():

+ 2 - 2
classes/content.py

@@ -12,9 +12,9 @@ class Summary(QLabel):
 
 
 
 
 
 
-class ContentTab(QWidget):
+class ContentStack(QWidget):
    def __init__(self, core):
    def __init__(self, core):
-      super(ContentTab, self).__init__()
+      super(ContentStack, self).__init__()
 
 
       # self.grid = QGridLayout()
       # self.grid = QGridLayout()
       hbox = QHBoxLayout()
       hbox = QHBoxLayout()

+ 6 - 6
classes/view.py

@@ -37,9 +37,9 @@ class CodeEditor(QPlainTextEdit):
       # https://pypi.python.org/pypi/QScintilla/2.9.2
       # https://pypi.python.org/pypi/QScintilla/2.9.2
 
 
 
 
-class ViewTab(QWidget):
+class ViewStack(QWidget):
    def __init__(self, core):
    def __init__(self, core):
-      super(ViewTab, self).__init__()
+      super(ViewStack, self).__init__()
 
 
       # self.grid = QGridLayout()
       # self.grid = QGridLayout()
       hbox = QHBoxLayout()
       hbox = QHBoxLayout()
@@ -65,7 +65,7 @@ class ViewTab(QWidget):
       hbox.addWidget(hsplitter)
       hbox.addWidget(hsplitter)
 
 
 
 
-   def onChanged(self, text):
-      print("ViewTba Layout Changed")
-      self.lbl.setText(text)
-      self.lbl.adjustSize()
+   # def onChanged(self, text):
+   #    print("ViewTba Layout Changed")
+   #    self.lbl.setText(text)
+   #    self.lbl.adjustSize()