Esempio n. 1
0
    def __renderFrame(self):
        # looping?
        if self.__head < 0:
            if self.__loop:
                self.__head += self.__frameCount
            else:
                self.__head = 0
                self.__play(0)
                return
        elif self.__head > self.__frameCount:
            if self.__loop:
                self.__head -= self.__frameCount
            else:
                self.__head = self.__frameCount
                self.__play(0)
                return

        idx = int(self.__head)
        if self.__last == idx:
            return
        self.__last = idx
        frame = _BUFFER[idx]
        core.add_texture("temp", frame, self.__width, self.__height)
        core.draw_image("Canvas",
                        "temp", [0, 0],
                        pmax=[self.__width, self.__height])
Esempio n. 2
0
 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])
Esempio n. 3
0
 def refresh(self):
     core.add_texture(
         "geomap",
         self.stored_map,
         256 * (2 * self.tile_radius + 1),
         256 * (2 * self.tile_radius + 1),
     )
     core.draw_image("canvas", "geomap", [0, 0], self.map_size)
Esempio n. 4
0
    def __init__(self):

        with simple.window(self.windowName):
            core.add_drawing(self.pictureName, width=1500, height=1500)
            core.draw_image(self.pictureName,
                            self.picturePath,
                            pmin=[0, 0],
                            pmax=[700, 700])
            core.set_resize_callback(callback=self.window_resize,
                                     handler=self.windowName)
        super().__init__()
Esempio n. 5
0
def produce_frame():
    global frame
    global running
    capture = cv.VideoCapture(0)
    running=True
    while capture.isOpened() and running:
        time.sleep(0.1)
        ret, frame = capture.read()
        # gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
        img =frame
        b = np.ones([img.shape[0], img.shape[1], 1]) * 255
        img = np.c_[img, b].astype(int)
        dpg_image2 = img.flatten().tolist()
        dpg.add_texture("texture id", dpg_image2, img.shape[1], img.shape[0])
        dpg.draw_image('drawing', "texture id", [0, 0], [500, 300])
        # return frame
        if cv.waitKey(30) == ord('q'):
            break
Esempio n. 6
0
    def _draw_duplicates_set(self, duplicate_images_list: FileMetaDataList) -> None:
        """ Draw a single image and all the files containing it.
            All the files in duplicate_images_list containg duplicate of same image.
        """
        
        try:

            file_path = duplicate_images_list[0].GetPath()

            core.add_drawing(
                file_path, 
                width=100, 
                height=100, 
                parent=self._window_name)

            core.draw_image(
                file_path, 
                file_path, 
                [0, 0], 
                pmax=[100, 100],
                uv_min=[0, 0], 
                uv_max=[1, 1], 
                tag="image")

            for file in duplicate_images_list:
                
                file_path = file.GetPath()

                core.add_button(
                    'Delete ##'+file_path, 
                    callback=self._delete_file_button_click_handler, 
                    callback_data=file,
                    parent=self._window_name)

                core.add_same_line(parent=self._window_name)

                core.add_text(
                file_path, 
                parent=self._window_name)

            core.add_separator(parent=self._window_name)

        except Exception as e:
            core.log_error('View::_draw_duplicates_set - Exception : [%s]' % (e))
    def __init__(self, new_scan_click_callback: callable):

        self._window_name: str = 'Hello Screen'

        self._new_scan_click_callback: callable = new_scan_click_callback

        main_window_size = core.get_main_window_size()

        self._window_x_pos: int = int(main_window_size[0] / 2) - 200
        self._window_y_pos: int = int(main_window_size[1] / 2) - 100

        self._logo_full_path = get_resource_full_path('resources/logo.png')

        with simple.window(self._window_name):
            core.configure_item(self._window_name,
                                width=300,
                                height=250,
                                x_pos=self._window_x_pos,
                                y_pos=self._window_y_pos,
                                label='Welcome!')

            core.add_text('Welcome to Duplicate Image Finder!')

            core.add_text('Version: ' + get_version())

            core.add_drawing(name='hello_screen_logo', width=100, height=100)

            core.draw_image(drawing='hello_screen_logo',
                            file=self._logo_full_path,
                            pmin=[0, 0],
                            pmax=[100, 100],
                            uv_min=[0, 0],
                            uv_max=[1, 1],
                            tag="image")

            core.add_button(name='start_new_scan_button',
                            label='Start New Scan',
                            callback=self._internal_new_scan_click_callback)

            core.add_button(name='visit_source_page_button',
                            label='Visit Github source page',
                            callback=self._visit_source_page_click_callback)
