mirror of https://github.com/sloumdrone/burrow
Added context menu to delete favorites
This commit is contained in:
parent
0d69c834ee
commit
daa3330760
36
gui.py
36
gui.py
|
@ -17,7 +17,7 @@ class GUI:
|
|||
self.history = []
|
||||
self.history_location = -1
|
||||
self.message_bar_content = ''
|
||||
self.config = None
|
||||
# self.config = None
|
||||
self.read_config()
|
||||
self.conn = conn()
|
||||
self.parser = parser()
|
||||
|
@ -76,6 +76,9 @@ class GUI:
|
|||
#status bar objects
|
||||
self.status_info = tk.Label(self.status_bar, textvariable=self.message_bar_content, bg=self.STATUS_BG, takefocus=0, fg=self.ACTIVELINK)
|
||||
|
||||
#menu objects
|
||||
self.fave_context = tk.Menu(self.body, tearoff=0)
|
||||
|
||||
|
||||
self.pack_geometry()
|
||||
self.add_status_titles()
|
||||
|
@ -145,6 +148,14 @@ class GUI:
|
|||
self.message_bar_content.set('Ready.')
|
||||
|
||||
|
||||
def show_fave_context(self, e, href):
|
||||
if self.fave_context.type(0):
|
||||
self.fave_context.delete(0)
|
||||
delete_favorite = (lambda event=e, link=href: self.remove_favorite(event, link))
|
||||
self.fave_context.add_command(label="Remove favorite", command=delete_favorite)
|
||||
self.fave_context.tk_popup(e.x_root, e.y_root)
|
||||
|
||||
|
||||
# ------------Start navigation methods----------------------------
|
||||
|
||||
def handle_request(self,event=False, url=False, history=True):
|
||||
|
@ -233,7 +244,7 @@ class GUI:
|
|||
self.add_to_history('home')
|
||||
data2 = self.load_favorites()
|
||||
link_count = self.send_to_screen(data, '1', True)
|
||||
self.send_to_screen(data2, '1', False, link_count)
|
||||
self.send_to_screen(data2, '1', False)
|
||||
|
||||
|
||||
def go_back(self, event):
|
||||
|
@ -308,7 +319,7 @@ class GUI:
|
|||
self.search = None
|
||||
|
||||
|
||||
def show_menu(self, data, clear=True, links=0):
|
||||
def show_menu(self, data, clear=True):
|
||||
if not data:
|
||||
#error handling will go here
|
||||
return False
|
||||
|
@ -332,7 +343,8 @@ class GUI:
|
|||
if clear:
|
||||
self.site_display.delete(1.0, tk.END)
|
||||
|
||||
link_count = links
|
||||
if clear:
|
||||
self.link_count = 0
|
||||
|
||||
for x in data:
|
||||
if x['type'] == 'i':
|
||||
|
@ -351,7 +363,7 @@ class GUI:
|
|||
else:
|
||||
link = 'gopher://{}{}/{}{}'.format(x['host'], x['port'], x['type'], x['resource'])
|
||||
|
||||
tag_name = 'link{}'.format(link_count)
|
||||
tag_name = 'link{}'.format(self.link_count)
|
||||
callback = (lambda event, href=link, tag_name=tag_name: self.gotolink(event, href, tag_name))
|
||||
hover = (lambda event, href=link, tag_name=tag_name: self.hoverlink(event, href, tag_name))
|
||||
favorite = [x for x in self.config['favorites'] if x['url'] == link]
|
||||
|
@ -362,17 +374,17 @@ class GUI:
|
|||
self.site_display.insert(tk.END, types[x['type']], ('type_tag',))
|
||||
self.site_display.insert(tk.END,'\t\t')
|
||||
if favorite:
|
||||
tag_name_f = 'favorite{}'.format(link_count)
|
||||
callback_f = (lambda event, href=link: self.remove_favorite(event, href))
|
||||
tag_name_f = 'favorite{}'.format(self.link_count)
|
||||
callback_f = (lambda event, href=link: self.show_fave_context(event, href))
|
||||
self.site_display.tag_bind(tag_name_f, '<Button-3>', callback_f)
|
||||
self.site_display.insert(tk.END, x['description'], (tag_name, tag_name_f, 'linkcolor'))
|
||||
else:
|
||||
self.site_display.insert(tk.END, x['description'], (tag_name,'linkcolor'))
|
||||
self.site_display.insert(tk.END, '\n')
|
||||
link_count += 1
|
||||
self.link_count += 1
|
||||
|
||||
self.site_display.config(state=tk.DISABLED)
|
||||
return link_count
|
||||
return self.link_count
|
||||
|
||||
|
||||
def show_text(self, data):
|
||||
|
@ -392,13 +404,12 @@ class GUI:
|
|||
self.site_display.config(state=tk.DISABLED)
|
||||
|
||||
|
||||
def send_to_screen(self, data, itemtype='1', clear=True, link_count=0):
|
||||
def send_to_screen(self, data, itemtype='1', clear=True):
|
||||
if itemtype == '0':
|
||||
self.show_text(data)
|
||||
elif itemtype in ['1','3','7']:
|
||||
data = self.parser.parse_menu(data)
|
||||
links = self.show_menu(data, clear, link_count)
|
||||
return links
|
||||
self.show_menu(data, clear)
|
||||
elif itemtype in ['p','I','g']:
|
||||
self.show_image(data)
|
||||
|
||||
|
@ -472,7 +483,6 @@ class GUI:
|
|||
|
||||
|
||||
def remove_favorite(self, event, href):
|
||||
print('remove!')
|
||||
index = None
|
||||
for ind, val in enumerate(self.config['favorites']):
|
||||
if val['url'] == href:
|
||||
|
|
Loading…
Reference in New Issue