ソースを参照

added create new project dialogue

Bachir Soussi Chiadmi 7 年 前
コミット
32feb7ef70

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 assets/scss/*.css
 assets/scss/*.css
 assets/images
 assets/images
 _index.html
 _index.html
+classes/__pycache__

+ 69 - 11
app.py

@@ -9,16 +9,17 @@
 # @Last modified time: 21-04-2017
 # @Last modified time: 21-04-2017
 # @License: GPL-V3
 # @License: GPL-V3
 
 
-import sys, os
+import sys, os, shutil
 
 
 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 QKeySequence, QFont, QSyntaxHighlighter
 from PyQt5.QtGui import QKeySequence, QFont, QSyntaxHighlighter
-from PyQt5.QtWidgets import QMainWindow, QWidget, QApplication, QShortcut, QGridLayout, QLabel, QTabWidget, QHBoxLayout, QVBoxLayout, QSplitter, QSplitterHandle, QPlainTextEdit
+from PyQt5.QtWidgets import QMainWindow, QAction, QWidget, QApplication, QShortcut, QGridLayout, QLabel, QTabWidget, QHBoxLayout, QVBoxLayout, QSplitter, QSplitterHandle, QPlainTextEdit, QInputDialog, QLineEdit, QFileDialog
 # 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
 
 
+import json
 
 
 from classes import server, compiler, view, content
 from classes import server, compiler, view, content
 
 
@@ -32,10 +33,15 @@ class MainWindow(QMainWindow):
    def __init__(self, core):
    def __init__(self, core):
       super(MainWindow, self).__init__()
       super(MainWindow, self).__init__()
 
 
+      # load core class
       self.core = core
       self.core = core
-
+      # restore previous preferences
       self.restorePreferences()
       self.restorePreferences()
 
 
+      self.setWindowTitle("Cascade")
+
+      self.initMenuBar()
+
       # self.setWindowFlags(QtCore.Qt.WindowTitleHint)
       # self.setWindowFlags(QtCore.Qt.WindowTitleHint)
       # QtCore.Qt.CustomizeWindowHint
       # QtCore.Qt.CustomizeWindowHint
       # | QtCore.Qt.Tool
       # | QtCore.Qt.Tool
@@ -72,12 +78,69 @@ class MainWindow(QMainWindow):
 
 
       self.setCentralWidget(self.tabwidget)
       self.setCentralWidget(self.tabwidget)
 
 
-      self.shortcut = QShortcut(QKeySequence("Ctrl+Q"), self)
-      self.shortcut.activated.connect(self.on_quit)
+      # self.shortcut = QShortcut(QKeySequence("Ctrl+Q"), self)
+      # self.shortcut.activated.connect(self.quit)
 
 
 
 
       self.show()
       self.show()
 
 
+   def initMenuBar(self):
+      # menu bar
+      bar = self.menuBar()
+      file = bar.addMenu("&File")
+
+      new = QAction("&New Project",self)
+      new.setShortcut("Ctrl+n")
+      file.addAction(new)
+
+      open = QAction("&Open",self)
+      open.setShortcut("Ctrl+o")
+      file.addAction(open)
+
+      quit = QAction("&Quit",self)
+      quit.setShortcut("Ctrl+q")
+      file.addAction(quit)
+
+      file.triggered[QAction].connect(self.processtrigger)
+
+      edit = bar.addMenu("Edit")
+      edit.addAction("copy")
+      edit.addAction("paste")
+
+
+   def processtrigger(self, q):
+      print(q.text()+" is triggered")
+      if q.text() == "&New Project":
+         self.newprojectdialogue()
+      elif q.text() == "&Open":
+         self.opendialogue()
+      elif q.text() == "&Quit":
+         self.quit()
+
+   def opendialogue(self):
+      print("open")
+
+   def newprojectdialogue(self):
+      projectname = QFileDialog.getSaveFileName(self, 'Dialog Title', '')
+      # TODO: no file type
+      if not os.path.isdir(projectname[0]):
+         self.core.cwd = projectname[0]
+         self.initnewproject()
+      else:
+         print("folder already exists")
+         # TODO: check if is cascade folder
+
+   def initnewproject(self):
+      shutil.copytree('templates/newproject', self.core.cwd)
+      self.core.prefs = json.loads(open(os.path.join(self.core.cwd,'.config/prefs.json')).read())
+      self.core.summary = json.loads(open(os.path.join(self.core.cwd,'.config/summary.json')).read())
+      # TODO: init git repos
+
+   def quit(self):
+     print("Quit")
+     self.savePreferences()
+     QCoreApplication.instance().quit()
+
    def restorePreferences(self):
    def restorePreferences(self):
       try:
       try:
          self.resize(self.core.settings.value('mainwindow/size', QtCore.QSize(1024, 768)))
          self.resize(self.core.settings.value('mainwindow/size', QtCore.QSize(1024, 768)))
@@ -89,14 +152,9 @@ class MainWindow(QMainWindow):
       self.core.settings.beginGroup("mainwindow")
       self.core.settings.beginGroup("mainwindow")
       self.core.settings.setValue('size', self.size())
       self.core.settings.setValue('size', self.size())
       self.core.settings.setValue('pos', self.pos())
       self.core.settings.setValue('pos', self.pos())
+      self.core.settings.setValue('cwd', self.core.cwd)
       self.core.settings.endGroup()
       self.core.settings.endGroup()
 
 
-   @pyqtSlot()
-   def on_quit(self):
-     print("Quit!")
-     self.savePreferences()
-     QCoreApplication.instance().quit()
-
 
 
 def main():
 def main():
    app = QApplication(sys.argv)
    app = QApplication(sys.argv)

BIN
classes/__pycache__/__init__.cpython-36.pyc


BIN
classes/__pycache__/compiler.cpython-36.pyc


BIN
classes/__pycache__/content.cpython-36.pyc


BIN
classes/__pycache__/server.cpython-36.pyc


BIN
classes/__pycache__/view.cpython-36.pyc


+ 4 - 0
templates/newproject/.config/prefs.json

@@ -0,0 +1,4 @@
+{
+  "prop1":1,
+  "prop2":2
+}

+ 7 - 0
templates/newproject/.config/summary.json

@@ -0,0 +1,7 @@
+[
+  {
+    "title":"Default page",
+    "file":"default.md",
+    "index":0
+  }
+]

+ 5 - 0
templates/newproject/assets/js/script.js

@@ -0,0 +1,5 @@
+jQuery(document).ready(function($) {
+
+  console.log("Hello Cascade");
+
+});

+ 1 - 0
templates/newproject/assets/scss/styles.scss

@@ -0,0 +1 @@
+// your styles here

+ 5 - 0
templates/newproject/contents/default.md

@@ -0,0 +1,5 @@
+# Default Page
+
+Welcome message
+
+insert her an image as example