def Push(self): if len(self.newAdditions) > 0: mycsv.write(mstr=self.newAdditions, lesson=True, new=True) self.controller.controller.doValues() self.curDecksAndLevels = srs.findDecksAndLevels() self.newAdditions = [] self.newDeckLevels = {} self.populateSessionAdditionsListbox() old = self.deckSelectListbox.curselection() self.populateDeckListbox() self.deckSelectListbox.selection_set(old) self.deckSelectListbox.selection_anchor(old) self.deckSelectListbox.see(tk.ANCHOR) old = self.levelSelectListbox.curselection() self.populateLevelsListbox() self.levelSelectListbox.selection_set(old) self.levelSelectListbox.selection_anchor(old) self.levelSelectListbox.see(tk.ANCHOR) self.populateEntriesListbox() def d(self): for i in self.imgDl: audio.preload(i, r=True) for i in self.audDl: audio.preload(i, r=True) threading.Thread(target=d, kwargs={ 'self': self }, daemon=True).start()
def on_show_frame(self, event): for widget in self.winfo_children(): widget.destroy() self.controller.controller.geometry(self.size) self.createWidgets() self.curDecksAndLevels = srs.findDecksAndLevels() self.newAdditions = [] self.newDeckLevels = {}
def createWidgets(self): self.changes = [ 'None,None,None,None,None,None,None,None,None,None,None,None,None,None' ] self.decksLBox = tk.Listbox(self, selectmode="BROWSE", exportselection=0, width=40, activestyle='none') for i in srs.findDecksAndLevels(): self.decksLBox.insert(tk.END, i) self.decksLBox.grid(column=0, row=0) self.decksLBox.bind('<<ListboxSelect>>', self.decksLBoxSelect) self.decksLBox.bind('<Key>', self.decksLBoxSelect) self.levelsLBox = tk.Listbox(self, selectmode="BROWSE", exportselection=0, width=40, activestyle='none') self.levelsLBox.grid(column=1, row=0) self.levelsLBox.bind('<<ListboxSelect>>', self.levelsLBoxSelect) self.levelsLBox.bind('<Key>', self.levelsLBoxSelect) self.entriesLBox = tk.Listbox(self, selectmode="BROWSE", exportselection=0, width=40, activestyle='none') self.entriesLBox.grid(column=2, row=0) self.entriesLBox.bind('<<ListboxSelect>>', self.entriesLBoxSelect) self.entriesLBox.bind('<Key>', self.entriesLBoxSelect) self.f = tk.Frame(self) self.f.grid(column=3, row=0, sticky='N') self.searchButton = tk.Button(self.f, text="Search", command=self.search) self.searchButton.grid(row=1) self.newButton = tk.Button(self.f, text="Add new decks and entries", command=self.new) self.newButton.grid(row=2) self.buttonGoBack = tk.Button(self.f, text="Go Back and commit entry saves", command=self.goMainMenu) self.buttonGoBack.grid(row=0) self.editFrame = tk.Frame(self)
def __init__(self, master, controller): tk.Frame.__init__(self, master) self.controller = controller self.size = '950x500' self.bind("<<ShowFrame>>", self.on_show_frame) self.newAdditions = [] self.newDeckLevels = {} self.curDecksAndLevels = srs.findDecksAndLevels() self.supportedLangs = consts.supportedLangs() self.supportedLangsReversed = { y: x for x, y in self.supportedLangs.items() } self.langCodes = [x for x in self.supportedLangs] self.langNames = [self.supportedLangs[x] for x in self.langCodes]
def doValues(self): try: #????????????????????????????????????????????????????????????????????????????????????????????????????????? self.frames['Analytics'].historyfiles() self.Analynew = False except: self.Analynew = True t = srs.findTo() self.toReview = t[0] self.toLearn = t[1] self.total = t[2] self.deck = None self.dandl = srs.findDecksAndLevels() self.reviewCounts = {} self.learnCounts = {} self.totalCounts = {} self.langs = [{ consts.supportedLangs()[x]: x } if x in consts.supportedLangs() else { 'Other': x } for x in list(set([x.split(',')[14] for x in self.total]))] self.langs = {v: k for d in self.langs for k, v in d.items()} self.deckLangs = {} for i in self.dandl: self.reviewCounts[i] = len( [x for x in self.toReview if i in x.split(",")[11]]) self.learnCounts[i] = len( [x for x in self.toLearn if i in x.split(",")[11]]) self.totalCounts[i] = len( [x for x in self.total if i in x.split(",")[11]]) for j in self.dandl[i]: for k in self.dandl[i][j]: if i not in self.deckLangs: self.deckLangs[i] = '' #if not k[14] == self.deckLangs[i] and not self.deckLangs[i] == '': # print('error found entry with different language in the deck') self.deckLangs[i] = self.langs[k[14]]
def makeBackup(): dal = srs.findDecksAndLevels() for folder, subfolders, files in os.walk("{}\{}".format( consts.cwd(), consts.fname())): subs = subfolders for i in subs: if i in dal: for folder, subfolders, files in os.walk("{}\{}\{}".format( consts.cwd(), consts.fname(), i)): nsubs = subfolders for j in nsubs: if j in dal[i]: for folder, subfolders, files in os.walk( "{}\{}\{}\{}".format( consts.cwd(), consts.fname(), i, j)): for f in files: nnsubs = [x[0].lower() for x in dal[i][j]] f = f.replace(".mp3", "").replace( "qchar", "?").replace("slashchar", "/") if f in nnsubs: pass else: if os.path.isfile("{}\{}.mp3".format( folder, f)): if not 'audio-' in "{}\{}.mp3".format( folder, f): os.remove("{}\{}.mp3".format( folder, f)) else: try: if not 'audio-' in "{}\{}".format( folder, f.replace( "?", "qchar") + '.mp3'): os.remove("{}\{}".format( folder, f.replace( "?", "qchar") + '.mp3')) except: pass else: for folder, subfolders, files in os.walk( "{}\{}\{}\{}".format( consts.cwd(), consts.fname(), i, j), topdown=False): for file in files: os.remove("{}\{}".format(folder, file)) os.rmdir(folder) else: for folder, subfolders, files in os.walk("{}\{}\{}".format( consts.cwd(), consts.fname(), i), topdown=False): for file in files: os.remove("{}\{}".format(folder, file)) os.rmdir(folder) d = str(datetime.datetime.now()).split(" ")[0] if not os.path.isdir(consts.backups() + d): os.makedirs(consts.backups() + d) for folder, subfolders, files in os.walk(consts.backups() + d): if len(files) == 0: p = consts.backups() + d + '\\session1.zip' else: p = consts.backups() + d + '\\session{}.zip'.format(len(files) + 1) mzip = zipfile.ZipFile(p, 'w') for folder, subfolders, files in os.walk(consts.cwd()): for file in files: if file.endswith('.csv'): mzip.write(os.path.join(folder, file), os.path.relpath(os.path.join(folder, file), consts.cwd()), compress_type=zipfile.ZIP_DEFLATED) mzip.close() for folder, subfolders, files in os.walk(consts.backups() + d): f = (consts.backups() + d + "\\" + files[len(files) - 2]) fc = Crc32Hasher(f) pc = Crc32Hasher(p) if fc == pc and not f == p: os.remove(p) for folder, subfolders, files in os.walk(consts.backups()): for i in subfolders: j = i.replace("-", "/").split("/") k = "{}/{}/{}".format(j[2], j[1], j[0]) if (convertStrTimeAddDays(mycsv.curdate)[1] - convertStrTimeAddDays(k)[1]).days > 5: for folder, subfolders, files in os.walk(consts.backups() + i): for file in files: os.remove(consts.backups() + i + "\\" + file) os.rmdir(consts.backups() + i)