Exemple #1
0
    def __init__(self, controller):
        self.almacenes = []
        self.selected = None

        self.controller = controller
        self.app = App(title="Interfaces", layout="grid", width=600, height=200)

        # 0, 0
        self.lista = ListBox(self.app, items=[], grid=[0,0], command=self.handleListChange)
        self.lista.width = 30

        # 1, 0
        self.detalle = Box(self.app, grid=[1,0], layout="grid")
        self.nombreLabel = Text(self.detalle, size=DETALLE_LABEL_FSIZE, text="Nombre", grid=[0,0])
        self.direcionLabel = Text(self.detalle, size=DETALLE_LABEL_FSIZE, text="Dirección", grid=[0,1])
        self.provinciaLabel = Text(self.detalle, size=DETALLE_LABEL_FSIZE, text="Provincia", grid=[0,2])
        self.cpLabel = Text(self.detalle, size=DETALLE_LABEL_FSIZE, text="CP", grid=[0,3])
        self.telefonoLabel = Text(self.detalle, size=DETALLE_LABEL_FSIZE, text="Teléfono", grid=[0,4])

        self.nombre = TextBox(self.detalle, "", grid=[1,0], width=30, enabled=False)
        self.direccion = TextBox(self.detalle, "", grid=[1,1], width=30, enabled=False)
        self.provincia = TextBox(self.detalle, "", grid=[1,2], width=30, enabled=False)
        self.cp = TextBox(self.detalle, "", grid=[1,3], width=30, enabled=False)
        self.telefono = TextBox(self.detalle, "", grid=[1,4], width=30, enabled=False)

        # 0, 1
        self.toolbar = Box(self.app, grid=[0,1], layout="grid")
        self.buttonEdit = PushButton(self.toolbar, command=self.handleEdit, text="Editar", grid=[0,0])
        self.buttonAdd = PushButton(self.toolbar, command=self.handleAdd, text="Añadir", grid=[1,0])

        # 1, 1
        self.detalleToolbar = Box(self.app, grid=[1,1], layout="grid")
        self.buttonSave = PushButton(self.detalleToolbar, command=self.handleSave, text="Guardar", grid=[0,0], enabled=False)
Exemple #2
0
def test_clear():
    a = App()
    l = ListBox(a, ["foo", "bar"])
    assert l.items == ["foo", "bar"]
    l.clear()
    assert l.items == []

    a.destroy()
Exemple #3
0
def test_getters_setters():
    a = App()
    l = ListBox(a, ["foo", "bar"])

    assert l.value == None
    l.value = "bar"
    assert l.value == "bar"

    a.destroy()
Exemple #4
0
def test_append():
    a = App()
    l = ListBox(a, ["foo", "bar"])

    assert l.items == ["foo", "bar"]
    l.append("car")
    assert l.items == ["foo", "bar", "car"]

    a.destroy()
Exemple #5
0
def test_insert():
    a = App()
    l = ListBox(a, ["foo", "bar"])

    assert l.items == ["foo", "bar"]
    l.insert(1, "car")
    assert l.items == ["foo", "car", "bar"]

    a.destroy()
Exemple #6
0
def test_remove():
    a = App()
    l = ListBox(a, ["foo", "bar", "foo"])

    assert l.items == ["foo", "bar", "foo"]
    l.remove("foo")
    assert l.items == ["bar", "foo"]

    a.destroy()
Exemple #7
0
def test_multi_getters_setters():
    a = App()
    l = ListBox(a, ["foo", "bar"], multiselect=True)

    assert l.value == None
    l.value = ["bar"]
    assert l.value == ["bar"]
    l.value = ["bar", "foo"]
    # test selected values are in value
    assert all(x in l.value for x in ['bar', 'foo'])

    a.destroy()
Exemple #8
0
def test_grid_layout():
    a = App(layout="grid")

    w = ListBox(a, grid=[1, 2])
    grid_layout_test(w, 1, 2, 1, 1, None)

    ws = ListBox(a, grid=[1, 2, 3, 4])
    grid_layout_test(ws, 1, 2, 3, 4, None)

    wa = ListBox(a, grid=[1, 2], align="top")
    grid_layout_test(wa, 1, 2, 1, 1, "top")

    a.destroy()
Exemple #9
0
def test_command_with_parameter():
    a = App()

    callback_event = Event()
    def callback(value):
        assert value == "bar"
        callback_event.set()

    l = ListBox(a, ["foo", "bar"], command = callback)
    l.value = "bar"
    assert not callback_event.is_set()

    l._listbox._command_callback()
    assert callback_event.is_set()

    a.destroy()
Exemple #10
0
def prev_motive():
    clean_contentlist()
    motive = readas_list("asset/motive.txt")
    content_list.append(
        Text(content_box,
             text="Motives Preview",
             grid=[0, 0, 2, 1],
             size=10,
             color="blue",
             width="fill"))

    content_list.append(
        Text(content_box,
             text="none",
             grid=[1, 2],
             size=10,
             color="red",
             align="left"))
    content_list.append(
        Text(content_box,
             text="Preview: ",
             grid=[0, 2],
             size=10,
             color="blue",
             align="left"))
    content_list.append(
        ListBox(content_box,
                scrollbar=True,
                items=motive,
                command=update_preview,
                grid=[0, 1, 2, 1],
                width="fill"))
    go_mainmenu([0, 3, 2, 1], False)
