gui/macapp: make submenu of aliases for 'webopen'
this changes the 'open webroot' menu item to be a submenu listing all aliases defined in ~/.tahoe. Note that the dock menu does not support submenus, so it only offers a single 'open webroot' option for the default tahoe: alias. I had trouble with this at first and concluded that the submenus didn't work, and made it a distinct 'WebUI' menu in it's own right. on further inspection, there are still problems but they seem to be something like once the dock menu has been used, sometimes the app's main menubar menus will cease to function, and this happens regardless of whether submenus or plain simple menus are used. I have no idea what the peoblem is, but it's not submenu specific.
This commit is contained in:
parent
57d9f6beb6
commit
9b10f46374
|
@ -133,21 +133,17 @@ class App(object):
|
||||||
self.reactor_shutdown.wait()
|
self.reactor_shutdown.wait()
|
||||||
log.msg('reactor shut down')
|
log.msg('reactor shut down')
|
||||||
|
|
||||||
def webopen(self):
|
def webopen(self, alias=None):
|
||||||
if self.files_exist(['node.url', 'private/root_dir.cap']):
|
log.msg('webopen: %r' % (alias,))
|
||||||
def read_file(f):
|
if alias is None:
|
||||||
fh = file(f, 'rb')
|
alias = 'tahoe'
|
||||||
contents = fh.read().strip()
|
root_uri = get_aliases(self.basedir).get(alias)
|
||||||
fh.close()
|
if root_uri:
|
||||||
return contents
|
nodeurl = file(os.path.join(self.basedir, 'node.url'), 'rb').read().strip()
|
||||||
nodeurl = read_file(os.path.join(self.basedir, 'node.url'))
|
|
||||||
if nodeurl[-1] != "/":
|
if nodeurl[-1] != "/":
|
||||||
nodeurl += "/"
|
nodeurl += "/"
|
||||||
root_dir = read_file(os.path.join(self.basedir, 'private/root_dir.cap'))
|
url = nodeurl + "uri/%s/" % urllib.quote(root_uri)
|
||||||
url = nodeurl + "uri/%s/" % urllib.quote(root_dir)
|
|
||||||
webbrowser.open(url)
|
webbrowser.open(url)
|
||||||
else:
|
|
||||||
print 'files missing, not opening initial webish root page'
|
|
||||||
|
|
||||||
def maybe_install_tahoe_script(self):
|
def maybe_install_tahoe_script(self):
|
||||||
path_candidates = ['/usr/local/bin', '~/bin', '~/Library/bin']
|
path_candidates = ['/usr/local/bin', '~/bin', '~/Library/bin']
|
||||||
|
@ -532,8 +528,18 @@ class MacGuiApp(wx.App):
|
||||||
menubar = wx.MenuBar()
|
menubar = wx.MenuBar()
|
||||||
file_menu = wx.Menu()
|
file_menu = wx.Menu()
|
||||||
if self.config['show-webopen']:
|
if self.config['show-webopen']:
|
||||||
item = file_menu.Append(WEBOPEN_ID, text='Open Web Root')
|
webopen_menu = wx.Menu()
|
||||||
|
# XXX should promote to mac app inst var
|
||||||
|
aliases = get_aliases(self.app.basedir)
|
||||||
|
self.webopen_menu_ids = {}
|
||||||
|
for alias in aliases:
|
||||||
|
mid = wx.NewId()
|
||||||
|
self.webopen_menu_ids[mid] = alias
|
||||||
|
item = webopen_menu.Append(mid, alias)
|
||||||
frame.Bind(wx.EVT_MENU, self.on_webopen, item)
|
frame.Bind(wx.EVT_MENU, self.on_webopen, item)
|
||||||
|
#log.msg('menu ids: %r' % (self.webopen_menu_ids,))
|
||||||
|
file_menu.AppendMenu(WEBOPEN_ID, 'Open Web UI', webopen_menu)
|
||||||
|
self.aliases = get_aliases(self.app.basedir)
|
||||||
item = file_menu.Append(ACCOUNT_PAGE_ID, text='Open Account Page')
|
item = file_menu.Append(ACCOUNT_PAGE_ID, text='Open Account Page')
|
||||||
frame.Bind(wx.EVT_MENU, self.on_account_page, item)
|
frame.Bind(wx.EVT_MENU, self.on_account_page, item)
|
||||||
item = file_menu.Append(MOUNT_ID, text='Mount Filesystem')
|
item = file_menu.Append(MOUNT_ID, text='Mount Filesystem')
|
||||||
|
@ -566,7 +572,9 @@ class MacGuiApp(wx.App):
|
||||||
self.ExitMainLoop()
|
self.ExitMainLoop()
|
||||||
|
|
||||||
def on_webopen(self, event):
|
def on_webopen(self, event):
|
||||||
self.app.webopen()
|
alias = self.webopen_menu_ids.get(event.GetId())
|
||||||
|
#log.msg('on_webopen() alias=%r' % (alias,))
|
||||||
|
self.app.webopen(alias)
|
||||||
|
|
||||||
def on_account_page(self, event):
|
def on_account_page(self, event):
|
||||||
webbrowser.open(DEFAULT_SERVER_URL + ACCOUNT_PAGE)
|
webbrowser.open(DEFAULT_SERVER_URL + ACCOUNT_PAGE)
|
||||||
|
|
Loading…
Reference in New Issue