replaced sys.modules checks with try: PyQt6, except: PyQt5
This commit is contained in:
parent
3f267898d4
commit
b549645a50
5 changed files with 70 additions and 32 deletions
10
console.py
10
console.py
|
@ -454,10 +454,10 @@ class ConsoleText(QtWidgets.QTextEdit):
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
if event.button() == QtCore.Qt.MouseButton.LeftButton:
|
if event.button() == QtCore.Qt.MouseButton.LeftButton:
|
||||||
if 'PyQt6' in sys.modules:
|
try:
|
||||||
# PyQt6
|
# PyQt6
|
||||||
url = self.anchorAt(event.position().toPoint())
|
url = self.anchorAt(event.position().toPoint())
|
||||||
elif 'PyQt5' in sys.modules:
|
except AttributeError:
|
||||||
# PyQt5
|
# PyQt5
|
||||||
url = self.anchorAt(event.pos())
|
url = self.anchorAt(event.pos())
|
||||||
if url != "":
|
if url != "":
|
||||||
|
@ -474,9 +474,11 @@ class ConsoleText(QtWidgets.QTextEdit):
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
# Change our cursor when we roll over links (anchors).
|
# Change our cursor when we roll over links (anchors).
|
||||||
super(ConsoleText, self).mouseMoveEvent(event)
|
super(ConsoleText, self).mouseMoveEvent(event)
|
||||||
if 'PyQt6' in sys.modules:
|
try:
|
||||||
|
# PyQt6
|
||||||
pos = event.position().toPoint()
|
pos = event.position().toPoint()
|
||||||
elif 'PyQt5' in sys.modules:
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
pos = event.pos()
|
pos = event.pos()
|
||||||
if self.anchorAt(pos):
|
if self.anchorAt(pos):
|
||||||
if self.viewport().cursor().shape != QtCore.Qt.CursorShape.PointingHandCursor:
|
if self.viewport().cursor().shape != QtCore.Qt.CursorShape.PointingHandCursor:
|
||||||
|
|
12
convo.py
12
convo.py
|
@ -530,9 +530,11 @@ class PesterText(QtWidgets.QTextEdit):
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
if event.button() == QtCore.Qt.MouseButton.LeftButton:
|
if event.button() == QtCore.Qt.MouseButton.LeftButton:
|
||||||
if 'PyQt6' in sys.modules:
|
try:
|
||||||
|
# PyQt6
|
||||||
url = self.anchorAt(event.position().toPoint())
|
url = self.anchorAt(event.position().toPoint())
|
||||||
if 'PyQt5' in sys.modules:
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
url = self.anchorAt(event.pos())
|
url = self.anchorAt(event.pos())
|
||||||
if url != "":
|
if url != "":
|
||||||
if url[0] == "#" and url != "#pesterchum":
|
if url[0] == "#" and url != "#pesterchum":
|
||||||
|
@ -549,9 +551,11 @@ class PesterText(QtWidgets.QTextEdit):
|
||||||
QtWidgets.QTextEdit.mousePressEvent(self, event)
|
QtWidgets.QTextEdit.mousePressEvent(self, event)
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
QtWidgets.QTextEdit.mouseMoveEvent(self, event)
|
QtWidgets.QTextEdit.mouseMoveEvent(self, event)
|
||||||
if 'PyQt6' in sys.modules:
|
try:
|
||||||
|
# PyQt6
|
||||||
pos = event.position().toPoint()
|
pos = event.position().toPoint()
|
||||||
if 'PyQt5' in sys.modules:
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
pos = event.pos()
|
pos = event.pos()
|
||||||
if self.anchorAt(pos):
|
if self.anchorAt(pos):
|
||||||
if self.viewport().cursor().shape != QtCore.Qt.CursorShape.PointingHandCursor:
|
if self.viewport().cursor().shape != QtCore.Qt.CursorShape.PointingHandCursor:
|
||||||
|
|
12
logviewer.py
12
logviewer.py
|
@ -277,9 +277,11 @@ class PesterLogText(PesterText):
|
||||||
def focusInEvent(self, event):
|
def focusInEvent(self, event):
|
||||||
QtWidgets.QTextEdit.focusInEvent(self, event)
|
QtWidgets.QTextEdit.focusInEvent(self, event)
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
if 'PyQt6' in sys.modules:
|
try:
|
||||||
|
# PyQt6
|
||||||
url = self.anchorAt(event.position().toPoint())
|
url = self.anchorAt(event.position().toPoint())
|
||||||
if 'PyQt5' in sys.modules:
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
url = self.anchorAt(event.pos())
|
url = self.anchorAt(event.pos())
|
||||||
if url != "":
|
if url != "":
|
||||||
if url[0] == "#" and url != "#pesterchum":
|
if url[0] == "#" and url != "#pesterchum":
|
||||||
|
@ -292,9 +294,11 @@ class PesterLogText(PesterText):
|
||||||
QtWidgets.QTextEdit.mousePressEvent(self, event)
|
QtWidgets.QTextEdit.mousePressEvent(self, event)
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
QtWidgets.QTextEdit.mouseMoveEvent(self, event)
|
QtWidgets.QTextEdit.mouseMoveEvent(self, event)
|
||||||
if 'PyQt6' in sys.modules:
|
try:
|
||||||
|
# PyQt6
|
||||||
pos = event.position().toPoint()
|
pos = event.position().toPoint()
|
||||||
if 'PyQt5' in sys.modules:
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
pos = event.pos()
|
pos = event.pos()
|
||||||
if self.anchorAt(pos):
|
if self.anchorAt(pos):
|
||||||
if self.viewport().cursor().shape != QtCore.Qt.CursorShape.PointingHandCursor:
|
if self.viewport().cursor().shape != QtCore.Qt.CursorShape.PointingHandCursor:
|
||||||
|
|
29
menus.py
29
menus.py
|
@ -1,3 +1,4 @@
|
||||||
|
import sys
|
||||||
import re
|
import re
|
||||||
from os import remove
|
from os import remove
|
||||||
|
|
||||||
|
@ -723,20 +724,40 @@ class PesterChooseQuirks(QtWidgets.QDialog):
|
||||||
elif vdict["type"] == "replace":
|
elif vdict["type"] == "replace":
|
||||||
vdict["from"] = str(page.itemAt(1).layout().itemAt(1).widget().text())
|
vdict["from"] = str(page.itemAt(1).layout().itemAt(1).widget().text())
|
||||||
vdict["to"] = str(page.itemAt(2).layout().itemAt(1).widget().text())
|
vdict["to"] = str(page.itemAt(2).layout().itemAt(1).widget().text())
|
||||||
vdict["checkstate"] = str(page.itemAt(3).layout().itemAt(0).widget().checkState().value)
|
try:
|
||||||
|
# PyQt6
|
||||||
|
vdict["checkstate"] = str(page.itemAt(3).layout().itemAt(0).widget().checkState().value)
|
||||||
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
|
vdict["checkstate"] = str(page.itemAt(3).layout().itemAt(0).widget().checkState())
|
||||||
elif vdict["type"] == "regexp":
|
elif vdict["type"] == "regexp":
|
||||||
vdict["from"] = str(page.itemAt(2).layout().itemAt(1).layout().itemAt(1).widget().text())
|
vdict["from"] = str(page.itemAt(2).layout().itemAt(1).layout().itemAt(1).widget().text())
|
||||||
vdict["to"] = str(page.itemAt(2).layout().itemAt(2).layout().itemAt(1).widget().text())
|
vdict["to"] = str(page.itemAt(2).layout().itemAt(2).layout().itemAt(1).widget().text())
|
||||||
vdict["checkstate"] = str(page.itemAt(2).layout().itemAt(3).layout().itemAt(0).widget().checkState().value)
|
try:
|
||||||
|
# PyQt6
|
||||||
|
vdict["checkstate"] = str(page.itemAt(2).layout().itemAt(3).layout().itemAt(0).widget().checkState().value)
|
||||||
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
|
vdict["checkstate"] = str(page.itemAt(2).layout().itemAt(3).layout().itemAt(0).widget().checkState())
|
||||||
elif vdict["type"] == "random":
|
elif vdict["type"] == "random":
|
||||||
vdict["from"] = str(self.quirkadd.regexp.text())
|
vdict["from"] = str(self.quirkadd.regexp.text())
|
||||||
vdict["checkstate"] = str(page.itemAt(2).layout().itemAt(2).layout().itemAt(0).widget().checkState().value)
|
try:
|
||||||
|
# PyQt6
|
||||||
|
vdict["checkstate"] = str(page.itemAt(2).layout().itemAt(2).layout().itemAt(0).widget().checkState().value)
|
||||||
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
|
vdict["checkstate"] = str(page.itemAt(2).layout().itemAt(2).layout().itemAt(0).widget().checkState())
|
||||||
randomlist = [str(self.quirkadd.replacelist.item(i).text())
|
randomlist = [str(self.quirkadd.replacelist.item(i).text())
|
||||||
for i in range(0,self.quirkadd.replacelist.count())]
|
for i in range(0,self.quirkadd.replacelist.count())]
|
||||||
vdict["randomlist"] = randomlist
|
vdict["randomlist"] = randomlist
|
||||||
elif vdict["type"] == "spelling":
|
elif vdict["type"] == "spelling":
|
||||||
vdict["percentage"] = self.quirkadd.slider.value()
|
vdict["percentage"] = self.quirkadd.slider.value()
|
||||||
vdict["checkstate"] = str(page.itemAt(3).layout().itemAt(0).widget().checkState().value)
|
try:
|
||||||
|
# PyQt6
|
||||||
|
vdict["checkstate"] = str(page.itemAt(3).layout().itemAt(0).widget().checkState().value)
|
||||||
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
|
vdict["checkstate"] = str(page.itemAt(3).layout().itemAt(0).widget().checkState())
|
||||||
if vdict["type"] in ("regexp", "random"):
|
if vdict["type"] in ("regexp", "random"):
|
||||||
try:
|
try:
|
||||||
re.compile(vdict["from"])
|
re.compile(vdict["from"])
|
||||||
|
|
|
@ -515,9 +515,11 @@ class chumArea(RightClickTree):
|
||||||
if thisitem.rfind(" (") != -1:
|
if thisitem.rfind(" (") != -1:
|
||||||
thisitem = thisitem[0:thisitem.rfind(" (")]
|
thisitem = thisitem[0:thisitem.rfind(" (")]
|
||||||
if thisitem == "Chums" or thisitem in self.groups:
|
if thisitem == "Chums" or thisitem in self.groups:
|
||||||
if 'PyQt6' in sys.modules:
|
try:
|
||||||
|
# PyQt6
|
||||||
droppos = self.itemAt(event.position().toPoint())
|
droppos = self.itemAt(event.position().toPoint())
|
||||||
elif 'PyQt5' in sys.modules:
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
droppos = self.itemAt(event.pos())
|
droppos = self.itemAt(event.pos())
|
||||||
if not droppos: return
|
if not droppos: return
|
||||||
droppos = str(droppos.text(0))
|
droppos = str(droppos.text(0))
|
||||||
|
@ -525,9 +527,11 @@ class chumArea(RightClickTree):
|
||||||
droppos = droppos[0:droppos.rfind(" ")]
|
droppos = droppos[0:droppos.rfind(" ")]
|
||||||
if droppos == "Chums" or droppos in self.groups:
|
if droppos == "Chums" or droppos in self.groups:
|
||||||
saveOpen = event.source().currentItem().isExpanded()
|
saveOpen = event.source().currentItem().isExpanded()
|
||||||
if 'PyQt6' in sys.modules:
|
try:
|
||||||
|
# PyQt6
|
||||||
saveDrop = self.itemAt(event.position().toPoint())
|
saveDrop = self.itemAt(event.position().toPoint())
|
||||||
if 'PyQt5' in sys.modules:
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
saveDrop = self.itemAt(event.pos())
|
saveDrop = self.itemAt(event.pos())
|
||||||
saveItem = self.takeTopLevelItem(self.indexOfTopLevelItem(event.source().currentItem()))
|
saveItem = self.takeTopLevelItem(self.indexOfTopLevelItem(event.source().currentItem()))
|
||||||
self.insertTopLevelItems(self.indexOfTopLevelItem(saveDrop)+1, [saveItem])
|
self.insertTopLevelItems(self.indexOfTopLevelItem(saveDrop)+1, [saveItem])
|
||||||
|
@ -543,9 +547,11 @@ class chumArea(RightClickTree):
|
||||||
self.mainwindow.config.saveGroups(gTemp)
|
self.mainwindow.config.saveGroups(gTemp)
|
||||||
# Drop item is a chum
|
# Drop item is a chum
|
||||||
else:
|
else:
|
||||||
if 'PyQt6' in sys.modules:
|
try:
|
||||||
|
# PyQt6
|
||||||
eventpos = event.position().toPoint()
|
eventpos = event.position().toPoint()
|
||||||
if 'PyQt5' in sys.modules:
|
except AttributeError:
|
||||||
|
# PyQt5
|
||||||
eventpos = event.pos()
|
eventpos = event.pos()
|
||||||
item = self.itemAt(eventpos)
|
item = self.itemAt(eventpos)
|
||||||
if item:
|
if item:
|
||||||
|
@ -2099,16 +2105,17 @@ class PesterWindow(MovingWindow):
|
||||||
def _setup_sounds(self, soundclass=None):
|
def _setup_sounds(self, soundclass=None):
|
||||||
"""Set up the event sounds for later use."""
|
"""Set up the event sounds for later use."""
|
||||||
# Set up the sounds we're using.
|
# Set up the sounds we're using.
|
||||||
if 'pygame' in sys.modules:
|
try:
|
||||||
# Pygame is imported (Linux)
|
# Pygame
|
||||||
soundclass = pygame.mixer.Sound
|
soundclass = pygame.mixer.Sound
|
||||||
elif 'PyQt6.QtMultimedia' in sys.modules:
|
except:
|
||||||
# QtMultimedia is imported (Windows, MacOS)
|
try:
|
||||||
soundclass = QtMultimedia.QSoundEffect
|
# QtMultimedia
|
||||||
else:
|
soundclass = QtMultimedia.QSoundEffect
|
||||||
# death
|
except:
|
||||||
soundclass = NoneSound
|
# death
|
||||||
PchumLog.warning("No sound module loaded?")
|
soundclass = NoneSound
|
||||||
|
PchumLog.warning("No sound module loaded?")
|
||||||
|
|
||||||
self.sound_type = soundclass
|
self.sound_type = soundclass
|
||||||
|
|
||||||
|
@ -3792,7 +3799,7 @@ class MainProgram(QtCore.QObject):
|
||||||
# we could set the frequency higher but i love how cheesy it sounds
|
# we could set the frequency higher but i love how cheesy it sounds
|
||||||
try:
|
try:
|
||||||
pygame.mixer.init()
|
pygame.mixer.init()
|
||||||
except pygame.error as err:
|
except (pygame.error, Exception) as err:
|
||||||
print("Warning: No sound! (pygame error: %s)" % err)
|
print("Warning: No sound! (pygame error: %s)" % err)
|
||||||
|
|
||||||
self.widget = PesterWindow(options, parent=self, app=self.app)
|
self.widget = PesterWindow(options, parent=self, app=self.app)
|
||||||
|
|
Loading…
Reference in a new issue