Esempio n. 1
0
def export():
    code = """

#############################################################
#     The following code was pre-generated by BreezyUI.     #
#Don't change any of the code if you don't know what it does#
#############################################################

import sys
if sys.version_info[0] == 2:
    import Tkinter as tkinter #backwards compatability
else:
    import tkinter

root = tkinter.Tk()
root.geometry("{0}x{1}") #Set the size of the window
    """.format(width_var.get(), height_var.get()) + "\n"
    for i in range(len(dragged_widgets)):
        widget = dragged_widgets[i]
        to_export = bUI.changed_dict(widget.attributes, bUI.get_attributes(widget.widget))
        code += "{0} = tkinter.{1}(root, {2})".format(widget.name, widget.widget_type, to_export) + "\n"

        code += "{0}.place(x={1},y={2})".format(widget.name, widget.widget.winfo_x(), widget.widget.winfo_y()) + "\n"

        if widget.widget_type == "Entry":
            if widget.widget.get():
                code += "{0}.insert(0, {1})".format(widget.name, widget.widget.get()) + "\n"

    code += ("\n#################END OF GENERATED CODE#################")
    root.filename = tkinter.filedialog.asksaveasfilename(initialdir = "/",title = "Select file",filetypes = (("python files","*.py"),("all files","*.*")))
    file = open(root.filename + ".py", "w")
    file.write(code)
    file.close()
    return
Esempio n. 2
0
def export():
    print("""

#############################################################
#The following code was pre-generated by BreezyUI           #
#Don't change any of the code if you don't know what it does#
#############################################################

import sys
if sys.version_info[0] == 2:
    import Tkinter as tkinter #backwards compatability
else:
    import tkinter

root = tkinter.Tk()
root.geometry("800x600") #Set the size of the window
    """)
    for i in range(len(dragged_widgets)):
        widget = dragged_widgets[i]
        to_export = bUI.changed_dict(widget.attributes,
                                     bUI.get_attributes(widget.widget))
        print("object{0} = tkinter.{1}(root, {2})".format(
            i, widget.widget_type, to_export))

        print("object{0}.place(x={1},y={2})".format(i, widget.widget.winfo_x(),
                                                    widget.widget.winfo_y()))

        if widget.widget_type == "Entry":
            if widget.widget.get():
                print("object{0}.insert(0, {1})".format(
                    i, widget.widget.get()))

    print("#################END OF GENERATED CODE#################")
Esempio n. 3
0
def export(event=None):
    code = ""
    code += bUI.START_COMMENT
    code += "import sys, bUI\n"
    code += "if sys.version_info[0] == 2:\n"
    code += "    import Tkinter as tkinter\n"
    code += "else:\n"
    code += "    import tkinter\n"
    code += "root = tkinter.Tk()\n"
    code += "root.geometry('{0}x{1}')\n".format(
        main_area.canvas.winfo_width(), main_area.canvas.winfo_height())

    for index in range(len(dragged_widgets)):
        widget = dragged_widgets[index]
        changed_attrs = bUI.changed_dict(widget.attributes,
                                         bUI.get_attributes(widget.widget))

        if widget.widget_type != "Text":
            code += "{0} = tkinter.{1}(root, {2})\n".format(
                widget.name, widget.widget_type, changed_attrs)

        if widget.widget_type == "Entry":
            if widget.widget.get():
                code += "{0}.insert(0, '{1}')\n".format(
                    widget.name, widget.widget.get())

        elif widget.widget_type == "Listbox":
            if len(widget.items):
                for item in widget.items[0].split("\n"):
                    code += "{0}.insert(0, '{1}')\n".format(widget.name, item)

        elif widget.widget_type == "Text":
            code += "{0} = bUI.Textbox(root, {1}, {2}, {3})\n".format(
                widget.name, widget.width, widget.height, changed_attrs)

        code += "{0}.place(x={1}, y={2})\n".format(widget.name,
                                                   widget.widget.winfo_x(),
                                                   widget.widget.winfo_y())

    code += bUI.END_COMMENT
    code += "\n\n\n\n\n\n\nroot.mainloop() #Ensure that you keep this line, as it was added by BreezyUI"

    with open("../Resources/directory.txt") as last_directory:
        directory = last_directory.read().strip()

    root.filename = tkinter.filedialog.asksaveasfilename(
        initialdir=directory,
        title="Select file",
        filetypes=(("python files", "*.py"), ("all files", "*.*")))

    with open("../Resources/directory.txt", "w") as last_directory:
        last_directory.write(os.path.dirname(root.filename))

    import shutil
    shutil.copy("../Libraries/bUI.py", os.path.dirname(root.filename))
    file = open(root.filename + ".py", "w")
    file.write(code)
    file.close()
