예제 #1
0
파일: old_mplay.py 프로젝트: ankit255/mplay
class playar(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.filenm=None
        self.pack(fill=BOTH, expand=1)
        self.parent = parent
        self.initplayer()

    def initplayer(self):
        self.videoFrame = Frame(self, width=800, height=480)
        self.videoFrame.pack(side="top", fill="both", expand=True)
        self.buttonframe = Frame(self, padding="2 2 11 11")
        self.buttonframe.pack(side="bottom", fill="x", expand=True)

        self.selectbutton = Button(self.buttonframe, text="Select")
        self.selectbutton.grid(column=0, row=0, sticky=W)
        self.playbutton = Button(self.buttonframe, text="Play").grid(column=1, row=0, sticky=W)
        for child in self.buttonframe.winfo_children(): child.grid_configure(padx=5, pady=5)
        self.buttonframe.rowconfigure(0, weight=1)
        self.buttonframe.columnconfigure(0, weight=1)
        self.buttonframe.columnconfigure(1, weight=1)

    def setwh(self,w,h):
        self.videoFrame.configure(width=w, height=h)

    def quit(self):
        print "QUIT CALLED"
        pg.quit()
        self.destroy()
예제 #2
0
    def __init__(self, master):
        self.master = master
        master.title("Convert SPC files")

        mf = Frame(master, padding="10")
        mf.grid(column=0, row=0, sticky=(N, W, E, S))
        mf.columnconfigure(0, weight=1)
        mf.rowconfigure(0, weight=1)
        self.message = "Enter folder containing *.SPC files"
        self.label_text = StringVar()
        self.folder = StringVar()
        self.output_fmt = StringVar()

        self.label_text.set(self.message)

        self.label = Label(mf, textvariable=self.label_text)
        self.folder_label = Label(mf, text="Folder")
        self.output_fmt_label = Label(mf, text="Output Format")

        self.fmt_txt = Radiobutton(mf, text="TXT", variable=self.output_fmt, value='txt')
        self.fmt_csv = Radiobutton(mf, text="CSV", variable=self.output_fmt, value='csv')
        self.folder_entry = Entry(mf, textvariable=self.folder)

        self.sel_foler = Button(mf, text="Browse", command=self.ask_dir)
        self.convert_btn = Button(mf, text="Convert", command=self.convert)

        # map on grid
        self.label.grid(row=0, column=0, columnspan=4, sticky=W + E)
        self.folder_label.grid(row=1, column=0, sticky=E)
        self.output_fmt_label.grid(row=2, column=0, sticky=E)
        self.folder_entry.grid(row=1, column=1, columnspan=2, sticky=W + E)
        self.fmt_txt.grid(row=2, column=1, sticky=W)
        self.fmt_csv.grid(row=2, column=2, sticky=W)
        self.sel_foler.grid(row=1, column=3, sticky=W)
        self.convert_btn.grid(row=3, column=1, columnspan=2, sticky=W + E)

        for child in mf.winfo_children():
            child.grid_configure(padx=5, pady=5)
예제 #3
0
class Window(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.initUI()
        self.UIwithGrid()

    def initUI(self):  # creating gui
        self.frame1 = Frame(self)
        self.frame2 = Frame(self)
        self.frame3 = Frame(self)
        self.frame4 = Frame(self)
        self.frame5 = Frame(self)

        # created multiple frames

        self.label1 = Label(self.frame1,
                            text="COURSE PROGRAM ESTIMATOR",
                            font='Helvetica 25 bold',
                            background="SpringGreen3",
                            foreground="black")
        self.label2 = Label(self.frame1,
                            text="     Training Data: ",
                            font="Times 14")
        self.entry = Entry(self.frame1, width=65)
        self.entry.insert(
            0,
            'https://www.sehir.edu.tr/tr/duyurular/2017-2018-Akademik-Yili-Ders-Programi'
        )
        self.color = Label(
            self.frame1,
            text="                   ",
            background="red",
        )
        self.button = Button(self.frame1,
                             text="Fetch and Train",
                             command=self.fetch)
        self.label3 = Label(self.frame2,
                            text="Individual Courses:",
                            font='Helvetica 10 bold')
        self.label4 = Label(self.frame3,
                            text="     Top 3 Estimates:",
                            font='Helvetica 10 bold')
        self.coursesListbox = Listbox(self.frame2, width=30)
        self.label5 = Label(self.frame4,
                            text=" Accuracy Analysis \nBased on Programs: ",
                            font='Helvetica 10 bold')
        self.programsListbox = Listbox(self.frame4, width=30)
        self.estimatesListbox = Text(self.frame5, width=30, height=10)

        self.scrollbar1 = Scrollbar(self.frame2, orient=VERTICAL)
        self.scrollbar2 = Scrollbar(self.frame4, orient=VERTICAL)
        self.scrollbar3 = Scrollbar(self.frame5, orient=VERTICAL)
        self.scrollbar1.config(command=self.coursesListbox.yview)
        self.scrollbar2.config(comman=self.programsListbox.yview)
        self.scrollbar3.config(command=self.estimatesListbox.yview)
        self.coursesListbox.config(yscrollcommand=self.scrollbar1.set)
        self.programsListbox.config(yscrollcommand=self.scrollbar2.set)
        self.estimatesListbox.config(yscrollcommand=self.scrollbar3.set)

    def UIwithGrid(self):
        self.frame1.grid(row=1, column=2, sticky=N + S + E + W)
        self.frame2.grid(row=2, column=1, columnspan=2, sticky=W)
        self.frame3.grid(row=2, column=2, sticky=N + E)
        self.frame4.grid(row=3, column=1, columnspan=2, sticky=W, pady=5)
        self.frame5.grid(row=3, column=2, columnspan=2, sticky=E, pady=5)
        self.label1.grid(row=1, column=2, sticky=E + W)
        self.label2.grid(row=2, column=1, columnspan=2, pady=25, sticky=W)
        self.entry.grid(row=2, column=2, columnspan=2, sticky=E)
        self.color.grid(row=3, column=2, columnspan=2)
        self.button.grid(row=3, column=2, sticky=E, padx=90)
        self.label3.grid(row=1, column=1)
        self.coursesListbox.grid(row=2, column=1)
        self.label4.pack(in_=self.frame3, side='left')
        self.label5.grid(row=1, column=1)
        self.programsListbox.grid(row=2, column=1)
        self.estimatesListbox.grid(row=2, column=3, sticky=E)
        self.scrollbar1.grid(row=2, column=1, sticky=N + S + E)
        self.scrollbar2.grid(row=2, column=1, sticky=N + E + S)
        self.scrollbar3.grid(row=2, column=2, columnspan=2, sticky=N + S + E)
        self.pack()

    def fetch(self):  # fetching phase
        self.color.config(background='yellow')
        self.course_list = []
        self.update()
        url = self.entry.get()
        self.dataobj = Data()  # creating data obj
        self.dataobj.init_data(url)
        self.courses = self.dataobj.courselist.keys()  # getting keys
        self.courses.sort()  # sorting keys
        self.obj_list = []
        for i in self.courses:
            self.obj_list.append(self.dataobj.courselist[i])
        self.classifier_obj = docclass.naivebayes(docclass.getwords)
        for i in self.obj_list:  # TRANING PHASE
            self.classifier_obj.train(i.split_name.lower(), i.first_code)
        r1 = re.compile("(.*?)\s*\(")
        for i in self.courses:  # adding courses to listbox
            course_name = self.dataobj.courselist[i].name
            name = r1.match(course_name)
            if name != None:
                name1 = i + '' + '(' + name.group(1) + ')'
            else:
                name1 = i + ' ' + '(' + course_name + ')'
            self.coursesListbox.insert(END, name1)
        for z in self.courses:  # adding course category to other listbox
            if self.dataobj.courselist[z].first_code not in self.course_list:
                self.course_list.append(self.dataobj.courselist[z].first_code)

            code = self.dataobj.courselist[z].first_code
            if code not in self.programsListbox.get(0, END):
                self.programsListbox.insert(END, code)
        self.color.config(background='green')
        self.update()
        self.coursesListbox.bind('<<ListboxSelect>>', self.estimate)
        self.programsListbox.bind('<<ListboxSelect>>', self.analyze)

    def estimate(self, event):  # estimating phase
        try:
            for wid in self.frame3.winfo_children():
                wid.destroy()
            self.label4 = Label(self.frame3,
                                text="     Top 3 Estimates:",
                                font='Helvetica 10 bold')
            self.label4.pack(in_=self.frame3)
        except:
            print 'ERROR !!!!'
        widget = event.widget
        selection = widget.curselection()
        picked = widget.get(selection[0])
        x = picked.split('(')
        dict_ = {}
        for cat in self.course_list:  # getting estimating scores
            dict_[cat] = self.classifier_obj.prob(x[1], cat) * 10

        scores = dict_
        sorted_scores = sorted(scores.items(),
                               key=operator.itemgetter(1),
                               reverse=True)  # sorting dictionary
        top_3 = sorted_scores[0:3]  # getting top 3 scores
        print top_3
        dict_temp = {x[0].split(' ')[0]: top_3}
        m = 1
        for key, value in dict_temp.items():  # adding items as labels
            for i in value:
                department, score = i
                if department != key:  # checking if it is true estimation or not
                    color = 'red'
                else:
                    color = 'green'
                self.first_element = Label(self.frame3,
                                           text=department + ':' + str(score),
                                           font='Helvetica 15 bold',
                                           background=color,
                                           width=20)
                if m == 1:
                    self.first_element.pack(in_=self.frame3)
                elif m == 2:
                    self.first_element.pack(in_=self.frame3)
                elif m == 3:
                    self.first_element.pack(in_=self.frame3)
                m = m + 1

    def analyze(self, event):
        try:
            self.estimatesListbox.delete('1.0', END)
        except:
            print 'ERROR'
        widget = event.widget
        selection = widget.curselection()
        picked = widget.get(selection[0])
        cat_ = picked
        course_names = {}
        for i in self.obj_list:  # creating a dict. keys name of courses, values code of
            if i.first_code == cat_:  # filtering
                print i.first_code, cat_
                name = i.name.split('(')[0]
                course_names[name] = i.code
            else:
                continue
        info = {}
        for course in course_names.keys():  # finds best match for each course
            score_dict = {}
            for cat in self.course_list:
                score_dict[cat] = self.classifier_obj.prob(course, cat)
            sorted_scores = sorted(score_dict.items(),
                                   key=operator.itemgetter(1),
                                   reverse=True)
            info[course] = sorted_scores[0][0]
        all_info = {
            'Total Number Of Courses: ': str(len(info))
        }  # creating initial analyzing data
        q = 0
        for item in info.values():  # amount of accurate data
            if item != cat_:
                q = q + 1
        all_info['Inaccurate Classification: '] = str(q)
        all_info['Accurately Classified: '] = len(info) - q
        all_info['Accuracy: '] = '%' + str(
            (float(all_info['Accurately Classified: ']) / float(len(info))) *
            100)
        _ = all_info.keys()
        _.sort()
        for infos in _:
            self.estimatesListbox.insert(END,
                                         infos + str(all_info[infos]) + '\n ')

        for course_ in info:
            self.estimatesListbox.insert(
                END,
                '\t' + course_names[course_] + '-->' + info[course_] + '\n')
file_text = fp.read()
input_txt_updated.insert('0.0', file_text)
fp.close()



used_background = "green"
unrelevant_background = "grey"
# here we configure the highlighting

input_txt.tag_configure("relatioship_highlight",background=relationship_background)
input_txt.tag_configure("relevant_term_highlight",background=relevant_term_background)
input_txt.tag_configure("used_highlight",background=used_background)
input_txt.tag_configure("unrelevant_highlight",background=unrelevant_background)

input_txt_updated.tag_configure("relatioship_highlight",background=relationship_background)
input_txt_updated.tag_configure("relevant_term_highlight",background=relevant_term_background)

input_txt_updated.tag_configure("used_highlight",background=used_background)
input_txt_updated.tag_configure("unrelevant_highlight",background=unrelevant_background)

######################################################################
for child in inputdoc_frm.winfo_children(): child.grid_configure(padx=5, pady=5)
for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5) 
for child in supermainframe.winfo_children(): child.grid_configure(padx=5, pady=5) 

#here we hide the form
inputdoc_frm_relationship.grid_forget()

root.mainloop()
예제 #5
0
botp = IntVar()

kpseqs = BooleanVar()
kprval = BooleanVar()
kpgdata = BooleanVar()

#CHILD FRAMES------------------------------
rootframe = Frame(root, padding="10 10 10 10")


mainframe = Frame(rootframe)
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)

