2022-04-10 23:57:13 -04:00
|
|
|
import os
|
2011-03-14 02:29:45 -04:00
|
|
|
import codecs
|
|
|
|
import re
|
2011-08-11 04:17:53 -04:00
|
|
|
import ostools
|
2011-03-14 02:29:45 -04:00
|
|
|
from time import strftime, strptime
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-08-19 07:12:58 -04:00
|
|
|
try:
|
|
|
|
from PyQt6 import QtCore, QtGui, QtWidgets
|
|
|
|
except ImportError:
|
|
|
|
print("PyQt5 fallback (logviewer.py)")
|
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
2011-04-14 03:04:33 -04:00
|
|
|
from generic import RightClickList, RightClickTree
|
2011-03-14 02:29:45 -04:00
|
|
|
from parsetools import convertTags
|
2011-03-17 21:26:35 -04:00
|
|
|
from convo import PesterText
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2011-08-16 03:56:54 -04:00
|
|
|
_datadir = ostools.getDataDir()
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
class PesterLogSearchInput(QtWidgets.QLineEdit):
|
2011-05-12 06:47:22 -04:00
|
|
|
def __init__(self, theme, parent=None):
|
2021-03-23 17:36:43 -04:00
|
|
|
QtWidgets.QLineEdit.__init__(self, parent)
|
2021-03-24 16:03:49 -04:00
|
|
|
self.setStyleSheet(theme["convo/input/style"] + "; margin-right:0px;")
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-05-12 06:47:22 -04:00
|
|
|
def keyPressEvent(self, event):
|
2021-03-23 17:36:43 -04:00
|
|
|
QtWidgets.QLineEdit.keyPressEvent(self, event)
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self.parent(), "textArea"):
|
2022-06-26 22:18:37 -04:00
|
|
|
if event.key() == QtCore.Qt.Key.Key_Return:
|
2011-05-13 15:24:35 -04:00
|
|
|
self.parent().logSearch(self.text())
|
|
|
|
if self.parent().textArea.find(self.text()):
|
|
|
|
self.parent().textArea.ensureCursorVisible()
|
|
|
|
else:
|
|
|
|
self.parent().logSearch(self.text())
|
2011-05-12 06:47:22 -04:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-05-12 07:54:19 -04:00
|
|
|
class PesterLogHighlighter(QtGui.QSyntaxHighlighter):
|
|
|
|
def __init__(self, parent):
|
|
|
|
QtGui.QSyntaxHighlighter.__init__(self, parent)
|
|
|
|
self.searchTerm = ""
|
|
|
|
self.hilightstyle = QtGui.QTextCharFormat()
|
2022-06-26 22:18:37 -04:00
|
|
|
self.hilightstyle.setBackground(QtGui.QBrush(QtCore.Qt.GlobalColor.green))
|
|
|
|
self.hilightstyle.setForeground(QtGui.QBrush(QtCore.Qt.GlobalColor.black))
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-05-12 07:54:19 -04:00
|
|
|
def highlightBlock(self, text):
|
2022-10-07 16:51:40 -04:00
|
|
|
for i in range(0, len(text) - (len(self.searchTerm) - 1)):
|
2023-02-19 15:10:35 -05:00
|
|
|
if text[i : i + len(self.searchTerm)].lower() == self.searchTerm.lower():
|
2011-05-12 07:54:19 -04:00
|
|
|
self.setFormat(i, len(self.searchTerm), self.hilightstyle)
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
class PesterLogUserSelect(QtWidgets.QDialog):
|
2011-03-14 02:29:45 -04:00
|
|
|
def __init__(self, config, theme, parent):
|
2021-03-23 17:36:43 -04:00
|
|
|
QtWidgets.QDialog.__init__(self, parent)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.setModal(False)
|
|
|
|
self.config = config
|
|
|
|
self.theme = theme
|
|
|
|
self.parent = parent
|
|
|
|
self.handle = parent.profile().handle
|
2022-10-07 16:51:40 -04:00
|
|
|
self.logpath = _datadir + "logs"
|
2011-03-14 02:29:45 -04:00
|
|
|
|
|
|
|
self.setStyleSheet(self.theme["main/defaultwindow/style"])
|
|
|
|
self.setWindowTitle("Pesterlogs")
|
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
instructions = QtWidgets.QLabel("Pick a memo or chumhandle:")
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
if os.path.exists("{}/{}".format(self.logpath, self.handle)):
|
|
|
|
chumMemoList = os.listdir("{}/{}/".format(self.logpath, self.handle))
|
2011-03-14 02:29:45 -04:00
|
|
|
else:
|
|
|
|
chumMemoList = []
|
|
|
|
chumslist = config.chums()
|
|
|
|
for c in chumslist:
|
|
|
|
if not c in chumMemoList:
|
|
|
|
chumMemoList.append(c)
|
|
|
|
chumMemoList.sort()
|
|
|
|
|
|
|
|
self.chumsBox = RightClickList(self)
|
|
|
|
self.chumsBox.setStyleSheet(self.theme["main/chums/style"])
|
2021-03-23 17:36:43 -04:00
|
|
|
self.chumsBox.optionsMenu = QtWidgets.QMenu(self)
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2023-02-09 14:52:26 -05:00
|
|
|
for _, t in enumerate(chumMemoList):
|
2021-03-23 17:36:43 -04:00
|
|
|
item = QtWidgets.QListWidgetItem(t)
|
2022-10-07 16:51:40 -04:00
|
|
|
item.setForeground(
|
|
|
|
QtGui.QBrush(QtGui.QColor(self.theme["main/chums/userlistcolor"]))
|
|
|
|
)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.chumsBox.addItem(item)
|
|
|
|
|
2011-05-12 06:47:22 -04:00
|
|
|
self.search = PesterLogSearchInput(theme, self)
|
|
|
|
self.search.setFocus()
|
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
self.cancel = QtWidgets.QPushButton("CANCEL", self)
|
|
|
|
self.cancel.clicked.connect(self.reject)
|
|
|
|
self.ok = QtWidgets.QPushButton("OK", self)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.ok.setDefault(True)
|
2021-03-23 17:36:43 -04:00
|
|
|
self.ok.clicked.connect(self.viewActivatedLog)
|
|
|
|
layout_ok = QtWidgets.QHBoxLayout()
|
2011-03-14 02:29:45 -04:00
|
|
|
layout_ok.addWidget(self.cancel)
|
|
|
|
layout_ok.addWidget(self.ok)
|
2021-03-23 17:36:43 -04:00
|
|
|
self.directory = QtWidgets.QPushButton("LOG DIRECTORY", self)
|
|
|
|
self.directory.clicked.connect(self.openDir)
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
layout_0 = QtWidgets.QVBoxLayout()
|
2011-03-14 02:29:45 -04:00
|
|
|
layout_0.addWidget(instructions)
|
|
|
|
layout_0.addWidget(self.chumsBox)
|
2011-05-12 06:47:22 -04:00
|
|
|
layout_0.addWidget(self.search)
|
2011-03-14 02:29:45 -04:00
|
|
|
layout_0.addLayout(layout_ok)
|
2011-07-23 17:53:05 -04:00
|
|
|
layout_0.addWidget(self.directory)
|
2011-03-14 02:29:45 -04:00
|
|
|
|
|
|
|
self.setLayout(layout_0)
|
|
|
|
|
|
|
|
def selectedchum(self):
|
|
|
|
return self.chumsBox.currentItem()
|
|
|
|
|
2011-05-12 06:47:22 -04:00
|
|
|
def logSearch(self, search):
|
2022-06-26 22:18:37 -04:00
|
|
|
found = self.chumsBox.findItems(search, QtCore.Qt.MatchFlag.MatchStartsWith)
|
2011-05-12 06:47:22 -04:00
|
|
|
if len(found) > 0 and len(found) < self.chumsBox.count():
|
|
|
|
self.chumsBox.setCurrentItem(found[0])
|
|
|
|
|
2011-03-14 02:29:45 -04:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def viewActivatedLog(self):
|
|
|
|
selectedchum = self.selectedchum().text()
|
2022-10-07 16:51:40 -04:00
|
|
|
if not hasattr(self, "pesterlogviewer"):
|
2011-03-14 02:29:45 -04:00
|
|
|
self.pesterlogviewer = None
|
|
|
|
if not self.pesterlogviewer:
|
2022-10-07 16:51:40 -04:00
|
|
|
self.pesterlogviewer = PesterLogViewer(
|
|
|
|
selectedchum, self.config, self.theme, self.parent
|
|
|
|
)
|
2021-03-23 17:36:43 -04:00
|
|
|
self.pesterlogviewer.rejected.connect(self.closeActiveLog)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.pesterlogviewer.show()
|
|
|
|
self.pesterlogviewer.raise_()
|
|
|
|
self.pesterlogviewer.activateWindow()
|
|
|
|
self.accept()
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def closeActiveLog(self):
|
|
|
|
self.pesterlogviewer.close()
|
|
|
|
self.pesterlogviewer = None
|
|
|
|
|
2011-07-23 17:53:05 -04:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def openDir(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
QtGui.QDesktopServices.openUrl(
|
|
|
|
QtCore.QUrl(
|
|
|
|
"file:///" + os.path.join(_datadir, "logs"),
|
|
|
|
QtCore.QUrl.ParsingMode.TolerantMode,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2011-07-23 17:53:05 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
class PesterLogViewer(QtWidgets.QDialog):
|
2011-03-14 02:29:45 -04:00
|
|
|
def __init__(self, chum, config, theme, parent):
|
2021-03-23 17:36:43 -04:00
|
|
|
QtWidgets.QDialog.__init__(self, parent)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.setModal(False)
|
|
|
|
self.config = config
|
|
|
|
self.theme = theme
|
|
|
|
self.parent = parent
|
2011-05-13 16:39:52 -04:00
|
|
|
self.mainwindow = parent
|
2011-03-14 02:29:45 -04:00
|
|
|
global _datadir
|
|
|
|
self.handle = parent.profile().handle
|
|
|
|
self.chum = chum
|
|
|
|
self.convos = {}
|
2022-10-07 16:51:40 -04:00
|
|
|
self.logpath = _datadir + "logs"
|
2011-03-14 02:29:45 -04:00
|
|
|
|
|
|
|
self.setStyleSheet(self.theme["main/defaultwindow/style"])
|
|
|
|
self.setWindowTitle("Pesterlogs with " + self.chum)
|
|
|
|
|
|
|
|
self.format = "bbcode"
|
2022-10-07 16:51:40 -04:00
|
|
|
if os.path.exists(
|
2023-01-14 16:59:59 -05:00
|
|
|
"{}/{}/{}/{}".format(self.logpath, self.handle, chum, self.format)
|
2022-10-07 16:51:40 -04:00
|
|
|
):
|
|
|
|
self.logList = os.listdir(
|
2023-01-14 16:59:59 -05:00
|
|
|
"{}/{}/{}/{}/".format(self.logpath, self.handle, self.chum, self.format)
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
2011-03-14 02:29:45 -04:00
|
|
|
else:
|
|
|
|
self.logList = []
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
if (
|
|
|
|
not os.path.exists(
|
2023-01-14 16:59:59 -05:00
|
|
|
"{}/{}/{}/{}".format(self.logpath, self.handle, chum, self.format)
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
|
|
|
or len(self.logList) == 0
|
|
|
|
):
|
2021-03-23 17:36:43 -04:00
|
|
|
instructions = QtWidgets.QLabel("No Pesterlogs were found")
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
self.ok = QtWidgets.QPushButton("CLOSE", self)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.ok.setDefault(True)
|
2021-03-23 17:36:43 -04:00
|
|
|
self.ok.clicked.connect(self.reject)
|
|
|
|
layout_ok = QtWidgets.QHBoxLayout()
|
2011-03-14 02:29:45 -04:00
|
|
|
layout_ok.addWidget(self.ok)
|
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
layout_0 = QtWidgets.QVBoxLayout()
|
2011-03-14 02:29:45 -04:00
|
|
|
layout_0.addWidget(instructions)
|
|
|
|
layout_0.addLayout(layout_ok)
|
|
|
|
|
|
|
|
self.setLayout(layout_0)
|
|
|
|
else:
|
2022-10-07 16:51:40 -04:00
|
|
|
self.instructions = QtWidgets.QLabel("Pesterlog with " + self.chum + " on")
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2011-03-17 21:26:35 -04:00
|
|
|
self.textArea = PesterLogText(theme, self.parent)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.textArea.setReadOnly(True)
|
|
|
|
self.textArea.setFixedWidth(600)
|
2021-03-23 17:36:43 -04:00
|
|
|
if "convo/scrollbar" in theme:
|
2022-10-07 16:51:40 -04:00
|
|
|
self.textArea.setStyleSheet(
|
|
|
|
"QTextEdit { width:500px; %s } QScrollBar:vertical { %s } QScrollBar::handle:vertical { %s } QScrollBar::add-line:vertical { %s } QScrollBar::sub-line:vertical { %s } QScrollBar:up-arrow:vertical { %s } QScrollBar:down-arrow:vertical { %s }"
|
|
|
|
% (
|
|
|
|
theme["convo/textarea/style"],
|
|
|
|
theme["convo/scrollbar/style"],
|
|
|
|
theme["convo/scrollbar/handle"],
|
|
|
|
theme["convo/scrollbar/downarrow"],
|
|
|
|
theme["convo/scrollbar/uparrow"],
|
|
|
|
theme["convo/scrollbar/uarrowstyle"],
|
|
|
|
theme["convo/scrollbar/darrowstyle"],
|
|
|
|
)
|
|
|
|
)
|
2011-03-14 02:29:45 -04:00
|
|
|
else:
|
2022-10-07 16:51:40 -04:00
|
|
|
self.textArea.setStyleSheet(
|
|
|
|
"QTextEdit { width:500px; %s }" % (theme["convo/textarea/style"])
|
|
|
|
)
|
2011-03-14 02:29:45 -04:00
|
|
|
|
|
|
|
self.logList.sort()
|
|
|
|
self.logList.reverse()
|
|
|
|
|
2011-04-14 03:04:33 -04:00
|
|
|
self.tree = RightClickTree()
|
2021-03-23 17:36:43 -04:00
|
|
|
self.tree.optionsMenu = QtWidgets.QMenu(self)
|
2011-03-16 00:33:17 -04:00
|
|
|
self.tree.setFixedSize(260, 300)
|
|
|
|
self.tree.header().hide()
|
2021-03-23 17:36:43 -04:00
|
|
|
if "convo/scrollbar" in theme:
|
2022-10-07 16:51:40 -04:00
|
|
|
self.tree.setStyleSheet(
|
|
|
|
"QTreeWidget { %s } QScrollBar:vertical { %s } QScrollBar::handle:vertical { %s } QScrollBar::add-line:vertical { %s } QScrollBar::sub-line:vertical { %s } QScrollBar:up-arrow:vertical { %s } QScrollBar:down-arrow:vertical { %s }"
|
|
|
|
% (
|
|
|
|
theme["convo/textarea/style"],
|
|
|
|
theme["convo/scrollbar/style"],
|
|
|
|
theme["convo/scrollbar/handle"],
|
|
|
|
theme["convo/scrollbar/downarrow"],
|
|
|
|
theme["convo/scrollbar/uparrow"],
|
|
|
|
theme["convo/scrollbar/uarrowstyle"],
|
|
|
|
theme["convo/scrollbar/darrowstyle"],
|
|
|
|
)
|
|
|
|
)
|
2011-03-16 00:33:17 -04:00
|
|
|
else:
|
|
|
|
self.tree.setStyleSheet("%s" % (theme["convo/textarea/style"]))
|
2021-03-23 17:36:43 -04:00
|
|
|
self.tree.itemSelectionChanged.connect(self.loadSelectedLog)
|
2011-03-16 00:33:17 -04:00
|
|
|
self.tree.setSortingEnabled(False)
|
2011-04-14 03:04:33 -04:00
|
|
|
|
2011-03-16 00:33:17 -04:00
|
|
|
child_1 = None
|
2022-10-07 16:51:40 -04:00
|
|
|
last = ["", ""]
|
|
|
|
# blackbrush = QtGui.QBrush(QtCore.Qt.GlobalColor.black)
|
2023-02-09 14:52:26 -05:00
|
|
|
for i, l in enumerate(self.logList):
|
2011-03-16 00:33:17 -04:00
|
|
|
my = self.fileToMonthYear(l)
|
|
|
|
if my[0] != last[0]:
|
2023-01-14 16:59:59 -05:00
|
|
|
child_1 = QtWidgets.QTreeWidgetItem(["{} {}".format(my[0], my[1])])
|
2022-10-07 16:51:40 -04:00
|
|
|
# child_1.setForeground(0, blackbrush)
|
2011-03-16 00:33:17 -04:00
|
|
|
self.tree.addTopLevelItem(child_1)
|
|
|
|
if i == 0:
|
|
|
|
child_1.setExpanded(True)
|
2021-03-23 17:36:43 -04:00
|
|
|
child_1.addChild(QtWidgets.QTreeWidgetItem([self.fileToTime(l)]))
|
2011-03-16 00:33:17 -04:00
|
|
|
last = self.fileToMonthYear(l)
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2011-05-12 07:54:19 -04:00
|
|
|
self.hilight = PesterLogHighlighter(self.textArea)
|
2022-10-07 16:51:40 -04:00
|
|
|
if len(self.logList) > 0:
|
|
|
|
self.loadLog(self.logList[0])
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2011-05-12 07:54:19 -04:00
|
|
|
self.search = PesterLogSearchInput(theme, self)
|
|
|
|
self.search.setFocus()
|
2021-03-23 17:36:43 -04:00
|
|
|
self.find = QtWidgets.QPushButton("Find", self)
|
2011-05-13 15:24:35 -04:00
|
|
|
font = self.find.font()
|
|
|
|
font.setPointSize(8)
|
|
|
|
self.find.setFont(font)
|
|
|
|
self.find.setDefault(True)
|
2011-05-13 16:39:52 -04:00
|
|
|
self.find.setFixedSize(40, 20)
|
2021-03-23 17:36:43 -04:00
|
|
|
layout_search = QtWidgets.QHBoxLayout()
|
2011-05-13 15:24:35 -04:00
|
|
|
layout_search.addWidget(self.search)
|
|
|
|
layout_search.addWidget(self.find)
|
2011-05-12 07:54:19 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
self.ok = QtWidgets.QPushButton("CLOSE", self)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.ok.setFixedWidth(80)
|
2021-03-23 17:36:43 -04:00
|
|
|
self.ok.clicked.connect(self.reject)
|
|
|
|
layout_ok = QtWidgets.QHBoxLayout()
|
2011-03-14 02:29:45 -04:00
|
|
|
layout_ok.addWidget(self.ok)
|
2022-06-26 22:18:37 -04:00
|
|
|
layout_ok.setAlignment(self.ok, QtCore.Qt.AlignmentFlag.AlignRight)
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
layout_logs = QtWidgets.QHBoxLayout()
|
2011-03-16 00:33:17 -04:00
|
|
|
layout_logs.addWidget(self.tree)
|
2021-03-23 17:36:43 -04:00
|
|
|
layout_right = QtWidgets.QVBoxLayout()
|
2011-05-12 07:54:19 -04:00
|
|
|
layout_right.addWidget(self.textArea)
|
2011-05-13 15:24:35 -04:00
|
|
|
layout_right.addLayout(layout_search)
|
2011-05-12 07:54:19 -04:00
|
|
|
layout_logs.addLayout(layout_right)
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
layout_0 = QtWidgets.QVBoxLayout()
|
2011-03-14 02:29:45 -04:00
|
|
|
layout_0.addWidget(self.instructions)
|
|
|
|
layout_0.addLayout(layout_logs)
|
|
|
|
layout_0.addLayout(layout_ok)
|
|
|
|
|
|
|
|
self.setLayout(layout_0)
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def loadSelectedLog(self):
|
2011-03-16 00:33:17 -04:00
|
|
|
if len(self.tree.currentItem().text(0)) > len("September 2011"):
|
|
|
|
self.loadLog(self.timeToFile(self.tree.currentItem().text(0)))
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2023-02-19 15:10:35 -05:00
|
|
|
def loadLog(self, fname: str):
|
2022-10-07 16:51:40 -04:00
|
|
|
fp = codecs.open(
|
|
|
|
"%s/%s/%s/%s/%s"
|
|
|
|
% (self.logpath, self.handle, self.chum, self.format, fname),
|
|
|
|
encoding="utf-8",
|
|
|
|
mode="r",
|
|
|
|
)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.textArea.clear()
|
|
|
|
for line in fp:
|
2022-10-07 16:51:40 -04:00
|
|
|
cline = (
|
|
|
|
line.replace("\r\n", "")
|
|
|
|
.replace("[/color]", "</c>")
|
|
|
|
.replace("[url]", "")
|
|
|
|
.replace("[/url]", "")
|
|
|
|
)
|
2023-01-14 16:59:59 -05:00
|
|
|
cline = re.sub(r"\[color=(#.{6})]", r"<c=\1>", cline)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.textArea.append(convertTags(cline))
|
|
|
|
textCur = self.textArea.textCursor()
|
2022-10-07 16:51:40 -04:00
|
|
|
# textCur.movePosition(1)
|
2011-03-14 02:29:45 -04:00
|
|
|
self.textArea.setTextCursor(textCur)
|
2022-10-07 16:51:40 -04:00
|
|
|
self.instructions.setText(
|
2023-02-19 15:10:35 -05:00
|
|
|
"Pesterlog with " + self.chum + " on " + self.fileToTime(fname)
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
2011-03-14 02:29:45 -04:00
|
|
|
|
2011-05-12 07:54:19 -04:00
|
|
|
def logSearch(self, search):
|
|
|
|
self.hilight.searchTerm = search
|
|
|
|
self.hilight.rehighlight()
|
|
|
|
|
2011-03-16 00:33:17 -04:00
|
|
|
def fileToMonthYear(self, fname):
|
2022-10-07 16:51:40 -04:00
|
|
|
time = strptime(
|
|
|
|
fname[(fname.index(".") + 1) : fname.index(".txt")], "%Y-%m-%d.%H.%M"
|
|
|
|
)
|
2011-03-16 00:33:17 -04:00
|
|
|
return [strftime("%B", time), strftime("%Y", time)]
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-03-14 02:29:45 -04:00
|
|
|
def fileToTime(self, fname):
|
2022-10-07 16:51:40 -04:00
|
|
|
timestr = fname[(fname.index(".") + 1) : fname.index(".txt")]
|
2011-03-14 02:29:45 -04:00
|
|
|
return strftime("%a %d %b %Y %H %M", strptime(timestr, "%Y-%m-%d.%H.%M"))
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-03-14 02:29:45 -04:00
|
|
|
def timeToFile(self, time):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.chum + strftime(
|
|
|
|
".%Y-%m-%d.%H.%M.txt", strptime(str(time), "%a %d %b %Y %H %M")
|
|
|
|
)
|
|
|
|
|
2011-03-17 21:26:35 -04:00
|
|
|
|
|
|
|
class PesterLogText(PesterText):
|
|
|
|
def __init__(self, theme, parent=None):
|
|
|
|
PesterText.__init__(self, theme, parent)
|
|
|
|
|
|
|
|
def focusInEvent(self, event):
|
2021-03-23 17:36:43 -04:00
|
|
|
QtWidgets.QTextEdit.focusInEvent(self, event)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-03-17 21:26:35 -04:00
|
|
|
def mousePressEvent(self, event):
|
2022-09-01 00:55:08 -04:00
|
|
|
try:
|
|
|
|
# PyQt6
|
2022-08-19 07:12:58 -04:00
|
|
|
url = self.anchorAt(event.position().toPoint())
|
2022-09-01 00:55:08 -04:00
|
|
|
except AttributeError:
|
|
|
|
# PyQt5
|
2022-08-19 07:12:58 -04:00
|
|
|
url = self.anchorAt(event.pos())
|
2011-03-17 21:26:35 -04:00
|
|
|
if url != "":
|
2011-04-14 03:43:45 -04:00
|
|
|
if url[0] == "#" and url != "#pesterchum":
|
|
|
|
self.parent().parent.showMemos(url[1:])
|
|
|
|
elif url[0] == "@":
|
2023-02-19 15:10:35 -05:00
|
|
|
handle = url[1:]
|
2011-04-14 03:43:45 -04:00
|
|
|
self.parent().parent.newConversation(handle)
|
|
|
|
else:
|
2022-10-07 16:51:40 -04:00
|
|
|
QtGui.QDesktopServices.openUrl(
|
|
|
|
QtCore.QUrl(url, QtCore.QUrl.ParsingMode.TolerantMode)
|
|
|
|
)
|
2021-03-23 17:36:43 -04:00
|
|
|
QtWidgets.QTextEdit.mousePressEvent(self, event)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-03-17 21:26:35 -04:00
|
|
|
def mouseMoveEvent(self, event):
|
2021-03-23 17:36:43 -04:00
|
|
|
QtWidgets.QTextEdit.mouseMoveEvent(self, event)
|
2022-09-01 00:55:08 -04:00
|
|
|
try:
|
|
|
|
# PyQt6
|
2022-08-19 07:12:58 -04:00
|
|
|
pos = event.position().toPoint()
|
2022-09-01 00:55:08 -04:00
|
|
|
except AttributeError:
|
|
|
|
# PyQt5
|
2022-08-19 07:12:58 -04:00
|
|
|
pos = event.pos()
|
|
|
|
if self.anchorAt(pos):
|
2022-10-07 16:51:40 -04:00
|
|
|
if (
|
|
|
|
self.viewport().cursor().shape
|
|
|
|
!= QtCore.Qt.CursorShape.PointingHandCursor
|
|
|
|
):
|
|
|
|
self.viewport().setCursor(
|
|
|
|
QtGui.QCursor(QtCore.Qt.CursorShape.PointingHandCursor)
|
|
|
|
)
|
2011-03-17 21:26:35 -04:00
|
|
|
else:
|
2022-06-26 22:18:37 -04:00
|
|
|
self.viewport().setCursor(QtGui.QCursor(QtCore.Qt.CursorShape.IBeamCursor))
|
2011-04-15 05:45:10 -04:00
|
|
|
|
|
|
|
def contextMenuEvent(self, event):
|
|
|
|
textMenu = self.createStandardContextMenu()
|
|
|
|
a = textMenu.actions()
|
|
|
|
a[0].setText("Copy Plain Text")
|
|
|
|
a[0].setShortcut(self.tr("Ctrl+C"))
|
2022-06-26 22:18:37 -04:00
|
|
|
textMenu.exec(event.globalPos())
|