fixed stars code editor tabs, removed some print

This commit is contained in:
Bachir Soussi Chiadmi
2017-06-05 17:17:09 +02:00
parent b6071cf87f
commit cb6db6a357
2 changed files with 38 additions and 38 deletions
+26 -24
View File
@@ -155,7 +155,6 @@ class WebViewToolBar(QWidget):
# page # page
self.gotopage = QLabel("Go to Page: /"+self.parent.core.docsettings['np']) self.gotopage = QLabel("Go to Page: /"+self.parent.core.docsettings['np'])
# TODO: refresh page number on change
self.hbox.addWidget(self.gotopage) self.hbox.addWidget(self.gotopage)
self.page = QSpinBox(self) self.page = QSpinBox(self)
# TODO: action # TODO: action
@@ -213,19 +212,19 @@ class WebViewToolBar(QWidget):
self.recToolbarState('facing', self.facing.isChecked()) self.recToolbarState('facing', self.facing.isChecked())
def onAddPage(self): def onAddPage(self):
print("onAddPage") # print("onAddPage")
self.parent.core.addPage() self.parent.core.addPage()
# self.refreshNumberPage() # self.refreshNumberPage()
def onRmPage(self): def onRmPage(self):
print("onAddPage") # print("onAddPage")
self.parent.core.rmPage() self.parent.core.rmPage()
# self.refreshNumberPage() # self.refreshNumberPage()
# def refreshNumberPage(self): # def refreshNumberPage(self):
def onReload(self): def onReload(self):
print("onReload") # print("onReload")
self.parent.webkitview.reload() self.parent.webkitview.reload()
def onGenPDF(self): def onGenPDF(self):
@@ -233,10 +232,10 @@ class WebViewToolBar(QWidget):
self.parent.webkitview.ongenPDF() self.parent.webkitview.ongenPDF()
def recToolbarState(self, prop, val): def recToolbarState(self, prop, val):
print('recToolbarState : '+prop, val) # print('recToolbarState : '+prop, val)
settings = QSettings('FiguresLibres', 'Cascade') settings = QSettings('FiguresLibres', 'Cascade')
settings.setValue('design/toolbar/'+prop, val) settings.setValue('design/toolbar/'+prop, val)
print('recToolbarState after : '+prop, settings.value('design/toolbar/'+prop)) # print('recToolbarState after : '+prop, settings.value('design/toolbar/'+prop))
def onRefresh(self): def onRefresh(self):
# apply precedent toolbar state # apply precedent toolbar state
@@ -260,48 +259,47 @@ class WebViewToolBar(QWidget):
# / /___/ /_/ / / /_/ /_/ / / # / /___/ /_/ / / /_/ /_/ / /
# /_____/\__,_/_/\__/\____/_/ # /_____/\__,_/_/\__/\____/_/
class CodeEditor(QPlainTextEdit): class CodeEditor(QPlainTextEdit):
def __init__(self, core, tabs, file, mode): def __init__(self, parent, core, tabs, file, mode):
super(CodeEditor, self).__init__() super(CodeEditor, self).__init__()
self.parent = parent
self.core = core self.core = core
self.tabs = tabs self.tabs = tabs
self.file = file self.file = file
self.hl= highlighter.Highlighter(self.document(),mode)
self.setText() self.setText()
self.setTabStopWidth(15) self.setTabStopWidth(15)
self.hl= highlighter.Highlighter(self.document(),mode)
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): def setText(self):
try: # try:
self.textChanged.disconnect(self.onTextChanged) # self.textChanged.disconnect(self.onTextChanged)
except Exception as e: # except Exception as e:
print(e) # print(e)
self.filepath = os.path.join(self.core.cwd,self.file) self.filepath = os.path.join(self.core.cwd,self.file)
self.clear() self.clear()
self.insertPlainText(open(self.filepath, 'r').read()) self.insertPlainText(open(self.filepath, 'r').read())
self.changed = False self.changed = False
self.textChanged.connect(self.onTextChanged)
font = QFont() font = QFont()
font.setFamily("Droid Sans Mono") font.setFamily("Droid Sans Mono")
font.setFixedPitch(True) font.setFixedPitch(True)
font.setPointSize(12) font.setPointSize(12)
self.setFont(font) self.setFont(font)
# self.highlighter = Highlighter(self.document())
# https://pypi.python.org/pypi/QScintilla/2.9.2
def onTextChanged(self): def onTextChanged(self):
# print('textChanged') print('textChanged')
# print(self.toPlainText()) # print(self.toPlainText())
# open(self.filepath, '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()
# self.tabs.setTabText(i, re.sub(r'^\**\s', '', self.tabs.tabText(i)))
self.tabs.setTabText(i, "* "+self.tabs.tabText(i)) self.tabs.setTabText(i, "* "+self.tabs.tabText(i))
# TODO: indicate that webview needs to be reloaded # TODO: indicate that webview needs to be reloaded
@@ -309,14 +307,15 @@ class CodeEditor(QPlainTextEdit):
if self.changed: if self.changed:
open(self.filepath, '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.parent.reloadView()
self.changed = False self.changed = False
# TODO: how to combine file save and project save # TODO: how to combine file save and project save
class Editor(QWidget): class Editor(QWidget):
def __init__(self, parent, core): def __init__(self, parent):
super(Editor, self).__init__() super(Editor, self).__init__()
self.core = core self.parent = parent
self.layout = QVBoxLayout(self) self.layout = QVBoxLayout(self)
self.layout.setContentsMargins(0,0,0,0) self.layout.setContentsMargins(0,0,0,0)
@@ -324,8 +323,8 @@ class Editor(QWidget):
# Initialize tab screen # Initialize tab screen
self.tabs = QTabWidget() self.tabs = QTabWidget()
self.scsstab = CodeEditor(core, self.tabs, 'assets/css/styles.scss', "scss") self.scsstab = CodeEditor(self, self.parent.core, self.tabs, 'assets/css/styles.scss', "scss")
self.jstab = CodeEditor(core, self.tabs, 'assets/js/script.js', 'js') self.jstab = CodeEditor(self, self.parent.core, self.tabs, 'assets/js/script.js', 'js')
# Add tabs # Add tabs
self.tabs.addTab(self.scsstab,"scss") self.tabs.addTab(self.scsstab,"scss")
@@ -339,6 +338,9 @@ class Editor(QWidget):
self.scsstab.setText() self.scsstab.setText()
self.jstab.setText() self.jstab.setText()
def reloadView(self):
self.parent.webkitview.reload()
# _____ __ __ # _____ __ __
# / ___// /_____ ______/ /__ # / ___// /_____ ______/ /__
# \__ \/ __/ __ `/ ___/ //_/ # \__ \/ __/ __ `/ ___/ //_/
@@ -387,7 +389,7 @@ class DesignStack(QWidget):
self.hsplitter.addWidget(self.webview) self.hsplitter.addWidget(self.webview)
# editor # editor
self.editor = Editor(self, core) self.editor = Editor(self)
self.hsplitter.addWidget(self.editor) self.hsplitter.addWidget(self.editor)
self.hsplitter.splitterMoved.connect(self.movedSplitter) self.hsplitter.splitterMoved.connect(self.movedSplitter)
+12 -14
View File
@@ -9,28 +9,26 @@
# @Last modified time: 03-06-2017 # @Last modified time: 03-06-2017
# @License: GPL-V3 # @License: GPL-V3
# TODO add link to the source # based on code from :
# Copyright (C) 2008 Christophe Kibleur <kib2@free.fr>
import sys import sys
import re import re
from PyQt5 import QtCore, QtGui # from PyQt5 import QtCore
from PyQt5.QtGui import QColor, QTextCharFormat, QFont, QSyntaxHighlighter
from pygments import highlight from pygments import highlight
from pygments.lexers import * from pygments.lexers import *
from pygments.formatter import Formatter from pygments.formatter import Formatter
from pygments.styles import get_all_styles, get_style_by_name from pygments.styles import get_all_styles, get_style_by_name
import time # import time
# Copyright (C) 2008 Christophe Kibleur <kib2@free.fr>
#
# This file is part of WikiParser (http://thewikiblog.appspot.com/).
#
def hex2QColor(c): def hex2QColor(c):
r=int(c[0:2],16) r=int(c[0:2],16)
g=int(c[2:4],16) g=int(c[2:4],16)
b=int(c[4:6],16) b=int(c[4:6],16)
return QtGui.QColor(r,g,b) return QColor(r,g,b)
class QFormatter(Formatter): class QFormatter(Formatter):
@@ -50,14 +48,14 @@ class QFormatter(Formatter):
self.styles={} self.styles={}
for token, style in self.style: for token, style in self.style:
qtf=QtGui.QTextCharFormat() qtf=QTextCharFormat()
if style['color']: if style['color']:
qtf.setForeground(hex2QColor(style['color'])) qtf.setForeground(hex2QColor(style['color']))
if style['bgcolor']: if style['bgcolor']:
qtf.setBackground(hex2QColor(style['bgcolor'])) qtf.setBackground(hex2QColor(style['bgcolor']))
if style['bold']: if style['bold']:
qtf.setFontWeight(QtGui.QFont.Bold) qtf.setFontWeight(QFont.Bold)
if style['italic']: if style['italic']:
qtf.setFontItalic(True) qtf.setFontItalic(True)
if style['underline']: if style['underline']:
@@ -81,11 +79,11 @@ class QFormatter(Formatter):
self.data.extend([self.styles[t],]*l) self.data.extend([self.styles[t],]*l)
class Highlighter(QtGui.QSyntaxHighlighter): class Highlighter(QSyntaxHighlighter):
def __init__(self, parent, mode): def __init__(self, parent, mode):
QtGui.QSyntaxHighlighter.__init__(self, parent) QSyntaxHighlighter.__init__(self, parent)
self.tstamp=time.time() # self.tstamp=time.time()
# Keep the formatter and lexer, initializing them # Keep the formatter and lexer, initializing them
# may be costly. # may be costly.
@@ -128,4 +126,4 @@ class Highlighter(QtGui.QSyntaxHighlighter):
# I may need to do something about this being called # I may need to do something about this being called
# too quickly. # too quickly.
self.tstamp=time.time() # self.tstamp=time.time()