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

Commit

Permalink
gui search ui 90% ++
Browse files Browse the repository at this point in the history
  • Loading branch information
Redcxx committed Aug 29, 2019
1 parent f509099 commit 04a1f65
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 63 deletions.
16 changes: 9 additions & 7 deletions gui/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import glob
import re
import sys
import tkinter
import tkinter as tk
from multiprocessing import Process
from tkinter import END, NORMAL, DISABLED, Text, Entry, TclError

Expand Down Expand Up @@ -39,6 +39,8 @@ def write(self, string, append=False):
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.see(END)
elif isinstance(self.text_component, Entry):
self.text_component.delete(0, END)
Expand Down Expand Up @@ -69,7 +71,7 @@ def flush(self):
pass


def crop_to_dimension(im, width_ratio, height_ratio, focus=tkinter.CENTER):
def crop_to_dimension(im, width_ratio, height_ratio, focus=tk.CENTER):
transformed_width = im.height / height_ratio * width_ratio
if transformed_width < im.width:
width = transformed_width
Expand All @@ -82,15 +84,15 @@ def crop_to_dimension(im, width_ratio, height_ratio, focus=tkinter.CENTER):
half_width = width / 2
half_height = height / 2

if focus == tkinter.CENTER:
if focus == tk.CENTER:
mid = mid
elif focus == tkinter.N:
elif focus == tk.N:
mid[1] = half_height
elif focus == tkinter.S:
elif focus == tk.S:
mid[1] = im.size[1] - half_height
elif focus == tkinter.W:
elif focus == tk.W:
mid[0] = half_width
elif focus == tkinter.E:
elif focus == tk.E:
mid[0] = im.size[0] - half_width
else:
raise ValueError(f'Invalid focus: {focus}')
Expand Down
4 changes: 2 additions & 2 deletions gui/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def download_clicked(self):
self.download_thread.start()
else:
if re.search(r'\d{8}', user_input, re.S):
sys.stdout.write('Ambiguous Id found, id should be 8 digits')
sys.stdout.write('Ambiguous ID found, ID should be 8 digits only')
else:
sys.stdout.write('No id found in input')
sys.stdout.write('No ID found in input')

def destroy(self):
self.frame.destroy()
3 changes: 2 additions & 1 deletion gui/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def make_entry(self, *args, **kwargs):
)

def make_text(self, *args, **kwargs):
return tk.Text(
text = tk.Text(
master=self.frame,
wrap=tk.WORD,
height=1,
Expand All @@ -245,3 +245,4 @@ def make_text(self, *args, **kwargs):
*args,
**kwargs
)
return text
86 changes: 33 additions & 53 deletions gui/search.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import sys
import tkinter as tk

from common import go_to_next_screen, StdoutTextWidgetRedirector, download
from download import DownloadWindow
from factory import NORMAL, grid, pack, DISABLED
from common import go_to_next_screen, download
from lib.pikax.util import clean_filename
from menu import MenuScreen
from models import PikaxGuiComponent
Expand All @@ -14,24 +13,18 @@ class SearchScreen(PikaxGuiComponent):
def __init__(self, master, pikax_handler):
super().__init__(master, pikax_handler)

self.grid_height = 10
self.grid_width = 15

# labels
self.keyword_label = self.make_label(text='keyword')
self.match_label = self.make_label(text='tag match')
self.sort_label = self.make_label(text='sort')
self.popularity_label = self.make_label(text='popularity')
self.limit_label = self.make_label(text='limit')
self.download_folder_label = self.make_label(text='download folder')

self.labels = [
self.keyword_label,
self.limit_label,
self.match_label,
self.sort_label,
self.popularity_label,
self.download_folder_label
]

# inputs
self.keyword_text_id = self.add_text(text='keyword', column=5, row=1)
self.match_text_id = self.add_text(text='tag match', column=5, row=2)
self.sort_text_id = self.add_text(text='sort', column=5, row=3)
self.popularity_text_id = self.add_text(text='popularity', column=5, row=4)
self.limit_text_id = self.add_text(text='limit', column=5, row=5)
self.download_folder_text_id = self.add_text(text='download folder', column=5, row=6)

# create inputs
self.keyword_entry = self.make_entry()
self.limit_entry = self.make_entry()
match_choices = ['exact', 'partial', 'any']
Expand All @@ -42,46 +35,33 @@ def __init__(self, master, pikax_handler):
self.popularity_dropdown = self.make_dropdown('any', popularity_choices)
self.download_folder_entry = self.make_entry()

self.inputs = [
self.keyword_entry,
self.limit_entry,
self.match_dropdown,
self.sort_dropdown,
self.popularity_dropdown,
self.download_folder_entry
]

# buttons
self.search_and_download_button = self.make_button(text='search and download')
self.search_and_download_button.configure(command=self.search_and_download_clicked)
# add inputs
self.keyword_entry_id = self.add_widget(widget=self.keyword_entry, column=9, row=1)
self.limit_entry_id = self.add_widget(widget=self.limit_entry, column=9, row=2)
self.match_dropdown_id = self.add_widget(widget=self.match_dropdown, column=9, row=3)
self.sort_dropdown_id = self.add_widget(widget=self.sort_dropdown, column=9, row=4)
self.popularity_dropdown_id = self.add_widget(widget=self.popularity_dropdown, column=9, row=5)
self.download_folder_entry = self.add_widget(widget=self.download_folder_entry, column=9, row=6)

# create buttons
self.search_and_download_button = self.make_button(text='download')
self.back_button = self.make_button(text='back')
self.back_button.configure(command=self.back_clicked)

# add buttons
self.back_button_id = self.add_widget(widget=self.back_button, column=5, row=7)
self.search_and_download_button_id = self.add_widget(self.search_and_download_button, column=9, row=7)

# config
self.config_buttons()
for widget in self.frame.children.values():
widget.bind('<Return>', self.search_and_download_clicked)

self.load()

def load(self):
# labels
for index, label in enumerate(self.labels):
label.grid_configure(row=index)
self.grid(label)

# inputs
for index, input in enumerate(self.inputs):
input.grid_configure(row=index, column=1)
self.grid(input)

# buttons
self.back_button.grid_configure(row=6, column=0)
self.back_button.configure(state=NORMAL)
self.search_and_download_button.grid_configure(row=6, column=1)
self.search_and_download_button.configure(state=NORMAL)

self.frame.pack_configure(expand=True)
self.pack(self.frame)

def config_buttons(self):
self.search_and_download_button.configure(command=self.search_and_download_clicked)
self.back_button.configure(command=self.back_clicked)

def destroy(self):
self.frame.destroy()

Expand Down

0 comments on commit 04a1f65

Please sign in to comment.