def sort_to_send(self): """The data is collected and prepared here""" course_names = self.courseName.get().split() courses.append(*course_names) self.Init_data = {} if not self.username.get(): creds = CS.get_netrc_creds() if not creds: raise Exception("No username passed and no .netrc credentials found, unable to login") else: username, password = creds else: username = self.username.get() # prompt the user for his password if not specified if not self.password.get(): password = getpass.getpass() else: password = self.password.get() # should we be trimming paths? #TODO: this is a simple hack, something more elaborate needed mppl = None if self.mppl_entry.get(): if platform.system() == "Windows": mppl = 90 print "Maximum length of a path component set to %s" % mppl else: # linux max path length is typically around 4060 so assume thats ok pass self.Init_data['max_path_part_len'] = mppl if self.proxy.get(): self.Init_data['proxy']= self.proxy.get() if self.parser.get(): self.Init_data['parser'] = self.parser.get() if self.gzip_courses: self.Init_data['gzip_courses'] = True if self.wkfilter.get(): self.Init_data['wk_filter'] = self.wkfilter.get() if self.ignoreFiles.get(): self.Init_data['ignorefiles']= self.ignoreFiles.get() else: # Ignorefiles is a bit buggy, as it would cause a AttributeError if not passed an empty string if the user hasn't entered anything self.Init_data['ignorefiles']= '' queue.append([username,password]) queue.append(self.Init_data) queue.append([self.destination, bool(self.reverse.get()), bool(self.gzip_courses.get())])
def InitUI(self): """Creates the base Interface""" self.subFrame = ttk.Frame(self.parent, relief=Tk.GROOVE, borderwidth=1) # The UI widgets self.username_label = ttk.Label(self.parent, text='E-mail :') self.username = ttk.Entry(self.parent, width= self.width) self.password_label = ttk.Label(self.parent, text='Password :'******'*', width= self.width) self.remember_Me_checkbox = ttk.Checkbutton(self.parent,text='Remember Me',variable=self.remember_Me,onvalue=1,offvalue=0) self.courseName_label = ttk.Label(self.parent, text='Course Name : ') self.courseName = ttk.Entry(self.parent, width= self.width,validate='key', validatecommand=self.allow_download) self.toggle_button = ttk.Checkbutton(self.parent, text='Advanced '+ six.unichr(9654), command=self.toggle_advanced_panel, variable=self.show_advanced, style='Toolbutton', state='selected') self.wkfilter_label = ttk.Label(self.subFrame, text='Weeks** : ') self.wkfilter = ttk.Entry(self.subFrame, width= self.width) self.proxy_label = ttk.Label(self.subFrame, text='Proxy** : ') self.proxy = ttk.Entry(self.subFrame, width= self.width) self.parser_label = ttk.Label(self.subFrame, text='Parser** : ') self.parser = ttk.Entry(self.subFrame, width= self.width) self.ignoreFiles_label = ttk.Label(self.subFrame,text='Ignored Files** : ') self.ignoreFiles = ttk.Entry(self.subFrame, width= self.width) self.mppl_label = ttk.Label(self.subFrame,text='MPPL** : ') self.mppl_entry = ttk.Entry(self.subFrame, width= self.width) self.gzip_courses_checkbox = ttk.Checkbutton(self.subFrame, text='gzip courses', variable=self.gzip_courses, onvalue=1, offvalue=0) self.reverse_checkbox = ttk.Checkbutton(self.subFrame, text='Reverse Sections', variable=self.reverse, onvalue=1, offvalue=0) self.directory_label = ttk.Label(self.parent, text='Target Folder :') self.directory_entry = ttk.Entry(self.parent, width= self.width, textvariable= self.directory, state='disabled') self.dest_button = ttk.Button(self.parent,text='Select Folder', command=self.select_dest) self.download_button = ttk.Button(self.parent,text='Download', command=self.submit_data, state='disabled') # Grid Allocation self.username_label.grid(column=0, row=0, padx=5) self.username.grid(column=1,row=0, columnspan=3, sticky=Tk.E+Tk.W) self.password_label.grid(column=0, row=1, padx=5) self.password.grid(column=1, row=1, columnspan=3, sticky=Tk.E+Tk.W) self.remember_Me_checkbox.grid(column=1, row=3) self.courseName_label.grid(column=0, row=4, padx=5) self.courseName.grid(column=1, row=4, columnspan=3, sticky=Tk.E+Tk.W) self.toggle_button.grid(column=0, row=6, pady=5, sticky=Tk.W, padx=5) self.wkfilter_label.grid(column=0, row=1) self.wkfilter.grid(column=1, row=1, columnspan=3, sticky=Tk.E+Tk.W) self.proxy_label.grid(column=0, row=2) self.proxy.grid(column=1, row=2, columnspan=3, sticky=Tk.E+Tk.W) self.parser_label.grid(column=0, row=3) self.parser.grid(column=1,row=3, columnspan=3, sticky=Tk.E+Tk.W) self.ignoreFiles_label.grid(column=0, row=4, padx=10) self.ignoreFiles.grid(column=1, row=4, columnspan=3, sticky=Tk.E+Tk.W) self.mppl_label.grid(column=0, row=5) self.mppl_entry.grid(column=1, row=5, columnspan=3, sticky=Tk.E+Tk.W) self.gzip_courses_checkbox.grid(column=1, row=6, pady=5) self.reverse_checkbox.grid(column=2, row=6) self.directory_label.grid(column=0, row=5) self.directory_entry.grid(column=1, row=5, columnspan=3, sticky=Tk.E+Tk.W) self.dest_button.grid(column=3, row=16, pady=5, padx = 10) self.download_button.grid(column=0, row=16, pady=5) #If credentials exist in .netrc file then display it creds = CS.get_netrc_creds() if creds: self.username.insert(Tk.END,creds[0]) self.password.insert(Tk.END,creds[1])
def sort_to_send(self): """The data is collected and prepared here""" course_names = self.courseName.get().split() courses.append(*course_names) self.Init_data = {} if not self.username.get(): creds = CS.get_netrc_creds() if not creds: tkMessageBox.showerror('Error',"No username passed and no .netrc credentials found, unable to login") return False else: username, password = creds else: username = self.username.get() # prompt the user for his password if not specified if not self.password.get(): password = getpass.getpass() else: password = self.password.get() # should we be trimming paths? # TODO: this is a simple hack, something more elaborate needed mppl = None try: if self.mppl_entry.get() and int(self.mppl_entry.get()) > 0: #if mppl specified, always use that mppl = int(self.mppl_entry.get()) elif platform.system() == "Windows": # if mppl is not specified on windows set manually mppl = 90 else: # linux max path length is typically around 4060 so assume thats ok pass except ValueError: tkMessageBox.showerror('Error','Maximum length of a path component should be a positive integer') return False self.Init_data['max_path_part_len'] = mppl if self.proxy.get(): self.Init_data['proxy']= self.proxy.get() if self.parser.get(): self.Init_data['parser'] = self.parser.get() if self.gzip_courses: self.Init_data['gzip_courses'] = True if self.wkfilter.get(): self.Init_data['wk_filter'] = self.wkfilter.get() if self.ignoreFiles.get(): self.Init_data['ignorefiles']= self.ignoreFiles.get() else: # Ignorefiles is a bit buggy, as it would cause a AttributeError if not passed an empty string if the user hasn't entered anything self.Init_data['ignorefiles']= '' if not self.destination: self.destination = self.directory.get() queue.append([username,password]) queue.append(self.Init_data) queue.append([self.destination, bool(self.reverse.get()), bool(self.gzip_courses.get())]) return True