Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/*.egg
/*.egg-info
venv
*.gif
5 changes: 5 additions & 0 deletions bin/gnews-gui
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env/python3
import os
os.system('python3 ./gnewsclient/GUI/GUI.py')


144 changes: 134 additions & 10 deletions gnewsclient/GUI/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,87 @@
from gnewsclient import gnewsclient
from gnewsclient import utils
from tkinter import ttk
from PIL import Image
import urllib.request
import webbrowser

def gotolink(event, x):
webbrowser.open_new(x)


class resizingCanvas(Canvas):
def on_resize(self,event):
# determine the ratio of old width/height to new width/height
wscale = float(event.width)/self.width
hscale = float(event.height)/self.height
self.width = event.width
self.height = event.height
# resize the canvas
self.config(width=self.width, height=self.height)
# rescale all the objects tagged with the "all" tag
self.scale("all",0,0,wscale,hscale)
self.configure(scrollregion=self.bbox('all'))

# def canvas_configure(self, event):
def __init__(self,parent,**kwargs):
Canvas.__init__(self,parent,**kwargs)
self.bind("<Configure>", self.on_resize)
self.height = self.winfo_reqheight()
self.width = self.winfo_reqwidth()



# function to load news in the east frame(level 1)
# see line numbers 189-234 for detailed explanation
def show_news():
global east_frame, myscrollbar, frame,canvas, photo
east_frame.destroy() # destroy old news' frame
east_frame = Frame(root, relief=GROOVE, bd=1) # new frame for fresh news
east_frame.pack(side=RIGHT)

canvas = resizingCanvas(east_frame)

frame = Frame(canvas)
myscrollbar = Scrollbar(east_frame, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=myscrollbar.set)
myscrollbar.pack(side="right", fill="y")

canvas.pack(side="left", padx=30, pady=30)
canvas.create_window((0, 0), window=frame, anchor='nw')

nws = client.get_news()

l = len(nws)
photo = {}
for i in range(l):
try:
imzlnk = nws[i]['img']
imz = Image.open(urllib.request.urlopen(imzlnk))
imz.save('file' + str(i) + '.gif')
f = Frame(frame)
lnk = nws[i]['link']
ttle = nws[i]['title']
photo[i] = PhotoImage(file='file' + str(i) + '.gif')
photolabel = Label(f, image=photo[i]).grid(row=0, column=0, rowspan=3, sticky=W, pady=10)
ttlelabel = Label(f, text=str(ttle), font=("Helvetica", 12)).grid(row=0, column=1, sticky=W, pady=10)
read_more = Label(f, text="Read more about this", fg="blue", cursor="hand2")
read_more.grid(row=1, column=1, sticky=W)
read_more.bind("<Button-1>", lambda event, link=str(lnk): gotolink(event, link))
f.grid(column=1, row=i, sticky=W)
except AttributeError:
imzlnk = nws[i]['img']
f = Frame(frame)
lnk = nws[i]['link']
ttle = nws[i]['title']
ttlelabel = Label(f, text=str(ttle), font=("Helvetica", 12)).grid(row=0, column=1, sticky=W)
read_more = Label(f, text="Read more about this", fg="blue", cursor="hand2")
read_more.grid(row=1, column=1, sticky=W)
read_more.bind("<Button-1>", lambda event, link=str(lnk): gotolink(event, link))
f.pack()
return





# function to set attributes(language, location, topic), and then fetch news accordingly
Expand All @@ -25,9 +106,7 @@ def news():
client.location = None

update_status(client,status)
for i in client.get_news():
print(i)
print("\n")
show_news()
return


Expand All @@ -36,7 +115,8 @@ def search():
global search_query,client,status
client.query= search_query.get()
update_status(client,status)
print(client.get_news())
# print(client.get_news())
show_news()
return

# helper function for status bar
Expand Down Expand Up @@ -73,7 +153,7 @@ def update_status(client, status):
search_button = Button(search_frame,text= "search", command=search).grid(row=1, column = 1)

west_frame = Frame(root)
west_frame.pack(side=LEFT)
west_frame.pack(side=LEFT, padx=10)


# frame for topic, location, and edition filters
Expand Down Expand Up @@ -106,12 +186,56 @@ def update_status(client, status):
location_query = StringVar()
location = Entry(tle_frame, textvariable=location_query).grid(row=4, column=1,pady=50)


# frame to enclose all the stuff related to show news(level 1)
east_frame=Frame(root,relief=GROOVE,bd=1)
east_frame.pack(side=RIGHT)

# canvas which keeps the news related stuff(level 2)
canvas = resizingCanvas(east_frame)

# the frame inside canvas which shows news and stuff(level 3)
frame = Frame(canvas)
# scrollbar so that the canvas can be scrolled(level 2)
myscrollbar=Scrollbar(east_frame, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=myscrollbar.set)
myscrollbar.pack(side="right",fill="y")

canvas.pack(side="left", padx=30, pady=30)
canvas.create_window((0,0),window=frame,anchor='nw')

# news list which has dictionaries for different news articles
nws = client.get_news() # has the default filtering parameters
l = len(nws)
photo = {} # dictionary which maps numbers with PhotoImage objects
for i in range(l):
try:
imzlnk = nws[i]['img']
imz = Image.open(urllib.request.urlopen(imzlnk))
imz.save('file'+str(i)+'.gif')
f = Frame(frame) # frame to display a news article(one frame per article)(level 4)
lnk = nws[i]['link']
ttle = nws[i]['title']
photo[i] = PhotoImage(file='file'+str(i)+'.gif')
photolabel = Label(f, image = photo[i]).grid(row=0, column=0, rowspan=3, sticky=W, pady=10)
ttlelabel = Label(f, text=str(ttle), font=("Helvetica", 12)).grid(row=0, column=1, sticky=W, pady=10, padx=5)
# ttlelabel.config()
read_more = Label(f, text="Read more about this", fg="blue", cursor="hand2")
read_more.grid(row=1, column=1, sticky=W, padx=5)
read_more.bind("<Button-1>", lambda event, link=str(lnk): gotolink(event, link))
f.grid(column=1, row=i, sticky=W)
except AttributeError:# incase there is no photo found, no photo rendering done here
imzlnk = nws[i]['img']
f = Frame(frame)
lnk = nws[i]['link']
ttle = nws[i]['title']
ttlelabel = Label(f, text=str(ttle), font=("Helvetica", 12)).grid(row=0, column=1, sticky=W)
read_more = Label(f, text="Read more about this", fg="blue", cursor="hand2")
read_more.grid(row=1, column=1, sticky=W)
read_more.bind("<Button-1>", lambda event, link=str(lnk): gotolink(event, link))
f.pack()

# button to fetch news
getnews = Button(tle_frame, command=news,text = "Get News!").grid(row=6,column=0,columnspan=2, pady=25)




img = PhotoImage(file='logo.png')
root.tk.call('wm', 'iconphoto', root._w, img)
root.mainloop()
Binary file added gnewsclient/GUI/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def readme():
'Topic :: Internet',
],
keywords = 'google news feed python client',
scripts = ['bin/gnews-gui'],
description = 'Python client for Google News feed.',
long_description = readme(),
url = 'http://github.com/nikhilkumarsingh/gnewsclient',
Expand All @@ -38,4 +39,4 @@ def readme():
[console_scripts]
gnews=gnewsclient.scripts.gnews:cli
''',
)
)