|
|
from UI import *
|
|
|
# import tkinter as tk
|
|
|
# from Instruction4 import SimMem
|
|
|
from tkinter import messagebox
|
|
|
|
|
|
|
|
|
class ClockStep:
|
|
|
def __init__(self):# 绘制控制器背景板
|
|
|
round_rectangle(74, 434, 533, 642, r=25, fill=BACK, width=0)
|
|
|
round_rectangle(97, 525, 276, 627, r=25, fill=BLACK, width=0)
|
|
|
self.dx2, self.dy2, self.dw2, self.dh2 = 95, 455, 200, 40# 时钟数字间隔
|
|
|
self.R, self.x0, self.y0, self.dx = 15, 113, 473, 35#时钟大小
|
|
|
|
|
|
|
|
|
def clo_mark(self, cv:Canvas):# 依据ClockStep[]的值显示时钟元素
|
|
|
for i in range(6):#遍历六个时钟刻,绘制各个时钟
|
|
|
cv.create_oval(i * self.dx + self.x0 - self.R, self.y0 - self.R, i * self.dx + self.x0 + self.R,
|
|
|
self.y0 + self.R, width=1)#绘制时钟圆圈
|
|
|
if cpu.clo[i] == True:# 如果存储结构中clo[i]为1,则该时钟高亮显示
|
|
|
cv.create_oval(self.x0 - self.R + self.dx * i, self.y0 - self.R,
|
|
|
self.x0 + self.R + self.dx * i, self.y0 + self.R, width=1, fill=RED)
|
|
|
else:# 如果存储结构中clo[i]为1,则该时钟正常显示
|
|
|
cv.create_oval(self.x0 - self.R + self.dx * i, self.y0 - self.R,
|
|
|
self.x0 + self.R + self.dx * i, self.y0 + self.R,
|
|
|
width=1, fill=WHITE)
|
|
|
cv.create_text(self.dx2 + 12, self.dy2 + 3, text='1 2 3 4 5 6', font=('微软雅黑', 18), anchor=NW)# 重新绘制各时钟编号
|
|
|
cv.update()#更新画布
|
|
|
|
|
|
# 实现仿真控制器的各个屏幕元素,同时依据ClockStep[]的值显示节拍元素
|
|
|
def show(self, cv: Canvas, root):
|
|
|
# 标记控制器各个部件名称
|
|
|
cv.create_text(95, 434, text='Clock', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)
|
|
|
cv.create_text(342, 434, text='PC', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)
|
|
|
cv.create_text(104, 500, text='SigCtrl', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)
|
|
|
cv.create_text(342, 540, text='IR', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)
|
|
|
# 根据当前控制器存储的值显示PC值
|
|
|
PC = tk.Label(root, text=cpu.PC(), fg=BLACK, font=('微软雅黑', 12), bg=WHITE)
|
|
|
PC.place(x=335, y=455, height=30, width=150)
|
|
|
# 根据当前控制器存储的值显示IR值
|
|
|
IR = tk.Label(root, text=cpu.IR(), fg=BLACK, font=('微软雅黑', 12), bg=WHITE)
|
|
|
IR.place(x=335, y=565, height=30, width=150)
|
|
|
# 绘制Clock背景板
|
|
|
bx2, by2, bw2, bh2 = 95, 455, 200, 40
|
|
|
round_rectangle(bx2, by2, bx2 + 215, by2 + 35, r=20, fill=WHITE, width=0)
|
|
|
# 绘制时钟名称
|
|
|
cv.create_text(bx2 + 12, by2 + 3, text='1 2 3 4 5 6', font=('微软雅黑', 18), anchor=NW, )
|
|
|
R = 15
|
|
|
x0 = 113
|
|
|
y0 = 473
|
|
|
dx = 35
|
|
|
# 绘制各个时钟
|
|
|
for i in range(6):
|
|
|
cv.create_oval(i * dx + x0 - R, y0 - R, i * dx + x0 + R, y0 + R, width=1)
|
|
|
self.clo_mark(cv)
|
|
|
# 更新画布
|
|
|
cv.update()
|
|
|
|
|
|
# 实现仿真控制器的各个屏幕元素,同时依据ClockStep[]的值显示节拍元素
|
|
|
def init(self, cv:Canvas, root):
|
|
|
cv.create_text(95, 434, text='Clock', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)# 标记PC名称
|
|
|
cv.create_text(342, 434, text='PC', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)# 标记PC名称
|
|
|
cv.create_text(104, 500, text='SigCtrl', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)# 标记sig_ctrl名称
|
|
|
cv.create_text(342, 540, text='IR', font=('微软雅黑', 12, 'bold'), anchor=NW, fill=WORD)# 标记IR名称
|
|
|
PC = tk.Label(root, text=cpu.PC(), fg=BLACK, font=('微软雅黑', 12), bg=WHITE)# 根据cpu存储的值显示PC值
|
|
|
PC.place(x=335, y=455, height=30, width=150)#放置PC值
|
|
|
IR = tk.Label(root, text=cpu.IR(), fg=BLACK, font=('微软雅黑', 12), bg=WHITE)# 根据cpu存储的值显示IR值
|
|
|
IR.place(x=335, y=565, height=30, width=150)#放置IR值
|
|
|
bx2, by2, bw2, bh2 = 95, 455, 200, 40# Clock背景板大小
|
|
|
round_rectangle(bx2, by2, bx2+215, by2+35, r=20, fill=WHITE, width=0)# 绘制Clock背景板
|
|
|
self.clo_mark(cv)#绘制六个时钟
|
|
|
cv.update()#更新面板
|
|
|
|
|
|
|
|
|
def jp(self, cv:Canvas, flag, num):
|
|
|
if flag:
|
|
|
cv.create_oval(self.x0 - self.R + self.dx * (num - 1), self.y0 - self.R, self.x0 + self.R + self.dx * (num - 1), self.y0 + self.R, width=1, fill=RED)
|
|
|
else:
|
|
|
cv.create_oval(self.x0 - self.R + self.dx * (num - 1), self.y0 - self.R, self.x0 + self.R + self.dx * (num - 1), self.y0 + self.R,
|
|
|
width=1, fill=WHITE)
|
|
|
cv.create_oval(self.x0 - self.R + self.dx * (num - 1), self.y0 - self.R, self.x0 + self.R + self.dx * (num - 1), self.y0 + self.R,
|
|
|
width=1)
|
|
|
cv.create_text(self.dx2 + 12, self.dy2 + 3, text='1 2 3 4 5 6', font=('微软雅黑', 18), anchor=NW)
|
|
|
cv.update()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
cl=ClockStep()
|
|
|
# cl.clo_mark(cv)
|
|
|
cl.init(cv,root)
|
|
|
'''
|
|
|
def add_program():
|
|
|
cl.init(cv, root)
|
|
|
# cl.show(cv, 1)
|
|
|
# cl.show(cv, 2)
|
|
|
# cl.show(cv, 3)
|
|
|
# cl.show(cv, 4)
|
|
|
# cl.show(cv, 5)
|
|
|
# cl.show(cv, 6)
|
|
|
|
|
|
# si.np()
|
|
|
# cv.create_line(485,469+4.5,485+120+12,469+4.5,width=9,fill=RED,arrow=LAST)
|
|
|
# cv.create_rectangle(485, 469, 485 + 120, 469 + 9, fill=RED)
|
|
|
def left1(event):
|
|
|
print(event.x,event.y)
|
|
|
cv.bind('<Button-1>', left1)
|
|
|
'''
|
|
|
mainloop() |