Parcourir la source

refactored classes in own modules files, added proto content module

Bachir Soussi Chiadmi il y a 7 ans
Parent
commit
aff2d0d033

+ 7 - 115
app.py

@@ -11,131 +11,23 @@
 
 
 import sys, os
 import sys, os
 
 
-from socket import socket
-import socketserver
-import http.server
-import threading
-
 from PyQt5 import QtCore
 from PyQt5 import QtCore
-from PyQt5.QtCore import QCoreApplication, QUrl, QFileSystemWatcher, 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, QWidget, QApplication, QShortcut, QGridLayout, QLabel, QTabWidget, QHBoxLayout, QVBoxLayout, QSplitter, QSplitterHandle, QPlainTextEdit
 # 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 sass
+
+from classes import server, compiler, view, content
 
 
 class Core():
 class Core():
    def __init__(self, parent=None):
    def __init__(self, parent=None):
-      self.server = Server()
-      self.compiler = Compiler()
+      self.server = server.Server()
+      self.compiler = compiler.Compiler()
       self.settings = QSettings('FiguresLibres', 'Cascade')
       self.settings = QSettings('FiguresLibres', 'Cascade')
 
 
-class Server():
-
-   def __init__(self, parent=None):
-
-      # find free port
-      sock = socket()
-      sock.bind(('', 0))
-
-      self._port = sock.getsockname()[1]
-      sock.close()
-
-      self.httpd = http.server.HTTPServer(('', self.port), http.server.SimpleHTTPRequestHandler)
-      self.thread = threading.Thread(target=self.httpd.serve_forever)
-      self.thread.daemon = True
-      self.thread.start()
-      print("serving at port", self._port)
-
-
-   @property
-   def port(self):
-        return self._port
-
-class Compiler():
-   def __init__(self,parent=None):
-      paths = [
-         'assets',
-         'assets/scss',
-         'assets/scss/styles.scss'
-      ]
-      self.fs_watcher = QFileSystemWatcher(paths)
-      # self.fs_watcher.directoryChanged.connect(self.directory_changed)
-      self.fs_watcher.fileChanged.connect(self.compile_scss)
-      self.compile_scss()
-
-   # def directory_changed(path):
-   #    print("Directory changed : %s" % path)
-
-   def compile_scss(path = ""):
-      print("compiling sass : %s" % path)
-      scss = sass.compile_file(b'assets/scss/main.scss')
-      with open('assets/scss/main.css', 'w') as fp:
-         fp.write(scss.decode('utf8'))
-
-class WebkitView(QWebView):
-   def __init__(self, port):
-      self.port = port
-      self.view = QWebView.__init__(self)
-      self.load(QUrl('http://localhost:'+str(self.port)))
-      self.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
-      # self.settings().setAttribute(QWebSettings.PluginsEnabled, True)
-
-
-class WebkitInspector(QWebInspector):
-   def __init__(self, webkitview):
-      super(WebkitInspector, self).__init__()
-      self.webkitview = webkitview
-      self.setPage(self.webkitview.page())
-      # TODO: webkitinspector is disappearing when chaging tabs
-
-class CodeEditor(QPlainTextEdit):
-   def __init__(self):
-      super(CodeEditor, self).__init__()
-      font = QFont()
-      font.setFamily('Courier')
-      font.setFixedPitch(True)
-      font.setPointSize(10)
-      self.setFont(font)
-      # self.highlighter = Highlighter(self.document())
-      # https://pypi.python.org/pypi/QScintilla/2.9.2
-
-
-class ViewTab(QWidget):
-   def __init__(self, core):
-      super(ViewTab, self).__init__()
-
-      # self.grid = QGridLayout()
-      hbox = QHBoxLayout()
-      hbox.setContentsMargins(0,0,0,0)
-      self.setLayout(hbox)
-
-
-      # webviewbox = QVBoxLayout()
-      vsplitter = QSplitter(QtCore.Qt.Vertical)
-
-      self.webkitview = WebkitView(core.server.port)
-      vsplitter.addWidget(self.webkitview)
-
-      self.webkitinspector = WebkitInspector(self.webkitview)
-      vsplitter.addWidget(self.webkitinspector)
-
-      hsplitter = QSplitter(QtCore.Qt.Horizontal)
-      hsplitter.addWidget(vsplitter)
-
-      self.codeeditor = CodeEditor()
-      hsplitter.addWidget(self.codeeditor)
-
-      hbox.addWidget(hsplitter)
-
-
-   def onChanged(self, text):
-      print("ViewTba Layout Changed")
-      self.lbl.setText(text)
-      self.lbl.adjustSize()
-
 class MainWindow(QMainWindow):
 class MainWindow(QMainWindow):
    def __init__(self, core):
    def __init__(self, core):
       super(MainWindow, self).__init__()
       super(MainWindow, self).__init__()
@@ -169,8 +61,8 @@ class MainWindow(QMainWindow):
          }
          }
         """)
         """)
 
 
-      self.viewtab = ViewTab(core)
-      self.contenttab = QLabel("Content (markdown editor).")
+      self.viewtab = view.ViewTab(core)
+      self.contenttab = content.ContentTab(core)
       self.versiontab = QLabel("Version (git).")
       self.versiontab = QLabel("Version (git).")
 
 
 
 

+ 0 - 0
classes/__init__.py


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


+ 26 - 0
classes/compiler.py