Esempio n. 4
0
def export():
    code = """

#############################################################
#     The following code was pre-generated by BreezyUI.     #
#Don't change any of the code if you don't know what it does#
#############################################################

import sys
if sys.version_info[0] == 2:
    import Tkinter as tkinter #backwards compatability
else:
    import tkinter

root = tkinter.Tk()
root.geometry("{0}x{1}") #Set the size of the window
    """.format(width_var.get(), height_var.get()) + "\n"
    for i in range(len(dragged_widgets)):
        widget = dragged_widgets[i]
        to_export = bUI.changed_dict(widget.attributes,
                                     bUI.get_attributes(widget.widget))
        code += "{0} = tkinter.{1}(root, {2})".format(
            widget.name, widget.widget_type, to_export) + "\n"

        code += "{0}.place(x={1},y={2})".format(widget.name,
                                                widget.widget.winfo_x(),
                                                widget.widget.winfo_y()) + "\n"

        if widget.widget_type == "Entry":
            if widget.widget.get():
                code += "{0}.insert(0, '{1}')".format(
                    widget.name, widget.widget.get()) + "\n"

    code += "\n#################END OF GENERATED CODE#################"
    code += "\n#Add your code beneath this line"
    code += "\n\n\nroot.mainloop() #No more code after this"

    last_dir_f = open("../Resources/directory.txt")
    last_dir = last_dir_f.read().strip("\n")
    last_dir_f.close()

    root.filename = tkinter.filedialog.asksaveasfilename(
        initialdir=last_dir,
        title="Select file",
        filetypes=(("python files", "*.py"), ("all files", "*.*")))

    last_dir_f = open("../Resources/directory.txt",
                      "w")  #Truncate the file on purpose.
    last_dir_f.write(os.path.dirname(root.filename))
    last_dir_f.close()

    file = open(root.filename + ".py", "w")
    file.write(code)
    file.close()
    return
Esempio n. 5
0
    def attach(self, canvas, x=10, y=10):
        '''
        Takes:
        - self
        - canvas [tkinter.Canvas()] -- The canvas the widget will be attached to
        - x [int] -- The x position of the widget (def. 10)
        - y [int] -- The y position of the widget (def. 10)

        Does:
        - Attaches the widget to the given canvas at the provided co-ordinates
        - Creates the widget
        - Binds it to functions allowing it to function

        Returns:
        - None
        '''

        global target_widget

        if canvas is self.canvas:
            self.canvas.coords(self._id, x, y)
            return

        if self.canvas:
            self.detach()

        if not canvas:
            return

        widget = eval("tkinter.{0}(canvas, {1})".format(
            self.widget_type,
            ', '.join([str(x) + '=' + self.kwargs[x] for x in self.kwargs])))

        _id = canvas.create_window(x, y, window=widget, anchor="nw")
        self.canvas = canvas
        self.widget = widget
        self._id = _id
        self.x_off = 0
        self.y_off = 0
        widget.bind("<ButtonPress>", self.press)
        self.widget.bind(
            "<Button-2>",
            functools.partial(edit_attributes,
                              source=self.widget,
                              dnd_source=self))
        self.txt_var = tkinter.StringVar()

        if self.widget_type == "Entry":
            self.widget[
                "textvariable"] = self.txt_var  #I love this line (see fix 001)
        else:
            self.widget["state"] = "normal"

        self.attributes = bUI.get_attributes(self.widget)
