Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed missing parts of file loader. Made operational. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions ankimaker/loaders/fileloader.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
import os.path
import tkinter
from tkinter import ttk
from tkinter import filedialog
from loaders.loader import Loader
from checkbutton import CheckButton

class FileLoader(Loader):

def __init__(self, parent):
super().__init__(parent, 'File', 'Load words from any kind of textfile')

def init_frame(self):
self.load_button = ttk.Button(self, text='Load',
command=self.load)
self.load_button.grid(column=0, row=2, columnspan = 2, rowspan = 2)
self.load_button.state(['disabled'])
self.textfile = ''

self.file_entry = ttk.Entry(self, width=25)
self.file_entry.grid(column=0, row=1, columnspan=2, sticky='W')


self.selecdb_button = ttk.Button(self, text='Browse',
command=self.select_file)
self.selecdb_button.grid(column=2, row=1, sticky='E')

self.load_button = ttk.Button(self, text='Load words',
command=self.load_words)
self.load_button.grid(column = 2, row = 2, sticky='W')

def select_file(self):
options = {'defaultextension':'txt',
'parent':self,
'title':'Select your text file'}

def load(self):
pass
self.textfile = filedialog.askopenfilename(**options)
if self.textfile != '':
self.file_entry.delete(0, tkinter.END)
self.file_entry.insert(0, self.textfile)

def load_words(self):
if not os.path.isfile(self.textfile) :
return None
file = open(self.textfile, "r")
lines = file.readlines()

words = {}

for line in lines:
words[line] = ''

self.parent.add_words(words)