예제 #1
0
    def draw(self):
        '''
        Draws the MainMenu
        '''
        with simple.window(self.title, **config.MENU_CONFIG):
            with simple.menu_bar('Main Menu'):

                with simple.menu('File'):
                    core.add_menu_item('New', callback=self.new)
                    core.add_menu_item('Open', callback=self.open_file)
                    core.add_menu_item('Save', callback=self.save)
                    core.add_menu_item('Save As', callback=self.save_as)

                with simple.menu('Settings'):
                    with simple.menu('Theme'):
                        for theme in config.THEMES:
                            core.add_menu_item(theme,
                                               callback=self.set_theme,
                                               check=True)

            if self.dedit.get_name():
                core.add_text("Tree: {}".format(self.dedit.get_name()))
            else:
                core.add_text("Tree: <unnamed>.json")

            self.dedit.draw()
예제 #2
0
    def make_gui(self):
        dpg.set_main_window_size(self.width, self.height)
        dpg.set_theme(self.theme)
        with simple.window("Main", no_title_bar=True):
            dpg.set_main_window_title("pytasker")
            with simple.menu_bar("Menu"):
                with simple.menu("File"):
                    dpg.add_menu_item("New Page", callback=self.new_tab)
                    dpg.add_menu_item("Load Page", callback=self.load_page)
                    dpg.add_menu_item("Save Page",
                                      callback=self.save_page_dialog)
                    dpg.add_separator()
                    dpg.add_menu_item("Quit", callback=self.exit_program)
                with simple.menu("Themes"):
                    dpg.add_menu_item("Dark", callback=self.theme_callback)
                    dpg.add_menu_item("Light", callback=self.theme_callback)
                    dpg.add_menu_item("Classic", callback=self.theme_callback)
                    dpg.add_menu_item("Dark 2", callback=self.theme_callback)
                    dpg.add_menu_item("Grey", callback=self.theme_callback)
                    dpg.add_menu_item("Dark Grey",
                                      callback=self.theme_callback)
                    dpg.add_menu_item("Cherry", callback=self.theme_callback)
                    dpg.add_menu_item("Purple", callback=self.theme_callback)
                    dpg.add_menu_item("Gold", callback=self.theme_callback)
                    dpg.add_menu_item("Red", callback=self.theme_callback)

            dpg.add_tab_bar(name="tab_bar_1", parent="Main")
            with simple.group("inittext"):
                dpg.add_text("Hello! Select File - New to get started")
예제 #3
0
class Menu:
    def theme_setting(sender, data):
        core.set_theme(data)

    def dump_db():
        user_services.delete_records_by_username()

    with simple.window("Main Window",
                       no_title_bar=True,
                       autosize=True,
                       no_resize=True):
        with simple.menu_bar(name="Main Menu"):
            with simple.menu(name="Settings"):
                with simple.menu("Theme"):
                    core.add_menu_item("Dark",
                                       callback=theme_setting,
                                       callback_data="Dark")
                    core.add_menu_item("Light",
                                       callback=theme_setting,
                                       callback_data="Light")
                    core.add_menu_item("Classic",
                                       callback=theme_setting,
                                       callback_data="Classic")
                    core.add_menu_item("Dark 2",
                                       callback=theme_setting,
                                       callback_data="Dark 2")
                    core.add_menu_item("Grey",
                                       callback=theme_setting,
                                       callback_data="Grey")
                    core.add_menu_item("Dark Grey",
                                       callback=theme_setting,
                                       callback_data="Dark Grey")
                    core.add_menu_item("Cherry",
                                       callback=theme_setting,
                                       callback_data="Cherry")
                    core.add_menu_item("Purple",
                                       callback=theme_setting,
                                       callback_data="Purple")
                    core.add_menu_item("Gold",
                                       callback=theme_setting,
                                       callback_data="Gold")
                    core.add_menu_item("Red",
                                       callback=theme_setting,
                                       callback_data="Red")
                with simple.menu(name="Database"):
                    core.add_menu_item("Dump database", callback=dump_db)
        core.add_spacing(count=10)
    simple.hide_item("Main Menu")
