Menu

[8f66b6]: / CodeBeagle.pyw  Maximize  Restore  History

Download this file

148 lines (130 with data), 7.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#! /usr/bin/python3
# -*- coding: utf-8 -*-
"""
Copyright (C) 2011 Oliver Tengler
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
from PyQt5.QtCore import QSettings, QUrl, pyqtSlot, Qt
from PyQt5.QtGui import QDesktopServices, QCloseEvent, QColor
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
from tools import FileTools
from dialogs.UserHintDialog import ButtonType, showUserHint
from dialogs.RegExTesterDlg import RegExTesterDlg
import AppConfig
from widgets.LineNumberArea import LineNumberArea
from widgets.HighlightingTextEdit import HighlightingTextEdit
from widgets.SyntaxHighlighter import SyntaxHighlighter
from PathVisualizerDelegate import PathVisualizerDelegate
from UpdateCheck import UpdateCheck
from SourceViewer import SourceViewer
from Ui_MainWindow import Ui_MainWindow
userHintNewVersionAvailable = """
<p align='justify'>Version %(version)s is available for download. Do you want to visit the download page now?</p>
"""
def main() -> None:
app = QApplication(sys.argv)
# Switch to application directory to be able to load the configuration and search scripts even if we are
# executed from a different working directory.
FileTools.switchToAppDir()
configureTheme(app)
wnd = MainWindow()
wnd.show()
sys.exit(app.exec_())
def configureTheme(app: QApplication) -> None:
if AppConfig.appConfig().theme == AppConfig.darkTheme:
import qdarkstyle
LineNumberArea.areaColor = QColor(qdarkstyle.DarkPalette.COLOR_BACKGROUND_NORMAL).darker(120)
PathVisualizerDelegate.newPathColor = QColor(204,204,204)
PathVisualizerDelegate.samePathColor = QColor(qdarkstyle.DarkPalette.COLOR_FOREGROUND_DARK)
PathVisualizerDelegate.fileColor = QColor(qdarkstyle.DarkPalette.COLOR_SELECTION_LIGHT).lighter(150)
PathVisualizerDelegate.selectedFileColor = QColor(qdarkstyle.DarkPalette.COLOR_SELECTION_LIGHT).lighter(200)
PathVisualizerDelegate.selectedPathColor = QColor(qdarkstyle.DarkPalette.COLOR_SELECTION_LIGHT).lighter(150)
PathVisualizerDelegate.selectionBackground = QColor(qdarkstyle.DarkPalette.COLOR_BACKGROUND_LIGHT)
HighlightingTextEdit.highlightOutlineColor = QColor(qdarkstyle.DarkPalette.COLOR_BACKGROUND_LIGHT).lighter(150)
HighlightingTextEdit.highlightSolidBackgroundColor = QColor(qdarkstyle.DarkPalette.COLOR_BACKGROUND_LIGHT).lighter(140)
HighlightingTextEdit.highlightSolidForegroundColor = None
SourceViewer.currentLineBackgroundColor = QColor(qdarkstyle.DarkPalette.COLOR_BACKGROUND_DARK).lighter(130)
SourceViewer.currentMatchLineBackgroundColor = QColor(qdarkstyle.DarkPalette.COLOR_SELECTION_DARK).darker(120)
SyntaxHighlighter.matchBackgroundColor = QColor(Qt.yellow).darker(120)
SyntaxHighlighter.matchForegroundColor = Qt.black
RegExTesterDlg.matchBackgroundColor = QColor(Qt.yellow).darker(120)
RegExTesterDlg.bracketColor = QColor(200,200,240)
RegExTesterDlg.repeatColor = QColor(240,200,200)
qdarkstyle.apply_stylesheet(app)
else:
import qlightstyle
qlightstyle.apply_stylesheet(app)
class MainWindow(QMainWindow):
def __init__(self) -> None:
super().__init__()
self.setAttribute(Qt.WA_DeleteOnClose)
# Restore last used search location name
self.appSettings = QSettings(AppConfig.appCompany, AppConfig.appName)
if self.appSettings.value("lastUsedSearchLocation"):
AppConfig.setLastUsedConfigName(
self.appSettings.value("lastUsedSearchLocation"))
# Now setup UI. This already uses the restored search location name
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.initialWindowTitle = self.windowTitle()
self.ui.tabWidget.requestWindowTitleChange.connect(self.changeWindowTitle)
self.__restoreGeometryAndState()
# Finally prepare and launch the update check
self.updateCheck = UpdateCheck(self)
if self.appSettings.value("lastUpdateCheck"):
self.updateCheck.lastUpdateCheck = int(
self.appSettings.value("lastUpdateCheck"))
self.updateCheck.newerVersionFound.connect(self.newerVersionFound)
self.updateCheck.checkForUpdates()
def closeEvent(self, event: QCloseEvent) -> None:
if AppConfig.appConfig().showCloseConfirmation:
res = QMessageBox.question(self,
self.tr("Really close?"),
self.tr("Do you really want to close the application?"),
QMessageBox.StandardButtons(QMessageBox.No | QMessageBox.Yes),
QMessageBox.Yes)
if QMessageBox.Yes != res:
event.ignore()
return
# this waits for the update check thread to complete
self.updateCheck.shutdownUpdateCheck()
if self.updateCheck.lastUpdateCheck:
self.appSettings.setValue(
"lastUpdateCheck", self.updateCheck.lastUpdateCheck)
self.appSettings.setValue(
"lastUsedSearchLocation", AppConfig.lastUsedConfigName())
self.__saveGeometryAndState()
event.accept()
def newerVersionFound(self, version: str) -> None:
text = userHintNewVersionAvailable % {"version": version}
result = showUserHint(self, "newVersion" + version, self.tr("New version available"), text,
ButtonType.Yes, True, ButtonType.No, False, bShowHintAgain=True)
if result == ButtonType.Yes:
url = QUrl("https://github.com/otengler/CodeBeagle/releases/latest")
QDesktopServices.openUrl(url)
def __restoreGeometryAndState(self) -> None:
if self.appSettings.value("geometry"):
self.restoreGeometry(self.appSettings.value("geometry"))
if self.appSettings.value("windowState"):
self.restoreState(self.appSettings.value("windowState"))
def __saveGeometryAndState(self) -> None:
self.appSettings.setValue("geometry", self.saveGeometry())
self.appSettings.setValue("windowState", self.saveState())
@pyqtSlot(str)
def changeWindowTitle(self, name: str) -> None:
if name:
self.setWindowTitle(self.initialWindowTitle + " - " + name)
else:
self.setWindowTitle(self.initialWindowTitle)
if __name__ == "__main__":
main()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.