Exemple #11
0
 def __init__(self):
     self.app = App(title="SATCOM", width=500, height=300, layout="grid")
     self.app.on_close(self.on_close)
     Text(self.app, text="Welcome to SATCOM", grid=[0, 0])
     self.satcom_time = Text(self.app,
                             text="SATCOM Time: UNKNOWN",
                             grid=[1, 0])
     self.satcom_time.text_color = "blue"
     Text(self.app, text="Satelite Connection Status: ", grid=[0, 1])
     self.satelite_status = Text(self.app, text="UNKNOWN", grid=[1, 1])
     self.satelite_status.text_color = "blue"
     Text(self.app, text="Satelite Messages: ", grid=[0, 2])
     self.satelite_msg = Text(self.app, text="0", grid=[1, 2])
     self.satelite_msg.text_color = "blue"
     Text(self.app, text="Current GPS Coordinates: ", grid=[0, 3])
     self.gps = Text(self.app, text="UNKNOWN", grid=[1, 3])
     self.gps.text_color = "blue"
     Text(self.app, text="Temp: ", grid=[0, 4])
     self.temp = Text(self.app, text="UNKNOWN", grid=[1, 4])
     self.temp.text_color = "blue"
     Text(self.app, text="Pressure: ", grid=[0, 5])
     self.pressure = Text(self.app, text="UNKNOWN", grid=[1, 5])
     self.pressure.text_color = "blue"
     Text(self.app, text="Humidity: ", grid=[0, 6])
     self.humidity = Text(self.app, text="UNKNOWN", grid=[1, 6])
     self.humidity.text_color = "blue"
     Text(self.app, text="Altitude: ", grid=[0, 7])
     self.altitude = Text(self.app, text="UNKNOWN", grid=[1, 7])
     self.altitude.text_color = "blue"
     self.send_message_window = Window(self.app,
                                       title="Send Message",
                                       width=400,
                                       height=80,
                                       layout="grid")
     Text(self.send_message_window, text="Message: ", grid=[0, 0])
     self.message_box = TextBox(self.send_message_window,
                                width=30,
                                grid=[1, 0])
     PushButton(self.send_message_window,
                text="Send",
                command=self.send_message,
                grid=[2, 0])
     self.send_message_window.hide()
     self.messages_window = Window(self.app,
                                   title="Messages",
                                   width=400,
                                   height=300)
     Text(self.messages_window, text="Messages")
     self.message_list = ListBox(self.messages_window)
     self.message_list.width = 40
     self.message_list.height = 15
     self.messages_window.hide()
     PushButton(self.app,
                text="Send Messages",
                command=self.show_send_message,
                grid=[0, 8])
     PushButton(self.app,
                text="Check Messages",
                command=self.show_messages,
                grid=[1, 8])
Exemple #12
0
def test_update_command_with_parameter():
    a = App()

    callback_event = Event()
    def callback(value):
        assert l.value == "foo"
        callback_event.set()

    l = ListBox(a, ["foo", "bar"])
    l.value = "foo"

    l.update_command(callback)

    l._listbox._command_callback()
    assert callback_event.is_set()

    a.destroy()
Exemple #13
0
def test_alt_values():
    a = App(layout="grid")
    l = ListBox(a, ["foo", "bar"], selected="bar", grid=[0, 1], align="top")

    assert l.value == "bar"
    assert l.items == ["foo", "bar"]
    assert l.grid[0] == 0
    assert l.grid[1] == 1
    assert l.align == "top"
    a.destroy()
Exemple #14
0
def SQLQueriesExecution(queryString, informationData):
    printData = []

    dataWindow = Window(app, title="Query Display", layout="grid")
    dataWindow.height = 1080
    dataWindow.width = 400
    dataWindow.bg = "Grey"

    dataRecord = connection.execute(queryString)
    printData.append(informationData)
    for row in dataRecord:
        printData.append(row)

    dataList = ListBox(dataWindow,
                       items=printData,
                       scrollbar=True,
                       grid=[0, 0],
                       align="top")
    dataList.height = 1080
    dataList.width = 400
    dataList.bg = "White"
Exemple #15
0
def test_default_values():
    a = App()
    l = ListBox(a)
    assert l.master == a
    assert l.value == None
    assert l.items == []
    assert l.grid == None
    assert l.align == None
    assert l.visible == True
    assert l.enabled == True
    assert l._listbox._multiselect == False
    a.destroy()