Esempio n. 8
0
def open_help_window(sender, data):
    """
    Opens new window with help annotations
    """
    with simple.window('Help##window',
                       width=1000,
                       height=600,
                       on_close=delete_items(['Help##window'])):
        with simple.tab_bar("Help tabs"):
            with simple.tab('Architectures##help'):
                core.add_drawing('armonk', width=72, height=75)
                core.draw_image('armonk', './backends/armonk.png', [72, 72])
                core.add_text('ibmq_armonk: 1 qubit.')
                core.add_spacing(name='##space10', count=10)

                core.add_drawing('athens', width=518, height=75)
                core.draw_image('athens', './backends/athens-santiago.png',
                                [0, 72])
                core.add_text('ibmq_athens and ibmq_santiago: 5 qubits.')
                core.add_spacing(name='##space12', count=10)

                core.add_drawing('yorktown', width=373, height=400)
                core.draw_image('yorktown', './backends/ibmqx2.png', [0, 400])
                core.add_text('ibmqx2: 5 qubits.')
                core.add_spacing(name='##space13', count=10)

                core.add_drawing('melb', width=1000, height=196)
                core.draw_image('melb', './backends/melbourne.png', [0, 196])
                core.add_text('ibmq_16_melbourne: 15 qubits.')
                core.add_spacing(name='##space14', count=10)

            with simple.tab('Instructions##help'):
                core.add_text(
                    '1. In the Selector block a user can select optimization parameters:'
                )
                core.add_spacing(name='##text_spacing1', count=5)

                core.add_text(
                    '* the level of optimization provided by IBM Q (ranging from 0 to 3)'
                )
                core.add_text(
                    '* IBM Original layout or advanced SWAP placement')
                core.add_text('* location of placement')
                core.add_text('* number of iterations.')
                core.add_spacing(name='##text_spacing2', count=5)

                core.add_text(
                    '2. In the Hardware & Circuit block choose between testing the circuit on a quantum computer (IBM Q) and simulator (Qasm).',
                    wrap=900)
                core.add_spacing(name='##text_spacing3', count=5)
                core.add_text(
                    '3. Choose quantum coupling (quantum computer architecture) - IBM Q or Qasm.',
                    wrap=900)
                core.add_spacing(name='##text_spacing4', count=5)
                core.add_text(
                    '4. Upload an input file. After selection, the file name will be displayed in the Hardware & Circuit block and the circuit representation will be displayed in the Circuit before the reduction block.',
                    wrap=900)
                core.add_spacing(name='##text_spacing5', count=5)
                core.add_text(
                    '5. When pressing on the Process button the tool will find the optimal mapping of the circuit onto the quantum computer architecture.',
                    wrap=900)
                core.add_spacing(name='##text_spacing6', count=5)
                core.add_text(
                    '6. The resulting mapping will appear in the Circuit after the reduction block.',
                    wrap=900)
