Best Python code snippet using lisa_python
astroui.py
Source:astroui.py  
...7label_color = '#c7c7c7'8content_font = ('Menlo', 18)9content_color = '#48bd90'10screen_width, screen_height = ui.get_screen_size()11def make_label(x, y, w, h, name=None, text="", style="label", align=ui.ALIGN_LEFT):12    label = ui.Label(frame=(x, y, w, h), text=text)13    label.alignment = align14    label.name = name15    if style == 'label':16        label.font = label_font17        label.text_color = label_color18    elif style == 'content':19        label.font = content_font20        label.text_color = content_color21    return label22def make_switch(x, y, w, h, name=None):23    switch = ui.Switch(frame=(x, y, w, h))24    switch.name = name25    return switch26def make_textfield(x, y, w, h, name=None):27    textfield = ui.TextField(frame=(x, y, w, h))28    textfield.name = name29    return textfield30class AstroDateView(ui.View):31    def __init__(self, width=300):32        self.background_color='clear'33        self.name="datetime_view"34        self.date = ad.AstroDate().alloc_now_utc()35        self.width = width36    def make_astrodate_panel(self):37        x, y, w, h = 0, 0, self.pts(1.0), 2138        date_label = make_label(x, y, w, h, text="Current Date/Time")39        self.add_subview(date_label)40    41        x, y, w, h = 0, y + h, self.pts(1.0), 3042        date_textfield = make_textfield(x, y, w, h, name="date_textfield")43        date_textfield.delegate = self44        date_textfield.text = self.date.get_pretty_string()45        self.add_subview(date_textfield)46    47        x, y, w, h = 0, y + h, self.pts(0.32), 2148        timezone_label = make_label(x, y, w, h, text="Time Zone")49        self.add_subview(timezone_label)50    51        x, y, w, h = x + w + self.pts(0.02), y, self.pts(0.16), h52        daysave_label = make_label(x, y, w, h, text="DS", align=ui.ALIGN_CENTER)53        self.add_subview(daysave_label)54    55        x, y, w, h = x + w + self.pts(0.02), y, self.pts(0.48), h56        longitude_label = make_label(x, y, w, h, text="Longitude")57        self.add_subview(longitude_label)58    59        x, y, w, h = 0, y + h, self.pts(0.32), 3060        timezone_textfield = make_textfield(x, y, w, h, name="timezone_textfield")61        timezone_textfield.delegate = self62        timezone_textfield.text = "%d" % self.date.get_zone_correction()63        self.add_subview(timezone_textfield)64    65        x, y, w, h = x + w + self.pts(0.02), y, self.pts(0.16), h66        daysave_switch = make_switch(x, y, w, h, name="daylight_savings_switch")67        daysave_switch.action = self.switch_changed68        daysave_switch.value = self.date.get_daylight_savings()69        self.add_subview(daysave_switch)70    71        x, y, w, h = x + w + self.pts(0.02), y, self.pts(0.48), h72        longitude_textfield = make_textfield(x, y, w, h, name="longitude_textfield")73        longitude_textfield.delegate = self74        longitude_textfield.text = "%.5f" % self.date.get_longitude()75        self.add_subview(longitude_textfield)76    77        x, y, w, h = self.pts(0.02), y + h + 5, self.pts(0.98), 2178        label = make_label(x, y, w, h, name="lct_label", style="content")79        self.add_subview(label)80    81        x, y, w, h = self.pts(0.02), y + h + 5, self.pts(0.98), 2182        label = make_label(x, y, w, h, name="utc_label", style="content")83        self.add_subview(label)84        x, y, w, h = self.pts(0.07), y + h + 5, self.pts(0.93), 2185        label = make_label(x, y, w, h, name="utc_jd_label", style="content")86        self.add_subview(label)87        x, y, w, h = self.pts(0.02), y + h + 5, self.pts(0.98), 2188        label = make_label(x, y, w, h, name="tdt_label", style="content")89        self.add_subview(label)90        x, y, w, h = self.pts(0.07), y + h + 5, self.pts(0.93), 2191        label = make_label(x, y, w, h, name="tdt_jd_label", style="content")92        self.add_subview(label)93            94        x, y, w, h = self.pts(0.02), y + h + 5, self.pts(0.98), 2195        label = make_label(x, y, w, h, name="gst_label", style="content")96        self.add_subview(label)97        x, y, w, h = self.pts(0.02), y + h + 5, self.pts(0.98), 2198        label = make_label(x, y, w, h, name="lst_label", style="content")99        self.add_subview(label)100                   101        return self.width, y + h102    def set_text_in_label(self, name, text):103        label = self[name]104        if label is not None:105            label.text = text106                107    def pts(self, pct):108        if pct < 0.0:109            return 0.0110        if pct > 1.0:111            pct = 1.0112        return pct * (self.width - 1)...gui_menu.py
Source:gui_menu.py  
1import webbrowser2from tkinter import *34from docker_command import Docker_images5from gui_button import Make_button6from gui_label import Make_label7from gui_scroll import Make_scrollbar8910class Make_menubutton():11# ---------------- create __init__ menu button ----------------------------------- #12    def __init__(self, top_frame, app_frame, startup_frame):13        self.top_frame = top_frame14        self.app_frame = app_frame15        self.startup_frame = startup_frame1617# ---------------- menu buttons -------------------------------------------------- #18    # ---------------- images ----------------------- #19    def menu_button_images(self):20        self.button = Button(self.app_frame, text = "images", bg="#0e1733", fg="white", cursor="hand2",21        activeforeground="#bfbfbf", activebackground="#0e1733", borderwidth=0, padx=55, pady=39, command=lambda:self.images_page(), font=("Courier", 16))22        self.button.place(x=0,y=0)2324    def images_page(self):25        # -------- reload page ---------- #26        try:27            self.startup_frame.destroy()28        except:29            pass30        try:31            self.remove_main_frame(main_frame)32        except:33            pass34        self.add_main_frame_img(self.top_frame)35        # -------- add scrollbar -------- #36        self.scrollbar_images = Make_scrollbar(scrollbar_frame, 485, 375, "#0e1733", "#0e1733")37        self.scrollbar_images.image_page_scrollbar(self.images_page)38        # -------- upload button -------- #39        self.upload_button = Make_button(main_frame, "upload", 0, 0, "#344658", 18, "white")40        self.upload_button.images_upload(self.images_page)41        self.upload_button.place(380, 120)4243    # ---------------- containers ------------------- #44    def menu_button_containers(self):45        self.button = Button(self.app_frame, text = "containers", bg="#0e1733", fg="white", cursor="hand2",46        activeforeground="#bfbfbf", activebackground="#0e1733", borderwidth=0, padx=40, pady=40, command=lambda:self.containers_page(), font=("Courier", 14))47        self.button.place(x=187,y=0)4849    def containers_page(self):50        # -------- reload page ---------- #51        try:52            self.startup_frame.destroy()53        except:54            pass55        try:56            self.remove_main_frame(main_frame)57        except:58            pass59        self.add_main_frame_cont(self.top_frame)60        # -------- add scrollbar -------- #61        self.scrollbar_images = Make_scrollbar(scrollbar_frame, 485, 443, "#0e1733", "#0e1733")62        self.scrollbar_images.containers_page_scrollbar(self.containers_page)6364    # ---------------- home ------------------------- #65    def menu_button_home(self):66        self.image = PhotoImage(file="./images/shark2.png")67        self.button = Button(self.app_frame, image=self.image, borderwidth=0, cursor="hand2", command=lambda:self.home_page())68        self.button.place(x=375,y=0)6970    def home_page(self):71        # -------- reload page ---------- #72        try:73            self.startup_frame.destroy()74        except:75            pass76        try:77            self.remove_main_frame(main_frame)78        except:79            pass80        self.add_main_frame_img(self.top_frame)81        f1 = Frame(main_frame, width=440, height=400, bg = "#00080f")82        f1.place(x = 30, y = 130)83        l1 = Make_label(f1, "hello and welcome to SHARK", 17, "white", "#00080f")84        l1.place(35,20)85        l2 = Make_label(f1, "so what is shark?", 12, "white", "#00080f")86        l2.place(30,55)87        l3 = Make_label(f1, "shark is a docker gui designed to help", 13, "white", "#00080f")88        l3.place(30,75)89        l4 = Make_label(f1, "with basic functions that the docker", 13, "white", "#00080f")90        l4.place(30,95)91        l5 = Make_label(f1, "user uses often.", 13, "white", "#00080f")92        l5.place(30,115)93        l6 = Make_label(f1, "this platfor was build in python so its not ideal", 9, "white", "#00080f")94        l6.place(30,150)95        l7 = Make_label(f1, "for a gui.", 9, "white", "#00080f")96        l7.place(30,165)97        l8 = Make_label(f1, "you should watch when you name your images", 9, "white", "#00080f")98        l8.place(30,180)99        l9 = Make_label(f1, "or your containers, some times if the name is", 9, "white", "#00080f")100        l9.place(30,195)101        l10 = Make_label(f1, "too long it will move the buttons and you wont", 9, "white", "#00080f")102        l10.place(30,210)103        l11 = Make_label(f1, "be able to use shark proparly.", 9, "white", "#00080f")104        l11.place(30,225)105        l12 = Make_label(f1, "same goes for when you add ports and vols in image run.", 9, "white", "#00080f")106        l12.place(30,240)107        l13 = Make_label(f1, "i'd be happy for your support (:", 13, "white", "#00080f")108        l13.place(30,320)109        110111        def callback(url):112            webbrowser.open_new(url)113114        link1 = Label(f1, text="github link", fg="#707ec7", cursor="hand2", bg="#00080f", font=("Courier",13), borderwidth=0)115        link1.place(x=30, y=350)116        link1.bind("<Button-1>", lambda e: callback("https://github.com/gavriel200/docker_gui"))117    118    def invoke(self):119        # -------- press button --------- #120        self.button.invoke()121122# ---------------- other functions ----------------------------------------------- #123    @staticmethod124    def add_main_frame_img(top_frame):125        global main_frame126        global scrollbar_frame127        main_frame = Frame(top_frame, width=500, height=550, bg="#0e1733")128        main_frame.pack()129130        #this is an invisble label to pulldown the main frame131        Label(main_frame, height=10, bg="#0e1733", borderwidth=0).grid(row=0,column=0)132133        scrollbar_frame = Frame(main_frame, width=500, height=550, bg="#0e1733")134        scrollbar_frame.grid(row=3,column=0)135136    @staticmethod137    def add_main_frame_cont(top_frame):138        global main_frame139        global scrollbar_frame140        main_frame = Frame(top_frame, width=500, height=550, bg="#0e1733")141        main_frame.pack()142143        #this is an invisble label to pulldown the main frame144        Label(main_frame, height=6, bg="#0e1733", borderwidth=0).grid(row=0,column=0)145146        scrollbar_frame = Frame(main_frame, width=500, height=550, bg="#0e1733")147        scrollbar_frame.grid(row=3,column=0)148    149    @staticmethod150    def remove_main_frame(frame):
...adverarial_search_graph_gen.py
Source:adverarial_search_graph_gen.py  
...5import graphviz as gv6from pathlib import Path7import pydot8from networkx.drawing.nx_agraph import graphviz_layout9def make_label(node_label, heuristic=None):10    """Create labeled nodes with optional heuristic values."""11    # TODO subscripts lost in translation / saving12    return (13        f"<<B>{node_label}</B> <SUB>{heuristic}</SUB>>"14        if heuristic15        else f"<<B>{node_label}</B>>"16    )17if __name__ == "__main__":18    # create the graph for the minimax / alpha-beta example19    h = gv.Graph(name="graph-with-labels", engine="dot")20    with h.subgraph(name="Legend") as legend:21        legend.node("Max", label=make_label("Max"))22        legend.node("Min", label=make_label("Min"), color="grey")23    h.node("A", label=make_label("A"))24    h.node("B", label=make_label("B"), color="grey")25    h.node("C", label=make_label("C"), color="grey")26    h.node("D", label=make_label("D", heuristic="8"))27    h.node("E", label=make_label("E", heuristic="2"))28    h.node("F", label=make_label("F", heuristic="6"))29    h.node("G", label=make_label("G", heuristic="8"))30    h.edge("A", "B")31    h.edge("A", "C")32    h.edge("B", "D")33    h.edge("B", "E")34    h.edge("C", "F")35    h.edge("C", "G")36    # Render the graph to file37    p = Path(".")38    filename = "minimax-7-node"39    gv_path = p / "graphs" / str(filename + ".gv")40    print(f"Saved {gv_path} as DOT file")41    h.save(filename=gv_path)42    (g,) = pydot.graph_from_dot_file(gv_path)43    img_path = p / "images" / str(filename + ".png")...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