Exemple #16
0
    def __init__(self, input_excel_db):
        self.min_size = 32
        self.no_bits = 8
        self.value = 0
        self.bit_map = {}
        self.bit_descr = {}
        self.endianess = "big"

        self.app = App(layout="grid", height=350, width=550)
        self.top_box = Box(self.app, layout = "grid", grid = [0, 0])
        self.bottom_box = Box(self.app, layout = "grid", grid = [0, 1])
        self.right_box = Box(self.app, grid = [1, 0, 1, 2])

        self.window = Window(self.app, width=250, height=150, visible=False)
        self.description = Text(self.window)

        # Create the text field to enter data
        self.input = TextBox(self.top_box, width=25, grid=[0,0,3,1], command=self.process_input)
        self.input.bg = "white"
        self.input.text_size = 16

        # Display the hex value
        self.out_hex = Text(self.top_box, grid=[2,1], text="0x<waiting for valid input>")
        # Display the min number of bits selector
        self.in_minsize = Combo(self.top_box, grid=[0, 1], options=["32"], command=self.process_minsize, selected="32")
        # Endianess selector
        self.in_endianess = Combo(self.top_box, grid=[1, 1], options=["little", "big"], command=self.process_endianess,
                                  selected=self.endianess)

        # Display the binary value
        self.out_bin = Text(self.top_box, grid=[0, 2, 2, 1], size=17, text="0b<waiting for valid input>")
        # Display little number after the binary value
        self.out_num = Text(self.top_box, grid=[0, 3, 2, 1], size=7, text="")


        # Prepare the waffle list
        self.waffle_list = []
        self.box_list = []
        self.text_list = []

        self.append_wb(4)
        self.append_tx(self.no_bits)

        # Read the worksheets in the input dictionary and create the list
        self.in_excel = openpyxl.load_workbook(filename = input_excel_db, read_only=True)
        self.in_regs = self.in_excel.sheetnames
        self.in_regs.insert(0, "OFF")

        # Display the list of registers
        self.in_reglist = ListBox(self.right_box, items = self.in_regs, command=self.process_reglist)

        self.input.focus()
        self.app.display()
Exemple #17
0
def test_command():
    a = App()

    callback_event = Event()
    def callback():
        callback_event.set()

    l = ListBox(a, ["foo", "bar"], command = callback)
    assert not callback_event.is_set()

    l._listbox._command_callback()
    assert callback_event.is_set()

    a.destroy()
Exemple #18
0
def test_multi_alt_values():
    a = App(layout="grid")
    l = ListBox(a, ["foo", "bar"],
                selected=["bar"],
                grid=[0, 1],
                align="top",
                multiselect=True)

    assert l.value == ["bar"]
    assert l.items == ["foo", "bar"]
    assert l.grid[0] == 0
    assert l.grid[1] == 1
    assert l.align == "top"
    assert l._listbox._multiselect == True
    a.destroy()
Exemple #19
0
    def __init__(self, resolution, black_mode=0):
        self.app = App(title="Gauss-Seidel", bg="#A4DDCA", layout="grid", height=900, width=1200) ##f79be0

        self.list_of_functions = ["(x0^2+x1-11)^2 + (x0+x1^2-7)^2-200", "(x1^2+x0-11)^2 + (x1+x0^2-7)^2-200",
                                  "(x0-2)^2 +(x0-x1^2)^2", "x0^2+x1^2", "x0^4+x1^4-x0^2-x1^2", "x0+x1+x2",
                                  "x0+x1+x2+x3+x4+x5+x6+x7+x8+x9", "x0^2-cos(18*x0)+x1^2-cos(18*x1)",
                                  "x0^2-cos(18*x0)+x1^2-cos(18*x1)+x2^2-cos(18*x2)" ]
        self.list_of_iterations = []
        self.list_of_results = []
        self.list_of_starters = [-3, 4]
        self.listbox = ListBox(self.app, items=self.list_of_functions, grid=[4, 1], command=self.change, scrollbar=True, align="left", width= 300, height=200)
        self.function_plot = PushButton(self.app, command=self.start_plot, grid=[0, 0], text="3D function", width=20)
        self.contour_plot = PushButton(self.app, command=self.start_contour, grid=[1, 0], text="Contours", width=20)
        self.checkbox = CheckBox(self.app, grid=[0, 1], align="left", text="Black mode")
        self.checkbox2 = CheckBox(self.app, grid=[0, 2], align="left", text="dynamically")
        self.text_range_a = Text(self.app, text="Function: ", grid=[3, 0], width=14)
        self.input_box = TextBox(self.app, grid= [4, 0], text= self.list_of_functions[0] , width=60)
        self.append_button = PushButton(self.app, grid=[5,0], text="Add", align="left",
                                        command=self.append_to_list, width=5, height=1)
        self.text_range_a = Text(self.app, text= "Range: ", grid=[0,2])
        self.range_a = TextBox(self.app, grid= [1, 2], align="left", text= -5, width=5)
        self.range_b = TextBox(self.app, grid=[1, 2], align="right", text=5, width=5)
        self.precision_text = Text(self.app, text= "Precision: ", grid=[0,3])
        self.precision_box = TextBox(self.app, grid=[1, 3], align="right", text=0.0001, width=10)
        self.precision = self.precision_box.value
        self.text_range_a = Text(self.app, text= "Start points: ", grid=[0,4], width=10)
        self.start_points = TextBox(self.app, grid= [1, 4], text= self.list_of_starters, width=20)
        self.start = self.start_points.value
        self.activate = PushButton(self.app, grid=[0, 5], text="Activate", command=self.activate_params, width=20, height=2)
        self.activate = PushButton(self.app, grid=[1, 5], text="Start", command=self.start_algorithm, width=20, height=2)
        self.iteration_points_text = Text(self.app, text="Iteration points", grid= [0, 6, 2, 6], align="top")
        self.iteration_points_box = ListBox(self.app, items=self.list_of_iterations, grid=[0, 7, 2, 7], command=self.change, scrollbar=True, width=650, height=400)
        self.results_points_box = ListBox(self.app, items=self.list_of_results, grid=[3, 7], scrollbar=True, width=80, height=400)
        self.number_of_iterations = Text(self.app, grid= [4,6], text= "{} iteracji".format(len(self.list_of_iterations)), align="left")
        self.random_button = PushButton(self.app, grid=[2, 4], text= "Random", align="right", command=self.random_start_points, width=5, height=1)
        self.random_button = PushButton(self.app, grid=[1, 4], text="validate", align="right",
                                        command=self.change_starters, width=5, height=1)
        self.iterations = TextBox(self.app, grid=[4, 5], text= "1000", width=6, align="left")
        self.iterations_text = Text(self.app, grid=[3, 5], text="max iterations:", align="left")
        self.resolution = resolution
        self.x_range = int(self.range_a.value)
        self.y_range = int(self.range_b.value)
        self.x = np.linspace(self.x_range, self.y_range, resolution)  # 13
        self.y = np.linspace(self.x_range, self.y_range, resolution)
        self.black_mode = black_mode

        self.points_x = []
        self.points_y = []
        self.points_z = []

        self.start_app()
        self.formula = ""
