def draw_memory_state(self, mem_box, size_box, start_height, temp_memory, *args):
# Unpack memory state details
memory_state = temp_memory['memory_state']
# wait_queue = temp_memory['processes_waiting']
event_details = temp_memory['event']
process_id,arrival_bit,curr_time,burst_time,process_size = event_details
chart_wid = Widget()
# Increment in width per unit size
self.inc = Window.width/(int(data_mem['mem_size'])*1.5)
# Add description labels
label = Label(text='Memory state: ', size_hint_x=None, width=self.margin_left)
mem_box.add_widget(label)
s_label = Label(text='Size: ', size_hint_x=None, width=self.margin_left, valign='top', halign='center')
s_label.text_size = s_label.size
size_box.add_widget(s_label)
# Draw the memory state rectangles and add size labels
if not memory_state:
self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', 0, data_mem['mem_size'])
else:
for i,memory_slot in enumerate(memory_state):
process_id1, start1, end1 = memory_slot
if(len(memory_state) == 1): # only tuple in list
if(start1 > 0):
self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', 0, start1)
self.add_process(chart_wid, mem_box, size_box, start_height, process_id1, start1, (end1-start1))
if(data_mem['mem_size']-end1 > 0):
self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', end1, (data_mem['mem_size']-end1))
elif(i == len(memory_state)-1): #last tuple, more tuples preceded
self.add_process(chart_wid, mem_box, size_box, start_height, process_id1, start1, (end1-start1))
if(data_mem['mem_size']-end1 > 0):
self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', end1, (data_mem['mem_size']-end1))
else:
process_id2,start2,end2 = memory_state[i+1]
if(i == 0): # first tuple, more tuples follow
if(start1 > 0):
self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', 0, start1)
self.add_process(chart_wid, mem_box, size_box, start_height, process_id1, start1, (end1-start1))
if(start2-end1 > 0):
self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', end1, (start2-end1))
# Add size label for the end of memory
s_label = Label(text=str(data_mem['mem_size']), size_hint_x=None, width=self.inc*(data_mem['mem_size']), halign='left', valign='top')
s_label.text_size = s_label.size
size_box.add_widget(s_label)
# Add the widget used to draw the meomory state on the screen
mem_box.add_widget(chart_wid)
# Drawing the wait queue
评论列表
文章目录