Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Commit

Permalink
gui v0.1.2 ui+++
Browse files Browse the repository at this point in the history
  • Loading branch information
Redcxx committed Aug 30, 2019
1 parent 04a1f65 commit 2907b76
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 103 deletions.
30 changes: 21 additions & 9 deletions gui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def remove_invalid_chars(string):
class StdoutTextWidgetRedirector:
def __init__(self, text_component):
self.text_component = text_component
self.text_component.tag_configure('center', justify=tk.CENTER)

def write(self, string, append=False):
try:
Expand All @@ -38,9 +39,7 @@ def write(self, string, append=False):
self.text_component.insert(END, '\n' + string)
else:
self.text_component.delete(1.0, END)
self.text_component.insert(1.0, string)
self.text_component.tag_configure('center', justify=tk.CENTER)
self.text_component.tag_add('center', 1.0, tk.END)
self.text_component.insert(1.0, string, 'center')
self.text_component.see(END)
elif isinstance(self.text_component, Entry):
self.text_component.delete(0, END)
Expand All @@ -62,8 +61,8 @@ def __init__(self, canvas, text_id):

def write(self, string):
try:
string = remove_invalid_chars(string)
self.canvas.itemconfigure(self.text_id, text=string)
self.canvas.itemconfigure(self.text_id, text=remove_invalid_chars(string))
self.canvas.configure(scrollregion=self.canvas.bbox('all'))
except TclError as e:
self.canvas.itemconfigure(self.text_id, text=remove_invalid_chars(str(e)))

Expand Down Expand Up @@ -106,7 +105,20 @@ def crop_to_dimension(im, width_ratio, height_ratio, focus=tk.CENTER):


def get_background_file_path():
for file in glob.glob(settings.IMAGES_PATH):
if re.search(settings.CANVAS_BACKGROUND_PATH, file):
return file
return None
import os
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath('.')

return os.path.join(base_path, settings.CANVAS_BACKGROUND_PATH)