Exemple #20
0
def test_alt_values():
    a = App(layout = "grid")
    l = ListBox(
        a,
        ["foo", "bar"],
        selected = "bar",
        grid = [0,1],
        align = "top",
        width=10,
        height=11,
        scrollbar=True)

    assert l.value == "bar"
    assert l.items == ["foo", "bar"]
    assert l.grid[0] == 0
    assert l.grid[1] == 1
    assert l.align == "top"
    assert l.width == 10
    assert l.height == 11

    a.destroy()
Exemple #21
0
def create_app():
    app = App(title="Main window for admin")
    status_for_all = Text(app, text="")
    status_for_all.repeat(1000, update_info_for_all_farms, [status_for_all])

    operation_history_text = Text(app, text="\n\nTransaction history:")
    history = ListBox(app, scrollbar=True)

    for i, farm in enumerate(farms):
        window = Window(app, title=f"Window for {farm.account_name}")
        text = Text(window, text="")
        text.repeat(1000, update_info_for_farm, [text, farm])
        bg = ButtonGroup(window, options=animals)
        text = Text(window, text="Send to:")
        whom = TextBox(window, text='')
        text = Text(window, text="Amount:")
        how_many = TextBox(window)
        status = Text(window, text="Status:")
        button = PushButton(window,
                            transfer,
                            text="Transfer!",
                            args=[farm, whom, bg, how_many, status, history])

    app.display()
Exemple #22
0
def test_update_command():
    a = App()

    callback_event = Event()
    def callback():
        callback_event.set()

    l = ListBox(a, ["foo", "bar"])

    l._listbox._command_callback()
    assert not callback_event.is_set()

    l.update_command(callback)
    l._listbox._command_callback()
    assert callback_event.is_set()
    callback_event.clear()

    l.update_command(None)
    l._listbox._command_callback()
    assert not callback_event.is_set()

    a.destroy()
# Set up the Box areas for our layout
add_box = Box(app, grid=[0,0], layout="grid")
search_box = Box(app, grid=[1,0])

# This section has the GUI widgets in the add_box area
heading = Text(add_box, text="Add new student", grid=[0,0])
name_lbl = Text(add_box, text="Name", grid=[0,1])
name_text = TextBox(add_box, grid=[1,1])
age_lbl = Text(add_box, text="Age", grid=[0,2])
age_text = TextBox(add_box, grid=[1,2])
phone_lbl = Text(add_box, text="Phone", grid=[0,3])
phone_text = TextBox(add_box, grid=[1,3])
gender_lbl = Text(add_box, text="Gender", grid=[0,4])
gender_combo = Combo(add_box, options=["Male", "Female", "Other"], grid=[1,4])
class_lbl = Text(add_box, text="Classes", grid=[0,5], align="top")
class_listbox = ListBox(add_box, ["GRA", "BIO", "PHY", "MAT", "DTC", "ART", "ENG", "XYZ"], grid=[1,5], multiselect=True)
add_button = PushButton(add_box, text="Add student", grid=[0,6, 2, 1], width=20,command=add_student)
success_lbl = Text(add_box, grid=[0,7,2,1])


# This is section where you add any GUI widgets to the search_box area
heading = Text(search_box, text="Search", color=(210, 45, 17))

search_textbox = TextBox(search_box)
search_button = PushButton(search_box, text="Search", command=search)

student_listbox = ListBox(search_box, command=display_details)

student_name = Text(search_box)
student_age = Text(search_box)
student_phone = Text(search_box)
Exemple #24
0
 def add_nutrients(self, missingnutrients):
     self.listbox = ListBox(self.app,
                            items=missingnutrients,
                            height=3,
                            width=30)
     self.lowbio = missingnutrients
