123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- # $Id$
- from PyQt4 import QtCore, QtGui
- from PyQt4.QtGui import QColor
- from qt_utils import connect
- class Cheatfinder(object):
- def __init__(self, bridge):
- self.__cfDialog = None
- self.__ui = None
- self.__bridge = bridge
- def show(self):
- dialog = self.__cfDialog
- if dialog is None:
- self.__cfDialog = dialog = QtGui.QDialog(
- None, # TODO: find a way to get the real parent
- QtCore.Qt.Dialog
- | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowSystemMenuHint
- )
- # Setup UI made in Qt Designer.
- from ui_cheatfinder import Ui_cheatFinder
- ui = Ui_cheatFinder()
- ui.setupUi(dialog)
- self.__ui = ui
- # Connect signals.
- connect(ui.FindCheatLess, 'clicked()', self.__findCheatLess)
- connect(ui.FindCheatLessEqual, 'clicked()',
- self.__findCheatLessEqual)
- connect(ui.FindCheatEqual, 'clicked()', self.__findCheatEqual)
- connect(ui.FindCheatNotEqual, 'clicked()', self.__findCheatNotEqual)
- connect(ui.FindCheatMoreEqual, 'clicked()',
- self.__findCheatMoreEqual)
- connect(ui.FindCheatMore, 'clicked()', self.__findCheatMore)
- connect(ui.FindCheatRestart, 'clicked()', self.__findCheatRestart)
- connect(ui.FindCheatValue, 'clicked()', self.__findCheatValue)
- connect(ui.EmulationTogglePause, 'clicked()',
- self.__emulationTogglePause)
- connect(ui.EmulationReset, 'clicked()', self.__emulationReset)
- connect(ui.rbCompare, 'clicked()', self.__disableDirectSearch)
- connect(ui.rbSearch, 'clicked()', self.__disableCompareSearch)
- dialog.show()
- dialog.raise_()
- dialog.activateWindow()
- self.__ui.CheatTable.verticalHeader().hide()
- self.__ui.CheatTable.horizontalHeader().setResizeMode(
- QtGui.QHeaderView.Stretch
- )
- def __disableDirectSearch(self):
- self.__ui.FindCheatValue.setEnabled(False)
- self.__ui.cheatVal.setEnabled(False)
- self.__ui.FindCheatLess.setEnabled(True)
- self.__ui.FindCheatLessEqual.setEnabled(True)
- self.__ui.FindCheatNotEqual.setEnabled(True)
- self.__ui.FindCheatEqual.setEnabled(True)
- self.__ui.FindCheatMoreEqual.setEnabled(True)
- self.__ui.FindCheatMore.setEnabled(True)
- def __disableCompareSearch(self):
- self.__ui.FindCheatValue.setEnabled(True)
- self.__ui.cheatVal.setEnabled(True)
- self.__ui.FindCheatLess.setEnabled(False)
- self.__ui.FindCheatLessEqual.setEnabled(False)
- self.__ui.FindCheatNotEqual.setEnabled(False)
- self.__ui.FindCheatEqual.setEnabled(False)
- self.__ui.FindCheatMoreEqual.setEnabled(False)
- self.__ui.FindCheatMore.setEnabled(False)
- def __emulationTogglePause(self):
- self.__bridge.command('toggle', 'pause')()
- def __emulationReset(self):
- self.__ui.FindCheatRestart.setEnabled(False)
- self.__bridge.command('reset')(self.__cheatListReply)
- def __findCheatLess(self):
- self.__ui.FindCheatRestart.setEnabled(False)
- self.__ui.cheatResults.append('Less')
- self.__bridge.command('findcheat', 'less')(self.__cheatListReply)
- def __findCheatLessEqual(self):
- self.__ui.FindCheatRestart.setEnabled(False)
- self.__ui.cheatResults.append('Less Or Equal')
- self.__bridge.command('findcheat', 'loe')(self.__cheatListReply)
- def __findCheatEqual(self):
- self.__ui.FindCheatRestart.setEnabled(False)
- self.__ui.cheatResults.append('Equal')
- self.__bridge.command('findcheat', 'equal')(self.__cheatListReply)
- def __findCheatNotEqual(self):
- self.__ui.FindCheatRestart.setEnabled(False)
- self.__ui.cheatResults.append('Search Not Equal')
- self.__bridge.command('findcheat', 'notequal')(self.__cheatListReply)
- def __findCheatMoreEqual(self):
- self.__ui.FindCheatRestart.setEnabled(False)
- self.__ui.cheatResults.append('Search More Or Equal')
- self.__bridge.command('findcheat', 'moe')(self.__cheatListReply)
- def __findCheatMore(self):
- self.__ui.FindCheatRestart.setEnabled(False)
- self.__ui.cheatResults.append('Search More')
- self.__bridge.command('findcheat', 'more')(self.__cheatListReply)
- def __findCheatRestart(self):
- cheatValue = self.__ui.cheatVal.text()
- self.__ui.FindCheatRestart.setEnabled(False)
- if len(cheatValue)<1:
- msgText = 'Start New Search:'
- else:
- msgText = 'Start New Search Equal To: ' + str(cheatValue)
- self.__ui.cheatResults.append(msgText)
- self.__bridge.command('findcheat', '-start', cheatValue)(
- self.__cheatListReply
- )
- def __findCheatValue(self):
- cheatValue = self.__ui.cheatVal.text()
- self.__ui.cheatResults.append('Searching For: ' + str(cheatValue))
- self.__bridge.command('findcheat', cheatValue)(self.__cheatListReply)
- def __cheatListReply(self, *words):
- line = ' '.join(words)
- text = self.__ui.cheatResults
- color = QColor()
- color.setRgb(0, 0, 255)
- text.setTextColor(color)
- # Check if no results are found (clear table and display message).
- if line == 'No results left':
- color = QColor()
- color.setRgb(255, 0, 0)
- text.setTextColor(color)
- text.append(line)
- else:
- if line.find('results') > 1:
- text.append(line)
- # Check if results are found.
- if line.find('results') < 1:
- # Format output to be put into an array.
- line = line.replace('->', ' ')
- line = line.replace(':', ' ')
- line = line.replace(' ', ' ')
- line = line.replace(' ', ';')
- line = line.replace(';;', ';')
- # Put resultset into array.
- cheatArray = line.split('\n')
- # Create the table to be filled, disable sorting and set grid size.
- self.__ui.CheatTable.setRowCount( len(cheatArray) - 1 )
- self.__ui.CheatTable.setSortingEnabled(0)
- self.__ui.CheatTable.verticalHeader().setResizeMode(
- QtGui.QHeaderView.ResizeToContents
- )
- row = 0
- for cheatLine in cheatArray[ : -1]:
- # Create sub array.
- cheatVal = cheatLine.split(';')
- # Fill address value item.
- addrItem = QtGui.QTableWidgetItem(cheatVal[0])
- addrItem.setFlags(
- QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
- )
- self.__ui.CheatTable.setItem(row, 0, addrItem)
- # Fill old value item.
- oldValItem = QtGui.QTableWidgetItem(
- cheatVal[1] + ' / ' + hex(int(cheatVal[1]))
- )
- oldValItem.setFlags(
- QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
- )
- self.__ui.CheatTable.setItem(row, 1, oldValItem)
- # Fill new value item.
- newValItem = QtGui.QTableWidgetItem(
- cheatVal[2] + ' / ' + hex(int(cheatVal[2]))
- )
- newValItem.setFlags(
- QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
- )
- self.__ui.CheatTable.setItem(row, 2, newValItem)
- row += 1
- text.append(str(row) + ' results found -> Displayed in table')
- # Enable sorting.
- self.__ui.CheatTable.setSortingEnabled(1)
- # Enable search button again.
- color = QColor()
- color.setRgb(0, 0, 0)
- text.setTextColor(color)
- self.__ui.FindCheatRestart.setEnabled(True)
|