Esempio n. 9
0
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)
Esempio n. 10
0
def show_demo():

    _create_static_textures()
    _create_dynamic_textures()

    with cxt.collapsing_header(label="Textures & Images"):

        with cxt.tree_node(label="Help"):

            dpg.add_separator()
            dpg.add_text("ABOUT TEXTURES:")
            dpg.add_text("Textures are buffers of RGBA data.",
                         bullet=True,
                         indent=20)
            dpg.add_text("Textures are used by 'image based' widgets:",
                         bullet=True,
                         indent=20)
            dpg.add_text("add_image", bullet=True, indent=50)
            dpg.add_text("add_image_button", bullet=True, indent=50)
            dpg.add_text("draw_image", bullet=True, indent=50)
            dpg.add_text("add_image_series", bullet=True, indent=50)
            dpg.add_text("Textures are themselves widgets.",
                         bullet=True,
                         indent=20)
            dpg.add_text(
                "Textures must be a child of a texture container widget.",
                bullet=True,
                indent=20)
            dpg.add_text(
                "Textures can be either static or dynamic (see following sections).",
                bullet=True,
                indent=20)

            dpg.add_separator()
            dpg.add_text("PROGRAMMER GUIDE:")
            dpg.add_text(
                "'image based' widgets hold a reference to a texture widget.",
                bullet=True,
                indent=20)
            dpg.add_text(
                "Deleting the texture widget will not affect widget's using it.",
                bullet=True,
                indent=50)
            dpg.add_text(
                "Textures are only free'd from the GPU when the reference count reaches 0.",
                bullet=True,
                indent=50)
            dpg.add_text(
                "The texture container widget is a root (has no parent).",
                bullet=True,
                indent=20)
            dpg.add_text("The texture container widget is hidden by default.",
                         bullet=True,
                         indent=20)
            dpg.add_text(
                "'Showing' it, opens a manager to inspect the textures within.",
                bullet=True,
                indent=50)
            dpg.add_same_line()
            dpg.add_button(label="Press Here",
                           small=True,
                           callback=lambda: dpg.configure_item(
                               demo_texture_container, show=True))
            dpg.add_separator()

        with cxt.tree_node(label="Static Textures"):

            dpg.add_separator()
            dpg.add_text("ABOUT STATIC TEXTURES:")
            dpg.add_text("Can NOT be modified after creation.",
                         bullet=True,
                         indent=20)
            dpg.add_text("Can be loaded from a file using the 'file' keyword.",
                         bullet=True,
                         indent=20)
            dpg.add_separator()

            with cxt.group(horizontal=True):

                with cxt.group():
                    dpg.add_text("Image Button")
                    dpg.add_image_button(demo_static_texture_1)

                with cxt.group():
                    dpg.add_text("Image")
                    dpg.add_image(demo_static_texture_2)

                with cxt.group():
                    dpg.add_text("Image (texture size)")
                    dpg.add_image(demo_static_texture_3)

                with cxt.group():
                    dpg.add_text("Image (2x texture size)")
                    dpg.add_image(demo_static_texture_3, width=200, height=200)

            dpg.add_image("INTERNAL_DPG_FONT_ATLAS")

        with cxt.tree_node(label="Dynamic Textures"):

            dpg.add_separator()
            dpg.add_text("ABOUT DYNAMIC TEXTURES:")
            dpg.add_text("Can be modified after creation with 'set_value'.",
                         bullet=True,
                         indent=20)
            dpg.add_text(
                "New data must be the same dimensions as the original",
                bullet=True,
                indent=20)
            dpg.add_separator()

            with cxt.group():
                dpg.add_color_picker(label="Texture 1",
                                     default_value=(255, 0, 255, 255),
                                     no_side_preview=True,
                                     alpha_bar=True,
                                     width=200,
                                     callback=_update_dynamic_textures,
                                     callback_data=1)
                dpg.add_text("Image Button")
                dpg.add_image_button(demo_dynamic_texture_1,
                                     width=100,
                                     height=100)

            dpg.add_same_line()

            with cxt.group():
                dpg.add_color_picker(label="Texture 2",
                                     default_value=(255, 255, 0, 255),
                                     no_side_preview=True,
                                     alpha_bar=True,
                                     width=200,
                                     callback=_update_dynamic_textures,
                                     callback_data=2)
                dpg.add_text("Image")
                dpg.add_image(demo_dynamic_texture_2)

        with cxt.tree_node(label="Image Series (plots)"):

            plot_id = dpg.add_plot(label="Image Plot", height=400)
            dpg.add_image_series("INTERNAL_DPG_FONT_ATLAS", [300, 300],
                                 [400, 400],
                                 label="font atlas",
                                 parent=plot_id)
            dpg.add_image_series(demo_static_texture_1, [0, 0], [100, 100],
                                 label="static 1",
                                 parent=plot_id)
            dpg.add_image_series(demo_static_texture_2, [150, 150], [200, 200],
                                 label="static 2",
                                 parent=plot_id)
            dpg.add_image_series(demo_static_texture_3, [200, -150],
                                 [300, -50],
                                 label="static 3",
                                 parent=plot_id)
            dpg.add_image_series(demo_dynamic_texture_1, [-200, 100],
                                 [-100, 200],
                                 label="dynamic 1",
                                 parent=plot_id)
            dpg.add_image_series(demo_dynamic_texture_2, [-200, -100],
                                 [-150, -50],
                                 label="dynamic 2",
                                 parent=plot_id)

        with cxt.tree_node(label="Drawlists"):

            with cxt.drawlist(width=400, height=300):
                dpg.draw_rectangle((0, 0), (400, 300),
                                   color=(100, 100, 100, 250),
                                   thickness=2)
                dpg.draw_image(demo_static_texture_3, [0, 0], [100, 100])
                dpg.draw_image(demo_dynamic_texture_1, [200, 100], [300, 200])
Esempio n. 11
0
    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])