fileframe = Frame(mainframe)
fileframe.grid(column=1, row=1, sticky=(W, E, N), columnspan=4)

paramsframe = LabelFrame(mainframe, text="Parameters")
paramsframe.grid(column=1, row=3, sticky=(W, N, E))

graphframe = LabelFrame(mainframe, text="Graph options")
graphframe.grid(column=2, row=3, sticky=(W, N, E))

optionsframe = LabelFrame(mainframe, text="Output Options")
optionsframe.grid(column=3, row=3, sticky=(W, N, E))

dialogframe = Frame(rootframe)
statusframe = Frame(rootframe)
예제 #6
0
class GUI(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)

        self.parent = parent
        self.initUI()
        self.n = 0
        self.difficulty = "E"
        self.cells = []
        self.puzzle = []
        self.sudokuGrid = Frame(self)
        self.sudokuGrid.grid(row=2, column=0, pady=5)

    def initUI(self):

        self.parent.title("Sudoku")
        Style().configure("TButton", padding=(0, 5, 0, 5), font='serif 10')
        #
        #
        # RWidth=self.parent.winfo_screenwidth()
        # RHeight=self.parent.winfo_screenheight()
        # self.parent.geometry(("%dx%d")%(RWidth,RHeight))
        self.parent.geometry("1000x800")

        menubar = Menu(self)
        titlePhotoFrame = Frame(self)
        titlePhotoFrame.grid(row=4, column=0)
        frame = Frame(self)
        frame.grid(row=0, column=0, padx=5)
        space = Frame(self)
        space.grid(row=1, column=0, pady=5)
        timer_frame = Frame(self)
        timer_frame.grid(row=2, column=0, pady=5)

        # cells = [] # A list of variables tied to entries
        # for i in range(9):
        #     cells.append([])
        #     for j in range(9):
        #         cells[i].append(StringVar())
        #
        # for i in range(9):
        #     for j in range(9):
        #         Entry(sudokuGrid, width = 3, justify = RIGHT,
        #               textvariable = cells[i][j]).grid(
        #             row = i+1, column = j+1)

        drag1 = PhotoImage(file="animated-dragon-image-0031.gif")
        label = Label(frame, image=drag1)
        label.photo = drag1
        label.pack(side="right", fill="both", expand="yes")

        titlePhoto = PhotoImage(file="SudokuTitl.gif")
        label = Label(titlePhotoFrame, image=titlePhoto)
        label.photo = titlePhoto
        label.pack(side="right", fill="both", expand="yes")

        photo = PhotoImage(file="dragon4.gif")
        label = Label(frame, image=photo)
        label.photo = photo
        label.pack(side="left", fill="both", expand="yes")

        generate = Tkinter.Button(frame,
                                  height=2,
                                  width=6,
                                  text="Generate",
                                  command=self.newPuzzle)
        solvePuzzle = Tkinter.Button(frame,
                                     height=2,
                                     width=5,
                                     text="Solve",
                                     command=self.solvePuzzle)
        importPuzzle = Tkinter.Button(frame,
                                      height=2,
                                      width=5,
                                      text="Import",
                                      command=self.readPuzzle)
        #code to add widgets will go here...
        generate.pack(side=RIGHT)

        solvePuzzle.pack(side=RIGHT)
        importPuzzle.pack(side=RIGHT)
        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="Generate Puzzle", command=self.newPuzzle)
        filemenu.add_command(label="Import Puzzle", command=self.readPuzzle)
        filemenu.add_command(label="Solve Puzzle", command=self.solvePuzzle)
        filemenu.add_separator()

        filemenu.add_command(label="Exit", command=self.quit)
        menubar.add_cascade(label="File", menu=filemenu)
        editmenu = Menu(menubar, tearoff=0)
        editmenu.add_command(label="Undo", command=self.donothing)

        menubar.add_cascade(label="Edit", menu=editmenu)
        helpmenu = Menu(menubar, tearoff=0)
        helpmenu.add_command(label="Help Index", command=self.donothing)
        helpmenu.add_command(label="About...", command=self.donothing)
        menubar.add_cascade(label="Help", menu=helpmenu)

        self.parent.config(menu=menubar)
        self.pack()

    def printN(self):
        print self.n

    def readPuzzle(self):
        filename = askopenfilename()
        if filename != "":
            strGrid = ""
            try:
                with open(filename) as f:
                    for line in f:
                        strGrid = strGrid + (line)
                f.close
            except OSError:
                print "Daha"

            self.cells = []
            grid = strGrid.splitlines()

            self.n = len(grid)
            print self.n

            grid = [[0 for x in range(self.n)] for x in range(self.n)]
            row = 0
            col = 0
            for i, v in enumerate(strGrid.splitlines()):
                for j, w in enumerate(v.split()):
                    if w != " " and w != "\n" and w != ".":
                        print w
                        if col == self.n:
                            row += 1
                            col = 0
                        if row == self.n:
                            break
                        grid[row][col] = int(w)
                        col += 1

            self.puzzle = grid
            print self.puzzle
            for i in range((self.n)):
                self.cells.append([])
                for j in range((self.n)):
                    self.cells[i].append(StringVar())
            for child in self.sudokuGrid.winfo_children():
                child.destroy()
            for i in range((self.n)):
                for j in range((self.n)):
                    self.cells[i][j].set(self.puzzle[i][j])
            for i in range((self.n)):
                for j in range(self.n):
                    Entry(self.sudokuGrid,
                          width=3,
                          justify=RIGHT,
                          textvariable=self.cells[i][j]).grid(row=i + 1,
                                                              column=j + 1)
            tkMessageBox.showinfo("Generated!",
                                  ("Valid Sudoku Puzzle Imported"))

            print grid

    def solvePuzzle(self):
        if self.n == 0:
            print "No grid. Generate a grid, or import one."

        elif self.n == 6 or self.n == 8 or self.n == 10 or self.n == 12:
            statement = TRUE
            for i in self.puzzle:
                if i != 0:
                    statement == FALSE
                    break
            if statement == TRUE:
                startTime = datetime.now()
                sudokuGen.evenRecSolve(self.puzzle)
                print self.puzzle
                for i in range(int(self.n)):
                    for j in range(int(self.n)):
                        self.cells[i][j].set(self.puzzle[i][j])
                tkMessageBox.showinfo(
                    "Solved!", ("It took this long to solve the puzzle: ",
                                (datetime.now() - startTime)))

        elif self.n == 4 or self.n == 9 or self.n == 16 or self.n == 25:
            statement = TRUE
            for i in self.puzzle:
                if i != 0:
                    statement == FALSE
                    break
            if statement == TRUE:
                startTime = datetime.now()
                sudokuGen.recSolve(self.puzzle)
                print self.puzzle
                for i in range(int(self.n)):
                    for j in range(int(self.n)):
                        self.cells[i][j].set(self.puzzle[i][j])
                tkMessageBox.showinfo(
                    "Solved!", ("It took this long to solve the puzzle: ",
                                (datetime.now() - startTime)))
            else:
                print "Already solved!"

    def newPuzzle(self):
        # sudokuGrid = Frame(self)
        # sudokuGrid.grid(row=2, column=0, pady=5)
        generator = Toplevel(self)
        inst = Label(generator, text="Enter your n")
        inst.grid(row=0, column=1)
        L1 = Label(generator, text="n")
        L1.grid(row=1, column=0)
        v = IntVar()
        j = StringVar()
        j.set("E")
        E1 = Entry(generator, bd=3, textvariable=v)
        D = Entry(generator, bd=3, textvariable=j)
        E1.grid(row=1, column=1)
        E1.config(state=DISABLED)
        D.grid(row=2, column=1)
        D.config(state=DISABLED)
        v.set(4)
        radiobuttons = Frame(generator)
        radiobuttons.grid(row=4, column=0)
        difficultButtons = Frame(generator)
        difficultButtons.grid(row=4, column=1)

        grids = [("4x4", 4), ("6x6", 6), ("8x8", 8), ("9x9", 9), ("10x10", 10),
                 ("12x12", 12), ("16x16", 16)]
        difficulties = [
            ("Hard", "H"),
            ("Medium", "M"),
            ("Easy", "E"),
        ]

        for text, n in grids:
            b = Radiobutton(difficultButtons, text=text, variable=v, value=n)
            b.pack(anchor=E)
        for text, d in difficulties:
            q = Radiobutton(radiobuttons, text=text, variable=j, value=d)
            q.pack(anchor=E)

        self.difficulty = j.get()
        self.n = v.get()

        def setN():

            self.cells = []
            self.n = int(E1.get())

            # A list of variables tied to entries
            if self.n == 4 or self.n == 9 or self.n == 16 or self.n == 25:
                self.n == int(math.sqrt(self.n))

                for i in range(self.n):
                    self.cells.append([])
                    for j in range(self.n):
                        self.cells[i].append(StringVar())
                grid = []
                startTime = datetime.now()
                stats = True
                while stats == True:
                    grid = sudokuGen.generator(int(math.sqrt(self.n)))
                    self.puzzle = sudokuGen.createPuzzle(grid, self.difficulty)
                    answer = copy.deepcopy(self.puzzle)
                    sudokuGen.recSolve(answer)
                    if answer != self.puzzle:
                        stats = False

                for child in self.sudokuGrid.winfo_children():
                    child.destroy()

                for i in range(self.n):
                    for j in range(self.n):
                        self.cells[i][j].set(self.puzzle[i][j])
                for i in range(self.n):
                    for j in range(self.n):
                        Entry(self.sudokuGrid,
                              width=3,
                              justify=RIGHT,
                              textvariable=self.cells[i][j]).grid(row=i + 1,
                                                                  column=j + 1)
                tkMessageBox.showinfo(
                    "Generated!", ("It took this long to make the puzzle: ",
                                   (datetime.now() - startTime)))
                print sudokuGen.toString(self.puzzle)
            elif self.n == 6 or self.n == 8 or self.n == 10 or self.n == 12:
                print "yes"
                print int(math.sqrt(self.n))
                self.n == int(self.n)
                for i in range(self.n):
                    self.cells.append([])
                    for j in range(self.n):
                        self.cells[i].append(StringVar())
                stats = True
                grid = []
                startTime = datetime.now()
                while stats == True:
                    grid = sudokuGen.altGenrator(self.n)
                    self.puzzle = sudokuGen.createPuzzle(grid, self.difficulty)
                    answer = copy.deepcopy(self.puzzle)
                    sudokuGen.evenRecSolve(answer)
                    print answer
                    print self.puzzle
                    print answer == self.puzzle
                    if answer != self.puzzle:
                        stats = False

                for child in self.sudokuGrid.winfo_children():
                    child.destroy()

                for i in range(self.n):
                    for j in range(self.n):
                        self.cells[i][j].set(self.puzzle[i][j])
                for i in range(self.n):
                    for j in range(self.n):
                        Entry(self.sudokuGrid,
                              width=3,
                              justify=RIGHT,
                              textvariable=self.cells[i][j]).grid(row=i + 1,
                                                                  column=j + 1)
                tkMessageBox.showinfo(
                    "Generated!", ("It took this long to make the puzzle: ",
                                   (datetime.now() - startTime)))
                print sudokuGen.toString(self.puzzle)

        def exitWind():
            generator.destroy()

        def two():
            setN()
            exitWind()

        ok = Tkinter.Button(generator, text="OK", command=two)
        ok.grid(row=3, column=1)

    def disable(self, event):
        event.widget["state"] = "disabled"
        event.widget[""]

    def donothing(self):
        pass

    def importPuzzle(self):
        pass
        self.pack()