from guizero import App, Box, ListBox, CheckBox, Combo, PushButton

app = App()

list_boxes = Box(app, width="fill")
ListBox(list_boxes, items=["Times New Roman", "Courier", "Verdana"], align="left", width="fill")
ListBox(list_boxes, items=["Regular", "Italic", "Bold", "Bold Italic"], align="left", width="fill")
ListBox(list_boxes, items=["8", "10", "12", "14", "16", "18"], align="left", width="fill")

combos = Box(app, width="fill")
combos.border = True
Combo(combos, options=["red", "green", "blue", "yellow"], align="left")
Combo(combos, options=["underline", "double underline"], align="right")

checks = Box(app, width="fill")
checks.border = True
CheckBox(checks, text="strike-through", align="left")
CheckBox(checks, text="double strike-through", align="left")
CheckBox(checks, text="sub-script", align="left")

buttons = Box(app, width="fill", align="bottom")
PushButton(buttons, text="Default", align="left")
PushButton(buttons, text="Ok", align="right")
PushButton(buttons, text="Cancel", align="right")

app.display()
Exemple #26
0
def print_selection():
    '''This funcation prints the values of the names selected.'''
    print(teacher_listbox.value)


# Empty lists to store all teachers and students
teacher_list = []
student_list = []

# Create some students to start with
Student("Jack", 16, "0273956577", "Male", ["GRA", "MAT", "ENG"])
Student("Jill", 15, "0271111111", "Female", ["MAT", "ART"])
Student("Matt", 17, "0217771117", "Male", ["MAT", "PHY", "ART"])

generate_teachers()
generate_students()

# create the application interface
app = App(title="Student management system")
# This is section where you add any GUI widgets
heading = Text(app, text="List of Teachers", color=(201, 50, 30))
teacher_names = []
for t in teacher_list:
    teacher_names.append(t.get_tname())
teacher_listbox = ListBox(app,
                          teacher_names,
                          selected="black",
                          command=print_selection)
