From 696af06e52e6c6b6fc5f177cce48aefa5162cdab Mon Sep 17 00:00:00 2001 From: Noiredd Date: Fri, 4 May 2018 04:59:45 +0200 Subject: [PATCH] fixed setup and a few other bugs * now properly invokes python.exe * also, forgot to install pillow before * call python instead of pythonw for console output * reordered operations for GUI construction - no longer empty box on startup * some cosmetics in database.py --- README.md | 10 ++++++--- fw-local.bat | 2 +- fw-local/database.py | 10 ++++----- fw-local/gui.py | 49 +++++++++++++++++++++----------------------- setup.bat | 5 +++-- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index c45e7c1..197396d 100644 --- a/README.md +++ b/README.md @@ -13,19 +13,23 @@ Razem z Twoimi ocenami, fw-local pobiera także podstawowe informacje o obejrzan ### Jak uruchomić fw-local? Na ten moment program nie ma instalatora, więc pierwsze uruchomienie może być mało wygodne. -0. Pobierz [pliki programu](https://github.com/Noiredd/fw-local/archive/1.0-alpha.2.zip) i wypakuj, gdzie Ci wygodnie. +0. Pobierz [pliki programu](https://github.com/Noiredd/fw-local/archive/1.0-alpha.3.zip) i wypakuj, gdzie Ci wygodnie. 1. Pierwszym krokiem będzie prawdopodobnie instalacja Python3 ([link do oficjalnego wydania](https://www.python.org/downloads/)) - na chwilę obecną najnowszym wydaniem jest Python 3.6.5. -fw-local nie uruchomi się w środowisku Python 2.x! +fw-local nie uruchomi się w środowisku Python 2.x!\* **Ważne:** na początku instalacji zaznacz `Add Python3 to PATH`! Jeśli już posiadasz Pythona, możesz przejść do instalacji wymaganych modułów. -2. Instalacja modułów. Jeśli to nie Twoje pierwsze starcie z Pythonem, to zainstaluj `requests_html` i `matplotlib`. +2. Instalacja modułów. Jeśli to nie Twoje pierwsze starcie z Pythonem, to zainstaluj `pillow`, `requests_html` i `matplotlib`. W przeciwnym razie po prostu odpal `setup.bat`, skrypt powinien wszystko zrobić za Ciebie. 3. Samo uruchomienie programu, jest już proste - zwyczajnie odpalasz `fw-local.bat`. Powinno ukazać Ci się okno jak w screenie wyżej (tylko puste). +\* - Uwaga dla posiadaczy Pythona 3 i 2.x *naraz* - w zależności od Twojej konfiguracji, skrypty instalacyjne/uruchamiające mogą znaleźć +różne wersje Pythona. Jeśli po uruchomieniu któregoś z nich widzisz tylko szybko znikające okienko konsoli, prawdopodobnie pierwsza +odnajdywana jest wersja 2.x (możesz to potwierdzić otwierając własne okno konsoli i wpisując `python`). + ### Co potrafi fw-local? Po pierwsze musisz zaimportować swoje oceny z filmwebu. fw-local poprosi Cię o to przy pierwszym uruchomieniu. Pojawi się okno logowania do filmweb.pl - po wprowadzeniu danych, fw-local chwilę "pomieli" (w oknie konsoli będzie widać znaki życia - diff --git a/fw-local.bat b/fw-local.bat index 33f6795..48373e9 100644 --- a/fw-local.bat +++ b/fw-local.bat @@ -1,2 +1,2 @@ cd fw-local -pythonw gui.py +python gui.py diff --git a/fw-local/database.py b/fw-local/database.py index d73d54c..dc39235 100644 --- a/fw-local/database.py +++ b/fw-local/database.py @@ -37,7 +37,7 @@ def softUpdate(self, scraper): #collect ids of movies we already know known_ids = [movie['id'] for movie in self.movies] #run scraper until we load a page containing some movie we already have - movies = [] + new_movies = [] fetched = scraper.processNext() found = False while scraper.isThereMore(): @@ -50,15 +50,15 @@ def softUpdate(self, scraper): #we load from the website in batches ('fetched'), so that we only look at #a single batch of movies at once, not all the movies we've loaded #we need to update the list by the fresh batch - movies += fetched + new_movies += fetched if found: break #now, if we've found a movie that we already knew, we have to merge the #gathered list with the known ones #most likely there will be some overlap between movies and self.movies; in #this case we will overwrite with the fresh values old_movies = self.movies - self.movies = movies - new_ids = [movie['id'] for movie in movies] + self.movies = new_movies + new_ids = [movie['id'] for movie in new_movies] for movie in old_movies: if movie['id'] not in new_ids: self.movies.append(movie) @@ -80,7 +80,7 @@ def hardUpdate(self, scraper): movies += scraper.processNext() #only forget the existing one if we have the full thing self.movies = movies - print("READ", scraper.pageIndex, "PAGES") + print("READ", scraper.pageIndex-1, "PAGES") self._save() def filterMovies(self, filters:dict={}): #convert the dict of variables into a callable criteria-checking function diff --git a/fw-local/gui.py b/fw-local/gui.py index 055e283..7536f00 100644 --- a/fw-local/gui.py +++ b/fw-local/gui.py @@ -21,7 +21,7 @@ def readConfigFile(): cf.write('genres\n') cf.write('#duration\n') cf.write('#countries\n') - cf.write('directors\n') + cf.write('#directors\n') cf.write('#cast\n') cf.write('#fwRating\n') cf.write('timeSeen\n') @@ -127,7 +127,7 @@ def _cancelClick(self): class Main(object): summary_format = 'Wyświetlono {0!s} z {1!s} filmów' - max_width = 1000 + max_width = 800 def __init__(self): self.root = root = tk.Tk() @@ -147,16 +147,18 @@ def __init__(self): 'director': '' } self.sorting = None + #prepare the window + root.title('FW local') + root.resizable(0,0) + self.constructMainWindow() #see if there already is a database, or create a new one if db.checkDataExists(): self.database = db.restoreFromFile() else: self._reloadData(newDatabase = True) self.database.setConfig(self.config) - #construct the window - root.title('FW local') - root.resizable(0,0) - self.constructMainWindow() + #fill the controls with data from the database + self._fillFilterData() #all set - refresh and pass control to user self._changeSorting('timeSeen') self._changeSorting('timeSeen') #twice - latest first @@ -203,7 +205,7 @@ def _constructFilterFrame(self): frame = tk.LabelFrame(self.root, text='Filtry') #frame for year filters _yearFrame = tk.Frame(frame) - tk.Label(_yearFrame, text='Rok produkcji:').grid(row=0, column=0, columnspan=4, sticky=tk.N+tk.W) + tk.Label(_yearFrame, text='Rok produkcji:').grid(row=0, column=0, columnspan=5, sticky=tk.N+tk.W) tk.Label(_yearFrame, text='Od:').grid(row=1, column=0, sticky=tk.W) tk.Label(_yearFrame, text='Do:').grid(row=1, column=2, sticky=tk.W) _yearFrom = tk.Entry(_yearFrame, width=5, textvariable=self.filters['year_from']) @@ -217,11 +219,11 @@ def _resetYearFrame(update=True): self.filters['year_to'].set('') if update: self._filtersUpdate() - tk.Button(_yearFrame, text='Reset', command=_resetYearFrame).grid(row=2, column=0, columnspan=4, sticky=tk.E) + tk.Button(_yearFrame, text='Reset', command=_resetYearFrame).grid(row=1, column=4, sticky=tk.E) _yearFrame.grid(row=1, column=0, padx=5, pady=5, sticky=tk.N+tk.W) #frame for rating filters _ratingFrame = tk.Frame(frame) - tk.Label(_ratingFrame, text='Moja ocena:').grid(row=0, column=0, columnspan=4, sticky=tk.N+tk.W) + tk.Label(_ratingFrame, text='Moja ocena:').grid(row=0, column=0, columnspan=5, sticky=tk.N+tk.W) tk.Label(_ratingFrame, text='Od:').grid(row=1, column=0, sticky=tk.W) tk.Label(_ratingFrame, text='Do:').grid(row=1, column=2, sticky=tk.W) _ratingFrom = tk.Entry(_ratingFrame, width=5, textvariable=self.filters['rating_from']) @@ -235,7 +237,7 @@ def _resetRatingFrame(update=True): self.filters['rating_to'].set('') if update: self._filtersUpdate() - tk.Button(_ratingFrame, text='Reset', command=_resetRatingFrame).grid(row=2, column=0, columnspan=4, sticky=tk.E) + tk.Button(_ratingFrame, text='Reset', command=_resetRatingFrame).grid(row=1, column=4, sticky=tk.E) _ratingFrame.grid(row=2, column=0, padx=5, pady=5, sticky=tk.N+tk.W) #frame for timeSeen filters _timeSeenFrame = tk.Frame(frame) @@ -272,7 +274,6 @@ def _resetTimeSeenFrame(update=True): self._filtersUpdate() tk.Button(_timeSeenFrame, text='Reset', command=_resetTimeSeenFrame).grid(row=3, column=0, columnspan=4, sticky=tk.N+tk.E) _timeSeenFrame.grid(row=3, column=0, padx=5, pady=5, sticky=tk.N+tk.W) - self.setYearChoices() #frame for genre filters _genreFrame = tk.Frame(frame) tk.Label(_genreFrame, text='Gatunek:').grid(row=0, column=0, columnspan=2, sticky=tk.N+tk.W) @@ -297,7 +298,6 @@ def _resetGenreFrame(update=True): self._filtersUpdate() tk.Button(_genreFrame, text='Reset', command=_resetGenreFrame).grid(row=2, column=1, sticky=tk.N+tk.E) _genreFrame.grid(row=1, column=1, rowspan=4, padx=5, pady=5, sticky=tk.N+tk.W) - self.setGenreChoices() #frame for country filters _countryFrame = tk.Frame(frame) tk.Label(_countryFrame, text='Kraj produkcji:').grid(row=0, column=0, sticky=tk.N+tk.W) @@ -316,7 +316,6 @@ def _resetCountryFrame(update=True): self._filtersUpdate() tk.Button(_countryFrame, text='Reset', command=_resetCountryFrame).grid(row=2, column=0, sticky=tk.N+tk.E) _countryFrame.grid(row=1, column=2, rowspan=4, padx=5, pady=5, sticky=tk.N+tk.W) - self.setCountryChoices() #frame for director filters _directorFrame = tk.Frame(frame) tk.Label(_directorFrame, text='Reżyser:').grid(row=0, column=0, sticky=tk.N+tk.W) @@ -335,7 +334,6 @@ def _resetDirectorFrame(update=True): self._filtersUpdate() tk.Button(_directorFrame, text='Reset', command=_resetDirectorFrame).grid(row=2, column=0, sticky=tk.N+tk.E) _directorFrame.grid(row=1, column=3, rowspan=4, padx=5, pady=5, sticky=tk.N+tk.W) - self.setDirectorChoices() #reset all filters def _resetAllFrames(): _resetYearFrame(False) @@ -422,6 +420,11 @@ def _changeSorting(self, column): self.tree.heading(column=restored_column_name, text=restored_heading) self.sorting = None self._changeSorting(column) + def _fillFilterData(self): + self.setYearChoices() + self.setGenreChoices() + self.setCountryChoices() + self.setDirectorChoices() #CALLBACKS def _filtersUpdate(self, event=None): @@ -472,12 +475,9 @@ def _updateData(self): self.session = self.loginHandler.requestLogin() if self.session is not None: self.database.softUpdate(self.session) - #refresh data used in the GUI - self.setYearChoices() - self.setGenreChoices() - self.setCountryChoices() - self.setDirectorChoices() - self._filtersUpdate() #triggers a full refresh + #refresh data used in the GUI and refill the view + self._fillFilterData() + self._filtersUpdate() def _reloadData(self, newDatabase=False): self.session = self.loginHandler.requestLogin(message='Zaloguj się by zaimportować oceny' if newDatabase else '') if self.session is None: @@ -485,12 +485,9 @@ def _reloadData(self, newDatabase=False): if newDatabase: self.database = db.Database(self.session.username) self.database.hardUpdate(self.session) - #refresh data used in the GUI - self.setYearChoices() - self.setGenreChoices() - self.setCountryChoices() - self.setDirectorChoices() - self._filtersUpdate() #triggers a full refresh + #refresh data used in the GUI and refill the view + self._fillFilterData() + self._filtersUpdate() def _quit(self): #saves data and exits self.root.quit() diff --git a/setup.bat b/setup.bat index 1ac2a91..e394720 100644 --- a/setup.bat +++ b/setup.bat @@ -1,3 +1,4 @@ cd fw-local -python3 -m pip install requests_html -python3 -m pip install matplotlib \ No newline at end of file +python -m pip install requests_html +python -m pip install matplotlib +python -m pip install pillow