Skip to content

Commit

Permalink
Finished WelcomeWizard
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyParedis committed Feb 8, 2020
1 parent 1a0f11c commit e988a68
Show file tree
Hide file tree
Showing 16 changed files with 13,435 additions and 92 deletions.
1 change: 1 addition & 0 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from main.extra import Constants
from main.MainWindow import MainWindow


if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
app.setApplicationName(Constants.APP_NAME)
Expand Down
20 changes: 15 additions & 5 deletions main/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author: Randy Paredis
Date: 14/12/2019
"""
from PyQt5 import QtWidgets, QtCore, QtGui, QtNetwork, uic
from PyQt5 import QtWidgets, QtCore, QtGui, uic

from main.FindReplace import FindReplace
from main.Preferences import Preferences, bool
Expand All @@ -12,15 +12,19 @@
from main.editor.CodeEditor import EditorWrapper, StatusBar
from main.extra.GraphicsView import GraphicsView
from main.extra import Constants, tabPathnames
from main.UpdateWizard import UpdateWizard
from main.wizards.UpdateWizard import UpdateWizard
from markdown.extensions.legacy_em import LegacyEmExtension as legacy_em
import os, sys, chardet, markdown
from main.extra.qrc import tango

from main.plugins import PluginLoader
from main.wizards.WelcomeWizard import WelcomeWizard

Config = IOHandler.get_preferences()
pluginloader = PluginLoader.instance()

rccv = tango.rcc_version

class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__(flags=QtCore.Qt.WindowFlags())
Expand All @@ -41,6 +45,10 @@ def __init__(self):
self.updateTitle()
self.setStatusBar(QtWidgets.QStatusBar())

# if len(Config.allKeys()) == 0:
wiz = WelcomeWizard()
wiz.exec_()

self.preferences = Preferences(self)
self.preferences.apply()

Expand Down Expand Up @@ -276,7 +284,7 @@ def restore(self):
if cursors is None:
cursors = []
for file in range(len(files)):
succ = self.openFile(files[file])
succ = self.openFile(files[file], True)
if succ and file < len(cursors):
curs = self.editor().textCursor()
curs.setPosition(cursors[file][0])
Expand Down Expand Up @@ -419,12 +427,14 @@ def updateFileType(self, indx=-1):
edit.filecontents = data.replace(linesep, "\n")
self.setEditorType(Constants.lookup(ext, exts, ""), indx)

def openFile(self, fileName):
def openFile(self, fileName, ignoreopen=False):
self.lockDisplay()
if fileName and fileName != "":
valid = True
try:
self.newTab(fileName)
edit = self.editor()
if ignoreopen or edit is None or (edit.filename == "" and not edit.isSaved()):
self.newTab(fileName)
self.editor().filename = fileName
self.updateFileType()
self.updateRecents(fileName)
Expand Down
67 changes: 16 additions & 51 deletions main/Preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,41 +251,11 @@ def rectify(self):
if True:
self.combo_style.setCurrentIndex(int(self.preferences.value("col/style", 0)))
self.combo_theme.setCurrentText(self.preferences.value("col/theme", "Light Lucy"))
# lst = self.names_general + self.names_editor + self.names_syntax
# for i in range(len(lst)):
# name = lst[i]
# cname = name.replace("_", ".")
# getattr(self, name).setColor(QtGui.QColor(self.preferences.value(cname, self.findColor(cname[4:]))))

# BUILTIN STANDARD THEME IN CASE SOMEONE MESSES WITH THE FILES:
self.col_foreground.setColor(QtGui.QColor(self.preferences.value("col/foreground", "#000000")))
self.col_window.setColor(QtGui.QColor(self.preferences.value("col/window", "#efefef")))
self.col_base.setColor(QtGui.QColor(self.preferences.value("col/base", "#ffffff")))
self.col_alternateBase.setColor(QtGui.QColor(self.preferences.value("col/alternateBase", "#f7f7f7")))
self.col_tooltipBase.setColor(QtGui.QColor(self.preferences.value("col/tooltipBase", "#ffffdc")))
self.col_tooltipText.setColor(QtGui.QColor(self.preferences.value("col/tooltipText", "#000000")))
self.col_text.setColor(QtGui.QColor(self.preferences.value("col/text", "#000000")))
self.col_button.setColor(QtGui.QColor(self.preferences.value("col/button", "#efefef")))
self.col_buttonText.setColor(QtGui.QColor(self.preferences.value("col/buttonText", "#000000")))
self.col_brightText.setColor(QtGui.QColor(self.preferences.value("col/brightText", "#dcdcff")))
self.col_highlight.setColor(QtGui.QColor(self.preferences.value("col/highlight", "#30acc6")))
self.col_highlightedText.setColor(QtGui.QColor(self.preferences.value("col/highlightedText", "#ffffff")))
self.col_link.setColor(QtGui.QColor(self.preferences.value("col/link", "#0000ff")))
self.col_visitedLink.setColor(QtGui.QColor(self.preferences.value("col/visitedLink", "#5500ff")))
self.col_cline.setColor(QtGui.QColor(self.preferences.value("col/cline", "#fffeb5")))
self.col_lnf.setColor(QtGui.QColor(self.preferences.value("col/lnf", "#000000")))
self.col_lnb.setColor(QtGui.QColor(self.preferences.value("col/lnb", "#f7f7f7")))
self.col_clnf.setColor(QtGui.QColor(self.preferences.value("col/clnf", "#ffffff")))
self.col_clnb.setColor(QtGui.QColor(self.preferences.value("col/clnb", "#30acc6")))
self.col_find.setColor(QtGui.QColor(self.preferences.value("col/find", "#8be9fd")))
self.col_keyword.setColor(QtGui.QColor(self.preferences.value("col/keyword", "#800000")))
self.col_attribute.setColor(QtGui.QColor(self.preferences.value("col/attribute", "#000080")))
self.col_number.setColor(QtGui.QColor(self.preferences.value("col/number", "#ff00ff")))
self.col_string.setColor(QtGui.QColor(self.preferences.value("col/string", "#158724")))
self.col_html.setColor(QtGui.QColor(self.preferences.value("col/html", "#158724")))
self.col_comment.setColor(QtGui.QColor(self.preferences.value("col/comment", "#0000ff")))
self.col_hash.setColor(QtGui.QColor(self.preferences.value("col/hash", "#0000ff")))
self.col_error.setColor(QtGui.QColor(self.preferences.value("col/error", "#ff0000")))
lst = self.names_general + self.names_editor + self.names_syntax
for i in range(len(lst)):
name = lst[i]
cname = name.replace("_", ".")
getattr(self, name).setColor(QtGui.QColor(self.preferences.value(cname, self.findColor(cname[4:]))))

# SHORTCUTS
if True:
Expand Down Expand Up @@ -335,9 +305,11 @@ def rectify(self):
# PLUGINS
if True:
plst = pluginloader.get()
pls = self.preferences.value("plugin/enabled", [p.name for p in plst])
pls = self.preferences.value("plugin/enabled", None)
if pls is None:
pls = [p.name for p in plst]
for plugin in plst:
plugin.enable(pls is not None and plugin.name in pls)
plugin.enable(plugin.name in pls)
for eid in self.pluginUi:
ui = self.pluginUi[eid]
grp = "plugin/%s" % re.sub(r"[^a-z ]", "", ui.plugin.name.lower()).replace(" ", "")
Expand Down Expand Up @@ -574,9 +546,9 @@ def applyPlugins(self):
# TODO: Select the first plugin, BUT this gives issues on Windows:
# the font size changes (it feels as if Rich Text QLabels are not
# rendered correctly when invisible on Windows)
# pll = self.pluginlist.findChildren(PluginButton)
# if len(pll) > 0:
# pll[0].click()
pll = self.pluginlist.findChildren(PluginButton)
if len(pll) > 0:
pll[0].click()
self.preferences.setValue("plugin/enabled", [p.name for p in pluginloader.get()])
for eid in self.pluginUi:
ui = self.pluginUi[eid]
Expand Down Expand Up @@ -724,20 +696,13 @@ def getSubSec(self):
return author if len(author) > 0 else version if len(version) > 0 else ""

def getDesc(self):
from sys import platform
desc = markdown.markdown(self.plugin.description, extensions=[legacy_em()])

if platform == "win32":
size = self.font().pixelSize() // 2
elif platform == "linux":
size = self.font().pointSize() // 4
else:
size = 12

size = "%ipt" % self.font().pointSize()
attrs = "<table width='100%%' cellspacing=10>%s</table>" % \
("".join(["<tr><td width='20%%' align='right'><b>%s</b></td><td>%s</td></tr>" %
(k, self.transform(v)) for k, v in self.plugin.attrs]))
return "<font size=%i>%s<br>%s<br></font>" % (size, desc, attrs)
return "<span style='font-size: %s;'>%s<br>%s<br></font>" % (size, desc, attrs)

def matches(self, txt):
return txt in self.plugin.name or txt in self.plugin.description
Expand Down Expand Up @@ -820,12 +785,12 @@ def click(self):
def install(self):
self.installer = PluginInstaller(self.plugin, self)
self.installer.installed.connect(self.installed)
self.installer.show()
self.installer.exec_()

def update_(self):
self.installer = PluginInstaller(self.plugin, update=True, parent=self)
self.installer.installed.connect(self.installed)
self.installer.show()
self.installer.exec_()

def installed(self, succ):
if succ:
Expand Down
4 changes: 2 additions & 2 deletions main/editor/CodeEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ def contextMenuEvent(self, event: QtGui.QContextMenuEvent):

def isSaved(self):
"""Returns True if the file was saved."""
if self.filename != "":
return self.toPlainText() == self.filecontents
txt = self.toPlainText()
if self.filename != "":
return txt == self.filecontents
if bool(Config.value("editor/emptyline")):
txt = txt[:-len(os.linesep)]
return txt == ""
Expand Down
2 changes: 1 addition & 1 deletion main/extra/GraphicsView.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

from PyQt5 import QtWidgets, QtCore, QtSvg, QtGui
from main.extra import IOHandler, isSVG, Constants, tango
from main.extra import IOHandler, isSVG, Constants
import os

Config = IOHandler.IOHandler.get_preferences()
Expand Down
Loading

0 comments on commit e988a68

Please sign in to comment.