mirror of
https://github.com/markqvist/NomadNet.git
synced 2025-01-14 00:29:26 -05:00
Added URL entry dialog
This commit is contained in:
parent
0d93e7e8d2
commit
913c7935c0
@ -17,6 +17,8 @@ class BrowserFrame(urwid.Frame):
|
||||
self.delegate.forward()
|
||||
elif key == "ctrl r":
|
||||
self.delegate.reload()
|
||||
elif key == "ctrl u":
|
||||
self.delegate.url_dialog()
|
||||
elif self.get_focus() == "body":
|
||||
return super(BrowserFrame, self).keypress(size, key)
|
||||
# if key == "up" and self.delegate.messagelist.top_is_visible:
|
||||
@ -411,6 +413,37 @@ class Browser:
|
||||
self.reloading = True
|
||||
self.load_page()
|
||||
|
||||
def close_dialogs(self):
|
||||
options = self.delegate.columns.options("weight", self.delegate.right_area_width)
|
||||
self.delegate.columns.contents[1] = (self.display_widget, options)
|
||||
|
||||
def url_dialog(self):
|
||||
e_url = urwid.Edit(caption="URL : ", edit_text=self.current_url())
|
||||
|
||||
def dismiss_dialog(sender):
|
||||
self.close_dialogs()
|
||||
|
||||
def confirmed(sender):
|
||||
self.retrieve_url(e_url.get_edit_text())
|
||||
self.close_dialogs()
|
||||
|
||||
dialog = UrlDialogLineBox(
|
||||
urwid.Pile([
|
||||
e_url,
|
||||
urwid.Columns([("weight", 0.45, urwid.Button("Cancel", on_press=dismiss_dialog)), ("weight", 0.1, urwid.Text("")), ("weight", 0.45, urwid.Button("Go", on_press=confirmed))])
|
||||
]), title="Enter URL"
|
||||
)
|
||||
dialog.confirmed = confirmed
|
||||
dialog.delegate = self
|
||||
bottom = self.display_widget
|
||||
|
||||
overlay = urwid.Overlay(dialog, bottom, align="center", width=("relative", 65), valign="middle", height="pack", left=2, right=2)
|
||||
|
||||
options = self.delegate.columns.options("weight", self.delegate.right_area_width)
|
||||
self.delegate.columns.contents[1] = (overlay, options)
|
||||
self.delegate.columns.focus_position = 1
|
||||
|
||||
|
||||
def load_page(self):
|
||||
if self.destination_hash != self.loopback:
|
||||
load_thread = threading.Thread(target=self.__load)
|
||||
@ -692,4 +725,13 @@ def size_str(num, suffix='B'):
|
||||
return "%.2f%s%s" % (num, unit, suffix)
|
||||
num /= 1000.0
|
||||
|
||||
return "%.2f%s%s" % (num, last_unit, suffix)
|
||||
return "%.2f%s%s" % (num, last_unit, suffix)
|
||||
|
||||
class UrlDialogLineBox(urwid.LineBox):
|
||||
def keypress(self, size, key):
|
||||
if key == "esc":
|
||||
self.delegate.close_dialogs()
|
||||
if key == "enter":
|
||||
self.confirmed(self)
|
||||
else:
|
||||
return super(UrlDialogLineBox, self).keypress(size, key)
|
@ -13,7 +13,7 @@ class NetworkDisplayShortcuts():
|
||||
self.app = app
|
||||
g = app.ui.glyphs
|
||||
|
||||
self.widget = urwid.AttrMap(urwid.Text("[C-l] Toggle Nodes/Announces view [C-x] Remove entry [C-w] Disconnect [C-d] Back [C-f] Forward [C-r] Reload"), "shortcutbar")
|
||||
self.widget = urwid.AttrMap(urwid.Text("[C-l] Toggle Nodes/Announces view [C-x] Remove entry [C-w] Disconnect [C-d] Back [C-f] Forward [C-r] Reload [C-u] Enter URL"), "shortcutbar")
|
||||
# "[C-"+g["arrow_u"]+g["arrow_d"]+"] Navigate Lists"
|
||||
|
||||
|
||||
@ -855,6 +855,8 @@ class NetworkLeftPile(urwid.Pile):
|
||||
self.parent.toggle_list()
|
||||
elif key == "ctrl w":
|
||||
self.parent.browser.disconnect()
|
||||
elif key == "ctrl u":
|
||||
self.parent.browser.url_dialog()
|
||||
else:
|
||||
return super(NetworkLeftPile, self).keypress(size, key)
|
||||
|
||||
@ -890,11 +892,12 @@ class NetworkDisplay():
|
||||
|
||||
self.left_area = self.left_pile
|
||||
self.right_area = self.browser.display_widget
|
||||
self.right_area_width = 1-NetworkDisplay.list_width
|
||||
|
||||
self.columns = urwid.Columns(
|
||||
[
|
||||
("weight", NetworkDisplay.list_width, self.left_area),
|
||||
("weight", 1-NetworkDisplay.list_width, self.right_area)
|
||||
("weight", self.right_area_width, self.right_area)
|
||||
],
|
||||
dividechars=0, focus_column=0
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user