123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- # @Author: Bachir Soussi Chiadmi <bach>
- # @Date: 23-05-2017
- # @Email: bachir@figureslibres.io
- # @Last modified by: bach
- # @Last modified time: 03-06-2017
- # @License: GPL-V3
- from __future__ import absolute_import, print_function, division, unicode_literals
- import os
- from PyQt5.QtGui import QIcon
- from PyQt5.QtWidgets import QMainWindow, QAction, QWidget, QLabel, QStackedWidget, QFileDialog, QMessageBox
- from . import design, content, docsetdialog
- class MainWindow(QMainWindow):
- def __init__(self, core):
- super(MainWindow, self).__init__()
- # load core class
- self.core = core
- self.setWindowTitle("Cascade")
- self.setWindowIcon(QIcon(os.path.join(self.core.appcwd,'assets/images/icon.png')))
- self.resize(self.core.mw_size)
- self.move(self.core.mw_pos)
- self.initMenuBar()
- self.initMainStack()
- 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)
- self.save_action = QAction("&Save Project as",self)
- self.save_action.setShortcut("Ctrl+Shift+s")
- file.addAction(self.save_action)
- self.save_action = QAction("&Save Project as",self)
- self.save_action.setShortcut("Ctrl+Shift+s")
- file.addAction(self.save_action)
- self.docset_action = QAction("&Document Settings",self)
- self.docset_action.setShortcut("Ctrl+d")
- file.addAction(self.docset_action)
- self.pdf_action = QAction("&PDF",self)
- self.pdf_action.setShortcut("Ctrl+p")
- file.addAction(self.pdf_action)
- self.quit_action = QAction("&Quit",self)
- self.quit_action.setShortcut("Ctrl+q")
- file.addAction(self.quit_action)
- file.triggered[QAction].connect(self.onfilemenutrigger)
- # edit menu
- edit = bar.addMenu("&Edit")
- # edit.addAction("©")
- # edit.addAction("&paste")
- edit.addAction("&build")
- self.reload_action = QAction("&Reload",self)
- self.reload_action.setShortcut("Ctrl+r")
- edit.addAction(self.reload_action)
- edit.addAction("&preferences")
- edit.triggered[QAction].connect(self.oneditmenutrigger)
- # 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)
- view.triggered[QAction].connect(self.onviewmenutrigger)
- # about menu
- about = bar.addMenu("About")
- about.addAction("&Website")
- def onfilemenutrigger(self, q):
- print(q.text()+" is triggered")
- if q.text() == "&New Project":
- self.newprojectdialogue()
- elif q.text() == "&Open":
- self.openprojectdialogue()
- elif q.text() == "&Save Project as":
- self.saveprojectdialogue()
- elif q.text() == "&Document Settings":
- self.onDocSettings()
- elif q.text() == "&PDF":
- self.genPDF()
- elif q.text() == "&Quit":
- self.quit()
- def openprojectdialogue(self):
- print("open")
- dialog = QFileDialog()
- dialog.setFileMode(QFileDialog.Directory)
- dialog.setAcceptMode(QFileDialog.AcceptOpen)
- options = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly
- folder = dialog.getExistingDirectory(
- self,
- 'Open Project',
- self.core.dialog_path,
- options
- )
- try:
- head, tail = os.path.split(folder)
- self.core.dialog_path = head
- # TODO: check if is cascade folder
- print(folder)
- if os.path.isdir(folder):
- self.core.openproject(folder)
- else:
- print("folder doesn't exists")
- except Exception as e:
- print('Exception', e)
- pass
- def newprojectdialogue(self):
- dialog = QFileDialog()
- dialog.setFileMode(QFileDialog.Directory)
- dialog.setAcceptMode(QFileDialog.AcceptOpen)
- projectname = dialog.getSaveFileName(
- self,
- 'New Project',
- self.core.dialog_path
- )[0]
- # TODO: no file type
- try:
- head, tail = os.path.split(projectname)
- self.core.dialog_path = head
- if not os.path.isdir(projectname):
- self.core.initnewproject(projectname)
- else:
- print("folder already exists")
- # TODO: check if is cascade folder
- except Exception as e:
- print('Exception', e)
- pass
- def saveprojectdialogue(self, quit=False):
- dialog = QFileDialog()
- dialog.setFileMode(QFileDialog.Directory)
- dialog.setAcceptMode(QFileDialog.AcceptOpen)
- projectname = dialog.getSaveFileName(
- self,
- 'Save Project',
- self.core.dialog_path
- )[0]
- # TODO: no file type
- try:
- head, tail = os.path.split(projectname)
- self.core.dialog_path = head
- if not os.path.isdir(projectname):
- self.core.saveproject(projectname)
- if quit:
- self.quit()
- else:
- print("folder already exists")
- # TODO: check if is cascade folder
- except Exception as e:
- print('Exception', e)
- pass
- def onDocSettings(self):
- d = docsetdialog.DocsetDialog(self)
- d.exec_()
- self.core.recordDocSettings({
- "ho":d.headerOdd.text(),
- "he":d.headerEven.text(),
- "np":d.np.text(),
- "pw":d.pw.text(),
- "ph":d.ph.text(),
- "mt":d.mt.text(),
- "mb":d.mb.text(),
- "me":d.me.text(),
- "mi":d.mi.text(),
- "cs":d.cs.text(),
- "bs":d.bs.text(),
- "cn":d.cn.text(),
- "cg":d.cg.text(),
- "rn":d.rn.text(),
- "rg":d.rg.text(),
- "lh":d.lh.text()
- })
- def genPDF(self):
- print('PDF')
- self.designstack.webkitview.ongenPDF()
- def quit(self):
- print("Quit")
- if self.core.tempcwd:
- buttonReply = QMessageBox.question(self, 'Project Not Saved', "Do you want to save your current project before quiting?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Cancel)
- if buttonReply == QMessageBox.Yes:
- self.saveprojectdialogue(quit=True)
- if buttonReply == QMessageBox.No:
- self.core.quit()
- else:
- self.core.quit()
- def oneditmenutrigger(self, q):
- print(q.text()+" is triggered")
- if q.text() == "&Reload":
- self.designstack.webkitview.reload()
- 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.designstack = design.DesignStack(self.core)
- self.contentstack = content.ContentStack(self.core)
- self.versionstack = QLabel("Version (git).")
- self.mainstack.addWidget(self.designstack)
- self.mainstack.addWidget(self.contentstack)
- self.mainstack.addWidget(self.versionstack)
- self.mainstack.setCurrentIndex(self.core.mw_curstack)
- # TODO: add an app console window (show sass compilation errors for example)
- self.setCentralWidget(self.mainstack)
|