# https://stackoverflow.com/questions/3352918/how-to-center-a-window-on-the-screen-in-tkinter
def center(win):
win.update_idletasks()
width = win.winfo_width()
height = win.winfo_height()
x = (win.winfo_screenwidth() // 2) - (width // 2)
y = (win.winfo_screenheight() // 2) - (height // 2)
win.geometry('{}x{}+{}+{}'.format(width, height, x, y))
Binary file added gui/dist/Pikax - Pixiv Downloader v0.1.2.exe
Binary file not shown.
66 changes: 29 additions & 37 deletions gui/download.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

import tkinter as tk
from threading import Thread
from tkinter import font

import settings
from common import center
from models import PikaxGuiComponent


Expand All @@ -15,59 +17,49 @@ def __init__(self, target, args=(), kwargs=(), output_area=None, button=None):
def run(self):
super().run()
self.button.configure(text='done')
if self.output_area:
if isinstance(self.output_area, tk.Text):
self.output_area.see(0.0)


# this class should be run in a different process
class DownloadWindow(PikaxGuiComponent):

def __init__(self, target, args=(), kwargs=()):
import tkinter as tk
self.window = tk.Tk()
self.window.geometry(settings.DOWNLOAD_WINDOW_SIZE)
self.width = settings.DOWNLOAD_WINDOW_WIDTH
self.height = settings.DOWNLOAD_WINDOW_HEIGHT
self.window.geometry('{}x{}'.format(self.width, self.height))
self.window.title(settings.PIKAX_DOWNLOADER_TITLE)
self.window.resizable(False, False)
center(self.window)
super().__init__(self.window, pikax_handler=None)

self.grid_width = 3
# add using the old grid height so that report button and cancel button are on the same height
self.cancel_button = self.make_button(text='cancel')
self.cancel_button.configure(command=self.cancel_clicked)
self.display_area = self.make_download_output()
self.redirect_output_to(self.display_area)

self.components = [
self.display_area,
self.cancel_button
]

self.buttons = [
self.cancel_button
]

self.download_thread = DownloadThread(target=target, args=args, kwargs=kwargs, output_area=self.display_area,
button=self.cancel_button)
self.load()

def cancel_clicked(self):
self.destroy()

def make_download_output(self):
text_area = self.make_text()
text_area.configure(height=20)
return text_area
self.cancel_button_id = self.add_widget(widget=self.cancel_button, column=1, row=self.grid_height - 30)

def load(self):
import tkinter as tk
for index, component in enumerate(self.components):
component.grid_configure(row=index)
self.grid(component)
self.grid_height = 9
self.text_font = font.Font(family=settings.DEFAULT_FONT_FAMILY, size=settings.DEFAULT_FONT_SIZE - 2)
self.display_area_height = 16
self.display_area_width = 75

for button in self.buttons:
button.configure(state=tk.NORMAL)
self.display_area = self.make_text()
self.display_area_id = self.add_widget(widget=self.display_area, row=4, column=0, columnspan=3)

# configure
self.config()
self.pack(self.frame)

self.window.grab_set()
self.download_thread = DownloadThread(target=target, args=args, kwargs=kwargs, output_area=self.display_area,
button=self.cancel_button)
self.download_thread.start()
self.window.mainloop()

def destroy(self):
def config(self):
self.cancel_button.configure(command=self.cancel_clicked)
self.display_area.configure(height=self.display_area_height, width=self.display_area_width)
self.redirect_output_to(self.display_area)

def cancel_clicked(self):
self.window.destroy()
6 changes: 4 additions & 2 deletions gui/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from common import go_to_next_screen
from models import PikaxGuiComponent
import tkinter as tk


class IDDownloadThread(Thread):
Expand Down Expand Up @@ -31,9 +32,9 @@ def __init__(self, master, pikax_handler):

# buttons
self.download_button = self.make_button(text='download')
self.download_button_id = self.add_widget(widget=self.download_button, row=4, column=8)
self.download_button_id = self.add_widget(widget=self.download_button, row=4, column=11)
self.back_button = self.make_button(text='back')
self.back_button_id = self.add_widget(widget=self.back_button, row=4, column=11)
self.back_button_id = self.add_widget(widget=self.back_button, row=4, column=8)

self.download_output = self.make_download_output()
self.download_output_id = self.add_widget(widget=self.download_output, row=6, column=9, columnspan=2)
Expand All @@ -45,6 +46,7 @@ def __init__(self, master, pikax_handler):
self.download_thread = None

self.id_or_url_entry.focus_set()
self.download_output.configure(state=tk.DISABLED)
self.frame.pack_configure(expand=True)
self.pack(self.frame)

Expand Down
15 changes: 3 additions & 12 deletions gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,19 @@
import settings
from login import LoginScreen
from pikaxhandler import PikaxHandler
from common import center


# [email protected]

# https://stackoverflow.com/questions/3352918/how-to-center-a-window-on-the-screen-in-tkinter
def center(win):
win.update_idletasks()
width = win.winfo_width()
height = win.winfo_height()
x = (win.winfo_screenwidth() // 2) - (width // 2)
y = (win.winfo_screenheight() // 2) - (height // 2)
win.geometry('{}x{}+{}+{}'.format(width, height, x, y))


def main():
root = Tk()
root.configure(borderwidth=0, highlightthickness=0)
root.geometry('{}x{}'.format(settings.MAIN_WINDOW_WIDTH, settings.MAIN_WINDOW_HEIGHT))
root.configure(borderwidth=0, highlightthickness=0)
root.title(settings.PIKAX_DOWNLOADER_TITLE)
root.resizable(False, False)
root.protocol("WM_DELETE_WINDOW", root.destroy)
center(root)
root.protocol("WM_DELETE_WINDOW", root.destroy)
LoginScreen(master=root, pikax_handler=PikaxHandler())
root.mainloop()

Expand Down
5 changes: 4 additions & 1 deletion gui/main.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
block_cipher = None


a = Analysis(['D:/University of Manchester/Projects/Pikax/gui/main.py'],
a = Analysis(['main.py'],
pathex=['D:\\University of Manchester\\Projects\\Pikax\\gui'],
binaries=[],
datas=[],
Expand All @@ -15,6 +15,9 @@ a = Analysis(['D:/University of Manchester/Projects/Pikax/gui/main.py'],
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)

a.datas += [('assets/images/background.jpg', './assets/images/background.jpg', 'DATA')]

pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
Expand Down
7 changes: 5 additions & 2 deletions gui/menu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tkinter import NORMAL
from models import PikaxGuiComponent
import tkinter as tk

from common import go_to_next_screen
from models import PikaxGuiComponent


class MenuScreen(PikaxGuiComponent):
Expand Down Expand Up @@ -37,6 +38,8 @@ def config_buttons(self):
self.rank_button.configure(command=self.rank_clicked)
self.id_button.configure(command=self.id_clicked)
self.back_button.configure(command=self.back_clicked)
if not self.pikax_handler.logged:
self.search_button.configure(state=tk.DISABLED)

def id_clicked(self):
from id import IdScreen
Expand Down
Loading

0 comments on commit 2907b76

Please sign in to comment.