예제 #4
0
    def run_gui(self):
        with window("Auto Pots"):
            set_start_callback(self.read_default_preferences)
            set_main_window_title('Auto Pots')
            set_window_pos("Auto Pots", 0, 0)
            add_spacing(count=12)

            add_button('Pick Maple Window', callback=self.pick_maple_window)
            add_text('Currently doing nothing. Pick MapleStory window.')
            add_spacing(count=12)

            add_text('Take HP Pot When Reaching', color=[232, 163, 33])
            add_slider_int("% HP", default_value=45, max_value=99, width=int(SCREEN_WIDTH * 0.8),
                           callback=self.change_hp_percentage)
            with menu('Select HP button on keyboard'):
                add_menu_item("Insert", callback=self.change_hp_keyboard_button)
                add_menu_item("Delete", callback=self.change_hp_keyboard_button)
                add_menu_item("Home", callback=self.change_hp_keyboard_button)
                add_menu_item("End", callback=self.change_hp_keyboard_button)
                add_menu_item("PgUp", callback=self.change_hp_keyboard_button)
                add_menu_item("PgDn", callback=self.change_hp_keyboard_button)

            add_spacing(count=12)
            add_text('Take MP Pot When Reaching', color=[232, 163, 33])
            add_slider_int("% MP", default_value=30, max_value=99, width=int(SCREEN_WIDTH * 0.8),
                           callback=self.change_mp_percentage)
            with menu('Select MP button on keyboard'):
                add_menu_item("Insert##1", callback=self.change_mp_keyboard_button)
                add_menu_item("Delete##1", callback=self.change_mp_keyboard_button)
                add_menu_item("Home##1", callback=self.change_mp_keyboard_button)
                add_menu_item("End##1", callback=self.change_mp_keyboard_button)
                add_menu_item("PgUp##1", callback=self.change_mp_keyboard_button)
                add_menu_item("PgDn##1", callback=self.change_mp_keyboard_button)

            add_spacing(count=12)
            add_button('Save Preferences As Default', callback=self.save_preferences)
            with popup("Save Preferences As Default", 'Save Popup', modal=True, mousebutton=mvMouseButton_Left):
                add_text('Your preferences has been saved')
                add_button("OK!", callback=lambda x, y: close_popup(item="Save Popup"))

            add_spacing(count=12)
            add_text('Currently doing nothing on HP. Pick button.')
            add_text('Currently doing nothing on MP. Pick button.')

        self.read_default_preferences()
        start_dearpygui(primary_window='Auto Pots')
예제 #5
0
def create_menu():
    with simple.menu_bar("main_menu_bar", parent="main_window"):
        with simple.menu("token_menu", label="Settings"):
            core.add_menu_item("signout_button",
                               callback=signout,
                               parent="token_menu",
                               label="Sign Out")
            core.add_menu_item("edit_token_menu",
                               callback=create_widget,
                               parent="token_menu",
                               label="Edit Token")
예제 #6
0
class Menu:
    def theme_setting(sender, data):
        core.set_theme(data)

    with simple.window("Main Window"):
        with simple.menu_bar(name="Main Menu"):
            with simple.menu(name="Notifications"):
                with simple.menu("Set notifications"):
                    core.add_menu_item("Every 30 minutes")
                    core.add_menu_item("Every 1 hour")
                    core.add_menu_item("Every 2 hours")
                    core.add_menu_item("Disable")
            with simple.menu(name="Settings"):
                with simple.menu("Theme"):
                    core.add_menu_item("Dark##Theme 1",
                                       callback=theme_setting,
                                       callback_data="Dark")
                    core.add_menu_item("Light##Theme 2",
                                       callback=theme_setting,
                                       callback_data="Light")
        core.add_spacing(count=10)
 def create_menu(self):
     """
     Creates menu with menu items
     :return: Menu
     """
     with s.menu(name="Settings##menu", parent=self.menu_bar_name):
         c.add_menu_item(
             name="ShowDataOption##Settings",
             label="Show local data storage",
             callback=self.show_local_storage,
         )
         c.add_menu_item(name="AdjustSettings##Settings",
                         label="Change Settings",
                         enabled=False)
    def _create_menu(self):
        """
        Creates menu with add and reset data options
        """
        with s.menu_bar("MenuBar"):
            with s.menu("Data Operations"):
                c.add_menu_item(
                    "Add Data",
                    callback=self.add_data_option,
                )

                c.add_menu_item(
                    "Reset Data",
                    callback=self.reset_data,
                )
예제 #9
0
from dearpygui import core, simple
from settings_window import SettingsWindow

core.enable_docking()
settingsWindow = SettingsWindow()

