def window_resize(self): data = core.get_item_rect_size(self.windowName) core.clear_drawing(self.pictureName) core.draw_image(self.pictureName, self.picturePath, pmin=[0, 0], pmax=[data[0] - 10, data[1] - 30])
def clear(self) -> None: """Clears the drawing. Warning: Any :class:`.DrawCommand` objects created using this canvas must not be used after this method is called. This includes reading or writing to any properties of :class:`DrawCommand` objects. """ dpgcore.clear_drawing(self.id)
def __threadRestart(self, filename: str): core.clear_drawing("Canvas") self.__play(0) self.__head = 0 fp = f"{self.__root}/{filename}" probe = ffmpeg.probe(fp) video_info = next(stream for stream in probe['streams'] if stream['codec_type'] == 'video') self.__width = int(video_info['width']) self.__height = int(video_info['height']) self.__frameCount = int(video_info['nb_frames']) global _BUFFER _BUFFER = [[0, 0, 0, 0] * self.__width * self.__height ] * self.__frameCount # kill the old if there... if self.__thread: self.__thread._stop() self.__thread = Process(fp, self.__width, self.__height) self.__thread.start()
def draw_visualisation(self): maxNeurons = max(self.containerData.listOfLayerNeurons) if max(self.containerData.listOfLayerNeurons) <10 else 10 ratio = (self.containerData.numberOfLayers) / maxNeurons if (self.height > self.width * ratio): gap = int(self.width / (self.scaleParam*maxNeurons)) radius = int(self.width / (self.scaleParam * 6 * maxNeurons)) thickness = int(self.width / 1200) else: gap = int(self.height / (self.scaleParam*self.containerData.numberOfLayers)) radius = int(self.height / (self.scaleParam*(6 * self.containerData.numberOfLayers))) thickness = int(self.height / 1200) core.clear_drawing(self.drawingName) for layer in range(self.containerData.numberOfLayers): if (self.containerData.listOfLayerTypes[layer] == 'Activation') or (self.containerData.listOfLayerTypes[layer] == 'Flatten'): self.containerData.listOfLayerNeurons[layer] = 1 additionalNeurons = self.containerData.listOfLayerNeurons[layer] - 10 outputString = ('\n+' + str(additionalNeurons) + " more") core.draw_text(self.drawingName, pos=[self.width - gap, self.coordinate_of_text(layer, 0, gap)[1]], text=(self.containerData.listOfLayerTypes[layer]+"\n"+self.containerData.listOfActivations[layer] +(outputString if additionalNeurons > 0 else '')), color=self.white, size=radius) for layer in range(self.containerData.numberOfLayers): for neuron in range(self.containerData.listOfLayerNeurons[layer] if self.containerData.listOfLayerNeurons[layer]<10 else 10): if layer != self.containerData.numberOfLayers - 1: for nextNeuron in range(self.containerData.listOfLayerNeurons[layer+1] if self.containerData.listOfLayerNeurons[layer+1]<10 else 10): core.draw_line(self.drawingName, self.coordinate_of(layer, neuron, gap), self.coordinate_of(layer + 1, nextNeuron, gap), color=self.grey, thickness=thickness) for layer in range(self.containerData.numberOfLayers): if layer == 0: color = [0, 200, 0, 255] elif layer == self.containerData.numberOfLayers - 1: color = [200, 0, 0, 255] else: color = [0, 0, 200, 255] if (self.containerData.listOfLayerTypes[layer] != 'Activation') and (self.containerData.listOfLayerTypes[layer] != 'Flatten'): for neuron in range(self.containerData.listOfLayerNeurons[layer] if self.containerData.listOfLayerNeurons[layer]<10 else 10): core.draw_circle(self.drawingName, self.coordinate_of(layer, neuron, gap), radius, color=color, fill=color) else: core.draw_triangle(self.drawingName, p1=[self.width/2-self.width/30, layer*gap+gap/2], p2=[self.width/2 - self.width/30 - gap/2, layer*gap], p3=[self.width/2-self.width/30+gap/2, layer*gap], color=self.white, fill=self.white)
def process(sender, data): """ Sends the data to SimpleCTG. """ directory = core.get_value('directory') file_directory = core.get_value('file_directory') opt_level = core.get_value('opt_level') num_of_iter = core.get_value('##num_of_iter') # converts layout type to boolean for SimpleCTG temp = core.get_value('layout_type') if temp == 0: layout_type = True else: layout_type = False # chooses the device if core.get_value('device_type') == 0: architecture = gui.backend_dict[0] arbitrary = False elif core.get_value('device_type') == 1: architecture = gui.backend_dict[core.get_value('architecture') + 1] arbitrary = False else: # load arbitrary couplings from file with open('arbitrary_coupling.pickle', 'rb') as arbitrary_file: custom_dict = pickle.load(arbitrary_file) for name, number in zip(custom_dict, range(len(custom_dict))): if number == core.get_value('architecture'): arhi_name = name architecture = custom_dict[arhi_name] arbitrary = True try: infoStr, circuit_features = SimpleCTG.gui_interaction( file_directory, directory, layout_type, opt_level, architecture, num_of_iter, arbitrary) # show program output core.configure_item('Program output will be displayed here', color=[255, 255, 255]) core.draw_image('input_circuit', circuit_features['logical_graph'], [0, 500], pmax=[200, 500]) core.draw_image('output_circuit', circuit_features['reduced_graph'], [0, 500], pmax=[200, 500]) gui.qasm_file = circuit_features['qasm_file'] core.set_value('##circuitImage', circuit_features['ibm_circuit']) gui.projection_map = circuit_features['mapping'] core.set_value( 'Program output will be displayed here', "Processed file: " + core.get_value('file_directory') + "\n" + infoStr) core.configure_item('Open qasm file', show=True) core.configure_item('Mapping', show=True) core.configure_item('Path to IBM circuit representation', show=True) except Exception as ex: # if error, then makes text red and removes features core.configure_item('Program output will be displayed here', color=[255, 0, 0]) core.set_value( 'Program output will be displayed here', "Processed file: " + core.get_value('file_directory') + "\n" + traceback.format_exc()) core.clear_drawing('input_circuit') core.clear_drawing('output_circuit') core.configure_item('Open qasm file', show=False) core.configure_item('Mapping', show=False) core.configure_item('##circuitImage', show=False) core.configure_item('Path to IBM circuit representation', show=False)
def update_alternative(self): core.clear_drawing(self.pictureName) self.window_resize()
def update_picture(self): core.clear_drawing(self.pictureName) core.render_dearpygui_frame() self.window_resize()
def clear(self): """ Clears the canvas drawing """ c.clear_drawing(self.name)
def draw_board(self): """ Dibuja el tablero pegando las piezas en una imagen vacia """ p_size = self.piece_size dpg.clear_drawing('canvas') board = Image.new('RGB',(self.size,self.size)) for row in range(8): for col in range(8): piece = self.board[row][col] piece = '' if piece == '_E' else piece x = p_size*col y = p_size*row if (-1)**(row+col) == 1: # fondo blanco im = Image.open(self.piece_p(str(piece)+'b')) else: # fondo negro im = Image.open(self.piece_p(str(piece)+'n')) im = im.resize((p_size,p_size)) # color boxes color = self.colored_boxes[row][col] if color: size = (self.piece_size,self.piece_size) im_color = Image.new('RGB',size,color) im = Image.blend(im, im_color, 0.5) board.paste(im,(x,y)) # draw lines im_arrows = Image.new('RGB',(self.size,self.size),'rgb(255,255,255)') draw = ImageDraw.Draw(im_arrows) for line in self.lines: init = line[0] end = line[1] draw.line([init,end],width=p_size//8,fill=line[2]) # agregar flecha x = end[0] y = end[1] d = 30 if x == init[0]: x0 = x if y-init[1] < 0: y0 = y+d else: y0 = y-d else: m, f = recta(init,end) c = math.sqrt(d**2/(1+m**2)) if x-init[0] < 0: x0 = x+c else: x0 = x-c y0 = f(x0) vector = (x0-x,y0-y) v_x = vector[0] v_y = vector[1] rad = math.pi / 4 x_ = v_x*math.cos(rad) - v_y*math.sin(rad) y_ = v_x*math.sin(rad) + v_y*math.cos(rad) arrow_1 = (int(x_+x),int(y_+y)) rad = (-1)*(math.pi / 4) x_ = v_x*math.cos(rad) - v_y*math.sin(rad) y_ = v_x*math.sin(rad) + v_y*math.cos(rad) arrow_2 = (int(x_+x),int(y_+y)) draw.line([end,arrow_1],width=p_size//8,fill=line[2]) draw.line([end,arrow_2],width=p_size//8,fill=line[2]) board = Image.blend(board,im_arrows,0.3) board.save('tmp.png') dpg.draw_image('canvas','tmp.png',[0,self.size])
def __refresh(self, full=True): core.clear_drawing("Canvas") if full: self.__fractal.parse(iteration=self.__iteration) self.__fractal.execute(drawCallback=self.__cbFractalDraw, drawCallBufferSize=500)