Skip to content
This repository was archived by the owner on Mar 31, 2020. It is now read-only.

Commit f3bf598

Browse files
committed
Bio complete
1 parent 30e7ef9 commit f3bf598

4 files changed

Lines changed: 36 additions & 20 deletions

File tree

res/template/profile

Whitespace-only changes.

src/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __del__(self):
3131
def __get(self, url, **kwargs):
3232
try:
3333
return requests.get(url, **kwargs)
34-
except ConnectionError as e:
34+
except requests.ConnectionError as e:
3535
return e
3636

3737
def __parse_image(self, data: List[dict]) -> dict:
@@ -56,7 +56,7 @@ def __parse_info(self, data: dict):
5656

5757
def get_profile(self):
5858
response = {k: self.__get(v) for k, v in self.api.items() if self.api_cache.get(k) is None}
59-
if ConnectionError not in response: # TODO Record connection errors
59+
if requests.ConnectionError not in response: # TODO Record connection errors
6060
if 'info' in response:
6161
self.api_cache['info'] = response['info'].json()
6262
if 'hobbies' in response:

src/front.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ def init(self):
5656
self.btn_dislike = widget.PrimaryButton(
5757
self.commandbar, text='Nope', bg='red', command=self.cmd_dislike
5858
)
59-
self.btn_bio = widget.PrimaryButton(
59+
self.btn_bio = widget.SecondaryButton(
6060
self.commandbar, text='Bio', command=self.cmd_bio
6161
)
6262
self.btn_like = widget.PrimaryButton(
6363
self.commandbar, text='Yep', bg='green', command=self.cmd_like
6464
)
6565
self.title.pack(fill='x', expand=True)
6666
self.window.pack(fill='both', expand=True)
67-
self.commandbar.pack(side='bottom', fill='x', expand=True)
67+
self.commandbar.pack(side='bottom', fill='both', expand=True)
6868

6969
self.btn_dislike.pack(side='left')
70-
self.btn_bio.pack(side='left')
71-
self.btn_like.pack(side='left')
70+
self.btn_like.pack(side='right')
71+
self.btn_bio.pack()
7272

7373
self.cache = ImageCache(self.cachesize)
7474
self.cache.start()
@@ -98,19 +98,32 @@ def init(self):
9898
self.config(height=height, width=width)
9999
self.pack_propagate(0)
100100

101-
def __make_item(self, name, value):
102-
item = widget.SecondaryFrame(self)
103-
name = widget.SecondaryLabel(item, text=name)
104-
value = widget.SecondaryLabel(item, text=value)
105-
name.pack(side='left')
106-
value.pack(side='left')
101+
def __build_info(self, info: dict):
102+
item = widget.PrimaryFrame(self)
103+
info = [
104+
f"Age: {info['age']}",
105+
info['gender'].capitalize(),
106+
f'{"She" if info["gender"].startswith("f") else "He"} is {info["location"]}.'
107+
]
108+
for val in info:
109+
name = widget.PrimaryLabel(item, text=val, font=('sys', 15), fg='gray')
110+
name.pack(fill='both')
107111
return item
108112

113+
def __build_hobbies(self, hobbies):
114+
frame = widget.PrimaryFrame(self)
115+
title = widget.PrimaryLabel(frame, text='Hobbies', font=('sys', 15), justify='left')
116+
title.pack(fill='both')
117+
for hobby in hobbies:
118+
val = widget.SecondaryLabel(frame, text=hobby)
119+
val.pack(fill='both')
120+
return frame
121+
109122
def load(self, data: dict):
110-
# print(data)
111-
for name, val in data.items():
112-
item = self.__make_item(name, val)
113-
item.pack(expand=True, fill='x')
123+
info = self.__build_info(data['info'])
124+
hobbies = self.__build_hobbies(data['hobbies'])
125+
info.pack(expand=True, fill='both')
126+
hobbies.pack(expand=True, fill='both')
114127

115128

116129
class Splash(widget.PrimaryFrame):

src/widget.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88

99
class SecondaryFrame(tk.Frame):
10-
DEFAULT = {}
10+
DEFAULT = {
11+
'bg': 'gray'
12+
}
1113

1214
def __init__(self, *args, **kwds):
1315
super().__init__(*args, **{**self.DEFAULT, **kwds})
@@ -30,7 +32,8 @@ def __init__(self, *args, **kwds):
3032
class SecondaryLabel(tk.Label):
3133
DEFAULT = {
3234
'justify': 'left',
33-
'width': 10
35+
'width': 10,
36+
'bg': 'gray'
3437
}
3538

3639
def __init__(self, *args, **kwds):
@@ -62,7 +65,7 @@ def __init__(self, *args, **kwds):
6265
class PrimaryButton(tk.Button):
6366
DEFAULT = {
6467
'height': 3,
65-
'width': 15
68+
'width': 10
6669
}
6770

6871
def __init__(self, *args, **kwds):
@@ -75,7 +78,7 @@ class PrimaryLabel(tk.Label):
7578
DEFAULT = {
7679
'font': ('Courier', 25),
7780
'bg': 'black',
78-
'fg': 'gray'
81+
'fg': 'blue'
7982
}
8083

8184
def __init__(self, *args, **kwds):

0 commit comments

Comments
 (0)