コード例 #1
0
ファイル: gbutton.py プロジェクト: boredom101/contextutron
class GButton:
    def __init__(self, theme, root, data, size):
        name = IconTheme.getIconPath(data.icon, theme=theme)
        self.photo = PhotoImage(
            data=svg2png(url=name, parent_width=size, parent_height=size))
        self.data = data
        self.view = Button(root,
                           image=self.photo,
                           command=self.data.call,
                           text=data.text,
                           compound="left")

    def __hash__(self):
        return hash(self.data)

    def destroy(self):
        self.view.destroy()
コード例 #2
0
class UserTab:
    def __init__(self, main_window, tab_control, username, user_controller):
        """Initializes the user tab with all visual elements"""
        self.main_window = main_window
        self.username = username
        self.user_controller = user_controller

        self.user_info = self.user_controller.get_user(self.username)

        self.user_tab = ttk.Frame(tab_control)
        tab_control.add(self.user_tab, text='User')

        self.new_password = StringVar()
        self.new_password_repeat = StringVar()
        self.new_firstname = StringVar(value=self.user_info['firstname'])
        self.new_lastname = StringVar(value=self.user_info['lastname'])
        self.new_email = StringVar(value=self.user_info['email'])

        # USER INFORMATION
        Label(self.user_tab,
              text="Your information:",
              font='Helvetica 16 bold').grid(row=0,
                                             column=0,
                                             padx=15,
                                             pady=15,
                                             sticky='w')

        Label(self.user_tab, text="Username:"******"First name:").grid(row=2,
                                                      column=0,
                                                      sticky='w',
                                                      padx=15,
                                                      pady=5)
        Label(self.user_tab, textvariable=self.new_firstname).grid(row=2,
                                                                   column=1,
                                                                   sticky='w',
                                                                   pady=5)

        Label(self.user_tab, text="Last name:").grid(row=3,
                                                     column=0,
                                                     sticky='w',
                                                     padx=15,
                                                     pady=5)
        Label(self.user_tab, textvariable=self.new_lastname).grid(row=3,
                                                                  column=1,
                                                                  sticky='w',
                                                                  pady=5)

        Label(self.user_tab, text="Email:").grid(row=4,
                                                 column=0,
                                                 sticky='w',
                                                 padx=15,
                                                 pady=5)
        Label(self.user_tab, textvariable=self.new_email).grid(row=4,
                                                               column=1,
                                                               sticky='w',
                                                               pady=5)

        # CHANGE USER INFORMATION BUTTON
        Button(self.user_tab,
               text='Modify information',
               command=self.change_information).grid(row=5,
                                                     column=1,
                                                     pady=10,
                                                     sticky='w')

        # CHANGE PASSWORT FIELDS AND BUTTON
        Label(self.user_tab, text="Change password:"******"New password:"******"Repeat password:"******"""Creates fields where new user information can be typed and button to save it"""
        self.nameentry = Entry(self.user_tab, textvariable=self.new_firstname)
        self.nameentry.grid(row=2, column=1, sticky='w')
        self.lnameentry = Entry(self.user_tab, textvariable=self.new_lastname)
        self.lnameentry.grid(row=3, column=1, sticky='w')
        self.mailentry = Entry(self.user_tab, textvariable=self.new_email)
        self.mailentry.grid(row=4, column=1, sticky='w')
        self.btn = Button(self.user_tab,
                          text='Submit changes',
                          command=self.submit_changes)
        self.btn.grid(row=5, column=1, pady=10, sticky='ew')

    def submit_changes(self):
        """
        Passes the new user information to user controller. If successful, fields are destroyed.
        If not, a messagebox is shown and the user can continue editing the information in the fields
        """
        success, message = self.user_controller.edit_user(
            self.username, self.new_firstname.get(), self.new_lastname.get(),
            self.new_email.get())

        if success:
            self.user_info = self.user_controller.get_user(self.username)
            self.new_firstname.set(self.user_info['firstname'])
            self.new_lastname.set(self.user_info['lastname'])
            self.new_email.set(self.user_info['email'])
            print(self.new_firstname.get(), self.new_lastname.get(),
                  self.new_email.get())
            self.nameentry.destroy()
            self.lnameentry.destroy()
            self.mailentry.destroy()
            self.btn.destroy()
            return
        else:
            messagebox.showerror("Input error", message)

    def change_password(self):
        """
        Verifies basic conditions, such that password is repeated correctly and then passes the password to the
        user controller to change it in the DB.
        Shows messagebox for success and failure.
        """
        if self.new_password.get() != self.new_password_repeat.get():
            messagebox.showerror(
                "Error",
                "Password wasn't repeated correctly. Please check your password entry again."
            )
            return

        password_changed, message = self.user_controller.edit_password(
            self.username, self.new_password.get())
        if password_changed:
            self.new_password.set('')
            self.new_password_repeat.set('')
            messagebox._show("Success", message)
        else:
            messagebox.showerror("Input error", message)

    def logout(self):
        """Function that is called when the logout button is clicked. Triggers the closing of the window"""
        self.main_window.close_main_window()
コード例 #3
0
class StreamFrame(Frame):
    def __init__(self, master):
        super(StreamFrame, self).__init__(master)
        self.root = master

        # check if user has saved the training sentiment analyzers
        pol_checkfile = os.path.exists('files/sa_polarity.pickle')
        subj_checkfile = os.path.exists('files/sa_subjectivity.pickle')

        if not (pol_checkfile
                and subj_checkfile):  # if we cant find the SA files
            # These frames will hold the widgets
            nofiles_frm = Frame(
                self
            )  # this for the the warning message and the back and exit buttons
            nofiles_frm.grid(row=3, column=0, pady=5)
            exit_frm = Frame(self)  # exit frame, contains back and exit button
            exit_frm.grid(row=4, column=0, pady=5)

            message = "SA files not found."
            read_write.log_message("[WARN] (frames.StreamFrame) : " + message)
            message += "\nClick Start Training first to train the NLTK classifiers."
            Label(nofiles_frm, text=message).grid(row=0,
                                                  column=0,
                                                  padx=10,
                                                  pady=5)

            self.mng_stream_btn = Button(
                nofiles_frm,
                text="Start Stream")  # ignore this, if there are no tweets

            # Build the widgets for nofiles_frm
            self.back_btn = Button(exit_frm, text="Back")
            self.back_btn.grid(row=1, column=1, ipadx=5, ipady=3, pady=15)
            self.exit_btn = Button(exit_frm,
                                   text="Exit",
                                   command=self.safe_exit)
            self.exit_btn.grid(row=1,
                               column=3,
                               ipadx=5,
                               ipady=3,
                               padx=15,
                               pady=10)
        else:
            # These frames will hold the widgets
            label_frm = Frame(self)  # this for the label and entry
            label_frm.grid(row=0,
                           column=2,
                           padx=10,
                           pady=10,
                           ipady=20,
                           ipadx=20)

            # Frame for keywords
            self.keywords_frm = Frame(
                self
            )  # this will be hidden until user wants to see previous keywords
            self.keywords_frm.grid(row=0, column=3, rowspan=3, pady=15)

            # Build the widgets for label_frm
            Label(label_frm, text="Keyword:").grid(row=0, column=0, padx=20)
            self.keyword_entry = Entry(label_frm, width=30)
            self.keyword_entry.grid(row=0, column=1, columnspan=3)

            # Build the widgets for button_frm
            self.mng_stream_btn = Button(
                label_frm,
                text="Start Stream")  # this will change from start to stop
            self.mng_stream_btn.grid(row=1,
                                     column=1,
                                     ipadx=5,
                                     ipady=3,
                                     pady=20)
            self.pause_stream_btn = Button(
                label_frm,
                text="Pause Stream")  # if user starts stream, show this button
            self.pause_stream_btn.grid(row=1,
                                       column=3,
                                       ipadx=5,
                                       ipady=3,
                                       padx=10,
                                       pady=20)
            self.pause_stream_btn.grid_remove()

            # Build the widgets for keywords_frm
            self.manage_keywords_btn = Button(
                self.keywords_frm, command=self.show_keywords,
                text=">>>")  # this will change into "<<<" when user clicks it
            self.manage_keywords_btn.grid(row=0,
                                          column=0,
                                          ipadx=5,
                                          ipady=3,
                                          padx=10)

            # Build the widgets for exit_frm
            self.back_btn = Button(label_frm, text="Back")
            self.back_btn.grid(row=2, column=1, ipadx=5, ipady=3, pady=15)
            self.exit_btn = Button(label_frm,
                                   text="Exit",
                                   command=self.safe_exit)
            self.exit_btn.grid(row=2,
                               column=3,
                               ipadx=5,
                               ipady=3,
                               padx=15,
                               pady=10)

    # this method creates a new list box and populates it with the data from keywords.json
    def show_keywords(self):
        # first re-configure the button to show the desired text and change the command into hiding method
        self.manage_keywords_btn.config(text="<<<", command=self.hide_keywords)

        self.previous_keywords = read_write.read_keywords(
        )  # get any previous keywords

        # if there are keywords and the list is not empty
        if len(self.previous_keywords) > 0:
            # build the list box
            self.keyword_lb = Listbox(self.keywords_frm, height=10)
            self.keyword_lb.grid(column=1,
                                 row=0,
                                 pady=10,
                                 padx=5,
                                 sticky=(N, S, E, W))
            # add a binding method
            self.keyword_lb.bind('<Double-1>', self.select_keyword)
            # and add the OK button. This happens here, because we don'w want a button without a list box
            self.select_keyword_btn = Button(self.keywords_frm,
                                             text="OK",
                                             command=self.select_keyword)
            self.select_keyword_btn.grid(row=3,
                                         column=1,
                                         ipady=3,
                                         ipadx=5,
                                         pady=10)

            # adding the keywords to the list box
            counter = 0
            for keyword in self.previous_keywords:
                self.keyword_lb.insert(counter, keyword)
                counter += 1

            # Colorize alternating lines of the listbox
            for i in range(0, len(self.previous_keywords), 2):
                self.keyword_lb.itemconfigure(i, background='#f0f0ff')

    # this method changes the button again and it is called to hide the list box
    def hide_keywords(self):
        self.manage_keywords_btn.config(text=">>>", command=self.show_keywords)
        try:
            # this may result to an error, because we can call hide_keywords before we initialize
            # the list box. This happening if no keywords are present in keywords.json
            self.keyword_lb.destroy()
            self.select_keyword_btn.destroy()
        except AttributeError:
            pass

    def select_keyword(self, *args):
        idxs = self.keyword_lb.curselection()
        if len(idxs) == 1:
            idx = int(idxs[0])
            name = self.previous_keywords[idx]
            self.keyword_entry.delete(0, "end")
            self.keyword_entry.insert(0, name)

    def safe_exit(self):
        x = messagebox.askyesno(title="Exit",
                                message="Are you sure you want to exit?",
                                icon="question")
        if x:
            stream_util.stream_controller.stop()
            read_write.log_message("[INFO]" + stream_util.LOG_NAME +
                                   "Exiting...")
            self.root.destroy()
コード例 #4
0
ファイル: Menu.py プロジェクト: gardan4/Data-Analyzer-Tool
class Menu:
    def __init__(self):
        self.chooseadvance()
        self.predictor = []
        self.tandf = []
        self.name = 0
        self.main = Main()
        self.mdlPredict = ModelPredict()
        root.geometry("1200x600")
        root.title("Data Predictor")
        self.button1 = Button(root,
                              text="Select a File",
                              command=lambda: [self.getfile()])
        self.button1.pack(side=TOP, pady=5)
        self.button2 = Button(root, text="Quit", command=lambda: [self.exit()])
        self.button2.pack(side=BOTTOM, pady=5)
        root.mainloop()

    # Get your file and change button name
    def getfile(self):
        file = tk.filedialog.askopenfilename()
        self.excel = pd.read_excel(file)
        self.name = os.path.basename(file)
        self.button1['text'] = self.name
        if self.advance == 'yes':
            self.mainmenupieces()
            self.dataselect()
        else:
            self.mainmenupieces()
            self.choosepredictor()

    # Make main pieces/screens of the program
    def mainmenupieces(self):
        self.text = Text(root, height=2, width=52)
        self.text.insert(INSERT, "Choose the prediction values")
        self.text.pack(padx=50)
        self.text.config(width=40, height=1, state=DISABLED)
        self.listbox1 = tk.Listbox(root)
        self.listbox1.pack(side=LEFT, padx=50)
        [self.listbox1.insert(END, i) for i in self.excel]
        self.listbox1.config(width=0, height=0)

    # make it so that advance user can choose his predictors
    def dataselect(self):
        self.listbox2 = tk.Listbox(root)
        self.listbox2.pack(side=RIGHT, padx=50)
        self.listbox2.config(width=0, height=0)
        self.listbox1.bind("<<ListboxSelect>>", lambda x: Menu.onclick(self))
        self.button3 = Button(root,
                              text="Confirm",
                              command=lambda: [Menu.trueandfalse(self)])
        self.button3.pack(side=BOTTOM, pady=5)

    # make the onclick commands for advance and the predictor
    def onclick(self):
        if self.advance == 'yes':
            if not self.tandf:
                click = self.listbox1.curselection()[0]
                value = self.listbox1.get(click)
                self.listbox2.insert(END, value)
                self.listbox2.config(width=0, height=0)
                # self.click1 = self.listbox2.curselection()[0]
            else:
                self.listbox3.delete(0, last=None)
                click = self.listbox1.curselection()[0]
                value = self.listbox1.get(click)
                self.listbox3.insert(END, value)
                self.listbox3.config(width=0, height=0)
        else:
            self.listbox3.delete(0, last=None)
            click = self.listbox1.curselection()[0]
            value = self.listbox1.get(click)
            self.listbox3.insert(END, value)
            self.listbox3.config(width=0, height=0)

    # make the list with true and false
    def trueandfalse(self):
        list2 = []
        boxlist = self.listbox2.get(0, END)
        for i in boxlist:
            list2.append(i)
        for x in self.excel:
            if x not in list2:
                self.tandf.append(False)
            else:
                if x in list2:
                    self.tandf.append(True)
        self.listbox1.pack_forget()
        self.listbox2.pack_forget()
        self.button3.destroy()
        self.choosepredictor()

    # Let the user choose his predictor
    def choosepredictor(self):
        self.text.config(width=40, height=1, state=NORMAL)
        self.text.delete("0.0", END)
        self.text.insert(INSERT, "Choose your predictor")
        self.text.pack(padx=50)
        self.text.config(width=40, height=1, state=DISABLED)
        self.listbox1.pack(side=TOP)
        self.listbox1.bind("<<ListboxSelect>>", lambda x: Menu.onclick(self))
        self.main.progressb(root)
        self.button5 = Button(
            root,
            text="Confirm",
            command=lambda: [self.listbox1.destroy(),
                             self.predict()])
        self.button5.pack(side=BOTTOM, pady=5)
        self.listbox3 = tk.Listbox(root)
        self.listbox3.pack(side=BOTTOM, pady=100)

    # confirm your predictor
    def predict(self):
        self.listbox1.destroy()
        self.button5.destroy()
        self.text.config(width=40, height=1, state=NORMAL)
        self.text.delete("0.0", END)
        self.text.insert(
            INSERT,
            "It's loading, can take a long time. Make yourself a nice beverage"
        )
        self.text.config(width=70, height=1, state=DISABLED)
        if self.advance == 'yes':
            boxlist = self.listbox3.get(0, END)
            for i in boxlist:
                self.predictor.append(i)
            self.listbox3.destroy()
            self.chooseaction()
        else:
            boxlist = self.listbox3.get(0, END)
            for i in boxlist:
                self.predictor.append(i)
            self.listbox3.destroy()
            root.update()
            self.main.bestXDummy(self.name, self.predictor, root)
            self.fillable()
            self.confirmdata()

    # Choose the specific program to run
    def chooseaction(self):
        self.text.config(width=40, height=1, state=NORMAL)
        self.text.delete("0.0", END)
        self.text.insert(INSERT, "Choose your Technique")
        self.text.pack(padx=50)
        self.text.config(width=40, height=1, state=DISABLED)
        self.button3 = Button(
            root,
            text="Logistic regression",
            command=lambda: [
                self.main.bestXAdvanced(self.name, self.tandf, "lr", self.
                                        predictor),
                self.fillable()
            ])
        self.button3.pack(side=TOP, pady=5)
        self.button4 = Button(
            root,
            text="K nearest neighbour",
            command=lambda: [
                self.main.bestXAdvanced(self.name, self.tandf, "knn", self.
                                        predictor),
                self.fillable()
            ])
        self.button4.pack(side=TOP, pady=5)
        self.button5 = Button(
            root,
            text="classification Tree",
            command=lambda: [
                self.main.bestXAdvanced(self.name, self.tandf, "ctree", self.
                                        predictor),
                self.fillable()
            ])
        self.button5.pack(side=TOP, pady=5)

    # Choose if you are a advance or a basic user
    def chooseadvance(self):
        self.advance = tk.messagebox.askquestion(
            title="Advanced?",
            message='Advance user or standard? yes for advance, no for standard'
        )
        if self.advance == 'yes':
            return self.advance
        else:
            return self.advance

    # let the user fill in his own data.
    def fillable(self):
        self.text.config(width=50, height=1, state=NORMAL)
        self.text.delete("0.0", END)
        self.text.insert(
            INSERT,
            "Empty the rows and fill in the appropriate data to make a prediction based on the best model."
        )
        self.text.config(width=100, height=1, state=DISABLED)
        self.button3 = Button(root,
                              text="confirm",
                              command=lambda: [self.confirmdata()])
        self.button3.pack(side=BOTTOM, pady=5)
        self.listbox4 = tk.Listbox(root)
        self.listbox4.pack(side=BOTTOM, padx=50)
        if self.advance == 'yes':
            self.topXText = []
            for i in self.listbox2.get(0, END):
                self.textdata = Text(
                    root,
                    height=2,
                    width=52,
                )
                self.topXText.append(self.textdata)
                self.textdata.insert(INSERT, i)
                self.textdata.pack()
                self.button4.destroy()
                self.button5.destroy()

        else:
            self.topXText = []
            for i in self.main.topX:
                self.textdata = Text(
                    root,
                    height=2,
                    width=52,
                )
                self.topXText.append(self.textdata)
                self.textdata.insert(INSERT, i)
                self.textdata.pack()

    def confirmdata(self):
        self.userD = []
        for i in self.topXText:
            self.userD.append(i.get("1.0", "end-1c"))
        self.userData = pd.DataFrame(self.userD).transpose()
        self.showresult()

    def showresult(self):
        self.listbox4.delete(0, last=END)
        self.listbox4.insert(
            END, "Predicted Advice:",
            self.mdlPredict.predict(self.main.topModel, self.userData))
        self.listbox4.config(width=0, height=0)

    # quit the program
    def exit(self):
        print(self.predictor, self.tandf)
        root.destroy()
        root.quit()
コード例 #5
0
ファイル: project.py プロジェクト: TheAntek/venerable
class View3:
    fon_title = 'Verdana 14'
    fon_normal = 'Verdana 10'

    def __init__(self, master, curs, spec, group):
        self.master = master
        self.curs = curs
        self.spec = spec
        self.group = group
        self.marks = []
        self.counter = 2
        self.simple = Model(self.curs, self.spec, self.group)
        self.headings = self.simple.sql_columns_names()
        master.wm_geometry("%dx%d+%d+%d" % (355, 290, 800, 200))

        # Функционал для добавления значения (labels, entries, buttons)
        self.label_caption = Label(master,
                                   text='Запис студента в базу даних',
                                   font=self.fon_title)
        self.label_caption.place(x=10, y=10)

        self.label_create_1 = Label(master, text='ПІБ', font=self.fon_normal)
        self.label_create_1.place(x=10, y=45)
        self.entry_create_1 = Entry(master, width=15)
        self.entry_create_1.place(x=70, y=45)

        self.label_create_2 = Label(master, text='id', font=self.fon_normal)
        self.label_create_2.place(x=10, y=75)
        self.entry_create_2 = Entry(master, width=3)
        self.entry_create_2.place(x=70, y=75)

        self.label_create_3 = Label(master,
                                    text=self.headings[self.counter],
                                    font=self.fon_normal)
        self.label_create_3.place(x=10, y=105)
        self.entry_create_3 = Entry(master, width=3)
        self.entry_create_3.place(x=70, y=105)

        self.button_create_add = Button_ttk(master,
                                            text='+',
                                            command=self.add_mark,
                                            width=5)
        self.button_create_add.place(x=130, y=102)

        self.button_create_final = Button_ttk(master,
                                              text='Додати',
                                              width=25,
                                              command=self.create)
        self.button_create_final.place(x=10, y=135)

        self.label_create_0 = Label(master,
                                    text='Оцінки:',
                                    font=self.fon_normal)
        self.label_info_1 = Label(master,
                                  text='Помилка!',
                                  foreground='gray30',
                                  font=self.fon_normal)

        # Функционал для удаления значения (labels, entries, buttons)
        self.label_caption_delete = Label(
            master,
            text='Видалення студента з бази даних',
            font=self.fon_title)
        self.label_caption_delete.place(x=10, y=190)

        self.label_delete = Label(master, text='id', font=self.fon_normal)
        self.label_delete.place(x=10, y=225)

        self.entry_delete = Entry(master, width=3)
        self.entry_delete.place(x=70, y=225)

        self.button_delete = Button_ttk(master,
                                        text='Видалити',
                                        width=25,
                                        command=self.delete)
        self.button_delete.place(x=10, y=255)

        self.label_info_2 = Label(master,
                                  text='Помилка!',
                                  foreground='gray30',
                                  font=self.fon_normal)

    def add_mark(self):
        self.counter += 1
        self.marks.append(self.entry_create_3.get())
        # print(self.marks)
        self.label_create_3.destroy()
        self.entry_create_3.destroy()
        try:
            self.label_create_3 = Label(self.master,
                                        text=self.headings[self.counter],
                                        font=self.fon_normal)
        except IndexError:
            self.label_create_3.destroy()
            self.entry_create_3.destroy()
            self.button_create_add.destroy()
            self.label_create_0.place(x=10, y=105)
            self.label_create_3 = Label(self.master,
                                        text=self.marks,
                                        font=self.fon_normal)
            self.label_create_3.place(x=65, y=105)
        else:
            self.label_create_3.place(x=10, y=105)
            self.entry_create_3 = Entry(self.master, width=3)
            self.entry_create_3.place(x=70, y=105)

    def delete(self):
        # print('deleting')
        try:
            student_id = self.entry_delete.get(
            )  # получаем id, которое ввел пользователь
            self.simple.sql_delete(
                student_id)  # вызываем функцию, которая удаляет студента
        except sqlite3.OperationalError:
            self.label_info_2.place(x=200, y=255)
        else:
            self.label_info_2.destroy()

    def create(self):
        try:
            name = self.entry_create_1.get()
            number = self.entry_create_2.get()
            info = self.marks  # строка. пример: '90 95 65 70 87 100..'

            info.insert(0, name)  # в начало списка вставляем ФИО студента
            info.insert(0, number)  # также в начало вставляем номер студента
            # print(info)  # переменная info выглядит след. образом: [id, 'Full Name', 90, 65, 70 ...]

            self.simple.sql_insert(info)
        except sqlite3.ProgrammingError:
            self.label_info_1.place(x=200, y=135)
        else:
            self.label_info_1.destroy()