Logging, soundslider, and mood icon in trollian.

This commit is contained in:
BuildTools 2021-04-11 01:21:21 +02:00
parent eb8a3e7df8
commit 1aa4e65c7d
9 changed files with 62 additions and 43 deletions

View file

@ -20,6 +20,7 @@
- Fixed "Report" string not being updated in convo window when changing theme. - Fixed "Report" string not being updated in convo window when changing theme.
- Fixed pesterChumAction's text not being updated in memo windows when changing theme. - Fixed pesterChumAction's text not being updated in memo windows when changing theme.
- Fixed incorrect sRGB profile in paperchum. - Fixed incorrect sRGB profile in paperchum.
- Fixed Sound slider in settings not working with pygame.
### Changed ### Changed
- Made it so handle and ident are passed to ``_max_msg_len``, so, hopefully the text cutoff will be *slightly* less restrictive. - Made it so handle and ident are passed to ``_max_msg_len``, so, hopefully the text cutoff will be *slightly* less restrictive.

View file

@ -292,7 +292,7 @@ class ConsoleWindow(QtWidgets.QDialog):
else: else:
# No errors. # No errors.
if result is not None: if result is not None:
print(repr(result)) logging.info(repr(result))
finally: finally:
# Restore system output. # Restore system output.
sys.stdout = sysout sys.stdout = sysout

View file

@ -18,7 +18,7 @@ class LuaQuirks(ScriptQuirks):
try: try:
return lua.require(name) return lua.require(name)
except Error as e: except Error as e:
print(e) logging.error(e)
return None return None
finally: finally:
os.chdir(CurrentDir) os.chdir(CurrentDir)

View file

@ -894,7 +894,7 @@ class PesterMemo(PesterConvo):
if c.lower() == self.channel.lower(): if c.lower() == self.channel.lower():
self.mainwindow.inviteOnlyChan['QString'].disconnect(self.closeInviteOnly) self.mainwindow.inviteOnlyChan['QString'].disconnect(self.closeInviteOnly)
if self.parent(): if self.parent():
print(self.channel) logging.info(self.channel)
i = self.parent().tabIndices[self.channel] i = self.parent().tabIndices[self.channel]
self.parent().tabClose(i) self.parent().tabClose(i)
else: else:

View file

@ -11,6 +11,7 @@ from quirks import ScriptQuirks
from pyquirks import PythonQuirks from pyquirks import PythonQuirks
from luaquirks import LuaQuirks from luaquirks import LuaQuirks
import dataobjs import dataobjs
import logging
# karxi: My own contribution to this - a proper lexer. # karxi: My own contribution to this - a proper lexer.
import pnc.lexercon as lexercon import pnc.lexercon as lexercon
@ -42,7 +43,7 @@ quirkloader = ScriptQuirks()
quirkloader.add(PythonQuirks()) quirkloader.add(PythonQuirks())
quirkloader.add(LuaQuirks()) quirkloader.add(LuaQuirks())
quirkloader.loadAll() quirkloader.loadAll()
print(quirkloader.funcre()) logging.info(quirkloader.funcre())
_functionre = re.compile(r"%s" % quirkloader.funcre()) _functionre = re.compile(r"%s" % quirkloader.funcre())
_groupre = re.compile(r"\\([0-9]+)") _groupre = re.compile(r"\\([0-9]+)")
@ -398,7 +399,7 @@ def kxsplitMsg(lexed, ctx, fmt="pchum", maxlen=None, debug=False):
while len(lexed) > 0: while len(lexed) > 0:
rounds += 1 rounds += 1
if debug: if debug:
print("[Starting round {}...]".format(rounds)) logging.info("[Starting round {}...]".format(rounds))
msg = lexed.popleft() msg = lexed.popleft()
msglen = 0 msglen = 0
is_text = False is_text = False
@ -439,7 +440,7 @@ def kxsplitMsg(lexed, ctx, fmt="pchum", maxlen=None, debug=False):
# instead? # instead?
subround += 1 subround += 1
if debug: if debug:
print("[Splitting round {}-{}...]".format( logging.info("[Splitting round {}-{}...]".format(
rounds, subround rounds, subround
)) ))
point = msg.rfind(' ', 0, lenl) point = msg.rfind(' ', 0, lenl)
@ -454,12 +455,12 @@ def kxsplitMsg(lexed, ctx, fmt="pchum", maxlen=None, debug=False):
# Remove what we just added. # Remove what we just added.
msg = msg[point:] msg = msg[point:]
if debug: if debug:
print("msg = {!r}".format(msg)) logging.info("msg = {!r}".format(msg))
else: else:
# Catch the remainder. # Catch the remainder.
stack.append(msg) stack.append(msg)
if debug: if debug:
print("msg caught; stack = {!r}".format(stack)) logging.info("msg caught; stack = {!r}".format(stack))
# Done processing. Pluck out the first portion so we can # Done processing. Pluck out the first portion so we can
# continue processing, clean it up a bit, then add the rest to # continue processing, clean it up a bit, then add the rest to
# our waiting list. # our waiting list.