core.set_main_window_title("NeuronApplication")
with simple.window('MainWindow'):
    core.add_menu_bar("MenuBar")
    with simple.menu("Motyw##demo"):
        core.add_menu_item("Ciemny", callback=lambda sender, data: core.set_theme("Dark"), check=True)
        core.add_menu_item("Jasny", callback=lambda sender, data: core.set_theme("Light"), check=True)
        core.add_menu_item("Klasyczny", callback=lambda sender, data: core.set_theme("Classic"), check=True)
        core.add_menu_item("Ciemny 2", callback=lambda sender, data: core.set_theme("Dark 2"), check=True)
        core.add_menu_item("Szary", callback=lambda sender, data: core.set_theme("Grey"), check=True)
        core.add_menu_item("Ciemno-Szary", callback=lambda sender, data: core.set_theme("Dark Grey"), check=True)
        core.add_menu_item("Wisniowy", callback=lambda sender, data: core.set_theme("Cherry"), check=True)
        core.add_menu_item("Purpurowy", callback=lambda sender, data: core.set_theme("Purple"), check=True)
        core.add_menu_item("Zloty", callback=lambda sender, data: core.set_theme("Gold"), check=True)
        core.add_menu_item("Czerwony", callback=lambda sender, data: core.set_theme("Red"), check=True)
    with simple.menu("Pozycja"):
        core.add_menu_item("Zresetuj wszystko", callback=lambda sender, data: settingsWindow.reset_all())
        pass
    with simple.menu("Ukryj"):
        core.add_menu_item("Okno ustawien", callback = lambda sender, data: settingsWindow.toggle_visibility())
        core.add_menu_item("Wizualizacja sieci", callback = lambda sender, data: settingsWindow.betterVisualizer.toggle_visibility())
        core.add_menu_item("Wczytaj plik", callback = lambda sender, data: settingsWindow.importWindow.toggle_visibility())
        core.add_menu_item("Odpowiedz sieci", callback = lambda sender, data: settingsWindow.outputVisualisationWindow.toggle_visibility())
        core.add_menu_item("Historia uczenia##temp2", callback = lambda sender, data: settingsWindow.historyGraphWindow.toggle_visibility())

예제 #10
0
def start():
    """
    Renders main window elements.
    """
    with open('token.txt', 'r') as token_file:
        token = token_file.readline()
        try:
            # Connect to IBM
            core.run_async_function(get_backends_async, data=token)
            core.set_render_callback(show_button)

            # Progress bar
            with simple.window('Please wait',
                               no_scrollbar=True,
                               height=70,
                               width=400,
                               x_pos=500,
                               y_pos=200):
                core.add_progress_bar('progress',
                                      value=0.0,
                                      overlay='Connecting to IBM...',
                                      width=400)
                core.run_async_function(progress_async, 0)

            # Menu bar
            with simple.menu_bar("Main Menu Bar"):

                with simple.menu("File"):

                    core.add_menu_item("Save", callback=print_me)
                    core.add_menu_item("Save As", callback=print_me)

                core.add_menu_item("Help", callback=open_help_window)
                core.add_menu_item("About", callback=open_about_window)

            # Parameters group
            with simple.group('left group', width=350):
                # Select file button
                core.add_child('##file_block',
                               width=350,
                               height=180,
                               show=False)
                core.add_button('File Selector', callback=file_picker)
                core.add_spacing(name='##space2', count=3)
                core.add_text('File location:')
                core.add_label_text('##filedir',
                                    value='None Selected',
                                    source='directory')
                core.add_spacing(name='##space3', count=3)
                core.add_text('File name:')
                core.add_label_text('##file',
                                    value='None Selected',
                                    source='file_directory')
                core.end()
                core.add_spacing(name='##space4', count=3)
                # Architecture type radio button
                core.add_child('##settings_block',
                               width=350,
                               height=450,
                               show=False)
                core.add_text('Architecture type:')
                core.add_radio_button('radio##1',
                                      items=[
                                          'IBM simulator',
                                          'IBM quantum computer',
                                          'Arbitrary computer coupling'
                                      ],
                                      callback=show_architecture_list,
                                      source='device_type')
                core.add_spacing(name='##space5', count=3)
                # "Create arbitrary coupling" button
                core.add_button('Create custom architecture',
                                callback=create_architecture,
                                show=False)
                core.add_spacing(name='##space11', count=3)
                # Layout radio button
                core.add_text('Quantum circuit layout method:')
                core.add_radio_button(
                    'radio##2',
                    items=['Original IBM layout', 'Advanced SWAP placement'],
                    source='layout_type')
                core.add_spacing(name='##space6', count=3)
                # Optimization level slider
                core.add_text('Optimization level:')
                core.add_slider_int(
                    '##optimization_lvl',
                    default_value=1,
                    min_value=0,
                    max_value=3,
                    tip='drag the slider to select an optimization level',
                    width=300,
                    source='opt_level')
                core.add_spacing(name='##space7', count=3)
                # Number of iterations slider
                core.add_text('Number of iterations:')
                core.add_input_int('##num_of_iter',
                                   width=300,
                                   callback=check_iteration_num,
                                   default_value=100)
                core.add_spacing(name='##space8', count=3)
                # Default settings button
                core.add_button('Set Default', callback=set_default)
                core.end()
                core.add_spacing(name='##space9', count=3)
                # Process button
                core.add_button('Process', callback=process, show=False)

            # graph images
            core.add_same_line(name='line##3', xoffset=370)
            with simple.group('center group'):
                core.add_child('##images_block', width=640, show=False)
                # Input circuit preview
                core.add_text('Input circuit:')
                core.add_drawing('input_circuit', width=600, height=500)
                core.draw_rectangle('input_circuit', [0, 150], [600, 500],
                                    [255, 255, 255, 0], [255, 255, 255, 50])
                # Output circuit view
                core.add_text('Output circuit:')
                core.add_drawing('output_circuit', width=600, height=500)
                core.draw_rectangle('output_circuit', [0, 150], [600, 500],
                                    [255, 255, 255, 0], [255, 255, 255, 50])
                core.end()

            # program output
            core.add_same_line(name='line##3', xoffset=1020)
            with simple.group('right group'):
                core.add_child('##output_block1',
                               width=460,
                               height=300,
                               show=False)
                core.add_button('Open qasm file', callback=open_qasm)
                core.add_text('Path to IBM circuit representation')
                core.add_label_text('##circuitImage')
                core.add_button('Mapping', callback=show_mapping)
                core.end()
                core.add_text('Program output:', show=False)
                core.add_child('##output_block2',
                               width=460,
                               height=180,
                               show=False)
                core.add_text('Program output will be displayed here',
                              wrap=440)
                core.end()

        except Exception as exc:
            print("[ERROR]: {}".format(exc))
