def test23_load(self): """Test method load(save_name)""" clear() touch(1,1) touch(2,2) save("unittestsave") oplisttest = load("unittestsave") opright1 = Operation('touch', ((1,1),), 1, 1.0, 0, 0, 0) opright2 = Operation('touch', ((2,2),), 1, 1.0, 0, 0, 0) optest1 = oplisttest[0] optest2 = oplisttest[1] self.assertEqual(opright1.optype, optest1.optype) self.assertTupleEqual(opright1.pointlist, optest1.pointlist) self.assertEqual(opright1.number, optest1.number) self.assertEqual(opright1.interval_time, optest1.interval_time) self.assertEqual(opright1.hold_time, optest1.hold_time) self.assertEqual(opright1.keyorstring, optest1.keyorstring) self.assertEqual(opright1.wait_time, optest1.wait_time) self.assertEqual(opright2.optype, optest2.optype) self.assertTupleEqual(opright2.pointlist, optest2.pointlist) self.assertEqual(opright2.number, optest2.number) self.assertEqual(opright2.interval_time, optest2.interval_time) self.assertEqual(opright2.hold_time, optest2.hold_time) self.assertEqual(opright2.keyorstring, optest2.keyorstring) self.assertEqual(opright2.wait_time, optest2.wait_time)
def dedicated_server_layer1(dsl1_socket): global values, name, close while True: new_values = dsl1_socket.recv(1024).decode() if new_values == "": close = True return values = {int(k): int(v) for k, v in json.loads(new_values).items()} Op.add_log("Logs/" + name + ".txt", values)
def dedicated_server_core_layer(dscl_socket): global values, mutex, close, name while True: new_values = dscl_socket.recv(1024).decode() if new_values == "": close = True return mutex.acquire() values = {int(k): int(v) for k, v in json.loads(new_values).items()} Op.add_log("Logs/" + name + ".txt", values) mutex.release()
def update_layer1_node(): global update_counter, layer1_node, values, last_op # Cada vegada que cridem la funció, vol dir que s'ha executat una nova escriptura update_counter += 1 Op.add_log("Logs/" + name + ".txt", values) if layer1_node is not None and 10 == update_counter: update_counter = 0 json_dict = json.dumps(values) layer1_node.send(json_dict.encode()) elif 10 == update_counter: update_counter = 0
def touch_drag(pointlist, touch_time=1.0, drag_time=1.0, touch_number=1, interval_time=1.0): """长按滑动测试 参数 ----------- pointlist : ((x1,y1),(x2,y2)) x,y均为int 按住的点和滑动的终点的坐标 touch_time : float 长按的时间,默认为1秒 drag_time : float 滑动的时间, 默认为1秒 touch_number : int 长按滑动的次数 interval_time : float 两次动作的间隔时间 """ op = Operation('touch_drag', pointlist, touch_number, interval_time, drag_time, 0, touch_time) oplist.append(op) allrandomlist.append(op) __writelog(__now() + "touch_drag test add success") return op
def multi_drag(pointlist, loop_number=1, interval_time=1.0, drag_time=1.0, loop_time=1.0): """多位置滑动测试 参数 --------------- pointlist : ((startx1,starty1,endx1,endy1),(startx2,starty2,endx2,endy2)...),均为int 多个(起点,终点)位置的坐标 loop_number : int 滑动的遍数,默认为1 interval_time : float 两次滑动的间隔时间,默认为1秒 drag_time : float 每次滑动的持续时间,默认为1秒 loop_time : float 两遍滑动的间隔时间,默认为1秒 """ op = Operation('multi_drag', pointlist, loop_number, interval_time, drag_time, 0, loop_time) oplist.append(op) __writelog(__now() + "multi_drag add success") return op
def long_touch(pos_x, pos_y, touch_time=1.0, touch_number=1, interval_time=1.0): """长按测试 参数 ----------- pos_x : int 点击的位置x pos_y : int 点击的位置y touch_time: float 按住的时间,默认为1秒 touch_number : int 长按的次数 interval_time : float 每次长按间隔的时间 """ op = Operation('long_touch', ((pos_x, pos_y), ), touch_number, interval_time, touch_time, 0, 0) oplist.append(op) allrandomlist.append(op) __writelog(__now() + "long_touch test add success") return op
def dedicated_server_client(dsc_socket): global update_counter, last_op, values, first_iteration global mutex, blocked, close transaction = dsc_socket.recv(1024).decode() if transaction == "": dsc_socket.close() close = True return operations = Op.parse_transaction(transaction) print("NOVA TRANSACCIó DETECTADA!") for op in operations: if op.type is 'r': string = "INDEX -> [" + str(op.index) \ + "]; VALUE -> [" + str(values.get(int(op.index), "POSICIÓ BUIDA")) + "]" dsc_socket.send(string.encode()) time.sleep(0.3) else: # Bloquejem Lock() if first_iteration is True: first_iteration = False blocked.acquire() # Processem a la vegada que enviem l'operació d'escriptura als nodes veïns (active replication) values[op.index] = op.value last_op = op.to_string() # Enviem l'operació als nodes veïns mutex.release() blocked.acquire() dsc_socket.send("ACK".encode()) dsc_socket.close()
def load(save_name): """读取存档 参数 ----------- save_name : string 存档的名字 返回值 ----------- bool : True 读取成功 False 读取失败 """ try: __clear() # 清空当前oplist f = open(save_name + '.save', 'r') data = f.readline() while data: data = eval(data) op = Operation(data['optype'], data['pointlist'], data['number'], data['interval_time'], data['hold_time'], data['keyorstring'], data['wait_time']) oplist.append(op) data = f.readline() f.close() __writelog(__now() + save_name + " load success") except: f.close() __writelog(_now() + save_name + " load fail") return False
def main(): cpte = Account("BNC", 500) print("Compte :", cpte.name) ope = Operation("29-12-2019", "DEP", "EPICERIE", -25) #ope.print_operation() cpte.add_operation(ope) bal = cpte.get_balance() print(bal)
def typestr(typestring): """键盘输入测试 参数 ------- typestring : string 要输入的字符串 """ op = Operation('typestr', None, 0, 0, 0, typestring, 0) oplist.append(op) __writelog(__now() + "typestr test add success")
def test13b_typestr(self): """Test method typestr(typestring)""" opright = Operation('typestr', None, 0, 0, 0, "", 0) optest = typestr("") self.assertEqual(opright.optype, optest.optype) self.assertIsNone(optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def wait(wait_time): """等待 参数 ------ wait_time : float 要等待的时间 """ op = Operation('wait', None, 0, 0, 0, 0, wait_time) oplist.append(op) __writelog(__now() + "wait test add success")
def test07a_random_touch(self): """Test method random_touch(pointlist, touch_number=1, interval_time=1.0)""" opright = Operation('random_touch', None, 1, 1.0, 0, 0, 0) optest = random_touch(None) self.assertEqual(opright.optype, optest.optype) self.assertIsNone(optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def test05b_long_touch(self): """Test method long_touch(pos_x, pos_y, touch_time=1.0, touch_number=1, interval_time=1.0)""" opright = Operation('long_touch',((200,400),),5,0.5,2.2,0,0) optest = long_touch(200,400,2.2,5,0.5) self.assertEqual(opright.optype, optest.optype) self.assertTupleEqual(opright.pointlist, optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def test14_wait(self): """Test method wait(wait_time)""" opright = Operation('wait', None, 0, 0, 0, 0, 0.5) optest = wait(0.5) self.assertEqual(opright.optype, optest.optype) self.assertIsNone(optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def press(key_name): """按键测试 参数 ----------- key_name : string 按键的名字 """ op = Operation('press', None, 0, 0, 0, key_name, 0) oplist.append(op) __writelog(__now() + "press test add success")
def test04a_touch(self): """Test method touch(pos_x, pos_y, touch_number=1, interval_time=1.0)""" opright = Operation('touch', ((100,200),), 1, 1.0, 0, 0, 0) optest = touch(100, 200) self.assertEqual(opright.optype, optest.optype) self.assertTupleEqual(opright.pointlist, optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def test12b_press(self): """Test method press(key_name)""" back = "KEYCODE_BACK" opright = Operation('press', None, 0, 0, 0, "KEYCODE_BACK", 0) optest = press(back) self.assertEqual(opright.optype, optest.optype) self.assertIsNone(optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def test08a_drag(self): """Test method drag(pointlist, drag_time=1.0, drag_number=1, interval_time=1.0)""" pointlist = ((30,40),(50,60)) opright = Operation('drag',pointlist, 1, 1.0, 1.0, 0, 0) optest = drag(pointlist) self.assertEqual(opright.optype, optest.optype) self.assertTupleEqual(opright.pointlist, optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def test07b_random_touch(self): """Test method random_touch(pointlist, touch_number=1, interval_time=1.0)""" pointlist = ((1,1),(300,300)) opright = Operation('random_touch', pointlist, 100, 0.5, 0, 0, 0) optest = random_touch(pointlist, 100, 0.5) self.assertEqual(opright.optype, optest.optype) self.assertTupleEqual(opright.pointlist, optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def dedicated_server_client(dsc_socket): transaction = dsc_socket.recv(1024).decode() operations = Op.parse_transaction(transaction) for op in operations: string = "INDEX -> [" + str(op.index) \ + "]; VALUE -> [" + str(values.get(int(op.index), "POSICIÓ BUIDA")) + "]" dsc_socket.send(string.encode()) time.sleep(0.3) dsc_socket.send("ACK".encode()) dsc_socket.close()
def test11b_touch_drag(self): """Test method touch_drag(pointlist, touch_time=1.0, drag_time=1.0, touch_number=1, interval_time=1.0)""" pointlist = ((303,305),(307,404)) opright = Operation('touch_drag',pointlist, 5, 0.5, 2.0, 0, 1.5) optest = touch_drag(pointlist, 1.5, 2.0, 5, 0.5) self.assertEqual(opright.optype, optest.optype) self.assertTupleEqual(opright.pointlist, optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def test10b_random_drag(self): """Test method random_drag(pointlist, drag_number=1, interval_time=1.0, drag_time=1.0)""" pointlist = ((1,1),(1000,1000)) opright = Operation('random_drag',pointlist, 100, 0.5, 2.0, 0, 0) optest = random_drag(pointlist, 100, 0.5, 2.0) self.assertEqual(opright.optype, optest.optype) self.assertTupleEqual(opright.pointlist, optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def test08b_drag(self): """Test method drag(pointlist, drag_time=1.0, drag_number=1, interval_time=1.0)""" pointlist = ((299,300),(433,60)) opright = Operation('drag',pointlist, 5, 0.1, 2.3, 0, 0) optest = drag(pointlist, 2.3, 5, 0.1) self.assertEqual(opright.optype, optest.optype) self.assertTupleEqual(opright.pointlist, optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def test06b_multi_touch(self): """Test method multi_touch(pointlist, loop_number=1, interval_time = 1.0, loop_time = 1.0)""" pointlist = ((1,1),(222,333),(577,600),(200,2),(300,3),(100,1),(200,2)) opright = Operation('multi_touch',pointlist, 5, 2.0, 0, 0, 0.5) optest = multi_touch(pointlist,5,2.0,0.5) self.assertEqual(opright.optype, optest.optype) self.assertTupleEqual(opright.pointlist, optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def main(): exit = "" operation = Operation(0,0,0,0) while exit != "n": try: execute_operation(operation) except ValueError: print("Invalid Value") except OverflowError: print("Overflow") except ZeroDivisionError: print("Value 2 reached a zero division, so we can't calculate") finally: exit = convert_input_value(str,"\nInsert n to exit, or anything to make another operation\n")
def test09a_multi_drag(self): """Test method multi_drag(pointlist, loop_number=1, interval_time = 1.0, drag_time=1.0, loop_time = 1.0)""" point1 = (1,2,3,4) point2 = (20,30,40,50) point3 = (33,44,77,88) pointlist = (point1,point2,point3) opright = Operation('multi_drag',pointlist, 1, 1.0, 1.0, 0, 1.0) optest = multi_drag(pointlist) self.assertEqual(opright.optype, optest.optype) self.assertTupleEqual(opright.pointlist, optest.pointlist) self.assertEqual(opright.number, optest.number) self.assertEqual(opright.interval_time, optest.interval_time) self.assertEqual(opright.hold_time, optest.hold_time) self.assertEqual(opright.keyorstring, optest.keyorstring) self.assertEqual(opright.wait_time, optest.wait_time)
def random_touch(pointlist, touch_number=1, interval_time=1.0): """随机点击屏幕测试 参数 ----------- pointlist : ((x1,y1),(x2,y2)) x,y均为int 或 None 由两个点围成的矩形为随机的范围 如果传入None 则没有范围,在全屏内随机 touch_number : int 点击的次数 interval_time : float 每两次点击间隔的时间,默认为1秒 """ op = Operation('random_touch', pointlist, touch_number, interval_time, 0, 0, 0) oplist.append(op) __writelog(__now() + "random_touch test add success")
def main(): sair = "" operacao = Operation(0,0,0,0) while sair != "n": try: executa_operacao(operacao) except ValueError: print("Valores invalidos") except OverflowError: print("Estouro de memoria") except ZeroDivisionError: print("Valor 2 resultou em uma divisao em 0, portanto nao sera calculado") finally: sair = trata_entrada(str,"Deseja fazer outra operacao? (n para sair)\n")
def __init__( self, master, title=__TITLE, base=__BASE) : self.__base = base #INITIALIZE THE STACK self.__stack = Stack() #Initialise the Operation class self.__operation = Operation(self.__stack) # Initialise main calculator window. Tk.__init__( self, master ) # Set title. self.title( title ) #Set not resizable self.resizable(0,0) # Save @master@. Not used... self.__master = master # Finish rest of initialisation. self.__initialise( base=base)
class Calculator( Tk ) : # Width of @IOPanel@ in pixels. __IO_PANEL_WIDTH = 200 # Height of @IOPanel@ in pixels. __IO_PANEL_HEIGHT = 50 # Row number of @IOPanel@ in grid layout of the calculator. __IO_PANEL_ROW = 0 # Column number of @IOPanel@ in grid layout of the calculator. __IO_PANEL_COL = 0 # Span of @IOPanel@ in widgets in the grid layout of the calculator. __IO_PANEL_SPAN = 3 # The default base of the calculator. __BASE = 10 # The title of this calculator's window. __TITLE = "Calculator" #The title of the Base selection menu __BASE_MENU_TITLE = 'Base' #The title of the Help menu __HELP_MENU_TITLE = 'Help' #The title of the Options Menu __OPTIONS_MENU_TITLE = "Options" # Row number of the first digit row in grid layout of the calculator. __DIGIT_ROW = 1 # Column number of the first digit row in grid layout of the calculator. __DIGIT_COL = 0 # Number of digit buttons per row in grid layout of the calculator. __DIGITS_PER_ROW = 3 # Text on the clear button. __CLEAR_TITLE = "C" # Text on the push button. __PUSH_TITLE = "P" #The operator for Clear Everything button __CLEAR_EVERYTHING_TITLE = 'CE' #Sticky for the stack panel __STACK_STICKY = 'NS' #String for recognising errors from operations __ERROR_TAG = 'Error' # Main constructor. # @parent@: The master widget of this @Calculator@ or @None@ # @base@: The number base for this @Calculator@. def __init__( self, master, title=__TITLE, base=__BASE) : self.__base = base #INITIALIZE THE STACK self.__stack = Stack() #Initialise the Operation class self.__operation = Operation(self.__stack) # Initialise main calculator window. Tk.__init__( self, master ) # Set title. self.title( title ) #Set not resizable self.resizable(0,0) # Save @master@. Not used... self.__master = master # Finish rest of initialisation. self.__initialise( base=base) # Utility method for initialising this @Calculator@'s components. # @base@: the number base of this @Calculator@'s operations. def __initialise( self, base,clearOption=CLEAR_STACK_DEFAULT, displayOption=DISPLAY_STACK_DEFAULT) : self.__clearStack = clearOption self.__displayStack = displayOption # Initialise the IO panel component. self.__initialiseIOPanel( ) # Initialise the digit panel component. self.__initialiseDigitPanel( base=base) #Initialise the operand panel component self.__initialiseOperandPanel() #Initialise the menu bar self.__initialiseMenu() #Add the Base Change dropdown self.__initialiseBaseMenu(base) #Add the Options dropdown self.__initialiseOptionsMenu() #Add the Help dropdown self.__initialiseHelpMenu() #Initialise the stack display panel, if the option is selected if self.__displayStack: self.__initialiseStackPanel() # Initialise the digit panel widget of this @Calculator@. # @base@: the number base of this @Calculator@'s operations. # @row@: row number in grid layout of this @Calculator@. # @col@: column number in grid layout of this @Calculator@. # @digitsPerRow@: digits per row in grid layout of this @Calculator@. def __initialiseDigitPanel( self, base, row=__DIGIT_ROW, col=__DIGIT_COL, digitsPerRow=__DIGITS_PER_ROW ) : appendee = self.__iopanel self.__base = base self.__positioner = GridPositioner( row=row, col=col, columns=digitsPerRow ) for digit in [ digit for digit in range( 1, base ) ] + [ 0 ] : button = Digit( master=self, digit=digit, appendee=appendee ) self.__positioner.add( button ) self.__addSpecialDigitPanelButton( text=Calculator.__CLEAR_TITLE, command=self.__onClearButtonClick ) self.__addSpecialDigitPanelButton( text=Calculator.__PUSH_TITLE, command=self.__onPushButtonClick ) # Utility method for adding additional button to the digit panel. # @text@: the text on the button. # @command@: the button's callback method. def __addSpecialDigitPanelButton( self, text, command ) : button = Button( master=self, text=text, command=command ) self.__positioner.add( button ) # Initialise the IO panel widget of this @Calculator@. def __initialiseIOPanel( self ) : width = Calculator.__IO_PANEL_WIDTH height = Calculator.__IO_PANEL_HEIGHT # create the IO panel. iopanel = IOPanel( master=self, width=width, height=height ) row = Calculator.__IO_PANEL_ROW col = Calculator.__IO_PANEL_COL span = Calculator.__IO_PANEL_SPAN # Add the IO panel to the current crid layout. iopanel.grid( row=row, column=col, columnspan=span ) # Save object reference to the IO panel for future use. self.__iopanel = iopanel def __initialiseOperandPanel( self ): #Add the Operand buttons to the panel operators = OPERATORS for operand in operators: command = lambda operand=operand:self.__onOperandButtonClick( operand) self.__addSpecialDigitPanelButton(operand, command) #Add the Clear Everything Button title = Calculator.__CLEAR_EVERYTHING_TITLE self.__addSpecialDigitPanelButton(title, self.__onClearEverythingButtonClick) def __initialiseMenu(self): #Initialises the menu bar self.__menu = Menu(self) self.config(menu=self.__menu) def __initialiseBaseMenu(self, base) : #Create the dropdown for selecting the base and add it to the #menu baseDropDown = BaseMenu(self, base) label = Calculator.__BASE_MENU_TITLE self.__menu.add_cascade(label=label, menu=baseDropDown) def __initialiseOptionsMenu(self): self.__options = OptionMenu(self, self.__clearStack, self.__displayStack) label = Calculator.__OPTIONS_MENU_TITLE self.__menu.add_cascade(label=label, menu=self.__options) def __initialiseHelpMenu(self): #Initialises the panel for giving help options. ie. instructions helpMenu = HelpMenu(self) label = Calculator.__HELP_MENU_TITLE self.__menu.add_cascade(label=label,menu=helpMenu) def __initialiseStackPanel(self): #Initialises the side panel that displays the current stack. height = Calculator.__IO_PANEL_HEIGHT width = Calculator.__IO_PANEL_WIDTH self.__stackPanel = StackPanel(master=self,height=height,width=width, stack=self.__stack) self.__showStack() def __showStack(self) : #A method for adding the stack panel to the window #This gets the last row used in the window rows = ceil(self.__positioner.addedWidgets / Calculator.__DIGITS_PER_ROW) + 1 sticky = Calculator.__STACK_STICKY row = Calculator.__IO_PANEL_ROW col = Calculator.__DIGITS_PER_ROW + 1 #Next to the rest of the stuff self.__stackPanel.grid(row=row, column=col, rowspan=rows, sticky=sticky) self.__stackPanel.update() def __hideStack(self) : #A method for hiding the stack panel self.__stackPanel.grid_forget() def onStackDisplayChange(self) : #A method for handling when the user changes the display stack option displayStack = self.__options.displayStack.get() if displayStack : #The stack is hidden, we need to add it back to view self.__showStack() else : #The stack is already visible, hide it self.__hideStack() # Callback method for push button def __onPushButtonClick( self ) : self.__pushInput() def __pushInput(self) : #push the value of the input field onto the stack var = self.__iopanel.get( ) if var != "": self.__stack.push(var) self.__stackPanel.update() self.__iopanel.reset( ) # Callback method for clear button def __onClearButtonClick( self ) : self.__iopanel.reset( ) #Handle presses of operand buttons def __onOperandButtonClick(self, operand) : #Handle the clicking of operand buttons #Push any input in the field onto the stack, if any self.__pushInput() #Run the apply function, then display the answer answer = self.__operation.apply(operand,self.__base) if answer != None : #We don't want to display None in the output field self.__iopanel.set(answer) if Calculator.__ERROR_TAG in answer : #If the last operation gave us an error, #we want to remove it from the stack self.__stack.pop() self.__stackPanel.update() def changeBase(self, newBase) : #Changes between the given bases self.__removeAllChildren() clearStack = self.__options.clearStack.get() displayStack = self.__options.displayStack.get() self.__stack.clear() if clearStack else self.__operation.convertStack( self.__stack,newBase,self.__base) self.__initialise(newBase,clearStack,displayStack) def __removeAllChildren(self) : #Removes all the children from self for widget in self.winfo_children() : #Destroy all widgets in self, without destroying self widget.destroy() def __onClearEverythingButtonClick(self): #clear the stack self.__stack.clear() self.__iopanel.set("") self.__stackPanel.update() self.__iopanel.reset()
def excuteIns(address): # insSequenceDic 是地址:指令 键值对 ins = insSequenceDic[str(address)] global cycle ins.cycle = cycle Output.slt.pasSim('--------------------\n') Output.slt.pasSim(ins.printInstruction(0)) ins.currentPC = address ins.nextPC = address + 4 if ins.opName == "NOP": Operation.ex_NOP(ins,regList) elif ins.opName == "ADD": Operation.ex_ADD(ins,regList) elif ins.opName == "SUB": Operation.ex_SUB(ins, regList) elif ins.opName == "MUL": Operation.ex_MUL(ins, regList) elif ins.opName == "AND": Operation.ex_AND(ins, regList) elif ins.opName == "OR": Operation.ex_OR(ins, regList) elif ins.opName == "XOR": Operation.ex_XOR(ins, regList) elif ins.opName == "NOR": Operation.ex_NOR(ins, regList) elif ins.opName == "SLT": Operation.ex_SLT(ins, regList) elif ins.opName == "ADDI": Operation.ex_ADDI(ins, regList) elif ins.opName == "ANDI": Operation.ex_ANDI(ins, regList) elif ins.opName == "ORI": Operation.ex_ORI(ins, regList) elif ins.opName == "XORI": Operation.ex_XORI(ins, regList) elif ins.opName == "J": Operation.ex_J(ins, regList) elif ins.opName == "JR": Operation.ex_JR(ins, regList) elif ins.opName == "BEQ": Operation.ex_BEQ(ins, regList) elif ins.opName == "BLTZ": Operation.ex_BLTZ(ins, regList) elif ins.opName == "BGTZ": Operation.ex_BGTZ(ins, regList) elif ins.opName == "BREAK": Operation.ex_BREAK(ins, regList) elif ins.opName == "SW": Operation.ex_SW(ins, regList, memDic) elif ins.opName == "LW": Operation.ex_LW(ins, regList, memDic) elif ins.opName == "SLL": Operation.ex_SLL(ins, regList) elif ins.opName == "SRL": Operation.ex_SRL(ins, regList) elif ins.opName == "SRA": Operation.ex_SRA(ins, regList) # Output.slt.pas()('nextPC',ins.nextPC) cycle += 1 printRegList(regList,memList) return ins.nextPC
__author__ = 'sunbeansoft' import Operation as o o.operation()