Esempio n. 6
0
def save_bUI_file():

    with open("../Resources/directory.txt") as last_directory:
        directory = last_directory.read().strip()

    bui_filetypes = (("BreezyUI Files", "*.bui"), ("all files", "*.*"))

    root.filename = tkinter.filedialog.asksaveasfilename(initialdir=directory, title="Select file", filetypes=bui_filetypes)

    with open("../Resources/directory.txt", "w") as last_directory:
        last_directory.write(os.path.dirname(root.filename))

    save_file = open(root.filename + ".bui", "w")
    contents = "[{0}, {1}]".format(width_var.get(), height_var.get())


    #Generate the bUI file
    for widget in dragged_widgets:

        widget_config = {
            "id" : widget.name,
            "display" : widget.display,
            "type" : widget.widget_type,
            "x" :  widget.widget.winfo_x(),
            "y" : widget.widget.winfo_y(),
            "attributes" : bUI.changed_dict(widget.attributes, bUI.get_attributes(widget.widget))
        }

        if widget.args != {}:
            for arg in widget.args:
                widget_config["attributes"][arg] = widget.args[arg]

        if widget.widget_type == "Entry":
            widget_config["attributes"]["Placeholder"] = "'" + widget.widget.get() + "'"

        if widget.widget_type in ["Text", "Listbox"]:
            widget_config["attributes"]["width"] = 200
            widget_config["attributes"]["height"] = 100
            widget_config["attributes"]["relief"] = "solid"
            widget_config["attributes"]["bd"] = 1

        if widget.widget_type == "OptionMenu":
            widget_config["attributes"]["value"] = "'{0}'".format(widget["text"])



        contents += str(widget_config)

    save_file.write(contents);save_file.close()

    #Add the bUI file to the recents list
    file = open("../Resources/recent.txt", "a")
    file.write(root.filename + ".bui" + "\n")
    file.close()
Esempio n. 7
0
def save_bUI_file():

    last_dir_f = open("../Resources/directory.txt")
    last_dir = last_dir_f.read().strip("\n")
    last_dir_f.close()

    root.filename = tkinter.filedialog.asksaveasfilename(
        initialdir=last_dir,
        title="Select file",
        filetypes=(("python files", "*.py"), ("all files", "*.*")))

    last_dir_f = open("../Resources/directory.txt",
                      "w")  #Truncate the file on purpose.
    last_dir_f.write(os.path.dirname(root.filename))
    last_dir_f.close()
    file = open(root.filename + ".bui", "w")
    file.write("[{0}, {1}]".format(width_var.get(), height_var.get()))

    #Generate the bUI file
    for widget in dragged_widgets:
        widget_config = {
            "id":
            widget.name,
            "type":
            widget.widget_type,
            "x":
            widget.widget.winfo_x(),
            "y":
            widget.widget.winfo_y(),
            "attributes":
            bUI.changed_dict(widget.attributes,
                             bUI.get_attributes(widget.widget))
        }

        if widget.widget_type == "Entry":
            widget_config["attributes"][
                "Placeholder"] = "'" + widget.widget.get() + "'"

        file.write(str(widget_config))

    #Add the bUI file to the recents list
    file = open("../Resources/recent.txt", "a")
    file.write(root.filename + ".bui" + "\n")
    file.close()
