open project seems to be funcional
This commit is contained in:
+28
-11
@@ -23,9 +23,7 @@ class Summary(QWidget):
|
|||||||
super(Summary, self).__init__(parent)
|
super(Summary, self).__init__(parent)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
||||||
jsonfilepath = os.path.join(self.parent.core.cwd,'.config/summary.json')
|
self.loadJson()
|
||||||
sum_json = open(jsonfilepath).read()
|
|
||||||
self.sum = json.loads(sum_json)
|
|
||||||
|
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
vbox.setContentsMargins(0,0,0,0)
|
vbox.setContentsMargins(0,0,0,0)
|
||||||
@@ -38,6 +36,12 @@ class Summary(QWidget):
|
|||||||
|
|
||||||
self.setLayout(vbox)
|
self.setLayout(vbox)
|
||||||
|
|
||||||
|
def loadJson(self):
|
||||||
|
jsonfilepath = os.path.join(self.parent.core.cwd,'.config/summary.json')
|
||||||
|
sum_json = open(jsonfilepath).read()
|
||||||
|
self.sum = json.loads(sum_json)
|
||||||
|
|
||||||
|
|
||||||
def addItem(self, text):
|
def addItem(self, text):
|
||||||
# file
|
# file
|
||||||
filename = re.sub(r'\W', "_", text)+".md"
|
filename = re.sub(r'\W', "_", text)+".md"
|
||||||
@@ -71,6 +75,10 @@ class Summary(QWidget):
|
|||||||
# reload content compiler
|
# reload content compiler
|
||||||
self.parent.core.contentcompiler.reload()
|
self.parent.core.contentcompiler.reload()
|
||||||
|
|
||||||
|
def reload(self):
|
||||||
|
self.loadJson()
|
||||||
|
self.list.setItems()
|
||||||
|
|
||||||
class SummaryList(QListWidget):
|
class SummaryList(QListWidget):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
super(SummaryList, self).__init__(parent)
|
super(SummaryList, self).__init__(parent)
|
||||||
@@ -89,9 +97,7 @@ class SummaryList(QListWidget):
|
|||||||
|
|
||||||
self.itemActivated.connect(self.onItemActivated)
|
self.itemActivated.connect(self.onItemActivated)
|
||||||
|
|
||||||
# add markdown files to the list
|
self.setItems()
|
||||||
for itemdata in self.parent.sum:
|
|
||||||
self.addNewItem(itemdata)
|
|
||||||
|
|
||||||
# self.setCurrentRow(0)
|
# self.setCurrentRow(0)
|
||||||
# self.setCurrentIndex()
|
# self.setCurrentIndex()
|
||||||
@@ -102,6 +108,12 @@ class SummaryList(QListWidget):
|
|||||||
# TODO: show activated item on the list
|
# TODO: show activated item on the list
|
||||||
# TODO: show modifed item on the list
|
# TODO: show modifed item on the list
|
||||||
|
|
||||||
|
def setItems(self):
|
||||||
|
self.clear()
|
||||||
|
# add markdown files to the list
|
||||||
|
for itemdata in self.parent.sum:
|
||||||
|
self.addNewItem(itemdata)
|
||||||
|
|
||||||
def onRowsMoved(self, model, start, end, dest):
|
def onRowsMoved(self, model, start, end, dest):
|
||||||
# print("onRowsMoved")
|
# print("onRowsMoved")
|
||||||
self.parent.recordNewList()
|
self.parent.recordNewList()
|
||||||
@@ -111,7 +123,7 @@ class SummaryList(QListWidget):
|
|||||||
|
|
||||||
def onItemActivated(self, item):
|
def onItemActivated(self, item):
|
||||||
# print('onItemActivated', item.data)
|
# print('onItemActivated', item.data)
|
||||||
self.parent.parent.editor.openFile()
|
self.parent.parent.editor.openFile(self.currentRow())
|
||||||
|
|
||||||
|
|
||||||
class SummaryListWidgetItem(QListWidgetItem):
|
class SummaryListWidgetItem(QListWidgetItem):
|
||||||
@@ -199,14 +211,14 @@ class MarkdownEditor(QWidget):
|
|||||||
|
|
||||||
self.refreshViewer()
|
self.refreshViewer()
|
||||||
|
|
||||||
def openFile(self):
|
def openFile(self, row = 0):
|
||||||
# print("openFile")
|
# print("openFile")
|
||||||
sumlist = self.parent.summary.list
|
sumlist = self.parent.summary.list
|
||||||
currentitem = sumlist.currentItem()
|
item = sumlist.item(row)
|
||||||
if currentitem:
|
if item:
|
||||||
if not self.changed:
|
if not self.changed:
|
||||||
self.editor.textChanged.disconnect(self.onTextChanged)
|
self.editor.textChanged.disconnect(self.onTextChanged)
|
||||||
filename = currentitem.data['file']
|
filename = item.data['file']
|
||||||
self.file = os.path.join(self.parent.core.cwd,'contents',filename)
|
self.file = os.path.join(self.parent.core.cwd,'contents',filename)
|
||||||
self.editor.clear()
|
self.editor.clear()
|
||||||
self.editor.insertPlainText(open(self.file, 'r').read())
|
self.editor.insertPlainText(open(self.file, 'r').read())
|
||||||
@@ -258,6 +270,7 @@ class ContentStack(QWidget):
|
|||||||
self.hsplitter.addWidget(self.summary)
|
self.hsplitter.addWidget(self.summary)
|
||||||
|
|
||||||
self.editor = MarkdownEditor(self)
|
self.editor = MarkdownEditor(self)
|
||||||
|
|
||||||
self.hsplitter.addWidget(self.editor)
|
self.hsplitter.addWidget(self.editor)
|
||||||
|
|
||||||
self.hsplitter.splitterMoved.connect(self.movedSplitter)
|
self.hsplitter.splitterMoved.connect(self.movedSplitter)
|
||||||
@@ -279,3 +292,7 @@ class ContentStack(QWidget):
|
|||||||
settings = QSettings('FiguresLibres', 'Cascade')
|
settings = QSettings('FiguresLibres', 'Cascade')
|
||||||
# print(self.hsplitter.sizes())
|
# print(self.hsplitter.sizes())
|
||||||
settings.setValue('content/hsplitter/sizes', self.hsplitter.sizes())
|
settings.setValue('content/hsplitter/sizes', self.hsplitter.sizes())
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
self.summary.reload()
|
||||||
|
self.editor.openFile()
|
||||||
|
|||||||
+21
-11
@@ -37,7 +37,12 @@ class Core():
|
|||||||
self.cwd = os.path.join(self.temp, 'cwd')
|
self.cwd = os.path.join(self.temp, 'cwd')
|
||||||
self.tempcwd = True
|
self.tempcwd = True
|
||||||
self.initnewproject()
|
self.initnewproject()
|
||||||
|
self.initDeamons()
|
||||||
|
else:
|
||||||
|
self.initDeamons()
|
||||||
|
|
||||||
|
|
||||||
|
def initDeamons(self):
|
||||||
self.server = server.Server(self)
|
self.server = server.Server(self)
|
||||||
self.sasscompiler = sasscompiler.Compiler(self)
|
self.sasscompiler = sasscompiler.Compiler(self)
|
||||||
self.contentcompiler = md2html.Compiler(self)
|
self.contentcompiler = md2html.Compiler(self)
|
||||||
@@ -83,19 +88,18 @@ class Core():
|
|||||||
settings.setValue('mainwindow/curstack', self._mw.mainstack.currentIndex())
|
settings.setValue('mainwindow/curstack', self._mw.mainstack.currentIndex())
|
||||||
|
|
||||||
def initnewproject(self, cwd = None):
|
def initnewproject(self, cwd = None):
|
||||||
|
print('initnewproject')
|
||||||
if cwd == None :
|
if cwd == None :
|
||||||
cwd = self.cwd
|
cwd = self.cwd
|
||||||
else :
|
|
||||||
self.changeCWD(cwd)
|
|
||||||
|
|
||||||
shutil.copytree('templates/newproject', cwd)
|
shutil.copytree(os.path.join(self.appcwd,'templates/newproject'), cwd)
|
||||||
self.prefs = json.loads(open(os.path.join(cwd,'.config/prefs.json')).read())
|
self.prefs = json.loads(open(os.path.join(cwd,'.config/prefs.json')).read())
|
||||||
self.summary = json.loads(open(os.path.join(cwd,'.config/summary.json')).read())
|
self.summary = json.loads(open(os.path.join(cwd,'.config/summary.json')).read())
|
||||||
self.repository = git.Repo.init(cwd)
|
self.repository = git.Repo.init(cwd)
|
||||||
self.repository.index.add(['assets','contents','.config'])
|
self.repository.index.add(['assets','contents','.config'])
|
||||||
self.repository.index.commit("initial commit")
|
self.repository.index.commit("initial commit")
|
||||||
# TODO: set mdtohtml compiler from project md to app index.html
|
|
||||||
# TODO: embed project styles.scss to app scss frame work
|
self.changeCWD(cwd)
|
||||||
|
|
||||||
def saveproject(self, cwd = None):
|
def saveproject(self, cwd = None):
|
||||||
if not cwd == None:
|
if not cwd == None:
|
||||||
@@ -103,13 +107,19 @@ class Core():
|
|||||||
self.tempcwd = False
|
self.tempcwd = False
|
||||||
self.changeCWD(cwd)
|
self.changeCWD(cwd)
|
||||||
|
|
||||||
|
def openproject(self, cwd=None):
|
||||||
|
if not cwd == None:
|
||||||
|
self.changeCWD(cwd)
|
||||||
|
|
||||||
def changeCWD(self, cwd):
|
def changeCWD(self, cwd):
|
||||||
self.cwd = cwd
|
if not cwd == self.cwd:
|
||||||
self.server.reload()
|
self.cwd = cwd
|
||||||
self.sasscompiler.reload()
|
self._mw.setWindowTitle("Cascade – "+self.cwd)
|
||||||
self.contentcompiler.reload()
|
self.server.reload()
|
||||||
# if not self.tempcwd:
|
self.sasscompiler.reload()
|
||||||
self._mw.setWindowTitle("Cascade – "+self.cwd)
|
self.contentcompiler.reload()
|
||||||
|
self._mw.designstack.refresh()
|
||||||
|
self._mw.contentstack.refresh()
|
||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
self.savePreferences()
|
self.savePreferences()
|
||||||
|
|||||||
+24
-8
@@ -95,20 +95,29 @@ class CodeEditor(QPlainTextEdit):
|
|||||||
super(CodeEditor, self).__init__()
|
super(CodeEditor, self).__init__()
|
||||||
self.core = core
|
self.core = core
|
||||||
self.tabs = tabs
|
self.tabs = tabs
|
||||||
# self.file = file
|
self.file = file
|
||||||
self.file = os.path.join(self.core.cwd,file)
|
self.setText()
|
||||||
|
|
||||||
self.insertPlainText(open(self.file, 'r').read())
|
|
||||||
self.changed = False
|
|
||||||
self.textChanged.connect(self.onTextChanged)
|
|
||||||
|
|
||||||
self.shortcut = QShortcut(QKeySequence("Ctrl+s"), self)
|
self.shortcut = QShortcut(QKeySequence("Ctrl+s"), self)
|
||||||
self.shortcut.activated.connect(self.save)
|
self.shortcut.activated.connect(self.save)
|
||||||
|
|
||||||
|
def setText(self):
|
||||||
|
try:
|
||||||
|
self.textChanged.disconnect(self.onTextChanged)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
self.filepath = os.path.join(self.core.cwd,self.file)
|
||||||
|
self.clear()
|
||||||
|
self.insertPlainText(open(self.filepath, 'r').read())
|
||||||
|
self.changed = False
|
||||||
|
self.textChanged.connect(self.onTextChanged)
|
||||||
|
|
||||||
|
|
||||||
def onTextChanged(self):
|
def onTextChanged(self):
|
||||||
# print('textChanged')
|
# print('textChanged')
|
||||||
# print(self.toPlainText())
|
# print(self.toPlainText())
|
||||||
# open(self.file, 'w').write(self.toPlainText())
|
# open(self.filepath, 'w').write(self.toPlainText())
|
||||||
if not self.changed:
|
if not self.changed:
|
||||||
self.changed = True
|
self.changed = True
|
||||||
i = self.tabs.currentIndex()
|
i = self.tabs.currentIndex()
|
||||||
@@ -116,7 +125,7 @@ class CodeEditor(QPlainTextEdit):
|
|||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
if self.changed:
|
if self.changed:
|
||||||
open(self.file, 'w').write(self.toPlainText())
|
open(self.filepath, 'w').write(self.toPlainText())
|
||||||
i = self.tabs.currentIndex()
|
i = self.tabs.currentIndex()
|
||||||
self.tabs.setTabText(i, re.sub(r'^\*\s', '', self.tabs.tabText(i)))
|
self.tabs.setTabText(i, re.sub(r'^\*\s', '', self.tabs.tabText(i)))
|
||||||
self.changed = False
|
self.changed = False
|
||||||
@@ -153,6 +162,9 @@ class Editor(QWidget):
|
|||||||
# self.highlighter = Highlighter(self.document())
|
# self.highlighter = Highlighter(self.document())
|
||||||
# https://pypi.python.org/pypi/QScintilla/2.9.2
|
# https://pypi.python.org/pypi/QScintilla/2.9.2
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
self.scsstab.setText()
|
||||||
|
self.jstab.setText()
|
||||||
|
|
||||||
class DesignStack(QWidget):
|
class DesignStack(QWidget):
|
||||||
def __init__(self, core):
|
def __init__(self, core):
|
||||||
@@ -226,3 +238,7 @@ class DesignStack(QWidget):
|
|||||||
# print(self.vsplitter.sizes())
|
# print(self.vsplitter.sizes())
|
||||||
settings.setValue('design/vsplitter/sizes', self.vsplitter.sizes())
|
settings.setValue('design/vsplitter/sizes', self.vsplitter.sizes())
|
||||||
settings.setValue('design/hsplitter/sizes', self.hsplitter.sizes())
|
settings.setValue('design/hsplitter/sizes', self.hsplitter.sizes())
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
self.editor.refresh()
|
||||||
|
self.webkitview.reload()
|
||||||
|
|||||||
@@ -110,6 +110,28 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def openprojectdialogue(self):
|
def openprojectdialogue(self):
|
||||||
print("open")
|
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):
|
def newprojectdialogue(self):
|
||||||
dialog = QFileDialog()
|
dialog = QFileDialog()
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ class Compiler():
|
|||||||
self.paths.append(os.path.join(self.parent.cwd,'assets/css',f))
|
self.paths.append(os.path.join(self.parent.cwd,'assets/css',f))
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
|
# print('Reload sass compiler')
|
||||||
self.fs_watcher.removePaths(self.paths)
|
self.fs_watcher.removePaths(self.paths)
|
||||||
self.refreshPaths()
|
self.refreshPaths()
|
||||||
|
# print('paths', self.paths)
|
||||||
self.fs_watcher.addPaths(self.paths)
|
self.fs_watcher.addPaths(self.paths)
|
||||||
|
# print('files', self.fs_watcher.files())
|
||||||
|
|||||||
Reference in New Issue
Block a user