more refactoring

This commit is contained in:
cidoku 2025-10-08 15:48:25 -03:00
parent b7ca988b13
commit b4a5c289f8
2 changed files with 257 additions and 251 deletions

View File

@ -339,12 +339,13 @@ class AOCharMovie(QtGui.QLabel):
placeholderPath = AO2XPpath + "themes/default/oldplaceholder.gif" placeholderPath = AO2XPpath + "themes/default/oldplaceholder.gif"
imgPath = "" imgPath = ""
downloadCharacters = ini.read_ini_bool("AO2XP.ini", "General", "download characters")
if apngPath: if apngPath:
imgPath = apngPath imgPath = apngPath
self.usePillow = 1 self.usePillow = 1
else: else:
if ini.read_ini_bool("AO2XP.ini", "General", "download characters"): if downloadCharacters:
url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".apng" url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".apng"
url = url.replace(" ", "%20") url = url.replace(" ", "%20")
thread.start_new_thread(downloadThread, (url, apngPath)) thread.start_new_thread(downloadThread, (url, apngPath))
@ -363,7 +364,7 @@ class AOCharMovie(QtGui.QLabel):
imgPath = pngPath imgPath = pngPath
self.usePillow = 0 self.usePillow = 0
else: else:
if ini.read_ini_bool("AO2XP.ini", "General", "download characters"): if downloadCharacters:
url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".png" url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".png"
url = url.replace(" ", "%20") url = url.replace(" ", "%20")
thread.start_new_thread(downloadThread, (url, pngPath)) thread.start_new_thread(downloadThread, (url, pngPath))
@ -382,7 +383,7 @@ class AOCharMovie(QtGui.QLabel):
imgPath = webpPath imgPath = webpPath
self.usePillow = 2 self.usePillow = 2
else: else:
if ini.read_ini_bool("AO2XP.ini", "General", "download characters"): if downloadCharacters:
url = "base/characters/" + pChar.lower() + "/"+pEmote.lower() + ".webp" url = "base/characters/" + pChar.lower() + "/"+pEmote.lower() + ".webp"
url = url.replace(" ", "%20") url = url.replace(" ", "%20")
thread.start_new_thread(downloadThread, (url, webpPath)) thread.start_new_thread(downloadThread, (url, webpPath))
@ -401,7 +402,7 @@ class AOCharMovie(QtGui.QLabel):
imgPath = gifPath imgPath = gifPath
self.usePillow = 0 self.usePillow = 0
else: else:
if ini.read_ini_bool("AO2XP.ini", "General", "download characters"): if downloadCharacters:
url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".gif" url = "base/characters/" + pChar.lower() + "/" + emotePrefix + pEmote.lower() + ".gif"
url = url.replace(" ", "%20") url = url.replace(" ", "%20")
thread.start_new_thread(downloadThread, (url, gifPath)) thread.start_new_thread(downloadThread, (url, gifPath))
@ -1362,7 +1363,8 @@ class GUI(QtGui.QWidget):
# Music list # Music list
self.musicItems = QtGui.QListWidget(self.tabMusic) self.musicItems = QtGui.QListWidget(self.tabMusic)
self.musicItems.itemDoubleClicked.connect(self.onMusicItemClicked) self.musicItems.itemClicked.connect(self.onMusicItemClicked)
self.musicItems.itemDoubleClicked.connect(self.onMusicItemDoubleClicked)
self.musicSearch = QtGui.QLineEdit(self.tabMusic) self.musicSearch = QtGui.QLineEdit(self.tabMusic)
self.musicSearch.setPlaceholderText("Search...") self.musicSearch.setPlaceholderText("Search...")
self.musicSearch.textChanged.connect(self.onMusicSearch) self.musicSearch.textChanged.connect(self.onMusicSearch)
@ -1513,7 +1515,7 @@ class GUI(QtGui.QWidget):
self.btnObjection.clicked.connect(self.ICChatFocus) self.btnObjection.clicked.connect(self.ICChatFocus)
self.btnHoldIt = buttons.Objections(self, 1) self.btnHoldIt = buttons.Objections(self, 1)
self.btnHoldIt.clicked.connect(self.ICChatFocus) self.btnHoldIt.clicked.connect(self.ICChatFocus)
self.objectSound = 0 self.sndObjection = 0
# Judge buttons # Judge buttons
self.btnDefenseBar = buttons.PenaltyBars(self, 1) self.btnDefenseBar = buttons.PenaltyBars(self, 1)
@ -2480,6 +2482,9 @@ class GUI(QtGui.QWidget):
self.stopMusic() self.stopMusic()
def onMusicItemClicked(self, item): def onMusicItemClicked(self, item):
pass
def onMusicItemDoubleClicked(self, item):
self.userPickedMusicItem = True self.userPickedMusicItem = True
self.sendMC(self.musicList[item.text()]) self.sendMC(self.musicList[item.text()])
@ -3680,31 +3685,32 @@ class GUI(QtGui.QWidget):
charName = str(charName) charName = str(charName)
except: except:
print "WARNING: Can't play objection sound if charName is unicode yet" print "WARNING: Can't play objection sound if charName is unicode yet"
return
if self.objectSound: if self.sndObjection:
if audio.handleIsActive(self.objectSound): if audio.handleIsActive(self.sndObjection):
audio.stopHandle(self.objectSound) audio.stopHandle(self.sndObjection)
audio.freeHandle(self.objectSound) audio.freeHandle(self.sndObjection)
objecting = ["holdit", "objection", "takethat", "custom"][objection-1] objecting = ["holdit", "objection", "takethat", "custom"][objection-1]
if objecting: if objecting:
if exists(AOpath + 'characters/' + charName + '/' + objecting + '.wav'): if exists(AOpath + 'characters/' + charName + '/' + objecting + '.wav'):
self.objectSound = audio.loadHandle(False, AOpath + 'characters/' + charName + '/' + objecting + '.wav', 0, 0, 0) self.sndObjection = audio.loadHandle(False, AOpath + 'characters/' + charName + '/' + objecting + '.wav', 0, 0, 0)
elif exists(AOpath + 'characters/' + charName + '/' + objecting + '.opus'): elif exists(AOpath + 'characters/' + charName + '/' + objecting + '.opus'):
self.objectSound = audio.loadHandle(False, AOpath + 'characters/' + charName + '/' + objecting + '.opus', 0, 0, 0) self.sndObjection = audio.loadHandle(False, AOpath + 'characters/' + charName + '/' + objecting + '.opus', 0, 0, 0)
else: else:
self.objectSound = None self.sndObjection = None
if ini.read_ini_bool("AO2XP.ini", "General", "download sounds", True): if ini.read_ini_bool("AO2XP.ini", "General", "download sounds", True):
thread.start_new_thread(downloadThread, ("base/characters/"+charName+"/"+objecting+".wav", AOpath + "characters/"+charName+"/"+objecting.lower() + ".wav")) thread.start_new_thread(downloadThread, ("base/characters/"+charName+"/"+objecting+".wav", AOpath + "characters/"+charName+"/"+objecting.lower() + ".wav"))
thread.start_new_thread(downloadThread, ("base/characters/"+charName+"/"+objecting+".opus", AOpath + "characters/"+charName+"/"+objecting.lower() + ".wav")) thread.start_new_thread(downloadThread, ("base/characters/"+charName+"/"+objecting+".opus", AOpath + "characters/"+charName+"/"+objecting.lower() + ".wav"))
if exists(AOpath + 'sounds/general/sfx-objection.opus'): if exists(AOpath + 'sounds/general/sfx-objection.opus'):
self.objectSound = audio.loadHandle(False, AOpath + 'sounds/general/sfx-objection.opus', 0, 0, 0) self.sndObjection = audio.loadHandle(False, AOpath + 'sounds/general/sfx-objection.opus', 0, 0, 0)
else: else:
self.objectSound = audio.loadHandle(False, AOpath + 'sounds/general/sfx-objection.wav', 0, 0, 0) self.sndObjection = audio.loadHandle(False, AOpath + 'sounds/general/sfx-objection.wav', 0, 0, 0)
audio.setHandleAttr(self.objectSound, BASS_ATTRIB_VOL, self.sliSoundVolume.value() / 100.0) audio.setHandleAttr(self.sndObjection, BASS_ATTRIB_VOL, self.sliSoundVolume.value() / 100.0)
audio.playHandle(self.objectSound, True) audio.playHandle(self.sndObjection, True)
def playSfx(self): def playSfx(self):
sfxName = self.mChatMessage[SFX] sfxName = self.mChatMessage[SFX]
@ -4204,5 +4210,6 @@ class GUI(QtGui.QWidget):
self.areaItems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "lock.png")) self.areaItems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "lock.png"))
else: else:
self.areaItems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "house.png")) self.areaItems.item(i).setIcon(QtGui.QIcon(AO2XPpath + "icons/" + "house.png"))
except: except Exception as e:
print "[debug] Couldn't update areas" print "[debug] Couldn't update areas. Details:"
print "[debug]", e