View file

@ -9,7 +9,7 @@ except NameError:
if os.path.dirname(sys.argv[0]): if os.path.dirname(sys.argv[0]):
os.chdir(os.path.dirname(sys.argv[0])) os.chdir(os.path.dirname(sys.argv[0]))
import logging import logging
logging.basicConfig(level=logging.WARNING) logging.basicConfig(level=logging.DEBUG)
from datetime import * from datetime import *
import random import random
@ -48,19 +48,26 @@ except ImportError as e:
if module.startswith("No module named ") or \ if module.startswith("No module named ") or \
module.startswith("cannot import name "): module.startswith("cannot import name "):
reqmissing.append(module[module.rfind(" ")+1:]) reqmissing.append(module[module.rfind(" ")+1:])
else: print(e) else: logging.critical(e)
del module del module
# Because pygame intro msg :3c
# See https://stackoverflow.com/questions/54246668/how-do-i-delete-the-hello-from-the-pygame-community-console-alert-while-using
try:
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
except:
logging.exception("Failed to set PYGAME_HIDE_SUPPORT_PROMPT, this is a non-issue.")
try: try:
import pygame import pygame
except ImportError as e: except ImportError as e:
pygame = None pygame = None
module = str(e) module = str(e)
if module[:16] == "No module named ": optmissing.append(module[16:]) if module[:16] == "No module named ": optmissing.append(module[16:])
else: print(e) else: logging.critical(e)
del module del module
if reqmissing: if reqmissing:
print("ERROR: The following modules are required for Pesterchum to run and are missing on your system:") logging.critical("ERROR: The following modules are required for Pesterchum to run and are missing on your system:")
for m in reqmissing: print("* "+m) for m in reqmissing: logging.critical("* "+m)
# False flag for some reason. # False flag for some reason.
#exit() #exit()
vnum = QtCore.qVersion() vnum = QtCore.qVersion()
@ -70,8 +77,8 @@ if vnum.find(".", vnum.find(".")+1) != -1:
else: else:
minor = int(vnum[vnum.find(".")+1:]) minor = int(vnum[vnum.find(".")+1:])
if not ((major > 5) or (major == 5 and minor >= 0)): if not ((major > 5) or (major == 5 and minor >= 0)):
print("ERROR: Pesterchum requires at least Qt version >= 5.0") logging.critical("ERROR: Pesterchum requires at least Qt version >= 5.0")
print("You currently have version " + vnum + ". Please upgrade Qt.") logging.critical("You currently have version " + vnum + ". Please upgrade Qt.")
exit() exit()
from version import _pcVersion from version import _pcVersion
@ -329,7 +336,7 @@ class chumArea(RightClickTree):
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def beginNotify(self): def beginNotify(self):
print("BEGIN NOTIFY") logging.info("BEGIN NOTIFY")
self.notify = True self.notify = True
def getOptionsMenu(self): def getOptionsMenu(self):
@ -1341,8 +1348,8 @@ class PesterWindow(MovingWindow):
self.lastping = int(time()) self.lastping = int(time())
self.pingtimer.start(1000*90) self.pingtimer.start(1000*90)
self.changeServerAskedToReset = False self.chooseServerAskedToReset = False
self.changeServer() self.chooseServer()
@QtCore.pyqtSlot(QString, QString) @QtCore.pyqtSlot(QString, QString)
def updateMsg(self, ver, url): def updateMsg(self, ver, url):
@ -1795,7 +1802,10 @@ class PesterWindow(MovingWindow):
self.mychumcolor.setStyleSheet("background: %s" % (self.profile().colorhtml())) self.mychumcolor.setStyleSheet("background: %s" % (self.profile().colorhtml()))
# I don't know why "if "main/mychumhandle/currentMood" in self.theme:" doesn't work, # I don't know why "if "main/mychumhandle/currentMood" in self.theme:" doesn't work,
# But this seems to work just as well :3c # But this seems to work just as well :3c
if self.theme.has_key("main/mychumhandle/currentMood"): # GWAHH why does inheriting not work with this </3
# For some reason, this only works on trollian with 'try' :/
#if self.theme.has_key("main/mychumhandle/currentMood"):
try:
moodicon = self.profile().mood.icon(theme) moodicon = self.profile().mood.icon(theme)
if hasattr(self, 'currentMoodIcon') and self.currentMoodIcon: if hasattr(self, 'currentMoodIcon') and self.currentMoodIcon:
self.currentMoodIcon.hide() self.currentMoodIcon.hide()
@ -1804,7 +1814,7 @@ class PesterWindow(MovingWindow):
self.currentMoodIcon.setPixmap(moodicon.pixmap(moodicon.realsize())) self.currentMoodIcon.setPixmap(moodicon.pixmap(moodicon.realsize()))
self.currentMoodIcon.move(*theme["main/mychumhandle/currentMood"]) self.currentMoodIcon.move(*theme["main/mychumhandle/currentMood"])
self.currentMoodIcon.show() self.currentMoodIcon.show()
else: except:
if hasattr(self, 'currentMoodIcon') and self.currentMoodIcon: if hasattr(self, 'currentMoodIcon') and self.currentMoodIcon:
self.currentMoodIcon.hide() self.currentMoodIcon.hide()
self.currentMoodIcon = None self.currentMoodIcon = None
@ -1846,6 +1856,7 @@ class PesterWindow(MovingWindow):
# # We don't have any options...just use fillers. # # We don't have any options...just use fillers.
# soundclass = NoneSound # soundclass = NoneSound
else: else:
logging.warning("Failed to define pygame mixer, is pygame imported?")
try: try:
soundclass = QtMultimedia.QSound soundclass = QtMultimedia.QSound
except: except:
@ -1883,13 +1894,14 @@ class PesterWindow(MovingWindow):
for sound in sounds: for sound in sounds:
try: try:
if pygame and pygame.mixer and \ if pygame and pygame.mixer and \
isinstance(sound, pygame.mixer.sound): isinstance(sound, pygame.mixer.Sound):#pygame.mixer.Sound is case sensitive!!
sound.set_volume(vol) sound.set_volume(vol)
elif not isinstance(sound, QtMultimedia.QSound): elif not isinstance(sound, QtMultimedia.QSound):
# We can't set a volume on those.... # We can't set a volume on those....
sound.setVolume(vol) sound.setVolume(vol)
except Exception as err: except Exception as err:
logging.info("Couldn't set volume: {}".format(err)) # Why was this set as "info"? ?w?
logging.warning("Couldn't set volume: {}".format(err))
def canSetVolume(self): def canSetVolume(self):
"""Returns the state of volume setting capabilities.""" """Returns the state of volume setting capabilities."""
@ -3004,7 +3016,7 @@ class PesterWindow(MovingWindow):
msgbox.setInformativeText("Incorrect format :(") msgbox.setInformativeText("Incorrect format :(")
msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok) msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok)
ret = msgbox.exec_() ret = msgbox.exec_()
self.changeServer() self.chooseServer()
return 1 return 1
with open(_datadir + "serverlist.json", "r") as server_file: with open(_datadir + "serverlist.json", "r") as server_file:
@ -3020,7 +3032,7 @@ class PesterWindow(MovingWindow):
logging.error("failed") logging.error("failed")
# Go back to original screen # Go back to original screen
self.changeServer() self.chooseServer()
def resetServerlist(self): def resetServerlist(self):
default_server_list = [{ default_server_list = [{
@ -3052,7 +3064,7 @@ class PesterWindow(MovingWindow):
with open(_datadir + "serverlist.json", "w") as server_file: with open(_datadir + "serverlist.json", "w") as server_file:
server_file.write(json.dumps(default_server_list, indent = 4) ) server_file.write(json.dumps(default_server_list, indent = 4) )
server_file.close() server_file.close()
self.changeServer() self.chooseServer()
def removeServer(self): def removeServer(self):
server_list_items = [] server_list_items = []
@ -3064,8 +3076,8 @@ class PesterWindow(MovingWindow):
for i in range(len(server_list_obj)): for i in range(len(server_list_obj)):
server_list_items.append(server_list_obj[i]["server"]) server_list_items.append(server_list_obj[i]["server"])
except: except:
if self.changeServerAskedToReset == False: if self.chooseServerAskedToReset == False:
self.changeServerAskedToReset = True self.chooseServerAskedToReset = True
self.resetServerlist() self.resetServerlist()
return 1 return 1
@ -3085,7 +3097,7 @@ class PesterWindow(MovingWindow):
logging.error("failed") logging.error("failed")
self.changeServer() self.chooseServer()
def setServer(self): def setServer(self):
if self.serverBox.currentText() == "Add a server [Prompt]": if self.serverBox.currentText() == "Add a server [Prompt]":
@ -3133,10 +3145,11 @@ class PesterWindow(MovingWindow):
# Connect # Connect
self.customServerDialog.accepted.connect(self.updateServerJson) self.customServerDialog.accepted.connect(self.updateServerJson)
self.customServerDialog.rejected.connect(self.changeServer) self.customServerDialog.rejected.connect(self.chooseServer)
# Show # Show
self.customServerDialog.show() self.customServerDialog.show()
self.customServerDialog.setFocus()
elif self.serverBox.currentText() == "Remove a server [Prompt]": elif self.serverBox.currentText() == "Remove a server [Prompt]":
# Read servers. # Read servers.
@ -3149,8 +3162,8 @@ class PesterWindow(MovingWindow):
for i in range(len(server_obj)): for i in range(len(server_obj)):
server_list_items.append(server_obj[i]["server"]) server_list_items.append(server_obj[i]["server"])
except: except:
if self.changeServerAskedToReset == False: if self.chooseServerAskedToReset == False:
self.changeServerAskedToReset = True self.chooseServerAskedToReset = True
self.resetServerlist() self.resetServerlist()
return 1 return 1
@ -3190,10 +3203,11 @@ class PesterWindow(MovingWindow):
# Connect # Connect
self.chooseRemoveServerWidged.accepted.connect(self.removeServer) self.chooseRemoveServerWidged.accepted.connect(self.removeServer)
self.chooseRemoveServerWidged.rejected.connect(self.changeServer) self.chooseRemoveServerWidged.rejected.connect(self.chooseServer)
# Show # Show
self.chooseRemoveServerWidged.show() self.chooseRemoveServerWidged.show()
self.chooseRemoveServerWidged.setFocus()
else: else:
logging.info(self.serverBox.currentText() + " chosen") logging.info(self.serverBox.currentText() + " chosen")
@ -3225,8 +3239,9 @@ class PesterWindow(MovingWindow):
pesterchum.reconnectok = False pesterchum.reconnectok = False
pesterchum.showLoading(pesterchum.widget) pesterchum.showLoading(pesterchum.widget)
self.show() # Not required? self.show() # Not required?
self.setFocus()
def changeServer(self): def chooseServer(self):
# Read servers. # Read servers.
server_list_items = [] server_list_items = []
try: try:
@ -3237,8 +3252,8 @@ class PesterWindow(MovingWindow):
for i in range(len(server_obj)): for i in range(len(server_obj)):
server_list_items.append(server_obj[i]["server"]) server_list_items.append(server_obj[i]["server"])
except: except:
if self.changeServerAskedToReset == False: if self.chooseServerAskedToReset == False:
self.changeServerAskedToReset = True self.chooseServerAskedToReset = True
self.resetServerlist() self.resetServerlist()
return 1 return 1
@ -3285,6 +3300,7 @@ class PesterWindow(MovingWindow):
# Show # Show
self.chooseServerWidged.show() self.chooseServerWidged.show()
self.chooseServerWidged.setFocus()
pcUpdate = QtCore.pyqtSignal('QString', 'QString') pcUpdate = QtCore.pyqtSignal('QString', 'QString')
closeToTraySignal = QtCore.pyqtSignal() closeToTraySignal = QtCore.pyqtSignal()

View file

@ -1,4 +1,4 @@
import os, sys, re, ostools import os, sys, re, ostools, logging
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
class ScriptQuirks(object): class ScriptQuirks(object):
@ -20,7 +20,7 @@ class ScriptQuirks(object):
self.last = self.quirks.copy() self.last = self.quirks.copy()
self.quirks.clear() self.quirks.clear()
for script in self.scripts: for script in self.scripts:
print(script.getExtension()) logging.info(script.getExtension())
script.load() script.load()
#print script.quirks #print script.quirks
for q in script.quirks: for q in script.quirks:
@ -31,9 +31,9 @@ class ScriptQuirks(object):
del self.quirks[k] del self.quirks[k]
#print self.quirks #print self.quirks
if self.quirks: if self.quirks:
print('Registered quirks:', '(), '.join(self.quirks) + "()") logging.info('Registered quirks:', '(), '.join(self.quirks) + "()")
else: else:
print("Warning: Couldn't find any script quirks") logging.warning("Couldn't find any script quirks")
def add(self, script): def add(self, script):
self.scripts.append(script) self.scripts.append(script)

View file

@ -1,4 +1,5 @@
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
import logging
RANDNICK = "randomEncounter" RANDNICK = "randomEncounter"
@ -65,5 +66,5 @@ class RandomHandler(QtCore.QObject):
msgbox.exec_() msgbox.exec_()
return return
name = str(l[1]) name = str(l[1])
print(name) logging.info("Random Encounter name is: " + name)
self.mainwindow.newConversation(name) self.mainwindow.newConversation(name)

View file

@ -24,7 +24,7 @@ class DefaultToast(object):
if t.title == self.title and t.msg == self.msg and t.icon == self.icon: if t.title == self.title and t.msg == self.msg and t.icon == self.icon:
self.machine.toasts.pop(0) self.machine.toasts.pop(0)
self.machine.displaying = False self.machine.displaying = False
print("Done") logging.info("Done")
class ToastMachine(object): class ToastMachine(object):
class __Toast__(object): class __Toast__(object):
@ -143,7 +143,7 @@ class ToastMachine(object):
if type in self.types: if type in self.types:
if type == "libnotify": if type == "libnotify":
if not pynotify or not pynotify.init("ToastMachine"): if not pynotify or not pynotify.init("ToastMachine"):
print("Problem initilizing pynotify") logging.info("Problem initilizing pynotify")
return return
#self.type = type = "default" #self.type = type = "default"
elif type == "twmn": elif type == "twmn":
@ -151,7 +151,7 @@ class ToastMachine(object):
try: try:
pytwmn.init() pytwmn.init()
except pytwmn.ERROR as e: except pytwmn.ERROR as e:
print("Problem initilizing pytwmn: " + str(e)) logging.error("Problem initilizing pytwmn: " + str(e))
return return
#self.type = type = "default" #self.type = type = "default"
self.type = type self.type = type