예제 #11
0
파일: gui.py 프로젝트: AryanAb/StockV
    print(type(predict[0]))
    core.add_line_series("Pred",
                         "Prediction",
                         predict.index.tolist(),
                         predict[0].tolist(),
                         color=[255, 50, 50, 100])


with simple.window("Stock", width=650, height=300, x_pos=10, y_pos=110):
    core.add_plot("Plot", height=-1)

with simple.window("Market Cap", width=650, height=300, x_pos=10, y_pos=415):
    core.add_plot("Cap", height=-1)

with simple.window("Select Company", height=90, x_pos=10, y_pos=5):
    with simple.menu("Companies##plot"):
        for file in os.listdir("dataset"):
            filename = os.fsdecode(file)
            if filename.endswith(".csv"):
                core.add_menu_item(filename.split('_')[0] + "##plot",
                                   callback_data=filename,
                                   callback=plot_callback)

    with simple.menu("Cap Interval"):
        core.add_menu_item("Daily",
                           callback_data="daily",
                           callback=cap_callback)
        core.add_menu_item("Monthly",
                           callback_data="monthly",
                           callback=cap_callback)
        core.add_menu_item("Quarterly",
예제 #12
0
def main():

    center_items = []
    core.add_data('item_center_list', center_items)

    with simple.window(TITLE):
        with simple.menu_bar('##menu_bar'):
            with simple.menu('File'):
                # core.add_menu_item('Import', callback=None)
                # core.add_menu_item('Export', callback=None)
                with simple.menu('Theme'):
                    themes = ['Dark', 'Light', 'Classic', 'Dark 2', 'Grey', 'Dark Grey', 'Cherry', 'Purple', 'Gold', 'Red']
                    for theme in themes:
                        core.add_menu_item(theme, callback=menu.update_theme)
                # core.add_menu_item('Exit', callback=None)
            with simple.menu('About'):
                core.add_menu_item('Version', callback=menu.show_version)

        with simple.group('##input_group'):
            # Title input
            core.add_text('Title:')
            core.add_input_text(TITLE_ID, hint='Enter title', width=WIDGET_WIDTH)
            core.add_spacing(count=2)

            # Identifier input
            core.add_text('Identifier:')
            core.add_input_text(IDENTIFIER_ID, hint='Enter identifier', width=WIDGET_WIDTH)
            core.add_spacing(count=2)

            # Password input
            core.add_text('Password:'******'Enter password', width=WIDGET_WIDTH)
            core.add_spacing(count=2)

            # Note input
            core.add_text('Note:')
            core.add_input_text(NOTE_ID, hint='Enter note info', width=WIDGET_WIDTH)
            core.add_spacing(count=10)

            # Save button
            save_clear_spacing = 50
            core.add_button('##save', label='Save', callback=input_field.save_password, width=WIDGET_HALF_WIDTH - (save_clear_spacing // 2))
            core.set_item_color('##save', core.mvGuiCol_Button, color=GREEN)
            core.add_same_line(spacing=save_clear_spacing)
            # Clear input entry button
            core.add_button('##clear_input', label='Clear input', callback=input_field.clear_input, width=WIDGET_HALF_WIDTH - (save_clear_spacing // 2))
            core.add_spacing(count=20)

        with simple.group('##log_group'):
            # Logger
            core.add_logger('##log_message', auto_scroll_button=False, copy_button=False, filter=False, clear_button=False, width=WIDGET_WIDTH, height=80)
            core.set_log_level(core.mvTRACE, logger='##log_message')
            core.add_spacing(count=10)

            # Clear log button
            core.add_button('##clear_log', label='Clear log', callback=logger.clear_log, width=WIDGET_WIDTH)
            core.add_spacing(count=10)

        with simple.group('##password_table_group'):
            # Password table
            header = ['No', 'Title', 'Identifier', 'Password', 'Note']
            core.add_table('##password_table', header, callback=table.table_printer, height=int(WINDOW_HEIGHT * 0.45), width=WIDGET_WIDTH)
            core.add_spacing(count=10)

            table.update_password_table()

            # Update password table button
            update_delete_spacing = 20
            core.add_button('##update_table', label='Update table', callback=table.update_password_table, width=WIDGET_HALF_WIDTH - (update_delete_spacing // 2))
            core.set_item_color('##update_table', core.mvGuiCol_Button, color=BLUE)
            core.add_same_line(spacing=update_delete_spacing)

            # Delete password table button
            core.add_button('##delete_table', label='Delete table', width=WIDGET_HALF_WIDTH - (update_delete_spacing // 2))
            core.set_item_color('##delete_table', core.mvGuiCol_Button, color=RED)
            with simple.popup('##delete_table', '##ask_delete', mousebutton=core.mvMouseButton_Left, modal=True):
                with simple.group('##delete_table_button_group'):
                    delete_table_spacing = 10
                    delete_table_half_width = core.get_main_window_size()[1] // 5 - delete_table_spacing

                    core.add_text('##delete_table_button', default_value='Are you sure to delete all data?')

                    core.add_spacing(count=delete_table_spacing)
                    core.add_button('##delete_table_button_yes', label='Yes', callback=table.delete_password_table, callback_data=True, width=delete_table_half_width)
                    core.add_same_line(spacing=delete_table_spacing)
                    core.add_button('##delete_table_button_no', label='No', callback=table.delete_password_table, callback_data=False, width=delete_table_half_width)

                    # TODO WONT WORK NEED TO FIX center_item FUNCTION
                    # center_item('##delete_table_button')
                    # center_item('##delete_table_button_yes')
                    # center_item('##delete_table_button_no')
                # center_item('##delete_table_button_group')

    if DEBUG_MODE:
        # core.show_logger()
        simple.show_debug()
        # simple.show_documentation()

    # Common Configuration
    core.set_theme(DEFAULT_THEME)
    core.add_additional_font(FONT, FONT_SIZE)
    core.set_main_window_title(TITLE)
    core.set_main_window_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    core.set_main_window_resizable(RESIZABLE)
    core.set_style_window_padding(WINDOW_PADDING, WINDOW_PADDING)
    core.set_exit_callback(model.close_connection)

    # core.set_render_callback(apply_centering)
    core.start_dearpygui(primary_window=TITLE)
예제 #13
0
def main():
    empty_board = [['_E','_E','_E','_E','_E','_E','_E','_E'],
                   ['_E','_E','_E','_E','_E','_E','_E','_E'],
                   ['_E','_E','_E','_E','_E','_E','_E','_E'],
                   ['_E','_E','_E','_E','_E','_E','_E','_E'],
                   ['_E','_E','_E','_E','_E','_E','_E','_E'],
                   ['_E','_E','_E','_E','_E','_E','_E','_E'],
                   ['_E','_E','_E','_E','_E','_E','_E','_E'],
                   ['_E','_E','_E','_E','_E','_E','_E','_E']]
    initial_board = [['Tn','Cn','An','Dn','Rn','An','Cn','Tn'],
                     ['Pn','Pn','Pn','Pn','Pn','Pn','Pn','Pn'],
                     ['_E','_E','_E','_E','_E','_E','_E','_E'],
                     ['_E','_E','_E','_E','_E','_E','_E','_E'],
                     ['_E','_E','_E','_E','_E','_E','_E','_E'],
                     ['_E','_E','_E','_E','_E','_E','_E','_E'],
                     ['Pb','Pb','Pb','Pb','Pb','Pb','Pb','Pb'],
                     ['Tb','Cb','Ab','Db','Rb','Ab','Cb','Tb']]

    def mouse_click_callback(sender,data):
        nonlocal c_board

        if data == 0 and c_board.current_selection != -1:
            m_position = dpg.get_mouse_pos()
            position = c_board.get_board_position(m_position)

            if not position:
                return

            if c_board.current_selection == 0:
                c_board.change_box('P', position) # put peon
            elif c_board.current_selection == 1:
                c_board.change_box('T', position) # put toker
            elif c_board.current_selection == 2:
                c_board.change_box('C', position) # put horse
            elif c_board.current_selection == 3:
                c_board.change_box('A', position) # put bishop
            elif c_board.current_selection == 4:
                c_board.change_box('D', position) # put queen
            elif c_board.current_selection == 5:
                c_board.change_box('R', position) # put king
            elif c_board.current_selection == 6:
                c_board.change_box(None,position) # remove
            elif c_board.current_selection == 7:
                # draw arrow
                size = c_board.piece_size
                c = size//2
                position = (position[0]*size+c,position[1]*size+c)
                if c_board.step == 0:
                    c_board.lines.append([(),(),''])
                    c_board.lines[-1][0] = position
                elif c_board.step == 1:
                    c_board.lines[-1][1] = position
                    color = dpg.get_value('drawing_color')
                    r = int(color[0])
                    g = int(color[1])
                    b = int(color[2])
                    color = 'rgb({},{},{})'.format(r,g,b)
                    c_board.lines[-1][2] = color

                c_board.step = (c_board.step+1)%2

                if c_board.step == 1:
                    return

            elif c_board.current_selection == 8:
                # delete arrow
                size = c_board.piece_size
                c = size//2
                position = (position[0]*size+c,position[1]*size+c)
                for i in range(len(c_board.lines)):
                    line = c_board.lines[i]
                    if position == line[0] or position == line[1]:
                        c_board.lines.remove(line)
                        break
            elif c_board.current_selection == 9:
                # color box
                color = dpg.get_value('drawing_color')
                r = int(color[0])
                g = int(color[1])
                b = int(color[2])
                color = 'rgb({},{},{})'.format(r,g,b)
                col = position[0]
                row = position[1]
                c_board.colored_boxes[row][col] = color
            elif c_board.current_selection == 10:
                # discolor box
                col = position[0]
                row = position[1]
                c_board.colored_boxes[row][col] = None

            c_board.draw_board()

        if data == 1:
            if c_board.piece_color == 'b':
                c_board.piece_color = 'n'
                dpg.set_value('color_piece', "Negro")
            else:
                 c_board.piece_color = 'b'
                 dpg.set_value('color_piece', "Blanco")

    def key_press_callback(sender, data):
        nonlocal c_board
        if data == dpg.mvKey_Right:
            if c_board.reading_pgn:
                pars.current_match.next_position()
                c_board.draw_board()
            else:
                return

        if data == dpg.mvKey_Left:
            if c_board.reading_pgn:
                pars.current_match.previews_position()
                c_board.draw_board()
            else:
                return

        if data == dpg.mvKey_Escape :
            c_board.current_selection = -1
            c_board.reading_pgn = False
            dpg.set_value("accion", "Sin seleccionar")
            dpg.set_value("pieza", "Sin seleccionar")
            return

    def load_callback(sender, data):
        def file_callback(sender, data):
            nonlocal c_board
            file = open(data[1],'rb')
            load_board = pickle.load(file)
            file.close()
            c_board = load_board
            c_board.draw_board()

        dpg.open_file_dialog(callback=file_callback, extensions=".sv")

    def save_callback(sender, data):
        nonlocal c_board

        c_board.save_board()

    def save_image_callback(sender,data):
        nonlocal c_board
        c_board.save_board_image()

    def clean_callback(sender, data):
        nonlocal c_board
        nonlocal empty_board
        c_board.reading_pgn = False
        c_board.board = copy.deepcopy(empty_board)
        c_board.lines = []
        c_board.colored_boxes = [[None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None]]
        c_board.draw_board()

    def default_board_callback(sender, data):
        nonlocal c_board
        nonlocal initial_board
        c_board.reading_pgn = False
        c_board.board = copy.deepcopy(initial_board)
        c_board.lines = []
        c_board.colored_boxes = [[None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None],
                                 [None,None,None,None,None,None,None,None]]
        c_board.draw_board()

    def close(sender,data):
        try:
            os.remove("tmp.png")
        except Exception as e:
            pass

    def pgn_reader(sender,data):

        def load_match(sender,data):
            nonlocal pars
            nonlocal c_board
            coords = dpg.get_table_selections(sender)
            dpg.delete_item('Partidas')
            dpg.delete_item('Lista de Partidas')
            i = coords[0][0]
            match = pars.matches[i]
            pars.current_match = match
            c_board.board = match.board
            c_board.reading_pgn = True
            dpg.set_value('accion','Leyendo partida PGN')
            dpg.set_value('pieza','Sin seleccionar')
            c_board.draw_board()

        def close_callback(sender,data):
            dpg.delete_item('Partidas')
            dpg.delete_item('Lista de Partidas')

        def file_callback(sender, data):
            nonlocal c_board
            nonlocal pars

            pars = Parser()
            pars.get_plays(data[0]+'/'+data[1])

            # Lista de partidas cargadas--------------------------------TODO
            dpg.add_window('Lista de Partidas',on_close=close_callback)
            colums = set()
            for match in pars.matches:
                for att in match.attr:
                    colums.add(att)
            colums = list(colums)
            # colums.sort()
            dpg.add_table("Partidas", colums, callback=load_match)

            rows = list()
            for match in pars.matches:
                row = list()
                for colum in colums:
                    row.append(match.attr[colum])

                rows.append(row)

            for row in rows:
                dpg.add_row("Partidas", row)

            dpg.end()

        dpg.open_file_dialog(callback=file_callback, extensions=".pgn")

    def control_button(sender,data):
        nonlocal c_board;
        c_board.reading_pgn = False

        add_arr = c_board.current_selection == 7
        if add_arr and c_board.step == 1:
            c_board.lines.pop()
            c_board.step = 0

        if sender == 'Peon':
            c_board.current_selection = 0
            dpg.set_value("accion", "Añadiendo Pieza")
            dpg.set_value("pieza", "Peon")
        elif sender == 'Torre':
            c_board.current_selection = 1
            dpg.set_value("accion", "Añadiendo Pieza")
            dpg.set_value("pieza", "Torre")
        elif sender == 'Caballo':
            c_board.current_selection = 2
            dpg.set_value("accion", "Añadiendo Pieza")
            dpg.set_value("pieza", "Caballo")
        elif sender == 'Alfil':
            c_board.current_selection = 3
            dpg.set_value("accion", "Añadiendo Pieza")
            dpg.set_value("pieza", "Alfil")
        elif sender == 'Reina':
            c_board.current_selection = 4
            dpg.set_value("accion", "Añadiendo Pieza")
            dpg.set_value("pieza", "Reina")
        elif sender == 'Rey':
            c_board.current_selection = 5
            dpg.set_value("accion", "Añadiendo Pieza")
            dpg.set_value("pieza", "Rey")
        elif sender == 'Eliminar Pieza':
            c_board.current_selection = 6
            dpg.set_value("accion", "Eliminando Pieza")
            dpg.set_value("pieza", "Sin seleccionar")
        elif sender == 'Añadir flecha':
            c_board.current_selection = 7
            dpg.set_value("accion", "Añadiendo flecha")
            dpg.set_value("pieza", "Sin seleccionar")
        elif sender == 'Eliminar flecha':
            c_board.current_selection = 8
            dpg.set_value("accion", "Eliminando flecha")
            dpg.set_value("pieza", "Sin seleccionar")
        elif sender == 'Colorear casilla':
            c_board.current_selection = 9
            dpg.set_value("accion", "Coloreando casilla")
            dpg.set_value("pieza", "Sin seleccionar")
        elif sender == 'Descolorear casilla':
            c_board.current_selection = 10
            dpg.set_value("accion", "Descolorando casilla")
            dpg.set_value("pieza", "Sin seleccionar")

    c_board = Board(board = copy.deepcopy(empty_board))
    pars = Parser()

    main_width = c_board.size+220
    main_height= c_board.size+240

    with dpgs.window('Diagramador'):
        dpg.set_main_window_size(main_width, main_height)
        dpg.set_main_window_resizable(False)
        dpg.set_exit_callback(close)

        with menu_bar('Menu bar'):
            with menu('Archivo'):
                dpg.add_menu_item("Guardar", callback=save_callback)
                dpg.add_menu_item("Guardar Imagen", callback=save_image_callback)
                dpg.add_menu_item("Cargar tablero", callback=load_callback)
            with menu('Herramientas'):
                dpg.add_menu_item("Leer archivo PGN", callback=pgn_reader)
            with menu('Color'):
                dpg.add_color_edit3('Seleccion de Color',source='drawing_color')

        dpg.add_drawing("canvas", width=c_board.size,height=c_board.size)
        dpg.add_image('board_img','',source=c_board.piece_p('Abb'))
        dpg.add_same_line()

        controles =(
            "\nControles\n"
            "Click Derecho : Cambiar color de pieza\n\n"
            "Flecha derecha: Mostrar siguiente jugada PGN\n\n"
            "Flecha izquierda: Mostrar la jugada PGN previa\n\n"
        )
        dpg.add_child('controls',autosize_x=True,height=c_board.size)
        dpg.add_button('Peon',callback=control_button)
        dpg.add_button('Torre',callback=control_button)
        dpg.add_button('Caballo',callback=control_button)
        dpg.add_button('Alfil',callback=control_button)
        dpg.add_button('Reina',callback=control_button)
        dpg.add_button('Rey',callback=control_button)
        dpg.add_button('Eliminar Pieza',callback=control_button)
        dpg.add_button('Añadir flecha',callback=control_button)
        dpg.add_button('Eliminar flecha',callback=control_button)
        dpg.add_button('Colorear casilla',callback=control_button)
        dpg.add_button('Descolorear casilla',callback=control_button)
        dpg.add_text(controles)
        dpg.end()

        dpg.set_value('drawing_color',[0,0,0])
        name = "Nombre de Archivo"
        dpg.add_input_text(name, width=250, source='save_name')
        name = "Nombre de Imagen"
        dpg.add_input_text(name, width=250, source='save_img_name')
        dpg.add_button("Limpiar tablero", callback=clean_callback)
        name = "Tablero por defecto"
        dpg.add_button(name, callback=default_board_callback)

        name = "Acción"
        dpg.add_label_text(name, default_value='Sin seleccionar', source="accion")
        dpg.add_label_text("Pieza", default_value='Sin seleccionar', source="pieza")
        dpg.add_label_text("Color de pieza", default_value='Blanco', source='color_piece')
        c_board.draw_board()

        dpg.set_key_press_callback(key_press_callback)
        dpg.set_mouse_click_callback(mouse_click_callback)

        dpg.start_dearpygui(primary_window = 'Diagramador')
예제 #14
0
    def run(self, width: int = 700, height: int = 800, **kwargs):
        # pylint: disable=arguments-differ
        """
        GUI definition and runs dearpygui
        :param width: pixel width of main window
        :param height: pixel height of main window
        :param kwargs: any simple.window kwargs
        :return:GUI although more probably 'void'
        """
        if self.development:
            x_pos = 300
        else:
            x_pos = 0

        with s.window(
                name="Timer",
                x_pos=x_pos,
                y_pos=0,
                width=width,
                height=height,
                no_close=True,
                no_title_bar=True,
                no_resize=not self.development,
                no_move=not self.development,
                no_bring_to_front_on_focus=True,
                **kwargs,
        ):
            with s.menu_bar("Main Menu Bar"):
                with s.menu("Projects##ProjectMenu"):
                    for name in self.db.get_project_names():
                        c.add_menu_item(name=name,
                                        callback=self.select_project,
                                        callback_data=name)
                    c.add_menu_item("Add project",
                                    callback=self.create_new_project)
                with s.menu("Range##FilterMenu"):
                    c.add_menu_item(name="Today",
                                    callback=self.filter_entries,
                                    check=False)
                    c.add_menu_item(name="All Time",
                                    callback=self.filter_entries,
                                    check=True)
                settings_menu.create_menu()

            c.add_spacing(count=40)
            c.add_input_text(name="Description",
                             default_value="coding",
                             label="Description")
            c.add_button(name="Start Timer", callback=self.flip_timer_state)
            c.add_same_line()
            c.add_button(name="Switch Task",
                         callback=self.switch_task,
                         show=False)

            c.add_spacing()
            entry_table.create_table(input_data=self.entries)
            c.add_spacing()
            task_chart.create_chart(data=[0.2, 0.5, 0.3],
                                    labels=self.db.get_project_names())
        timer_display.create_timer(x_pos=(x_pos + 60), y_pos=20)
        c.set_render_callback(self.render)
        c.start_dearpygui()