app.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. # @Author: Bachir Soussi Chiadmi <bach>
  4. # @Date: 23-05-2017
  5. # @Email: bachir@figureslibres.io
  6. # @Last modified by: bach
  7. # @Last modified time: 21-04-2017
  8. # @License: GPL-V3
  9. import sys, os
  10. from PyQt5 import QtCore
  11. from PyQt5.QtCore import QCoreApplication, QUrl, pyqtSlot, QSettings
  12. from PyQt5.QtGui import QKeySequence, QFont, QSyntaxHighlighter
  13. from PyQt5.QtWidgets import QMainWindow, QWidget, QApplication, QShortcut, QGridLayout, QLabel, QTabWidget, QHBoxLayout, QVBoxLayout, QSplitter, QSplitterHandle, QPlainTextEdit
  14. # from PyQt5.QtNetwork import QNetworkProxyFactory, QNetworkRequest
  15. from PyQt5.QtWebKit import QWebSettings
  16. from PyQt5.QtWebKitWidgets import QWebPage, QWebView, QWebInspector
  17. from classes import server, compiler, view, content
  18. class Core():
  19. def __init__(self, parent=None):
  20. self.server = server.Server()
  21. self.compiler = compiler.Compiler()
  22. self.settings = QSettings('FiguresLibres', 'Cascade')
  23. class MainWindow(QMainWindow):
  24. def __init__(self, core):
  25. super(MainWindow, self).__init__()
  26. self.core = core
  27. self.restorePreferences()
  28. # self.setWindowFlags(QtCore.Qt.WindowTitleHint)
  29. # QtCore.Qt.CustomizeWindowHint
  30. # | QtCore.Qt.Tool
  31. # | QtCore.Qt.FramelessWindowHint
  32. # | QtCore.Qt.WindowTitleHint
  33. # | QtCore.Qt.WindowStaysOnTopHint
  34. self.tabwidget = QTabWidget()
  35. # self.tabwidget.setContentsMargins(0,0,0,0)
  36. self.tabwidget.setStyleSheet("""
  37. QTabWidget::pane {
  38. border:0px solid inherted;
  39. margin:0px;
  40. padding:0px;
  41. }
  42. QTabBar::tab {
  43. padding: 4px;
  44. font-size:12px;
  45. }
  46. QTabBar::tab:selected {
  47. font-weight:bold;
  48. }
  49. """)
  50. self.viewtab = view.ViewTab(core)
  51. self.contenttab = content.ContentTab(core)
  52. self.versiontab = QLabel("Version (git).")
  53. self.tabwidget.addTab(self.viewtab, "View")
  54. self.tabwidget.addTab(self.contenttab, "Content")
  55. self.tabwidget.addTab(self.versiontab, "Version")
  56. self.setCentralWidget(self.tabwidget)
  57. self.shortcut = QShortcut(QKeySequence("Ctrl+Q"), self)
  58. self.shortcut.activated.connect(self.on_quit)
  59. self.show()
  60. def restorePreferences(self):
  61. try:
  62. self.resize(self.core.settings.value('mainwindow/size', QtCore.QSize(1024, 768)))
  63. self.move(self.core.settings.value('mainwindow/pos', QtCore.QPoint(0, 0)))
  64. except:
  65. pass
  66. def savePreferences(self):
  67. self.core.settings.beginGroup("mainwindow")
  68. self.core.settings.setValue('size', self.size())
  69. self.core.settings.setValue('pos', self.pos())
  70. self.core.settings.endGroup()
  71. @pyqtSlot()
  72. def on_quit(self):
  73. print("Quit!")
  74. self.savePreferences()
  75. QCoreApplication.instance().quit()
  76. def main():
  77. app = QApplication(sys.argv)
  78. core = Core()
  79. mainappwindow = MainWindow(core)
  80. sys.exit(app.exec_())
  81. if __name__ == "__main__":
  82. main()