Skip to content

Commit

Permalink
fixed setup and a few other bugs
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Noiredd committed May 4, 2018
1 parent 6c3fe1e commit 696af06
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 37 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
2 changes: 1 addition & 1 deletion fw-local.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cd fw-local
pythonw gui.py
python gui.py
10 changes: 5 additions & 5 deletions fw-local/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)
Expand All @@ -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
Expand Down
49 changes: 23 additions & 26 deletions fw-local/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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'])
Expand All @@ -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'])
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -472,25 +475,19 @@ 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:
return
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()
Expand Down
5 changes: 3 additions & 2 deletions setup.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cd fw-local
python3 -m pip install requests_html
python3 -m pip install matplotlib
python -m pip install requests_html
python -m pip install matplotlib
python -m pip install pillow

0 comments on commit 696af06

Please sign in to comment.