View File

@ -25,33 +25,33 @@ class Settings(QtGui.QDialog):
self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint) self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint)
self.hide() self.hide()
main_layout = QtGui.QVBoxLayout(self) layMain = QtGui.QVBoxLayout(self)
save_layout = QtGui.QHBoxLayout() laySave = QtGui.QHBoxLayout()
self.tabs = QtGui.QTabWidget() self.tabs = QtGui.QTabWidget()
self.tabs.resize(320-16, 480-40) self.tabs.resize(320-16, 480-40)
self.tabs.move(8, 8) self.tabs.move(8, 8)
general_tab = QtGui.QWidget() tabGeneral = QtGui.QWidget()
audio_tab = QtGui.QWidget() tabAudio = QtGui.QWidget()
callwords_tab = QtGui.QWidget() tabCallwords = QtGui.QWidget()
general_layout = QtGui.QVBoxLayout(general_tab) layGeneral = QtGui.QVBoxLayout(tabGeneral)
general_layout.setAlignment(QtCore.Qt.AlignTop) layGeneral.setAlignment(QtCore.Qt.AlignTop)
audio_layout = QtGui.QFormLayout(audio_tab) layAudio = QtGui.QFormLayout(tabAudio)
audio_layout.setLabelAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) layAudio.setLabelAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
audio_layout.setFormAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) layAudio.setFormAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
callwords_layout = QtGui.QVBoxLayout(callwords_tab) layCallwords = QtGui.QVBoxLayout(tabCallwords)
callwords_layout.setAlignment(QtCore.Qt.AlignTop) layCallwords.setAlignment(QtCore.Qt.AlignTop)
self.savebtn = QtGui.QPushButton() self.btnSave = QtGui.QPushButton()
self.savebtn.setText("Save") self.btnSave.setText("Save")
self.savebtn.clicked.connect(self.onSaveClicked) self.btnSave.clicked.connect(self.onSaveClicked)
self.cancelbtn = QtGui.QPushButton() self.btnCancel = QtGui.QPushButton()
self.cancelbtn.setText("Cancel") self.btnCancel.setText("Cancel")
self.cancelbtn.clicked.connect(self.onCancelClicked) self.btnCancel.clicked.connect(self.onCancelClicked)
self.aboutbtn = QtGui.QPushButton() self.btnAbout = QtGui.QPushButton()
self.aboutbtn.setText("About...") self.btnAbout.setText("About...")
self.aboutbtn.clicked.connect(self.onAboutClicked) self.btnAbout.clicked.connect(self.onAboutClicked)
separators = [] separators = []
for i in range(5): for i in range(5):
@ -60,279 +60,280 @@ class Settings(QtGui.QDialog):
separators.append(separator) separators.append(separator)
###### General tab ###### ###### General tab ######
defaultoocname_layout = QtGui.QHBoxLayout() layDefaultOOCName = QtGui.QHBoxLayout()
defaultoocname_label = QtGui.QLabel("Default OOC name") lblDefaultOOCName = QtGui.QLabel("Default OOC name")
self.defaultoocname = QtGui.QLineEdit() self.defaultOOCName = QtGui.QLineEdit()
defaultoocname_layout.addWidget(defaultoocname_label) layDefaultOOCName.addWidget(lblDefaultOOCName)
defaultoocname_layout.addWidget(self.defaultoocname) layDefaultOOCName.addWidget(self.defaultOOCName)
defaultshowname_label = QtGui.QLabel("Default showname") lblDefaultShowname = QtGui.QLabel("Default showname")
self.defaultshowname = QtGui.QLineEdit() self.defaultShowname = QtGui.QLineEdit()
defaultoocname_layout.addWidget(defaultshowname_label) layDefaultOOCName.addWidget(lblDefaultShowname)
defaultoocname_layout.addWidget(self.defaultshowname) layDefaultOOCName.addWidget(self.defaultShowname)
savetolog_layout = QtGui.QHBoxLayout() laySaveToLog = QtGui.QHBoxLayout()
self.savetolog = QtGui.QCheckBox() self.cbSaveToLog = QtGui.QCheckBox()
self.savetolog.setText("Save chat logs to a file") self.cbSaveToLog.setText("Save chat logs to a file")
self.savetolog.setChecked(False) self.cbSaveToLog.setChecked(False)
self.savetolog_combine = QtGui.QCheckBox() self.cbCombineLogs = QtGui.QCheckBox()
self.savetolog_combine.setText("Combine OOC and IC chat logs in the same file") self.cbCombineLogs.setText("Combine OOC and IC chat logs in the same file")
self.savetolog_combine.setChecked(False) self.cbCombineLogs.setChecked(False)
savetolog_layout.addWidget(self.savetolog) laySaveToLog.addWidget(self.cbSaveToLog)
savetolog_layout.addWidget(self.savetolog_combine) laySaveToLog.addWidget(self.cbCombineLogs)
savedemos_layout = QtGui.QHBoxLayout() laySaveDemos = QtGui.QHBoxLayout()
self.savedemos = QtGui.QCheckBox() self.cbSaveDemos = QtGui.QCheckBox()
self.savedemos.setText("Record demo files") self.cbSaveDemos.setText("Record demo files")
self.savedemos.setChecked(False) self.cbSaveDemos.setChecked(False)
savedemos_layout.addWidget(self.savedemos) laySaveDemos.addWidget(self.cbSaveDemos)
textstaytime_layout = QtGui.QHBoxLayout() layTextStayTime = QtGui.QHBoxLayout()
textstaytime_label = QtGui.QLabel("Text stay time (milliseconds)") lblTextStayTime = QtGui.QLabel("Text stay time (milliseconds)")
self.textstaytime = QtGui.QSpinBox() self.sbTextStayTime = QtGui.QSpinBox()
self.textstaytime.setMinimum(0) self.sbTextStayTime.setMinimum(0)
self.textstaytime.setMaximum(10000) self.sbTextStayTime.setMaximum(10000)
textstaytime_layout.addWidget(textstaytime_label) layTextStayTime.addWidget(lblTextStayTime)
textstaytime_layout.addWidget(self.textstaytime) layTextStayTime.addWidget(self.sbTextStayTime)
slide_layout = QtGui.QHBoxLayout() laySlide = QtGui.QHBoxLayout()
self.enableslide = QtGui.QCheckBox() self.cbEnableSlide = QtGui.QCheckBox()
self.enableslide.setText("(Experimental) Display courtroom slide (pan-tilt) animations") self.cbEnableSlide.setText("(Experimental) Display courtroom slide (pan-tilt) animations")
self.enableslide.setChecked(True) self.cbEnableSlide.setChecked(True)
slide_layout.addWidget(self.enableslide) laySlide.addWidget(self.cbEnableSlide)
allowdownload = QtGui.QLabel()
allowdownload.setText("Automatically download or stream online from WebAO:")
allowdownload_layout = QtGui.QHBoxLayout()
self.allowdownload_chars = QtGui.QCheckBox("Characters")
self.allowdownload_sounds = QtGui.QCheckBox("Sounds")
self.allowdownload_music = QtGui.QCheckBox("Music")
self.allowdownload_evidence = QtGui.QCheckBox("Evidence")
allowdownload_layout.addWidget(self.allowdownload_chars)
allowdownload_layout.addWidget(self.allowdownload_sounds)
allowdownload_layout.addWidget(self.allowdownload_music)
allowdownload_layout.addWidget(self.allowdownload_evidence)
currtheme_layout = QtGui.QHBoxLayout() layTheme = QtGui.QHBoxLayout()
currtheme_label = QtGui.QLabel("Current theme") lblTheme = QtGui.QLabel("Current theme")
self.currtheme = QtGui.QComboBox() self.cbThemes = QtGui.QComboBox()
self.themes = listdir(AO2XPpath + "ao2xp_themes") self.themes = listdir(AO2XPpath + "ao2xp_themes")
for theme in self.themes: for theme in self.themes:
if exists(AO2XPpath + "ao2xp_themes/"+theme+"/theme.py"): if exists(AO2XPpath + "ao2xp_themes/"+theme+"/theme.py"):
self.currtheme.addItem(theme) self.cbThemes.addItem(theme)
currtheme_layout.addWidget(currtheme_label) layTheme.addWidget(lblTheme)
currtheme_layout.addWidget(self.currtheme) layTheme.addWidget(self.cbThemes)
autoconnect_layout = QtGui.QHBoxLayout() layAutoConnect = QtGui.QHBoxLayout()
autoconnect_label = QtGui.QLabel("Connect automatically to this server") lblAutoConnect = QtGui.QLabel("Connect automatically to this server")
self.autoconnect = QtGui.QComboBox() self.cbServers = QtGui.QComboBox()
layAutoConnect.addWidget(lblAutoConnect)
layAutoConnect.addWidget(self.cbServers)
autopick_layout = QtGui.QHBoxLayout() self.cbServers.addItem("Always show server list")
autopick_label = QtGui.QLabel("Pick this character automatically on join")
self.autopick = QtGui.QComboBox()
for folder in listdir(unicode(AOpath + 'characters')):
if exists(AOpath + 'characters/' + folder + '/char.ini'):
self.autopick.addItem(folder)
self.autopick.setEditable(1)
autopick_layout.addWidget(autopick_label)
autopick_layout.addWidget(self.autopick)
autojoinarea_layout = QtGui.QHBoxLayout()
autojoinarea_label = QtGui.QLabel("Go to this area automatically on join")
self.autojoinarea = QtGui.QLineEdit()
autojoinarea_layout.addWidget(autojoinarea_label)
autojoinarea_layout.addWidget(self.autojoinarea)
self.autoconnect.addItem("Always show server list")
if exists('serverlist.txt'): if exists('serverlist.txt'):
with open('serverlist.txt') as file: with open('serverlist.txt') as file:
for server in [line.rstrip().split(':') for line in file]: for server in [line.rstrip().split(':') for line in file]:
self.autoconnect.addItem(server[-1]) self.cbServers.addItem(server[-1])
autoconnect_layout.addWidget(autoconnect_label)
autoconnect_layout.addWidget(self.autoconnect)
update_layout = QtGui.QHBoxLayout() layAutoPick = QtGui.QHBoxLayout()
self.check_updates = QtGui.QCheckBox("Check for AO2XP updates on startup") lblAutoPick = QtGui.QLabel("Pick this character automatically on join")
self.check_updates_btn = QtGui.QPushButton() self.cbCharacters = QtGui.QComboBox()
self.check_updates_btn.setText("Check now...") for folder in listdir(unicode(AOpath + 'characters')):
self.check_updates_btn.clicked.connect(self.onUpdateClicked) if exists(AOpath + 'characters/' + folder + '/char.ini'):
update_layout.addWidget(self.check_updates) self.cbCharacters.addItem(folder)
update_layout.addWidget(self.check_updates_btn) self.cbCharacters.setEditable(1)
layAutoPick.addWidget(lblAutoPick)
layAutoPick.addWidget(self.cbCharacters)
layAutoJoinArea = QtGui.QHBoxLayout()
lblAutoJoinArea = QtGui.QLabel("Go to this area automatically on join")
self.autoJoinArea = QtGui.QLineEdit()
layAutoJoinArea.addWidget(lblAutoJoinArea)
layAutoJoinArea.addWidget(self.autoJoinArea)
general_layout.addLayout(defaultoocname_layout) lblDownloads = QtGui.QLabel()
general_layout.addLayout(savetolog_layout) lblDownloads.setText("Automatically download or stream online from WebAO:")
general_layout.addLayout(savedemos_layout) layDownloads = QtGui.QHBoxLayout()
general_layout.addWidget(separators[0]) self.cbDownloadChars = QtGui.QCheckBox("Characters")
general_layout.addLayout(textstaytime_layout) self.cbDownloadSounds = QtGui.QCheckBox("Sounds")
general_layout.addLayout(slide_layout) self.cbDownloadMusic = QtGui.QCheckBox("Music")
general_layout.addWidget(separators[1]) self.cbDownloadEvidence = QtGui.QCheckBox("Evidence")
general_layout.addLayout(currtheme_layout) layDownloads.addWidget(self.cbDownloadChars)
general_layout.addLayout(autoconnect_layout) layDownloads.addWidget(self.cbDownloadSounds)
general_layout.addLayout(autopick_layout) layDownloads.addWidget(self.cbDownloadMusic)
general_layout.addLayout(autojoinarea_layout) layDownloads.addWidget(self.cbDownloadEvidence)
general_layout.addWidget(separators[2])
general_layout.addWidget(allowdownload) layUpdate = QtGui.QHBoxLayout()
general_layout.addLayout(allowdownload_layout) self.cbCheckUpdates = QtGui.QCheckBox("Check for AO2XP updates on startup")
general_layout.addWidget(separators[3]) self.btnCheckUpdatesNow = QtGui.QPushButton()
general_layout.addLayout(update_layout) self.btnCheckUpdatesNow.setText("Check now...")
self.btnCheckUpdatesNow.clicked.connect(self.onUpdateClicked)
layUpdate.addWidget(self.cbCheckUpdates)
layUpdate.addWidget(self.btnCheckUpdatesNow)
layGeneral.addLayout(layDefaultOOCName)
layGeneral.addLayout(laySaveToLog)
layGeneral.addLayout(laySaveDemos)
layGeneral.addWidget(separators[0])
layGeneral.addLayout(layTextStayTime)
layGeneral.addLayout(laySlide)
layGeneral.addWidget(separators[1])
layGeneral.addLayout(layTheme)
layGeneral.addLayout(layAutoConnect)
layGeneral.addLayout(layAutoPick)
layGeneral.addLayout(layAutoJoinArea)
layGeneral.addWidget(separators[2])
layGeneral.addWidget(lblDownloads)
layGeneral.addLayout(layDownloads)
layGeneral.addWidget(separators[3])
layGeneral.addLayout(layUpdate)
###### Audio tab ###### ###### Audio tab ######
device_label = QtGui.QLabel("Audio device") lblAudioDevice = QtGui.QLabel("Audio device")
self.device_list = QtGui.QComboBox() self.cbDevices = QtGui.QComboBox()
audio_layout.setWidget(0, QtGui.QFormLayout.LabelRole, device_label) layAudio.setWidget(0, QtGui.QFormLayout.LabelRole, lblAudioDevice)
audio_layout.setWidget(0, QtGui.QFormLayout.FieldRole, self.device_list) layAudio.setWidget(0, QtGui.QFormLayout.FieldRole, self.cbDevices)
audio_layout.setWidget(1, QtGui.QFormLayout.FieldRole, separators[4]) layAudio.setWidget(1, QtGui.QFormLayout.FieldRole, separators[4])
volumelabel = QtGui.QLabel("Sound volume") lblMusicVolume = QtGui.QLabel("Music")
musiclabel = QtGui.QLabel("Music") lblSoundVolume = QtGui.QLabel("Sounds")
soundlabel = QtGui.QLabel("Sounds") lblBlipsVolume = QtGui.QLabel("Blips")
bliplabel = QtGui.QLabel("Blips")
self.sliMusicVolume = QtGui.QSlider(QtCore.Qt.Horizontal, self) self.sliMusicVolume = QtGui.QSlider(QtCore.Qt.Horizontal, self)
self.sliSoundVolume = QtGui.QSlider(QtCore.Qt.Horizontal, self) self.sliSoundVolume = QtGui.QSlider(QtCore.Qt.Horizontal, self)
self.sliBlipsVolume = QtGui.QSlider(QtCore.Qt.Horizontal, self) self.sliBlipsVolume = QtGui.QSlider(QtCore.Qt.Horizontal, self)
self.sliMusicVolume.setRange(0, 100) self.sliMusicVolume.setRange(0, 100)
self.sliSoundVolume.setRange(0, 100) self.sliSoundVolume.setRange(0, 100)
self.sliBlipsVolume.setRange(0, 100) self.sliBlipsVolume.setRange(0, 100)
audio_layout.setWidget(2, QtGui.QFormLayout.LabelRole, musiclabel) layAudio.setWidget(2, QtGui.QFormLayout.LabelRole, lblMusicVolume)
audio_layout.setWidget(2, QtGui.QFormLayout.FieldRole, self.sliMusicVolume) layAudio.setWidget(2, QtGui.QFormLayout.FieldRole, self.sliMusicVolume)
audio_layout.setWidget(3, QtGui.QFormLayout.LabelRole, soundlabel) layAudio.setWidget(3, QtGui.QFormLayout.LabelRole, lblSoundVolume)
audio_layout.setWidget(3, QtGui.QFormLayout.FieldRole, self.sliSoundVolume) layAudio.setWidget(3, QtGui.QFormLayout.FieldRole, self.sliSoundVolume)
audio_layout.setWidget(4, QtGui.QFormLayout.LabelRole, bliplabel) layAudio.setWidget(4, QtGui.QFormLayout.LabelRole, lblBlipsVolume)
audio_layout.setWidget(4, QtGui.QFormLayout.FieldRole, self.sliBlipsVolume) layAudio.setWidget(4, QtGui.QFormLayout.FieldRole, self.sliBlipsVolume)
self.reloadaudio = QtGui.QPushButton(text="Reload audio system") self.btnReloadAudioSystem = QtGui.QPushButton(text="Reload audio system")
self.reloadaudio.clicked.connect(self.onReloadAudio) self.btnReloadAudioSystem.clicked.connect(self.onReloadAudioSystemClicked)
audio_layout.setWidget(5, QtGui.QFormLayout.FieldRole, self.reloadaudio) layAudio.setWidget(5, QtGui.QFormLayout.FieldRole, self.btnReloadAudioSystem)
for device in audio.getDevices(): for device in audio.getDevices():
self.device_list.addItem(device) self.cbDevices.addItem(device)
###### Callwords tab ###### ###### Callwords tab ######
self.callwords_edit = QtGui.QTextEdit() self.callwords = QtGui.QTextEdit()
callwords_wordwrap = QtGui.QCheckBox("Word Wrap") cbCallwordsWordWrap = QtGui.QCheckBox("Word Wrap")
callwords_wordwrap.setChecked(True) cbCallwordsWordWrap.setChecked(True)
callwords_wordwrap.stateChanged.connect(self.callwordsWordWrapCheckbox) cbCallwordsWordWrap.stateChanged.connect(self.callwordsWordWrapCheckbox)
callwords_instructions = QtGui.QLabel() cbCallwordsInstructions = QtGui.QLabel()
callwords_instructions.setText("Separate callwords with newlines (ENTER key).") cbCallwordsInstructions.setText("Separate callwords with newlines (ENTER key).")
callwords_layout.addWidget(self.callwords_edit) layCallwords.addWidget(self.callwords)
callwords_layout.addWidget(callwords_wordwrap, 0, QtCore.Qt.AlignRight) layCallwords.addWidget(cbCallwordsWordWrap, 0, QtCore.Qt.AlignRight)
callwords_layout.addWidget(callwords_instructions) layCallwords.addWidget(cbCallwordsInstructions)
self.tabs.addTab(general_tab, "General") ### Main settings window
self.tabs.addTab(audio_tab, "Audio")
self.tabs.addTab(callwords_tab, "Callwords")
save_layout.addWidget(self.savebtn, 100, QtCore.Qt.AlignRight) self.tabs.addTab(tabGeneral, "General")
save_layout.addWidget(self.cancelbtn, 0, QtCore.Qt.AlignRight) self.tabs.addTab(tabAudio, "Audio")
save_layout.addWidget(self.aboutbtn, 0, QtCore.Qt.AlignLeft) self.tabs.addTab(tabCallwords, "Callwords")
main_layout.addWidget(self.tabs)
main_layout.addLayout(save_layout)
self.savebtn.setFocus() laySave.addWidget(self.btnSave, 100, QtCore.Qt.AlignRight)
laySave.addWidget(self.btnCancel, 0, QtCore.Qt.AlignRight)
laySave.addWidget(self.btnAbout, 0, QtCore.Qt.AlignLeft)
layMain.addWidget(self.tabs)
layMain.addLayout(laySave)
# If they're different from the respective checkbox on save, tell the gui to start/stop logging self.btnSave.setFocus()
self.savelogs_state = False
self.combinelogs_state = False # If they're different from the respective checkbox on save, tell the
self.savedemos_state = False # gui to start/stop logging
self.theme_state = "" self.saveLogsState = False
self.combineLogsState = False
self.saveDemosState = False
self.themeState = ""
def showSettings(self): def showSettings(self):
if exists("AO2XP.ini"): if exists("AO2XP.ini"):
self.inifile.read("AO2XP.ini") self.inifile.read("AO2XP.ini")
self.savetolog.setChecked(ini.read_ini_bool(self.inifile, "General", "save logs", False)) self.cbSaveToLog.setChecked(ini.read_ini_bool(self.inifile, "General", "save logs", False))
self.savetolog_combine.setChecked(ini.read_ini_bool(self.inifile, "General", "combined logs", False)) self.cbCombineLogs.setChecked(ini.read_ini_bool(self.inifile, "General", "combined logs", False))
self.savedemos.setChecked(ini.read_ini_bool(self.inifile, "General", "record demos", False)) self.cbSaveDemos.setChecked(ini.read_ini_bool(self.inifile, "General", "record demos", False))
try: try:
self.defaultoocname.setText(ini.read_ini(self.inifile, "General", "OOC name").decode("utf-8")) self.defaultOOCName.setText(ini.read_ini(self.inifile, "General", "OOC name").decode("utf-8"))
except: except:
self.defaultoocname.setText(ini.read_ini(self.inifile, "General", "OOC name")) self.defaultOOCName.setText(ini.read_ini(self.inifile, "General", "OOC name"))
try: try:
self.defaultshowname.setText(ini.read_ini(self.inifile, "General", "showname").decode("utf-8")) self.defaultShowname.setText(ini.read_ini(self.inifile, "General", "showname").decode("utf-8"))
except: except:
self.defaultshowname.setText(ini.read_ini(self.inifile, "General", "showname")) self.defaultShowname.setText(ini.read_ini(self.inifile, "General", "showname"))
self.enableslide.setChecked(ini.read_ini_bool(self.inifile, "General", "slide", False)) self.cbEnableSlide.setChecked(ini.read_ini_bool(self.inifile, "General", "slide", False))
self.allowdownload_chars.setChecked(ini.read_ini_bool(self.inifile, "General", "download characters", False)) self.cbDownloadChars.setChecked(ini.read_ini_bool(self.inifile, "General", "download characters", False))
self.allowdownload_sounds.setChecked(ini.read_ini_bool(self.inifile, "General", "download sounds", False)) self.cbDownloadSounds.setChecked(ini.read_ini_bool(self.inifile, "General", "download sounds", False))
self.allowdownload_music.setChecked(ini.read_ini_bool(self.inifile, "General", "download music")) self.cbDownloadMusic.setChecked(ini.read_ini_bool(self.inifile, "General", "download music"))
self.allowdownload_evidence.setChecked(ini.read_ini_bool(self.inifile, "General", "download evidence", False)) self.cbDownloadEvidence.setChecked(ini.read_ini_bool(self.inifile, "General", "download evidence", False))
self.currtheme.setCurrentIndex(self.themes.index(ini.read_ini(self.inifile, "General", "theme", "default"))) self.cbThemes.setCurrentIndex(self.themes.index(ini.read_ini(self.inifile, "General", "theme", "default")))
self.autoconnect.setCurrentIndex(ini.read_ini_int(self.inifile, "General", "auto connect", -1) + 1) self.cbServers.setCurrentIndex(ini.read_ini_int(self.inifile, "General", "auto connect", -1) + 1)
self.autopick.setEditText(ini.read_ini(self.inifile, "General", "auto pick").decode('utf-8')) self.cbCharacters.setEditText(ini.read_ini(self.inifile, "General", "auto pick").decode('utf-8'))
self.autojoinarea.setText(ini.read_ini(self.inifile, "General", "auto join area").decode('utf-8')) self.autoJoinArea.setText(ini.read_ini(self.inifile, "General", "auto join area").decode('utf-8'))
self.textstaytime.setValue(ini.read_ini_int(self.inifile, "General", "text stay time", 200)) self.sbTextStayTime.setValue(ini.read_ini_int(self.inifile, "General", "text stay time", 200))
self.check_updates.setChecked(ini.read_ini_bool(self.inifile, "General", "install updates", False)) # Automatic updates are opt-in! self.cbCheckUpdates.setChecked(ini.read_ini_bool(self.inifile, "General", "install updates", False)) # Automatic updates are opt-in!
self.device_list.setCurrentIndex(ini.read_ini_int(self.inifile, "Audio", "device", audio.getCurrDevice())) self.cbDevices.setCurrentIndex(ini.read_ini_int(self.inifile, "Audio", "device", audio.getCurrDevice()))
self.sliMusicVolume.setValue(ini.read_ini_int(self.inifile, "Audio", "Music volume", 100)) self.sliMusicVolume.setValue(ini.read_ini_int(self.inifile, "Audio", "Music volume", 100))
self.sliSoundVolume.setValue(ini.read_ini_int(self.inifile, "Audio", "Sound volume", 100)) self.sliSoundVolume.setValue(ini.read_ini_int(self.inifile, "Audio", "Sound volume", 100))
self.sliBlipsVolume.setValue(ini.read_ini_int(self.inifile, "Audio", "Blip volume", 100)) self.sliBlipsVolume.setValue(ini.read_ini_int(self.inifile, "Audio", "Blip volume", 100))
else: else:
self.savetolog.setChecked(False) self.cbSaveToLog.setChecked(False)
self.savetolog_combine.setChecked(False) self.cbCombineLogs.setChecked(False)
self.savedemos.setChecked(False) self.cbSaveDemos.setChecked(False)
self.defaultoocname.setText("") self.defaultOOCName.setText("")
self.defaultshowname.setText("") self.defaultShowname.setText("")
self.enableslide.setChecked(False) self.cbEnableSlide.setChecked(False)
self.allowdownload_sounds.setChecked(True) self.cbDownloadSounds.setChecked(True)
self.allowdownload_music.setChecked(True) self.cbDownloadMusic.setChecked(True)
self.allowdownload_evidence.setChecked(True) self.cbDownloadEvidence.setChecked(True)
self.currtheme.setCurrentIndex(self.themes.index("default")) self.cbThemes.setCurrentIndex(self.themes.index("default"))
self.check_updates.setChecked(False) self.cbCheckUpdates.setChecked(False)
self.textstaytime.setValue(200) self.sbTextStayTime.setValue(200)
self.autopick.setEditText("") self.cbCharacters.setEditText("")
self.autojoinarea.setText("") self.autoJoinArea.setText("")
self.device_list.setCurrentIndex(audio.getCurrDevice()) self.cbDevices.setCurrentIndex(audio.getCurrDevice())
self.sliMusicVolume.setValue(100) self.sliMusicVolume.setValue(100)
self.sliSoundVolume.setValue(100) self.sliSoundVolume.setValue(100)
self.sliBlipsVolume.setValue(100) self.sliBlipsVolume.setValue(100)
self.callwords_edit.clear() self.callwords.clear()
if exists(AO2XPpath + "callwords.ini"): if exists(AO2XPpath + "callwords.ini"):
with open(AO2XPpath + "callwords.ini") as f: with open(AO2XPpath + "callwords.ini") as f:
for line in f: for line in f:
self.callwords_edit.append(line.rstrip().decode("utf-8")) self.callwords.append(line.rstrip().decode("utf-8"))
self.savelogs_state = self.savetolog.isChecked() self.saveLogsState = self.cbSaveToLog.isChecked()
self.combinelogs_state = self.savetolog_combine.isChecked() self.combineLogsState = self.cbCombineLogs.isChecked()
self.savedemos_state = self.savedemos.isChecked() self.saveDemosState = self.cbSaveDemos.isChecked()
self.theme_state = self.currtheme.currentText() self.themeState = self.cbThemes.currentText()
self.tabs.setCurrentIndex(0) self.tabs.setCurrentIndex(0)
self.show() self.show()
def callwordsWordWrapCheckbox(self, newstate): def callwordsWordWrapCheckbox(self, newstate):
if newstate: if newstate:
self.callwords_edit.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere) self.callwords.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere)
else: else:
self.callwords_edit.setWordWrapMode(0) self.callwords.setWordWrapMode(0)
def onSaveClicked(self): def onSaveClicked(self):
if not self.inifile.has_section("General"): self.inifile.add_section("General") if not self.inifile.has_section("General"): self.inifile.add_section("General")
if not self.inifile.has_section("Audio"): self.inifile.add_section("Audio") if not self.inifile.has_section("Audio"): self.inifile.add_section("Audio")
self.inifile.set("General", "save logs", self.savetolog.isChecked()) self.inifile.set("General", "save logs", self.cbSaveToLog.isChecked())
self.inifile.set("General", "combined logs", self.savetolog_combine.isChecked()) self.inifile.set("General", "combined logs", self.cbCombineLogs.isChecked())
self.inifile.set("General", "record demos", self.savedemos.isChecked()) self.inifile.set("General", "record demos", self.cbSaveDemos.isChecked())
self.inifile.set("General", "OOC name", self.defaultoocname.text().toUtf8()) self.inifile.set("General", "OOC name", self.defaultOOCName.text().toUtf8())
self.inifile.set("General", "showname", self.defaultshowname.text().toUtf8()) self.inifile.set("General", "showname", self.defaultShowname.text().toUtf8())
self.inifile.set("General", "text stay time", self.textstaytime.value()) self.inifile.set("General", "text stay time", self.sbTextStayTime.value())
self.inifile.set("General", "slide", self.enableslide.isChecked()) self.inifile.set("General", "slide", self.cbEnableSlide.isChecked())
self.inifile.set("General", "download characters", self.allowdownload_chars.isChecked()) self.inifile.set("General", "download characters", self.cbDownloadChars.isChecked())
self.inifile.set("General", "download sounds", self.allowdownload_sounds.isChecked()) self.inifile.set("General", "download sounds", self.cbDownloadSounds.isChecked())
self.inifile.set("General", "download music", self.allowdownload_music.isChecked()) self.inifile.set("General", "download music", self.cbDownloadMusic.isChecked())
self.inifile.set("General", "download evidence", self.allowdownload_evidence.isChecked()) self.inifile.set("General", "download evidence", self.cbDownloadEvidence.isChecked())
self.inifile.set("General", "theme", self.currtheme.currentText()) self.inifile.set("General", "theme", self.cbThemes.currentText())
self.inifile.set("General", "auto connect", self.autoconnect.currentIndex() - 1) self.inifile.set("General", "auto connect", self.cbServers.currentIndex() - 1)
self.inifile.set("General", "auto pick", self.autopick.currentText().toUtf8()) self.inifile.set("General", "auto pick", self.cbCharacters.currentText().toUtf8())
self.inifile.set("General", "auto join area", self.autojoinarea.text().toUtf8()) self.inifile.set("General", "auto join area", self.autoJoinArea.text().toUtf8())
self.inifile.set("General", "install updates", self.check_updates.isChecked()) self.inifile.set("General", "install updates", self.cbCheckUpdates.isChecked())
self.inifile.set("Audio", "device", self.device_list.currentIndex()) self.inifile.set("Audio", "device", self.cbDevices.currentIndex())
self.inifile.set("Audio", "Music volume", self.sliMusicVolume.value()) self.inifile.set("Audio", "Music volume", self.sliMusicVolume.value())
self.inifile.set("Audio", "Sound volume", self.sliSoundVolume.value()) self.inifile.set("Audio", "Sound volume", self.sliSoundVolume.value())
self.inifile.set("Audio", "Blip volume", self.sliBlipsVolume.value()) self.inifile.set("Audio", "Blip volume", self.sliBlipsVolume.value())
@ -341,27 +342,27 @@ class Settings(QtGui.QDialog):
self.inifile.write(f) self.inifile.write(f)
with open(AO2XPpath + "callwords.ini", "w") as f: with open(AO2XPpath + "callwords.ini", "w") as f:
f.write(self.callwords_edit.toPlainText().toUtf8()) f.write(self.callwords.toPlainText().toUtf8())
self.gamewindow.gamewidget.textWaitTime = self.textstaytime.value() self.gamewindow.gamewidget.textWaitTime = self.sbTextStayTime.value()
slideEnabled = self.enableslide.isChecked() slideEnabled = self.cbEnableSlide.isChecked()
self.gamewindow.gamewidget.slideEnabled = slideEnabled self.gamewindow.gamewidget.slideEnabled = slideEnabled
self.gamewindow.gamewidget.cbSlide.setEnabled(slideEnabled) self.gamewindow.gamewidget.cbSlide.setEnabled(slideEnabled)
if not slideEnabled: if not slideEnabled:
self.gamewindow.gamewidget.cbSlide.setChecked(False) self.gamewindow.gamewidget.cbSlide.setChecked(False)
if not self.theme_state == self.currtheme.currentText(): if not self.themeState == self.cbThemes.currentText():
self.gamewindow.gamewidget.loadTheme(True) self.gamewindow.gamewidget.loadTheme(True)
if not self.gamewindow.gamewidget.demoPlaying: if not self.gamewindow.gamewidget.demoPlaying:
if not (self.savelogs_state == self.savetolog.isChecked() and self.combinelogs_state == self.savetolog_combine.isChecked()): if not (self.saveLogsState == self.cbSaveToLog.isChecked() and self.combineLogsState == self.cbCombineLogs.isChecked()):
self.gamewindow.gamewidget.OOCLog.setLogFiles() self.gamewindow.gamewidget.OOCLog.setLogFiles()
self.gamewindow.gamewidget.ICLog.setLogFiles(self.gamewindow.gamewidget.OOCLog.logfile) self.gamewindow.gamewidget.ICLog.setLogFiles(self.gamewindow.gamewidget.OOCLog.logfile)
if not self.savedemos_state == self.savedemos.isChecked(): if not self.saveDemosState == self.cbSaveDemos.isChecked():
if self.savedemos.isChecked(): if self.cbSaveDemos.isChecked():
self.gamewindow.gamewidget.startDemoRecorder() self.gamewindow.gamewidget.startDemoRecorder()
else: else:
self.gamewindow.gamewidget.demoRecorder = None self.gamewindow.gamewidget.demoRecorder = None
@ -380,10 +381,8 @@ class Settings(QtGui.QDialog):
if code == 0: if code == 0:
subprocess.Popen(["./AO2XPupdat"]) subprocess.Popen(["./AO2XPupdat"])
_exit(0) _exit(0)
#elif osname == "Darwin": # bundle
# os.chdir(Cocoa.NSBundle.mainBundle().resourcePath()) # return to Resources folder
def onReloadAudio(self): def onReloadAudioSystemClicked(self):
audio.free() audio.free()
audio.init() audio.init()
print "[audio] Reloaded audio system" print "[audio] Reloaded audio system"