Compare commits

..

4 Commits

Author SHA1 Message Date
9eeb7897f1 have autocaps deal with some more closing special chars 2025-02-23 15:32:09 -03:00
98e1da8225 add some shortcuts 2025-02-23 15:12:18 -03:00
b072f5dafd tabs -> spaces 2025-02-23 15:12:06 -03:00
b66ee7e619 handle some file open()s better 2025-02-23 14:09:24 -03:00
3 changed files with 215 additions and 211 deletions

View File

@ -3,195 +3,195 @@ import os
from constants import *
class AOToggleButton(QtGui.QLabel):
pressed = False
clicked = QtCore.pyqtSignal()
pressed = False
clicked = QtCore.pyqtSignal()
def __init__(self, parent, x, y, btnname):
super(AOToggleButton, self).__init__(parent)
self.parent = parent
self.notpressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/%s.png" % btnname)
self.pressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/%s_pressed.png" % btnname)
self.setPixmap(self.notpressed_pix)
self.setGeometry(x, y, self.notpressed_pix.size().width(), self.notpressed_pix.size().height())
self.show()
def setPressed(self, on):
self.pressed = on
self.setPixmap(self.pressed_pix if on else self.notpressed_pix)
def isPressed(self):
return self.pressed
def mousePressEvent(self, event):
self.setPressed(not self.isPressed())
self.clicked.emit()
def __init__(self, parent, x, y, btnname):
super(AOToggleButton, self).__init__(parent)
self.parent = parent
self.notpressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/%s.png" % btnname)
self.pressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/%s_pressed.png" % btnname)
self.setPixmap(self.notpressed_pix)
self.setGeometry(x, y, self.notpressed_pix.size().width(), self.notpressed_pix.size().height())
self.show()
def setPressed(self, on):
self.pressed = on
self.setPixmap(self.pressed_pix if on else self.notpressed_pix)
def isPressed(self):
return self.pressed
def mousePressEvent(self, event):
self.setPressed(not self.isPressed())
self.clicked.emit()
class CustomObjection(QtGui.QLabel):
pressed = False
def __init__(self, parent, x, y):
super(CustomObjection, self).__init__(parent)
self.parent = parent
self.setGeometry(x, y, 76, 28)
self.notpressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/custom.png")
self.pressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/custom_selected.png")
self.setPixmap(self.notpressed_pix)
self.show()
def setPressed(self, on):
self.pressed = on
if on:
self.setPixmap(self.pressed_pix)
else:
self.setPixmap(self.notpressed_pix)
def isPressed(self):
return self.pressed
def mousePressEvent(self, event):
self.setPressed(not self.isPressed())
self.parent.objectbtn.setPressed(False)
self.parent.holditbtn.setPressed(False)
self.parent.takethatbtn.setPressed(False)
pressed = False
def __init__(self, parent, x, y):
super(CustomObjection, self).__init__(parent)
self.parent = parent
self.setGeometry(x, y, 76, 28)
self.notpressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/custom.png")
self.pressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/custom_selected.png")
self.setPixmap(self.notpressed_pix)
self.show()
def setPressed(self, on):
self.pressed = on
if on:
self.setPixmap(self.pressed_pix)
else:
self.setPixmap(self.notpressed_pix)
def isPressed(self):
return self.pressed
def mousePressEvent(self, event):
self.setPressed(not self.isPressed())
self.parent.objectbtn.setPressed(False)
self.parent.holditbtn.setPressed(False)
self.parent.takethatbtn.setPressed(False)
class WTCEbuttons(QtGui.QLabel):
clicked = QtCore.pyqtSignal(int, int)
type = 0
variant = 0
def __init__(self, parent, x, y, type, variant=0):
super(WTCEbuttons, self).__init__(parent)
self.setGeometry(x, y, 85, 42)
if type == 0:
self.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/witnesstestimony.png"))
elif type == 1:
self.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/crossexamination.png"))
elif type == 2:
if variant == 0:
self.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/notguilty.png"))
elif variant == 1:
self.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/guilty.png"))
self.type = type
self.variant = variant
def mousePressEvent(self, event):
self.clicked.emit(self.type, self.variant)
clicked = QtCore.pyqtSignal(int, int)
type = 0
variant = 0
def __init__(self, parent, x, y, type, variant=0):
super(WTCEbuttons, self).__init__(parent)
self.setGeometry(x, y, 85, 42)
if type == 0:
self.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/witnesstestimony.png"))
elif type == 1:
self.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/crossexamination.png"))
elif type == 2:
if variant == 0:
self.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/notguilty.png"))
elif variant == 1:
self.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/guilty.png"))
self.type = type
self.variant = variant
def mousePressEvent(self, event):
self.clicked.emit(self.type, self.variant)
class Objections(QtGui.QLabel):
pressed = False
type = 0
def __init__(self, parent, x, y, type):
super(Objections, self).__init__(parent)
self.parent = parent
self.type = type
self.setGeometry(x, y, 76, 28)
if type == 1:
self.notpressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/holdit.png")
self.pressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/holdit_selected.png")
elif type == 2:
self.notpressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/objection.png")
self.pressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/objection_selected.png")
elif type == 3:
self.notpressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/takethat.png")
self.pressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/takethat_selected.png")
self.setPixmap(self.notpressed_pix)
self.show()
def setPressed(self, on):
self.pressed = on
if on:
self.setPixmap(self.pressed_pix)
else:
self.setPixmap(self.notpressed_pix)
def isPressed(self):
return self.pressed
def mousePressEvent(self, event):
self.setPressed(not self.isPressed())
self.parent.customobject.setPressed(False)
if self.type == 1:
self.parent.objectbtn.setPressed(False)
self.parent.takethatbtn.setPressed(False)
elif self.type == 2:
self.parent.holditbtn.setPressed(False)
self.parent.takethatbtn.setPressed(False)
elif self.type == 3:
self.parent.objectbtn.setPressed(False)
self.parent.holditbtn.setPressed(False)
pressed = False
type = 0
def __init__(self, parent, x, y, type):
super(Objections, self).__init__(parent)
self.parent = parent
self.type = type
self.setGeometry(x, y, 76, 28)
if type == 1:
self.notpressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/holdit.png")
self.pressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/holdit_selected.png")
elif type == 2:
self.notpressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/objection.png")
self.pressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/objection_selected.png")
elif type == 3:
self.notpressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/takethat.png")
self.pressed_pix = QtGui.QPixmap(AO2XPpath+"themes/default/takethat_selected.png")
self.setPixmap(self.notpressed_pix)
self.show()
def setPressed(self, on):
self.pressed = on
if on:
self.setPixmap(self.pressed_pix)
else:
self.setPixmap(self.notpressed_pix)
def isPressed(self):
return self.pressed
def mousePressEvent(self, event):
self.setPressed(not self.isPressed())
self.parent.customobject.setPressed(False)
if self.type == 1:
self.parent.objectbtn.setPressed(False)
self.parent.takethatbtn.setPressed(False)
elif self.type == 2:
self.parent.holditbtn.setPressed(False)
self.parent.takethatbtn.setPressed(False)
elif self.type == 3:
self.parent.objectbtn.setPressed(False)
self.parent.holditbtn.setPressed(False)
class PixmapButton(QtGui.QAbstractButton):
def __init__(self, parent, pixmap):
super(PixmapButton, self).__init__(parent)
self.pixmap = pixmap
def __init__(self, parent, pixmap):
super(PixmapButton, self).__init__(parent)
self.pixmap = pixmap
def paintEvent(self, event):
painter = QtGui.QPainter(self)
painter.drawPixmap(event.rect(), self.pixmap)
def paintEvent(self, event):
painter = QtGui.QPainter(self)
painter.drawPixmap(event.rect(), self.pixmap)
def sizeHint(self):
return self.pixmap.size()
def setPixmap(self, pixmap):
self.pixmap = pixmap
def sizeHint(self):
return self.pixmap.size()
def setPixmap(self, pixmap):
self.pixmap = pixmap
class PixmapButton2(QtGui.QLabel):
clicked = QtCore.pyqtSignal()
rightClicked = QtCore.pyqtSignal()
def __init__(self, parent, pixmap):
super(PixmapButton2, self).__init__(parent)
self.setPixmap(pixmap)
self.show()
def mousePressEvent(self, ev):
if ev.buttons() == QtCore.Qt.LeftButton:
self.clicked.emit()
elif ev.buttons() == QtCore.Qt.RightButton:
self.rightClicked.emit()
clicked = QtCore.pyqtSignal()
rightClicked = QtCore.pyqtSignal()
def __init__(self, parent, pixmap):
super(PixmapButton2, self).__init__(parent)
self.setPixmap(pixmap)
self.show()
def mousePressEvent(self, ev):
if ev.buttons() == QtCore.Qt.LeftButton:
self.clicked.emit()
elif ev.buttons() == QtCore.Qt.RightButton:
self.rightClicked.emit()
class PenaltyBars(QtGui.QLabel):
minusClicked = QtCore.pyqtSignal(int)
plusClicked = QtCore.pyqtSignal(int)
def __init__(self, parent, type):
super(PenaltyBars, self).__init__(parent)
self.parent = parent
self.penaltybars = []
self.type = type
self.health = 10
self.resize(84, 14)
if type == 1: #defense bar.
for i in range(11):
self.penaltybars.append(QtGui.QPixmap(AO2XPpath+"themes/default/defensebar"+str(i)+".png"))
side = "def"
elif type == 2: #prosecution bar
for i in range(11):
self.penaltybars.append(QtGui.QPixmap(AO2XPpath+"themes/default/prosecutionbar"+str(i)+".png"))
side = "pro"
self.side = side
self.minusbtn = PixmapButton(parent, QtGui.QPixmap(AO2XPpath+"themes/default/"+side+"minus.png"))
self.plusbtn = PixmapButton(parent, QtGui.QPixmap(AO2XPpath+"themes/default/"+side+"plus.png"))
self.minusbtn.clicked.connect(self.minusClick)
self.plusbtn.clicked.connect(self.plusClick)
self.setPixmap(self.penaltybars[10])
self.minusbtn.show()
self.plusbtn.show()
self.show()
def moveBar(self, x, y):
self.move(x, y)
self.minusbtn.move(x-(9/2), y+(14/2)-(9/2))
self.plusbtn.move(x+84-(9/2), y+(14/2)-(9/2))
def plusClick(self):
self.plusClicked.emit(self.type)
def minusClick(self):
self.minusClicked.emit(self.type)
def setHealth(self, health):
self.minusbtn.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/"+self.side+"minus.png"))
self.plusbtn.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/"+self.side+"plus.png"))
self.setPixmap(self.penaltybars[health])
self.health = health
def getHealth(self):
return self.health
minusClicked = QtCore.pyqtSignal(int)
plusClicked = QtCore.pyqtSignal(int)
def __init__(self, parent, type):
super(PenaltyBars, self).__init__(parent)
self.parent = parent
self.penaltybars = []
self.type = type
self.health = 10
self.resize(84, 14)
if type == 1: #defense bar.
for i in range(11):
self.penaltybars.append(QtGui.QPixmap(AO2XPpath+"themes/default/defensebar"+str(i)+".png"))
side = "def"
elif type == 2: #prosecution bar
for i in range(11):
self.penaltybars.append(QtGui.QPixmap(AO2XPpath+"themes/default/prosecutionbar"+str(i)+".png"))
side = "pro"
self.side = side
self.minusbtn = PixmapButton(parent, QtGui.QPixmap(AO2XPpath+"themes/default/"+side+"minus.png"))
self.plusbtn = PixmapButton(parent, QtGui.QPixmap(AO2XPpath+"themes/default/"+side+"plus.png"))
self.minusbtn.clicked.connect(self.minusClick)
self.plusbtn.clicked.connect(self.plusClick)
self.setPixmap(self.penaltybars[10])
self.minusbtn.show()
self.plusbtn.show()
self.show()
def moveBar(self, x, y):
self.move(x, y)
self.minusbtn.move(x-(9/2), y+(14/2)-(9/2))
self.plusbtn.move(x+84-(9/2), y+(14/2)-(9/2))
def plusClick(self):
self.plusClicked.emit(self.type)
def minusClick(self):
self.minusClicked.emit(self.type)
def setHealth(self, health):
self.minusbtn.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/"+self.side+"minus.png"))
self.plusbtn.setPixmap(QtGui.QPixmap(AO2XPpath+"themes/default/"+self.side+"plus.png"))
self.setPixmap(self.penaltybars[health])
self.health = health
def getHealth(self):
return self.health