# Start the program
app.display()
Exemple #27
0
def analyze():
    ldict = {}
    result = []

    rdict.clear()
    term_dict.clear()

    if (len(btn_list) > 0):
        for btn in btn_list:
            btn.destroy()
        btn_list.clear()

    if (len(lbox_list) > 0):
        for lbox in lbox_list:
            lbox.destroy()
        lbox_list.clear()

    with open('conditions.csv', newline='') as f:
        reader = csv.reader(f)
        data = list(reader)

        for line in data:
            #line[1] = line[1].replace(" ","")
            ldict[line[0]] = line[1:][0].split(',')

    data = text_box.value
    data_lower = data.lower()
    tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')

    if (preprocess_checkbox.value == 0):
        remove_history = re.sub('past medical history: diagnosis.*?drug use',
                                ' drug use ',
                                data_lower,
                                flags=re.DOTALL)
        remove_physicala = re.sub('physical exam.*?assessment/plan',
                                  '. ASSESSMENT',
                                  remove_history,
                                  flags=re.DOTALL)
        remove_complete = re.sub('physical exam.*?assessment and plan',
                                 '. ASSESSMENT',
                                 remove_physicala,
                                 flags=re.DOTALL)
        sentence_list = tokenizer.tokenize(remove_complete)

    else:
        sentence_list = tokenizer.tokenize(data_lower)

    for sentence in sentence_list:
        for (key, terms) in ldict.items():
            for term in terms:
                fixed_word = term.lower()
                # If have a special date character $date$
                # Insert the found dates into the ldict array as a term
                if fixed_word == "$date$":
                    ldict[key].extend(date_match)
                    continue
                if fixed_word in sentence:
                    dup_check = [key, sentence]
                    # If a sub term comes up we save it
                    if (sentence, key) in term_dict:
                        term_dict[(sentence, key)].append(fixed_word)
                    else:
                        term_dict[(sentence, key)] = [fixed_word]
                    if dup_check not in result:
                        result.append([key, sentence])
                        if key in rdict:
                            rdict[key].append(sentence)
                        else:
                            rdict[key] = [sentence]

    lbox_list.append(
        ListBox(form_box,
                items=sentence_list,
                width="fill",
                height=resolution[rt]['lbox_height'],
                command=dispay_full,
                multiselect=True,
                scrollbar=True))
    lbox_list[0].bg = "#C8D7E9"

    counter = 0
    btn = ""

    for (k, vl) in ldict.items():

        if (counter < 4):
            if k in rdict:
                if (platform != 'win32'):
                    btn = PushButton(button_box_r1,
                                     align="left",
                                     width="10",
                                     text=str("█" + k),
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                else:
                    btn = PushButton(button_box_r1,
                                     align="left",
                                     width="10",
                                     text=k,
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                btn.update_command(pval, [k, lbox_list[0]])
                btn.bg = "#9EF844"
            else:
                btn = PushButton(button_box_r1,
                                 align="left",
                                 width="10",
                                 text=k,
                                 pady=resolution[rt]['button_pady'])
                btn.bg = "#F84446"
        elif (counter < 8):
            if k in rdict:

                if (platform != 'win32'):
                    btn = PushButton(button_box_r2,
                                     align="left",
                                     width="10",
                                     text=str("█" + k),
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                else:
                    btn = PushButton(button_box_r2,
                                     align="left",
                                     width="10",
                                     text=k,
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                btn.update_command(pval, [k, lbox_list[0]])
                btn.bg = "#9EF844"
            else:
                btn = PushButton(button_box_r2,
                                 align="left",
                                 width="10",
                                 text=k,
                                 pady=resolution[rt]['button_pady'])
                btn.bg = "#F84446"
        elif (counter < 12):

            if k in rdict:

                if (platform != 'win32'):
                    btn = PushButton(button_box_r3,
                                     align="left",
                                     width="10",
                                     text=str("█" + k),
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                else:
                    btn = PushButton(button_box_r3,
                                     align="left",
                                     width="10",
                                     text=k,
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                btn.update_command(pval, [k, lbox_list[0]])
                btn.bg = "#9EF844"
            else:
                btn = PushButton(button_box_r3,
                                 align="left",
                                 width="10",
                                 text=k,
                                 pady=resolution[rt]['button_pady'])
                btn.bg = "#F84446"
        elif (counter < 16):

            if k in rdict:

                if (platform != 'win32'):
                    btn = PushButton(button_box_r4,
                                     align="left",
                                     width="10",
                                     text=str("█" + k),
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                else:
                    btn = PushButton(button_box_r4,
                                     align="left",
                                     width="10",
                                     text=k,
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                btn.update_command(pval, [k, lbox_list[0]])
                btn.bg = "#9EF844"
            else:
                btn = PushButton(button_box_r4,
                                 align="left",
                                 width="10",
                                 text=k,
                                 pady=resolution[rt]['button_pady'])
                btn.bg = "#F84446"
        elif (counter < 20):
            if k in rdict:

                if (platform != 'win32'):
                    btn = PushButton(button_box_r5,
                                     align="left",
                                     width="10",
                                     text=str("█" + k),
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                else:
                    btn = PushButton(button_box_r5,
                                     align="left",
                                     width="10",
                                     text=k,
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                btn.update_command(pval, [k, lbox_list[0]])
                btn.bg = "#9EF844"
            else:
                btn = PushButton(button_box_r5,
                                 align="left",
                                 width="10",
                                 text=k,
                                 pady=resolution[rt]['button_pady'])
                btn.bg = "#F84446"
        elif (counter < 24):
            if k in rdict:
                if (platform != 'win32'):
                    btn = PushButton(button_box_r6,
                                     align="left",
                                     width="10",
                                     text=str("█" + k),
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                else:
                    btn = PushButton(button_box_r6,
                                     align="left",
                                     width="10",
                                     text=k,
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                btn.update_command(pval, [k, lbox_list[0]])
                btn.bg = "#9EF844"
            else:
                btn = PushButton(button_box_r6,
                                 align="left",
                                 width="10",
                                 text=k,
                                 pady=resolution[rt]['button_pady'])
                btn.bg = "#F84446"
        elif (counter < 28):
            if k in rdict:
                if (platform != 'win32'):
                    btn = PushButton(button_box_r7,
                                     align="left",
                                     width="10",
                                     text=str("█" + k),
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                else:
                    btn = PushButton(button_box_r7,
                                     align="left",
                                     width="10",
                                     text=k,
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                btn.update_command(pval, [k, lbox_list[0]])
                btn.bg = "#9EF844"
            else:
                btn = PushButton(button_box_r7,
                                 align="left",
                                 width="10",
                                 text=k,
                                 pady=resolution[rt]['button_pady'])
                btn.bg = "#F84446"
        elif (counter < 32):
            if k in rdict:
                if (platform != 'win32'):
                    btn = PushButton(button_box_r8,
                                     align="left",
                                     width="10",
                                     text=str("█" + k),
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                else:
                    btn = PushButton(button_box_r8,
                                     align="left",
                                     width="10",
                                     text=k,
                                     command=pval,
                                     pady=resolution[rt]['button_pady'])
                btn.update_command(pval, [k, lbox_list[0]])
                btn.bg = "#9EF844"
            else:
                btn = PushButton(button_box_r8,
                                 align="left",
                                 width="10",
                                 text=k,
                                 pady=resolution[rt]['button_pady'])
                btn.bg = "#F84446"
        counter += 1
        btn_list.append(btn)
Exemple #28
0
class AppGui:
    def __init__(self, resolution, black_mode=0):
        self.app = App(title="Gauss-Seidel", bg="#A4DDCA", layout="grid", height=900, width=1200) ##f79be0

        self.list_of_functions = ["(x0^2+x1-11)^2 + (x0+x1^2-7)^2-200", "(x1^2+x0-11)^2 + (x1+x0^2-7)^2-200",
                                  "(x0-2)^2 +(x0-x1^2)^2", "x0^2+x1^2", "x0^4+x1^4-x0^2-x1^2", "x0+x1+x2",
                                  "x0+x1+x2+x3+x4+x5+x6+x7+x8+x9", "x0^2-cos(18*x0)+x1^2-cos(18*x1)",
                                  "x0^2-cos(18*x0)+x1^2-cos(18*x1)+x2^2-cos(18*x2)" ]
        self.list_of_iterations = []
        self.list_of_results = []
        self.list_of_starters = [-3, 4]
        self.listbox = ListBox(self.app, items=self.list_of_functions, grid=[4, 1], command=self.change, scrollbar=True, align="left", width= 300, height=200)
        self.function_plot = PushButton(self.app, command=self.start_plot, grid=[0, 0], text="3D function", width=20)
        self.contour_plot = PushButton(self.app, command=self.start_contour, grid=[1, 0], text="Contours", width=20)
        self.checkbox = CheckBox(self.app, grid=[0, 1], align="left", text="Black mode")
        self.checkbox2 = CheckBox(self.app, grid=[0, 2], align="left", text="dynamically")
        self.text_range_a = Text(self.app, text="Function: ", grid=[3, 0], width=14)
        self.input_box = TextBox(self.app, grid= [4, 0], text= self.list_of_functions[0] , width=60)
        self.append_button = PushButton(self.app, grid=[5,0], text="Add", align="left",
                                        command=self.append_to_list, width=5, height=1)
        self.text_range_a = Text(self.app, text= "Range: ", grid=[0,2])
        self.range_a = TextBox(self.app, grid= [1, 2], align="left", text= -5, width=5)
        self.range_b = TextBox(self.app, grid=[1, 2], align="right", text=5, width=5)
        self.precision_text = Text(self.app, text= "Precision: ", grid=[0,3])
        self.precision_box = TextBox(self.app, grid=[1, 3], align="right", text=0.0001, width=10)
        self.precision = self.precision_box.value
        self.text_range_a = Text(self.app, text= "Start points: ", grid=[0,4], width=10)
        self.start_points = TextBox(self.app, grid= [1, 4], text= self.list_of_starters, width=20)
        self.start = self.start_points.value
        self.activate = PushButton(self.app, grid=[0, 5], text="Activate", command=self.activate_params, width=20, height=2)
        self.activate = PushButton(self.app, grid=[1, 5], text="Start", command=self.start_algorithm, width=20, height=2)
        self.iteration_points_text = Text(self.app, text="Iteration points", grid= [0, 6, 2, 6], align="top")
        self.iteration_points_box = ListBox(self.app, items=self.list_of_iterations, grid=[0, 7, 2, 7], command=self.change, scrollbar=True, width=650, height=400)
        self.results_points_box = ListBox(self.app, items=self.list_of_results, grid=[3, 7], scrollbar=True, width=80, height=400)
        self.number_of_iterations = Text(self.app, grid= [4,6], text= "{} iteracji".format(len(self.list_of_iterations)), align="left")
        self.random_button = PushButton(self.app, grid=[2, 4], text= "Random", align="right", command=self.random_start_points, width=5, height=1)
        self.random_button = PushButton(self.app, grid=[1, 4], text="validate", align="right",
                                        command=self.change_starters, width=5, height=1)
        self.iterations = TextBox(self.app, grid=[4, 5], text= "1000", width=6, align="left")
        self.iterations_text = Text(self.app, grid=[3, 5], text="max iterations:", align="left")
        self.resolution = resolution
        self.x_range = int(self.range_a.value)
        self.y_range = int(self.range_b.value)
        self.x = np.linspace(self.x_range, self.y_range, resolution)  # 13
        self.y = np.linspace(self.x_range, self.y_range, resolution)
        self.black_mode = black_mode

        self.points_x = []
        self.points_y = []
        self.points_z = []

        self.start_app()
        self.formula = ""
    def append_to_list(self):
        formula = self.input_box.value
        self.list_of_functions.append(formula)
        self.listbox.append(formula)

    def change_starters(self):
        temp = self.start_points.value
        temp = temp[1:-1]
        temp = temp.split(",")
        temp_list = []
        for element in temp:
            temp_list.append(float(element))
        temp = [float(i) for i in temp]
        print(temp)
        self.start_points.value = temp
        self.list_of_starters = temp

    def count_variables(self):
        formula = self.get_formula_and_refactor()
        print(formula)
        variables = ["x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9"]
        for v in variables:
            if v not in formula:
                print(v)
                print(variables.index(v))
                return variables.index(v)
        return 10

    def activate_params(self):
        self.x_range = int(self.range_a.value)
        self.y_range = int(self.range_b.value)
        self.x = np.linspace(self.x_range, self.y_range, self.resolution)  # 13
        self.y = np.linspace(self.x_range, self.y_range, self.resolution)
        self.start = self.start_points.value

        self.precision = self.precision_box.value
        self.points_x.clear()
        self.points_y.clear()
        self.points_z.clear()
        self.iteration_points_box.clear()
        self.number_of_iterations.clear()
        self.list_of_iterations.clear()
        self.list_of_results.clear()
        self.results_points_box.clear()
        self.formula = self.input_box.value

    def start_algorithm(self):
        self.golden_search = Golden_search.GoldenSearch(self.x_range, self.y_range, self.list_of_starters,
                                                        float(self.precision), self.formula)
        self.golden_search.test_search(int(self.iterations.value), self.count_variables(), self.checkbox2.value)
        self.list_of_iterations = self.golden_search.points
        self.list_of_results = self.golden_search.results_of_function
        self.iterations_to_box()
        self.results_to_box()
        self.number_of_iterations = "{} iteracji".format(len(self.list_of_iterations))

    def iterations_to_box(self):
        for element in self.list_of_iterations:
            self.iteration_points_box.append(element)

    def results_to_box(self):
        for element in self.list_of_results:
            self.results_points_box.append(str(round(float(element),4)))

    def return_result_of_function(self, x0, x1, f):
        return eval(f)

    def random_start_points(self):
        temp = []
        for _ in range(self.count_variables()):
            temp.append(round(random.uniform(float(self.range_a.value), float(self.range_b.value)),3))
        self.start_points.value = temp
        self.list_of_starters = temp

    def replace_power_symbol(self, expression):
        return expression.replace('^','**')

    def add_np_to_functions(self, expression):
        functions = ["log", "sin", "cos", "tan", "exp", "sqrt"]
        for fun in functions:
            expression = expression.replace(fun, "np."+fun)
        return expression

    def compile(self, formula, x0, x1, x2=0): #x0, x1
        return eval(parser.expr(formula).compile())

    def set_xyz_labels(self, ax):
        ax.set_xlabel('x')
        ax.set_ylabel('y')
        ax.set_zlabel('z')
        return ax

    def create_new_3d_plot(self, formula, x, y):
        fig = plt.figure()
        X, Y = np.meshgrid(x, y)
        Z = self.compile(formula, X, Y)
        ax = plt.axes(projection='3d')
        ax = self.set_xyz_labels(ax)
        if not self.checkbox.value:
            ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='viridis', edgecolor='black')
        else:
            ax.contour3D(X, Y, Z, 50, cmap='binary')
        plt.show()


    def create_contours(self, formula, x, y, points):
        fig, ax = plt.subplots()
        X, Y = np.meshgrid(x, y)
        Z = self.compile(formula, X, Y)
        CS = ax.contour(X, Y, Z, levels=50)
        ax.clabel(CS, inline=1, fontsize=8)
        points_x = []
        points_y = []
        for dict in points:
            points_x.append(float(dict["x0"]))
            points_y.append(float(dict["x1"]))
        plt.plot(points_x, points_y, linestyle="--", marker="o", color="r")
        # size = max(float(self.range_a.get()), float(self.range_b.get()))
        plt.show()

    def get_formula_and_refactor(self):
        formula = self.input_box.value
        formula = self.replace_power_symbol(formula)
        formula = self.add_np_to_functions(formula)
        return formula

    def start_plot(self):
        formula = self.get_formula_and_refactor()
        return self.create_new_3d_plot(formula, self.x, self.y)

    def start_contour(self):
        formula = self.get_formula_and_refactor()
        print(self.list_of_iterations)
        return self.create_contours(formula, self.x, self.y, self.list_of_iterations)

    def change(self, value):
        self.input_box.value = value
        self.function_plot.enabled = self.count_variables() == 2
        self.contour_plot.enabled = self.count_variables()  == 2
        self.checkbox.enabled = self.count_variables()  == 2

    def start_app(self):
        self.app.display()
for course in course_list:
    course_btn = PushButton(cbox, text=course.get_cname(), width=10, height=3)
    course_btn.bg = (129, 217, 222)
    course_btn.text_color = (255, 255, 255)
    course_btn.update_command(food_details, [course.get_cname()])

admin_button = PushButton(cbox,
                          text="Admin",
                          command=admin_access,
                          width=10,
                          height=3)
admin_button.bg = (129, 217, 222)
admin_button.text_color = (255, 255, 255)

food_listbox = ListBox(fbox)
food_listbox.update_command(add_food)
order_listbox = ListBox(obox, width=200, height=200)
delete_button = PushButton(obox, text="Undo", command=undo)
clear_button = PushButton(obox, text="Clear", command=clear_order)
finish_button = PushButton(obox, text="Finish", command=finish_order)
cost_lbl = Text(obox, text="Total Cost:")

success_lbl = Text(afbox)

for course in course_list:
    course_btn = PushButton(aabox, text=course.get_cname(), width=10, height=3)
    course_btn.bg = (129, 217, 222)
    course_btn.text_color = (255, 255, 255)
    course_btn.update_command(admin_food_details, [course.get_cname()])
teacher_list = []
student_list = []

# Create some students to start with
Student("Jack", 16, "0273956577", "Male", ["GRA", "MAT", "ENG"])
Student("Jill", 15, "0271111111", "Female", ["MAT", "ART", "XYZ"])
Student("Matt", 17, "0217771117", "Male", ["MAT", "PHY", "ART"])

generate_teachers()
generate_students()

# create the application interface
app = App(title="Student management system")

from guizero import App, ListBox, TextBox, PushButton, warn

# ListBox contains names of all teachers
# Set up list of names and ids of teachers
list_content = []
for teacher in teacher_list:
    list_content.append([teacher.get_tname(), teacher.get_tid()])
teacher_listbox = ListBox(app, items=[], command=display_details)

name_textbox = TextBox(app)
class_textbox = TextBox(app)

update_button = PushButton(app, text="Update details", command=update_details)

# Start the program
app.display()