예제 #7
0
파일: mplay.py 프로젝트: ankit255/mplay
class mainframe(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.filenm=None
        self.streamnm = None
        self.pack(fill=BOTH, expand=1)
        self.parent = parent
        self.initplayer()
        self.player_process = None
        self.seekthread = None
        self.fstate = False
        self.paused = True
        self.trackmouse = True
        self.stdout_thread = None
        self.stream = False
        self.inhibit_slider_trigger = False
        self.q = LifoQueue()
        self.currtime = 0
        self.endtime = -1

    def initplayer(self):
        self.parentframe = Frame(self)
        self.parentframe.pack(fill=BOTH, expand=True)
        self.videoFrame = Frame(self.parentframe, width=800, height=480)
        self.videoFrame.pack(side="top", fill="both", expand=True)
        self.buttonframe = Frame(self.parentframe, padding="2 2 1 1")
        self.buttonframe.pack(side="bottom", fill="x", expand=False)

        self.seekbar = Scale(self.buttonframe, from_= 0, to=100, orient=HORIZONTAL)
        self.seekbar.grid(column=0, columnspan=4, row=0, sticky=[N, E, S, W])
        self.seekbar.configure(command=self.seeked)

        self.selectbutton = Button(self.buttonframe, text="Select File")
        self.selectbutton.grid(column=0, row=1, sticky=[E,W])
        self.streambutton = Button(self.buttonframe, text="Open HTTP", command=self.streamopen)
        self.streambutton.grid(column=1, row=1, sticky=[E,W])
        self.playbutton = Button(self.buttonframe, text="Play")
        self.playbutton.config(command=self.playpause)
        self.playbutton.grid(column=2, row=1, sticky=[E,W])
        self.fullscreenbutton = Button(self.buttonframe, text="Fullscreen", command=self.togglefullscreen)
        self.fullscreenbutton.grid(column=3, row=1, sticky=[E,W])
        for child in self.buttonframe.winfo_children(): child.grid_configure(padx=5, pady=5)
        self.buttonframe.rowconfigure(0, weight=1)
        self.buttonframe.rowconfigure(1, weight=1)
        self.buttonframe.columnconfigure(0, weight=1)
        self.buttonframe.columnconfigure(1, weight=1)
        self.buttonframe.columnconfigure(2, weight=1)
        self.buttonframe.columnconfigure(3, weight=1)

        self.selectbutton.configure(command=self.fileopen)
        self.videoFrame.bind("<Button-1>",self.playpause)
        self.parent.bind("<F11>", self.togglefullscreen)
        self.parent.bind("<Motion>",self.mouseops)

    def mouseops(self,event=None):
        self.videoFrame.config(cursor="")
        self.videoFrame.after(5000,self.cursorhandler)
        if self.trackmouse:
            x, y = self.parent.winfo_pointerx(), self.parent.winfo_pointery()
            windowx, windowy = self.parent.winfo_width(), self.parent.winfo_height()
            if windowy - 30 <= y:
                if self.fstate:
                    self.buttonframe.pack(side="bottom", fill="x", expand=False)
                    self.trackmouse = False
                    self.parent.after(5000, self.mousetracker)
                self.inhibit_slider_trigger = False
            elif self.fstate:
                self.buttonframe.pack_forget()
                self.inhibit_slider_trigger = True
            else:
                self.inhibit_slider_trigger = True

    def mousetracker(self):
        print 'Mouse Tracker'
        self.trackmouse = True
        self.videoFrame.after(0,self.mouseops)

    def cursorhandler(self):
        self.videoFrame.config(cursor="none")

    def togglefullscreen(self, event=None):
        self.fstate = not self.fstate
        self.parent.attributes("-fullscreen",self.fstate)
        if self.fstate:
            self.fullscreenbutton.config(text="Exit Fullscreen")
            self.buttonframe.pack_forget()
            self.videoFrame.config(cursor="none")
        else:
            self.fullscreenbutton.config(text="Fullscreen")
            self.buttonframe.pack(side="bottom", fill="x", expand=False)
            self.videoFrame.after(5000, self.cursorhandler)

    def fileopen(self):
        self.filenm = askopenfilename(filetypes=[("Supported Files","*.mp4;*.mkv;*.mpg;*.avi;*.mov"),("All Files","*.*")])
        self.stream = False
        self.play()

    def streamopen(self):
        self.streamnm = Dlog(self.parent)
        if self.streamnm.result is not None:
            s = str(self.streamnm)
        else:
            return
        if s.startswith('http'):
            self.stream = True
            self.play()
        else:
            self.stream = False
            showerror("Error","Incorrect Entry")

    def play(self):
        global fifofilename
        if self.filenm is not None and self.filenm != "":
            winid = self.videoFrame.winfo_id()
            if self.mplayer_isrunning():
                self.stop()
            try:
                self.paused = False
                self.playbutton.configure(text="Pause")
                if not self.stream:
                    self.player_process = Popen(["mplayer","-fs","-slave","-quiet","-wid",str(winid),self.filenm],stdin=PIPE, stdout=PIPE)
                else:
                    self.player_process = Popen(["mplayer","-fs","-slave","-quiet","-wid",str(winid),self.streamnm], stdin=PIPE, stdout=PIPE)
                self.stdout_thread = Thread(target=self.enqueue_pipe, args=(self.player_process.stdout, self.q))
                self.stdout_thread.daemon = True
                self.stdout_thread.start()
                self.emptypipe()
                self.seekthread = Thread(target=self.seekbar_setup, args=())
                self.seekthread.daemon = True
                self.seekthread.start()
            except:
                showerror("Error","".join(["Couldn't play video:\n",str(sys.exc_info()[:])]))

    def getvidtime(self):
        if self.mplayer_isrunning():
            self.command_player("get_time_length")
            output = self.readpipe()
            while "ANS_LENGTH" not in output:
                output = self.readpipe()
            if "ANS_LENGTH" in output:
                return output.split('ANS_LENGTH=')[1]
            else:
                return 0

    def playpause(self, event=None):
        if self.player_process is None:
            return
        self.paused = not self.paused
        if self.paused:
            print "VIDEO IS PAUSED /B/RO"
            self.playbutton.configure(text="Play")
        else:
            self.playbutton.configure(text="Pause")
        self.command_player("pause")

    def setwh(self,w,h):
        self.videoFrame.configure(width=w, height=h)

    def quit(self):
        print "QUIT CALLED"
        self.destroy()

    def mplayer_isrunning(self):
        if self.player_process is not None:
            return (self.player_process.poll() is None)
        else:
            return False

    def command_player(self, comd):
        global fifofilename
        if self.mplayer_isrunning():
            try:
                self.player_process.stdin.flush()
                self.player_process.stdin.write("\r\n%s\r\n"%comd)
                # for _ in itertools.repeat(None,8192):
                #     self.player_process.stdin.write("\n")
                self.player_process.stdin.flush()
            except:
                showerror("Error","Error passing command to mplayer\n%s"%sys.exc_info()[1])

    def enqueue_pipe(self, out, q):
        print 'Working on reading mplayer pipe output...'
        for line in iter(out.readline, b''):
            q.put(line)
        out.close()

    def seekbar_setup(self):
        pos = '0'
        trial = 0
        while float(pos)<1:
            trial += 1
            pos = self.getvidtime()
        self.seekbar.config(to=int(float(pos)))
        self.endtime = int(float(pos))
        Timer(1, self.seekbar_updater).start()

    def seekbar_updater(self):
        if not self.paused and self.inhibit_slider_trigger:
            self.currtime += 1
            self.seekbar.set(self.currtime)
        else:
            self.currtime = self.seekbar.get()
        Timer(1, self.seekbar_updater).start()

    def seeked(self,e):
        pos = self.seekbar.get()
        print "We changed pos to :%d"% pos

        x, y = self.parent.winfo_pointerx(), self.parent.winfo_pointery()
        windowx, windowy = self.parent.winfo_width(), self.parent.winfo_height()
        if not self.inhibit_slider_trigger and windowy - 30 <= y:
            self.command_player("seek %d 2"%pos)
            if self.paused:
                self.command_player("pause")

    def startmousetrack(self):
        self.trackmouse = True

    def readpipe(self):
        line = ""
        try:
            line = self.q.get_nowait()
        except Empty:
            print "Empty PIPE"
        finally:
            return line

    def emptypipe(self):
        str = ''
        try:
            while not self.q.empty():
                str += self.q.get_nowait()
        except Empty:
            print "Empty Pipe"
        finally:
            return str

    def stop(self):
        if self.mplayer_isrunning():
            self.player_process.stdin.write("quit\n")
            self.player_process.stdin.flush()
            print self.emptypipe()
        self.player_process = None
예제 #8
0
파일: GUI.py 프로젝트: taichatha/mysudoku
class GUI(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)

        self.parent = parent
        self.initUI()
        self.n = 0
        self.difficulty = "E"
        self.cells = []
        self.puzzle = []
        self.sudokuGrid = Frame(self)
        self.sudokuGrid.grid(row=2, column=0, pady=5)

    def initUI(self):

        self.parent.title("Sudoku")
        Style().configure("TButton", padding=(0, 5, 0, 5),
                          font='serif 10')
        #
        #
        # RWidth=self.parent.winfo_screenwidth()
        # RHeight=self.parent.winfo_screenheight()
        # self.parent.geometry(("%dx%d")%(RWidth,RHeight))
        self.parent.geometry("1000x800")

        menubar = Menu(self)
        titlePhotoFrame = Frame(self)
        titlePhotoFrame.grid(row = 4, column = 0)
        frame = Frame(self)
        frame.grid(row=0, column=0, padx=5)
        space = Frame(self)
        space.grid(row=1, column=0, pady=5)
        timer_frame = Frame(self)
        timer_frame.grid(row=2, column=0, pady=5)



        # cells = [] # A list of variables tied to entries
        # for i in range(9):
        #     cells.append([])
        #     for j in range(9):
        #         cells[i].append(StringVar())
        #
        # for i in range(9):
        #     for j in range(9):
        #         Entry(sudokuGrid, width = 3, justify = RIGHT,
        #               textvariable = cells[i][j]).grid(
        #             row = i+1, column = j+1)

        drag1 = PhotoImage(file = "animated-dragon-image-0031.gif")
        label = Label(frame, image = drag1)
        label.photo = drag1
        label.pack(side = "right", fill = "both", expand = "yes")

        titlePhoto = PhotoImage(file = "SudokuTitl.gif")
        label = Label(titlePhotoFrame, image = titlePhoto)
        label.photo = titlePhoto
        label.pack(side = "right", fill = "both", expand = "yes")

        photo = PhotoImage(file = "dragon4.gif")
        label = Label(frame, image = photo)
        label.photo = photo
        label.pack(side = "left", fill = "both", expand = "yes")

        generate = Tkinter.Button(frame, height = 2, width = 6, text = "Generate", command = self.newPuzzle)
        solvePuzzle = Tkinter.Button(frame, height = 2, width = 5, text = "Solve", command = self.solvePuzzle)
        importPuzzle = Tkinter.Button(frame, height = 2, width = 5, text = "Import", command = self.readPuzzle)
        #code to add widgets will go here...
        generate.pack(side = RIGHT)


        solvePuzzle.pack(side = RIGHT)
        importPuzzle.pack(side = RIGHT)
        filemenu = Menu(menubar, tearoff = 0)
        filemenu.add_command(label="Generate Puzzle", command=self.newPuzzle)
        filemenu.add_command(label="Import Puzzle", command=self.readPuzzle)
        filemenu.add_command(label="Solve Puzzle", command=self.solvePuzzle)
        filemenu.add_separator()

        filemenu.add_command(label="Exit", command=self.quit)
        menubar.add_cascade(label="File", menu=filemenu)
        editmenu = Menu(menubar, tearoff=0)
        editmenu.add_command(label="Undo", command=self.donothing)

        menubar.add_cascade(label="Edit", menu=editmenu)
        helpmenu = Menu(menubar, tearoff=0)
        helpmenu.add_command(label="Help Index", command=self.donothing)
        helpmenu.add_command(label="About...", command=self.donothing)
        menubar.add_cascade(label="Help", menu=helpmenu)

        self.parent.config(menu = menubar)
        self.pack()

    def printN(self):
        print self.n

    def readPuzzle(self):
        filename = askopenfilename()
        if filename != "":
            strGrid = ""
            try:
                with open(filename) as f:
                    for line in f:
                        strGrid = strGrid+ (line)
                f.close
            except OSError:
                print "Daha"

            self.cells = []
            grid = strGrid.splitlines()


            self.n = len(grid)
            print self.n


            grid = [[0 for x in range(self.n)] for x in range(self.n)]
            row = 0
            col = 0
            for i, v in enumerate(strGrid.splitlines()):
                for j, w in enumerate(v.split()):
                    if w != " " and w != "\n" and w != "." :
                        print w
                        if col == self.n:
                            row += 1
                            col = 0
                        if row == self.n:
                            break
                        grid[row][col] = int(w)
                        col+=1

            self.puzzle = grid
            print self.puzzle
            for i in range((self.n)):
                self.cells.append([])
                for j in range((self.n)):
                    self.cells[i].append(StringVar())
            for child in self.sudokuGrid.winfo_children():
                child.destroy()
            for i in range((self.n)):
                for j in range((self.n)):
                    self.cells[i][j].set(self.puzzle[i][j])
            for i in range((self.n)):
                for j in range(self.n):
                    Entry(self.sudokuGrid, width=3, justify=RIGHT,
                          textvariable=self.cells[i][j]).grid(
                        row=i+1, column=j+1)
            tkMessageBox.showinfo( "Generated!", ("Valid Sudoku Puzzle Imported"))




            print grid


    def solvePuzzle(self):
        if self.n == 0:
            print "No grid. Generate a grid, or import one."

        elif self.n == 6 or self.n == 8 or self.n == 10 or self.n == 12:
            statement = TRUE
            for i in self.puzzle:
                if i != 0:
                    statement == FALSE
                    break
            if statement == TRUE:
                startTime = datetime.now()
                sudokuGen.evenRecSolve(self.puzzle)
                print self.puzzle
                for i in range(int(self.n)):
                    for j in range(int(self.n)):
                        self.cells[i][j].set(self.puzzle[i][j])
                tkMessageBox.showinfo( "Solved!", ("It took this long to solve the puzzle: ",(datetime.now()-startTime)))

        elif self.n == 4 or self.n == 9 or self.n == 16 or self.n == 25:
            statement = TRUE
            for i in self.puzzle:
                if i != 0:
                    statement == FALSE
                    break
            if statement == TRUE:
                startTime = datetime.now()
                sudokuGen.recSolve(self.puzzle)
                print self.puzzle
                for i in range(int(self.n)):
                    for j in range(int(self.n)):
                        self.cells[i][j].set(self.puzzle[i][j])
                tkMessageBox.showinfo( "Solved!", ("It took this long to solve the puzzle: ",(datetime.now()-startTime)))
            else:
                print "Already solved!"




    def newPuzzle(self):
        # sudokuGrid = Frame(self)
        # sudokuGrid.grid(row=2, column=0, pady=5)
        generator = Toplevel(self)
        inst = Label(generator, text="Enter your n")
        inst.grid(row=0, column=1)
        L1 = Label(generator, text="n")
        L1.grid(row=1, column=0)
        v = IntVar()
        j = StringVar()
        j.set("E")
        E1 = Entry(generator, bd=3, textvariable=v)
        D = Entry(generator, bd = 3, textvariable = j)
        E1.grid(row=1, column=1)
        E1.config(state = DISABLED)
        D.grid(row=2, column=1)
        D.config(state = DISABLED)
        v.set(4)
        radiobuttons = Frame(generator)
        radiobuttons.grid(row = 4, column =0)
        difficultButtons = Frame(generator)
        difficultButtons.grid(row = 4, column = 1)

        grids = [
            ("4x4", 4),
            ("6x6",  6),
            ("8x8", 8),
            ("9x9", 9),
            ("10x10", 10),
            ("12x12", 12),
            ("16x16", 16)]
        difficulties = [
            ("Hard", "H"),
            ("Medium", "M"),
            ("Easy", "E"),
        ]



        for text, n in grids:
            b = Radiobutton(difficultButtons, text=text,
                            variable=v, value=n)
            b.pack(anchor=E)
        for text, d in difficulties:
            q = Radiobutton(radiobuttons, text=text,
                            variable=j, value=d)
            q.pack(anchor=E)

        self.difficulty = j.get()
        self.n = v.get()

        def setN():

            self.cells = []
            self.n = int(E1.get())

             # A list of variables tied to entries
            if self.n == 4 or self.n == 9 or self.n == 16 or self.n == 25:
                self.n == int(math.sqrt(self.n))

                for i in range(self.n):
                    self.cells.append([])
                    for j in range(self.n):
                        self.cells[i].append(StringVar())
                grid = []
                startTime = datetime.now()
                stats = True
                while stats == True:
                    grid = sudokuGen.generator(int(math.sqrt(self.n)))
                    self.puzzle = sudokuGen.createPuzzle(grid, self.difficulty)
                    answer = copy.deepcopy(self.puzzle)
                    sudokuGen.recSolve(answer)
                    if answer != self.puzzle:
                        stats = False

                for child in self.sudokuGrid.winfo_children():
                    child.destroy()

                for i in range(self.n):
                    for j in range(self.n):
                        self.cells[i][j].set(self.puzzle[i][j])
                for i in range(self.n):
                    for j in range(self.n):
                        Entry(self.sudokuGrid, width=3, justify=RIGHT,
                              textvariable=self.cells[i][j]).grid(
                            row=i+1, column=j+1)
                tkMessageBox.showinfo( "Generated!", ("It took this long to make the puzzle: ",(datetime.now()-startTime)))
                print sudokuGen.toString(self.puzzle)
            elif self.n == 6 or self.n == 8 or self.n == 10 or self.n == 12:
                print "yes"
                print int(math.sqrt(self.n))
                self.n == int(self.n)
                for i in range(self.n):
                    self.cells.append([])
                    for j in range(self.n):
                        self.cells[i].append(StringVar())
                stats = True
                grid = []
                startTime = datetime.now()
                while stats == True:
                    grid = sudokuGen.altGenrator(self.n)
                    self.puzzle = sudokuGen.createPuzzle(grid, self.difficulty)
                    answer = copy.deepcopy(self.puzzle)
                    sudokuGen.evenRecSolve(answer)
                    print answer
                    print self.puzzle
                    print answer == self.puzzle
                    if answer != self.puzzle:
                        stats = False

                for child in self.sudokuGrid.winfo_children():
                    child.destroy()

                for i in range(self.n):
                    for j in range(self.n):
                        self.cells[i][j].set(self.puzzle[i][j])
                for i in range(self.n):
                    for j in range(self.n):
                        Entry(self.sudokuGrid, width=3, justify=RIGHT,
                              textvariable=self.cells[i][j]).grid(
                            row=i+1, column=j+1)
                tkMessageBox.showinfo( "Generated!", ("It took this long to make the puzzle: ",(datetime.now()-startTime)))
                print sudokuGen.toString(self.puzzle)


        def exitWind():
            generator.destroy()
        def two():
            setN()
            exitWind()
        ok = Tkinter.Button(generator, text = "OK", command = two)
        ok.grid(row = 3, column = 1)





    def disable(self, event):
        event.widget["state"] = "disabled"
        event.widget[""]

    def donothing(self):
        pass
    def importPuzzle(self):
        pass
        self.pack()
예제 #9
0
파일: rvd.py 프로젝트: sanket-desai/rvd-git
    def __init__(self, master):
        self.master = master
        self.screen1 = None
        master.title("RVD")
        #mf = Frame(master, padding="20")
        master.geometry('575x300')
        #self.menu=Menu(master)
        #file_item=Menu(self.menu)

        #self.menu.add_cascade(label='File', menu=file_item)
        #file_item.add_command(label='About', command=self.about)
        #file_item.add_separator()
        #file_item.add_command(label='Exit', command=self.master.quit)
        mf = Frame(master, padding="15")
        mf.grid(column=0, row=0, sticky=(N, W, E, S))
        mf.columnconfigure(0, weight=1)
        mf.rowconfigure(0, weight=1)
        self.infomessage = "Raman spectra based RNA Virus Detection (RVD) program\n"
        self.developer = "\nDeveloped by Sanket Desai, Dutt laboratory, TMC-ACTREC"
        self.infolabel_text = StringVar()
        self.developer_text = StringVar()
        self.proname = StringVar()
        self.message = "Enter folder containing *.SPC files"
        self.label_text = StringVar()
        self.folder = StringVar()
        #self.output_fmt = StringVar()
        self.outputdir = StringVar()
        self.prolabel = Label(mf, text="Project name")
        self.infolabel_text.set(self.infomessage)
        self.developer_text.set(self.developer)
        self.label_text.set(self.message)
        self.ilabel = Label(mf, textvariable=self.infolabel_text)
        self.developerlabel = Label(mf, textvariable=self.developer_text)
        self.label = Label(mf, textvariable=self.label_text)
        self.folder_label = Label(mf, text="Input Directory")
        self.output_folder_label = Label(mf, text="Output Directory")
        #self.output_fmt_label = Label(mf, text="Output Format")
        #self.fmt_txt = Radiobutton(mf, text="TXT", variable=self.output_fmt, value='txt')
        #self.fmt_csv = Radiobutton(mf, text="CSV", variable=self.output_fmt, value='csv')

        self.proname_entry = Entry(mf, textvariable=self.proname)
        self.folder_entry = Entry(mf, textvariable=self.folder)
        self.sel_foler = Button(mf, text="Browse", command=self.ask_dir)
        self.folder_entry2 = Entry(mf, textvariable=self.outputdir)
        self.sel_foler2 = Button(mf, text="Browse", command=self.ask_odir)
        self.convert_btn = Button(mf, text="Submit", command=self.convert)
        # map on grid
        #self.menu.grid(row=0,column=0, sticky=E)
        self.ilabel.grid(row=0, column=2, sticky=E)
        self.prolabel.grid(row=2, column=1, sticky=E)
        self.proname_entry.grid(row=2, column=2, columnspan=2, sticky=W + E)
        self.label.grid(row=3, column=2, columnspan=4, sticky=W + E)
        self.folder_label.grid(row=4, column=1, sticky=E)
        #self.output_fmt_label.grid(row=3, column=0, sticky=E)
        self.folder_entry.grid(row=4, column=2, columnspan=2, sticky=W + E)
        #self.fmt_txt.grid(row=2, column=1, sticky=W)
        #self.fmt_csv.grid(row=2, column=2, sticky=W)
        self.sel_foler.grid(row=4, column=4, sticky=W)
        self.output_folder_label.grid(row=5, column=1, sticky=E)
        self.folder_entry2.grid(row=5, column=2, columnspan=2, sticky=W + E)
        self.sel_foler2.grid(row=5, column=4, sticky=W)
        self.convert_btn.grid(row=6, column=2, columnspan=2, sticky=W + E)
        self.developerlabel.grid(row=7, column=2, sticky=E)
        for child in mf.winfo_children():
            child.grid_configure(padx=5, pady=5)