@@ -0,0 +1,26 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from PyQt5.QtCore import QFileSystemWatcher
+import sass
+
+class Compiler():
+   def __init__(self,parent=None):
+      paths = [
+         'assets',
+         'assets/scss',
+         'assets/scss/styles.scss'
+      ]
+      self.fs_watcher = QFileSystemWatcher(paths)
+      # self.fs_watcher.directoryChanged.connect(self.directory_changed)
+      self.fs_watcher.fileChanged.connect(self.compile_scss)
+      self.compile_scss()
+
+   # def directory_changed(path):
+   #    print("Directory changed : %s" % path)
+
+   def compile_scss(path = ""):
+      print("compiling sass : %s" % path)
+      scss = sass.compile_file(b'assets/scss/main.scss')
+      with open('assets/scss/main.css', 'w') as fp:
+         fp.write(scss.decode('utf8'))

+ 35 - 0
classes/content.py

@@ -0,0 +1,35 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from PyQt5 import QtCore
+from PyQt5.QtGui import QFont, QSyntaxHighlighter
+from PyQt5.QtWidgets import QWidget, QLabel, QTabWidget, QHBoxLayout, QSplitter, QPlainTextEdit
+
+
+class Summary(QLabel):
+   def __init__(self):
+      super(Summary, self).__init__()
+
+
+
+class ContentTab(QWidget):
+   def __init__(self, core):
+      super(ContentTab, self).__init__()
+
+      # self.grid = QGridLayout()
+      hbox = QHBoxLayout()
+      hbox.setContentsMargins(0,0,0,0)
+      self.setLayout(hbox)
+
+      hsplitter = QSplitter(QtCore.Qt.Horizontal)
+
+      self.summary = QLabel("Summary (markdown files list).")
+      hsplitter.addWidget(self.summary)
+
+      self.mdsource = QLabel("Content (markdown src).")
+      hsplitter.addWidget(self.mdsource)
+
+      self.mdpreview = QLabel("Content (markdown preview).")
+      hsplitter.addWidget(self.mdpreview)
+
+      hbox.addWidget(hsplitter)

+ 34 - 0
classes/server.py

@@ -0,0 +1,34 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+
+import sys, os
+
+from socket import socket
+
+import socketserver
+import http.server
+import threading
+
+
+class Server():
+
+   def __init__(self, parent=None):
+
+      # find free port
+      sock = socket()
+      sock.bind(('', 0))
+
+      self._port = sock.getsockname()[1]
+      sock.close()
+
+      self.httpd = http.server.HTTPServer(('', self.port), http.server.SimpleHTTPRequestHandler)
+      self.thread = threading.Thread(target=self.httpd.serve_forever)
+      self.thread.daemon = True
+      self.thread.start()
+      print("serving at port", self._port)
+
+
+   @property
+   def port(self):
+        return self._port

+ 71 - 0
classes/view.py

@@ -0,0 +1,71 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from PyQt5 import QtCore
+from PyQt5.QtCore import QUrl
+from PyQt5.QtGui import QFont, QSyntaxHighlighter
+from PyQt5.QtWidgets import QWidget, QLabel, QTabWidget, QHBoxLayout, QSplitter, QPlainTextEdit
+from PyQt5.QtWebKit import QWebSettings
+from PyQt5.QtWebKitWidgets import QWebView, QWebInspector
+
+
+class WebkitView(QWebView):
+   def __init__(self, port):
+      self.port = port
+      self.view = QWebView.__init__(self)
+      self.load(QUrl('http://localhost:'+str(self.port)))
+      self.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
+      # self.settings().setAttribute(QWebSettings.PluginsEnabled, True)
+
+
+class WebkitInspector(QWebInspector):
+   def __init__(self, webkitview):
+      super(WebkitInspector, self).__init__()
+      self.webkitview = webkitview
+      self.setPage(self.webkitview.page())
+      # TODO: webkitinspector is disappearing when chaging tabs
+
+class CodeEditor(QPlainTextEdit):
+   def __init__(self):
+      super(CodeEditor, self).__init__()
+      font = QFont()
+      font.setFamily('Courier')
+      font.setFixedPitch(True)
+      font.setPointSize(10)
+      self.setFont(font)
+      # self.highlighter = Highlighter(self.document())
+      # https://pypi.python.org/pypi/QScintilla/2.9.2
+
+
+class ViewTab(QWidget):
+   def __init__(self, core):
+      super(ViewTab, self).__init__()
+
+      # self.grid = QGridLayout()
+      hbox = QHBoxLayout()
+      hbox.setContentsMargins(0,0,0,0)
+      self.setLayout(hbox)
+
+
+      # webviewbox = QVBoxLayout()
+      vsplitter = QSplitter(QtCore.Qt.Vertical)
+
+      self.webkitview = WebkitView(core.server.port)
+      vsplitter.addWidget(self.webkitview)
+
+      self.webkitinspector = WebkitInspector(self.webkitview)
+      vsplitter.addWidget(self.webkitinspector)
+
+      hsplitter = QSplitter(QtCore.Qt.Horizontal)
+      hsplitter.addWidget(vsplitter)
+
+      self.codeeditor = CodeEditor()
+      hsplitter.addWidget(self.codeeditor)
+
+      hbox.addWidget(hsplitter)
+
+
+   def onChanged(self, text):
+      print("ViewTba Layout Changed")
+      self.lbl.setText(text)
+      self.lbl.adjustSize()