Esempio n. 8
0
def save_bUI_file():
    root.filename = tkinter.filedialog.asksaveasfilename(
        initialdir="/",
        title="Select file",
        filetypes=(("python files", "*.py"), ("all files", "*.*")))
    file = open(root.filename + ".bui", "w")

    #Generate the bUI file
    for widget in dragged_widgets:
        widget_config = {
            "id":
            widget.name,
            "x":
            widget.widget.winfo_x(),
            "y":
            widget.widget.winfo_y(),
            "attributes":
            bUI.changed_dict(widget.attributes,
                             bUI.get_attributes(widget.widget))
        }
        #TODO: Figure out how to get placeholder of entries.
        file.write(str(widget_config))
Esempio n. 9
0
    def attach(self, canvas, x=10, y=10):
        '''
        Takes:
        - self
        - canvas [tkinter.Canvas()] -- The canvas the widget will be attached to
        - x [int] -- The x position of the widget (def. 10)
        - y [int] -- The y position of the widget (def. 10)

        Does:
        - Attaches the widget to the given canvas at the provided co-ordinates
        - Creates the widget
        - Binds it to functions allowing it to function

        Returns:
        - None
        '''

        global target_widget

        if canvas is self.canvas:
            self.canvas.coords(self._id, x, y)
            return

        if self.canvas:
            self.detach()

        if not canvas:
            return

        widget = eval("tkinter.{0}(canvas, {1}{2})".format(
            self.display, self.aargs, ', '.join([
                str(x) + '=\'\'\'' + str(self.kwargs[x]) + "\'\'\'"
                for x in self.kwargs
            ])))

        _id = canvas.create_window(x, y, window=widget, anchor="nw")
        self.canvas = canvas
        self.widget = widget
        self._id = _id
        self.x_off = 0
        self.y_off = 0
        widget.bind("<ButtonPress>", self.press)
        self.widget.bind(
            "<Button-2>",
            functools.partial(edit_attributes,
                              source=self.widget,
                              dnd_source=self))
        self.txt_var = tkinter.StringVar()
        self.bool_var = tkinter.BooleanVar()

        if self.widget_type == "Entry":
            self.widget[
                "textvariable"] = self.txt_var  #I love this line (see fix 001)
            self.widget["state"] = "disabled"

            if "Placeholder" in dir(self):
                self.widget["state"] = "normal"
                self.widget.delete(0, tkinter.END)
                self.widget.insert(0, self.Placeholder)
                self.widget['state'] = "disabled"

        elif self.widget_type == "Checkbutton":
            self.widget["variable"] = self.bool_var
            self.widget["state"] = "disabled"

        elif self.widget_type == "Radiobutton":
            self.widget.deselect()

        elif self.widget_type == "Spinbox":
            self.widget["state"] = tkinter.DISABLED

        elif self.widget_type == "OptionMenu":
            self.widget["state"] = tkinter.DISABLED
        else:
            self.widget["state"] = "normal"
            del self.txt_var
            del self.bool_var

        if self.widget_type == "Listbox":
            self.widget.create_text(100, 50, text="Listbox Object")

        elif self.widget_type == "Text":
            self.widget.create_text(100, 50, text="Text Object")

        elif self.widget_type == "Frame":
            self.widget.create_text(100, 50, text="Frame Object")

        self.attributes = bUI.get_attributes(self.widget)
Esempio n. 10
0
def save_bUI_file():
    root.filename = tkinter.filedialog.asksaveasfilename(initialdir = "/",title = "Select file",filetypes = (("python files","*.py"),("all files","*.*")))
    file = open(root.filename + ".bui", "w")

    #Generate the bUI file
    for widget in dragged_widgets:
        widget_config = {"id" : widget.name, "type" : widget.widget_type, "x" : widget.widget.winfo_x(), "y" : widget.widget.winfo_y(), "attributes" : bUI.changed_dict(widget.attributes, bUI.get_attributes(widget.widget))}

        if widget.widget_type == "Entry":
            widget_config["attributes"]["Placeholder"] = widget.widget.get()

        file.write(str(widget_config))

    #Add the bUI file to the recents list
    file = open("../Resources/recent.txt", "a")
    file.write(root.filename + ".bui" + "\n")
    file.close()