View File

@ -827,7 +827,7 @@ class gui(QtGui.QWidget):
self.oocinput.setPlaceholderText('Server chat/OOC chat...')
self.oocinput.returnPressed.connect(self.onOOCreturn)
self.ooclogin = QtGui.QPushButton("Login", self)
self.ooclogin = QtGui.QPushButton("Lo&gin", self)
self.ooclogin.clicked.connect(self.onOOCLoginBtn)
self.musicareatabs = QtGui.QTabWidget(self)
@ -989,17 +989,17 @@ class gui(QtGui.QWidget):
self.misc_layout.addWidget(self.spacebartext)
self.misc_layout.addWidget(self.autocaps)
self.gametabs.addTab(self.gametab_log, 'Log')
self.gametabs.addTab(self.gametab_evidence, 'Evidence')
self.gametabs.addTab(self.gametab_mute, 'Mute')
self.gametabs.addTab(self.gametab_iniswap, 'INI swap')
self.gametabs.addTab(self.gametab_pair, 'Pair')
self.gametabs.addTab(self.gametab_misc, 'Misc')
self.gametabs.addTab(self.gametab_msgqueue, 'Queue')
self.gametabs.addTab(self.gametab_log, '&Log')
self.gametabs.addTab(self.gametab_evidence, '&Evidence')
self.gametabs.addTab(self.gametab_mute, 'Mu&te')
self.gametabs.addTab(self.gametab_iniswap, '&INI swap')
self.gametabs.addTab(self.gametab_pair, 'Pai&r')
self.gametabs.addTab(self.gametab_misc, 'Mi&sc')
self.gametabs.addTab(self.gametab_msgqueue, '&Queue')
self.musicareatabs.addTab(self.musicitems, "Music")
self.musicareatabs.addTab(self.areaitems, "Areas")
self.musicareatabs.addTab(self.gametab_players, 'Players')
self.musicareatabs.addTab(self.musicitems, "&Music")
self.musicareatabs.addTab(self.areaitems, "&Areas")
self.musicareatabs.addTab(self.gametab_players, 'Pla&yers')
self.icchatinput = QtGui.QLineEdit(self)
self.icchatinput.returnPressed.connect(self.onICreturn)
@ -1020,14 +1020,14 @@ class gui(QtGui.QWidget):
self.flipbutton = QtGui.QCheckBox(self)
self.flipbutton.stateChanged.connect(self.changeFlipCheck)
self.flipbutton.setText('Flip')
self.flipbutton.setText('&Flip')
self.flipbutton.resize(self.flipbutton.sizeHint())
self.flipbutton.setToolTip("Mirror your character horizontally")
self.sfxbutton = QtGui.QCheckBox(self)
self.sfxbutton.setChecked(True)
self.sfxbutton.stateChanged.connect(self.changeSfxCheck)
self.sfxbutton.setText('Play pre-animation')
self.sfxbutton.setText('Play &pre-animation')
self.sfxbutton.setToolTip("Play a character-specific animation before the next message")
self.nointerruptbtn = QtGui.QCheckBox(self)
@ -1060,7 +1060,7 @@ class gui(QtGui.QWidget):
self.settingsbtn.clicked.connect(self.gamewindow.showSettings)
self.changechar = QtGui.QPushButton(self)
self.changechar.setText('Switch character')
self.changechar.setText('&Switch character')
self.changechar.clicked.connect(self.onClick_changeChar)
spacing = 1
@ -1197,7 +1197,8 @@ class gui(QtGui.QWidget):
self.height = 730
theme = get_option("General", "theme", "default")
try:
exec open(AO2XPpath+"ao2xp_themes/"+theme+"/theme.py")
with open(AO2XPpath+"ao2xp_themes/"+theme+"/theme.py") as t:
exec t
except Exception as e:
QtGui.QMessageBox.critical(None, "Unable to load theme", "There was a problem loading the current theme \"%s\":\n\n%s." % (theme, e))
os._exit(-2)
@ -1601,8 +1602,9 @@ class gui(QtGui.QWidget):
inifile.set(id, "name", evi[0].replace('\n', '\\n').encode('utf-8'))
inifile.set(id, "description", evi[1].replace('\n', '\\n').encode('utf-8'))
inifile.set(id, "image", evi[2].encode('utf-8'))
inifile.write(open(path, "wb"))
with open(path, "wb") as f:
inifile.write(f)
def onImportEvidence(self, is_autoload=False):
if not is_autoload:
@ -1865,7 +1867,7 @@ class gui(QtGui.QWidget):
self.playerList.clear()
self.playerKick.setDisabled(True)
self.playerBan.setDisabled(True)
self.ooclogin.setText("Login")
self.ooclogin.setText("Lo&gin")
self.login = False
self.privateinv = False
self.charselect.onDisconnect()
@ -1922,7 +1924,7 @@ class gui(QtGui.QWidget):
l = QtCore.QStringList(list(text))
l[0] = l[0].toUpper()
last = [".", "?", "!"]
last = [".", "?", "!", ")", "]"]
if not l[-1] in last:
l.append(".")
text = l.join("").replace(" i ", " I ").replace("i'm", "I'm").replace("it's", "It's")
@ -1936,16 +1938,14 @@ class gui(QtGui.QWidget):
self.oocinput.clear()
def onICreturn(self):
text = str(self.icchatinput.text().toUtf8()).replace('#', '<num>').replace('%', '<percent>').replace('&', '<and>').replace('$', '<dollar>').replace('/n', '\n')
#if not text:
# return
text = str(self.icchatinput.text().toUtf8()).replace('#', '<num>').replace('%', '<percent>').replace('&', '<and>').replace('$', '<dollar>')#.replace('/n', '\n')
if self.mocktext.isChecked():
text = mockStr(text)
if self.autocaps.isChecked():
l = list(text)
l[0] = l[0].upper()
last = [".", "?", "!"]
last = [".", "?", "!", "<", ">", ")", "]"]
if not l[-1] in last:
l.append(".")
text = "".join(l).replace(" i ", " I ").replace("i'm", "I'm").replace("it's", "It's")
@ -2545,14 +2545,15 @@ class gui(QtGui.QWidget):
self.anim_state = 3
if exists(AO2XPpath+"callwords.ini"):
callwords = [line.rstrip() for line in open(AO2XPpath+"callwords.ini")]
for callword in callwords:
if callword.decode('utf-8').lower() in self.m_chatmessage[CHATMSG].lower().split(" "):
self.ooclog.append("<b>%s called you.</b>" % f_char)
snd = audio.loadhandle(False, "word_call.wav", 0, 0, BASS_STREAM_AUTOFREE)
if snd:
audio.playhandle(snd, True)
break
with open(AO2XPpath+"callwords.ini") as f:
callwords = [line.rstrip() for line in f]
for callword in callwords:
if callword.decode('utf-8').lower() in self.m_chatmessage[CHATMSG].lower().split(" "):
self.ooclog.append("<b>%s called you.</b>" % f_char)
snd = audio.loadhandle(False, "word_call.wav", 0, 0, BASS_STREAM_AUTOFREE)
if snd:
audio.playhandle(snd, True)
break
def do_effect(self, fx_name, fx_sound, p_char, p_folder):
effect = ini.get_effect(fx_name, p_char, p_folder)
@ -3104,6 +3105,8 @@ class gui(QtGui.QWidget):
self.tcpthread.updatePlayerList.connect(self.updatePlayerList)
self.tcpthread.rainbowColor.connect(self.text.setStyleSheet)
self.tcpthread.start()
self.icchatinput.setFocus()
def allEvidence(self, evi):
self.evidence = evi
@ -3559,12 +3562,12 @@ class TCP_Thread(QtCore.QThread):
self.parent.login = True
self.parent.playerKick.setDisabled(False)
self.parent.playerBan.setDisabled(False)
self.parent.ooclogin.setText("Log out")
self.parent.ooclogin.setText("Lo&g out")
elif status == -1:
self.parent.login = False
self.parent.playerKick.setDisabled(True)
self.parent.playerBan.setDisabled(True)
self.parent.ooclogin.setText("Login")
self.parent.ooclogin.setText("Lo&gin")
self.OOC_Log.emit("<b>%s</b>" % (statusStrings[status+1]))
elif header == "CHECK": #ping

View File

@ -296,7 +296,8 @@ class Settings(QtGui.QDialog):
self.inifile.set("Audio", "Sound volume", self.soundslider.value())
self.inifile.set("Audio", "Blip volume", self.blipslider.value())
self.inifile.write(open("AO2XP.ini", "wb"))
with open("AO2XP.ini", "wb") as f:
self.inifile.write(f)
with open(AO2XPpath+"callwords.ini", "w") as f:
f.write(self.callwords_edit.toPlainText().toUtf8())