def start_browse_mode(self,frame): logger.info("Creating browse tab") tk.Label(frame,text="Replays").grid(row=0,column=0,sticky="NS") ttk.Button(frame,text="Filter", command=self.filter_replays).grid(row=2,column=0,sticky="WE") tk.Label(frame,text="Staged").grid(row=0,column=2,sticky="NS") ttk.Button(frame,text="Unstage",command=self.unstage_all).grid(row=2,column=2,sticky="WE") f = tk.Frame(frame) f2 = tk.Frame(frame) scrollbar = ttk.Scrollbar(f, orient=tk.VERTICAL) self.tracked_replays = ReplayList(f,yscrollcommand=scrollbar.set,exportselection=0) self.tracked_replays.bind("<MouseWheel>",lambda event : self.tracked_replays.yview("scroll",-event.delta/120,"units")) self.tracked_replays.bind("<Delete>", lambda e : self.delete_tracked_replay_popup()) scrollbar.config(command=self.tracked_replays.yview) scrollbar.pack(side=tk.RIGHT, fill=tk.Y) self.tracked_replays.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) #self.process_new() self.startup_procedure() print "After fetch" scrollbar2 = ttk.Scrollbar(f2, orient=tk.VERTICAL) self.staged_list = ReplayList(f2,yscrollcommand=scrollbar2.set) self.staged_list.bind("<MouseWheel>",lambda event : self.staged_list.yview("scroll",-event.delta/120,"units")) self.staged_list.bind("<Delete>", lambda event :self.staged_list.delete_selected()) scrollbar2.config(command=self.staged_list.yview) scrollbar2.pack(side=tk.RIGHT, fill=tk.Y) self.staged_list.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) #Remember to undo these comments later. self.staged_list.set_insert_callback(self.copy_to_staging) self.staged_list.set_delete_callback(self.delete_from_staging) # self.tracked_replays.grid(row=1,column=0,sticky="NSWE") # self.staged_list.grid(row=1,column=2,sticky="NSWE") f.grid(row=1,column=0,sticky="NSWE") f2.grid(row=1,column=2,sticky="NSWE") self.info = ReplayInfoFrame(frame)#tk.Frame(self,width=100,height=100) print "Info grid" self.info.grid(row=1,column=1,rowspan=2,sticky="NSWE") self.tracked_replays.link(self.staged_list) self.staged_list.link(self.tracked_replays) frame.grid_columnconfigure(0,weight=1) frame.grid_columnconfigure(1,weight=1) frame.grid_columnconfigure(2,weight=1) frame.grid_rowconfigure(1,weight=1) logger.info("Browse tab created")
class ReplayManager(tk.Frame): def __init__(self,parent, **kw): logger.info("Creating Manager") rl_paths.make_dirs() tk.Frame.__init__(self, parent, **kw) n = ttk.Notebook(self) f1 = tk.Frame(n) # first page, which would get widgets gridded into it f2 = tk.Frame(n) # second page n.add(f1, text='browse',sticky="nswe") #n.add(f2, text='add',sticky="nswe") n.pack(fill="both",expand=1) self.start_browse_mode(f1) #self.start_add_mode(f2) # if(self.tracked_replays.size() == 0): # n.select(1) logger.info("Manager created") btk.recursive_widget_bind(self,"<Control-e>",lambda e : self.edit()) def start_browse_mode(self,frame): logger.info("Creating browse tab") tk.Label(frame,text="Replays").grid(row=0,column=0,sticky="NS") ttk.Button(frame,text="Filter", command=self.filter_replays).grid(row=2,column=0,sticky="WE") tk.Label(frame,text="Staged").grid(row=0,column=2,sticky="NS") ttk.Button(frame,text="Unstage",command=self.unstage_all).grid(row=2,column=2,sticky="WE") f = tk.Frame(frame) f2 = tk.Frame(frame) scrollbar = ttk.Scrollbar(f, orient=tk.VERTICAL) self.tracked_replays = ReplayList(f,yscrollcommand=scrollbar.set,exportselection=0) self.tracked_replays.bind("<MouseWheel>",lambda event : self.tracked_replays.yview("scroll",-event.delta/120,"units")) self.tracked_replays.bind("<Delete>", lambda e : self.delete_tracked_replay_popup()) scrollbar.config(command=self.tracked_replays.yview) scrollbar.pack(side=tk.RIGHT, fill=tk.Y) self.tracked_replays.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) #self.process_new() self.startup_procedure() print "After fetch" scrollbar2 = ttk.Scrollbar(f2, orient=tk.VERTICAL) self.staged_list = ReplayList(f2,yscrollcommand=scrollbar2.set) self.staged_list.bind("<MouseWheel>",lambda event : self.staged_list.yview("scroll",-event.delta/120,"units")) self.staged_list.bind("<Delete>", lambda event :self.staged_list.delete_selected()) scrollbar2.config(command=self.staged_list.yview) scrollbar2.pack(side=tk.RIGHT, fill=tk.Y) self.staged_list.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) #Remember to undo these comments later. self.staged_list.set_insert_callback(self.copy_to_staging) self.staged_list.set_delete_callback(self.delete_from_staging) # self.tracked_replays.grid(row=1,column=0,sticky="NSWE") # self.staged_list.grid(row=1,column=2,sticky="NSWE") f.grid(row=1,column=0,sticky="NSWE") f2.grid(row=1,column=2,sticky="NSWE") self.info = ReplayInfoFrame(frame)#tk.Frame(self,width=100,height=100) print "Info grid" self.info.grid(row=1,column=1,rowspan=2,sticky="NSWE") self.tracked_replays.link(self.staged_list) self.staged_list.link(self.tracked_replays) frame.grid_columnconfigure(0,weight=1) frame.grid_columnconfigure(1,weight=1) frame.grid_columnconfigure(2,weight=1) frame.grid_rowconfigure(1,weight=1) logger.info("Browse tab created") def replay_insert(self, replay_tup): replay = replay_tup[0] staged = replay_tup[1] self.tracked_replays.insert("end",replay[2],replay) if staged: self.staged_list.insert("end",replay[2],replay) def process_new(self): print "processing new replays" #Stop the active task (has no effect if it already is stopped) if self.fetch_task: self.fetch_task[1].stopnow = True #Make sure the thread is stopped. self.fetch_task[0].join() self.tracked_replays.clear() self.staged_list.clear() self.fetch_task = tasks.start_task(self,self.replay_insert,tasks.scan_refresh) def startup_procedure(self): self.fetch_task = tasks.start_task(self,self.replay_insert, tasks.startup_procedure) def fetch_replays(self,replayfilters={},tagfilters={},playerfilters={},groupfilters={}): #Stop the active task (has no effect if it already is stopped) if self.fetch_task: self.fetch_task[1].stopnow = True #Make sure the thread is stopped. self.fetch_task[0].join() #Clear the replay list if self.tracked_replays.size() > 0: self.tracked_replays.delete(0,self.tracked_replays.size()) logger.info("Emptied tracked_replay list") #Start task for fetching with filters. self.fetch_task = tasks.start_task(self,self.replay_insert,tasks.fetch_replays,replayfilters,tagfilters,playerfilters,groupfilters) def replay_displayinfo(self,replay_headers): logger.info("Info now displaying: %s",replay_headers) self.info.clear() tasks.start_task(self,self.info.display,tasks.fetch_display_data,replay_headers) # self.info.display(list(replay_headers)) def save(self): self.info.save() def copy_to_staging(self,variables_list): #print "Starting task: COPY TO STAGING" tasks.start_task(self,None,tasks.copy_to_staging,variables_list) def delete_from_staging(self,variables_list): for variables in variables_list: try: os.remove(rl_paths.demo_folder(variables[1])) logger.info("Unstaged replay %s",variables[1]) except WindowsError,e: logger.error("Error unstaging file %s ",variables[1]) logger.error("Error: %s",e)