Support opening multiple windows via init args.

This commit is contained in:
Florian Bruhin 2014-09-29 18:46:20 +02:00
parent e6fe358d73
commit 6e61f4c586
2 changed files with 21 additions and 12 deletions

View File

@ -219,12 +219,17 @@ class Application(QApplication):
# we make sure the GUI is refreshed here, so the start seems faster. # we make sure the GUI is refreshed here, so the start seems faster.
self.processEvents(QEventLoop.ExcludeUserInputEvents | self.processEvents(QEventLoop.ExcludeUserInputEvents |
QEventLoop.ExcludeSocketNotifiers) QEventLoop.ExcludeSocketNotifiers)
tabbed_browser = objreg.get('tabbed-browser', scope='window', window=0) win_id = 0
for cmd in self._args.command: for cmd in self._args.command:
if cmd.startswith(':'): if cmd.startswith(':'):
log.init.debug("Startup cmd {}".format(cmd)) log.init.debug("Startup cmd {}".format(cmd))
self._commandrunner.run_safely_init(0, cmd.lstrip(':')) self._commandrunner.run_safely_init(0, cmd.lstrip(':'))
elif not cmd:
log.init.debug("Empty argument")
win_id = mainwindow.create_window(True)
else: else:
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
log.init.debug("Startup URL {}".format(cmd)) log.init.debug("Startup URL {}".format(cmd))
try: try:
url = urlutils.fuzzy_url(cmd) url = urlutils.fuzzy_url(cmd)
@ -234,16 +239,19 @@ class Application(QApplication):
else: else:
tabbed_browser.tabopen(url) tabbed_browser.tabopen(url)
if tabbed_browser.count() == 0: for win_id in objreg.window_registry:
log.init.debug("Opening startpage") tabbed_browser = objreg.get('tabbed-browser', scope='window',
for urlstr in config.get('general', 'startpage'): window=win_id)
try: if tabbed_browser.count() == 0:
url = urlutils.fuzzy_url(urlstr) log.init.debug("Opening startpage")
except urlutils.FuzzyUrlError as e: for urlstr in config.get('general', 'startpage'):
message.error(0, "Error when opening startpage: " try:
"{}".format(e)) url = urlutils.fuzzy_url(urlstr)
else: except urlutils.FuzzyUrlError as e:
tabbed_browser.tabopen(url) message.error(0, "Error when opening startpage: "
"{}".format(e))
else:
tabbed_browser.tabopen(url)
def _python_hacks(self): def _python_hacks(self):
"""Get around some PyQt-oddities by evil hacks. """Get around some PyQt-oddities by evil hacks.

View File

@ -91,7 +91,8 @@ def get_argparser():
parser.add_argument('command', nargs='*', help="Commands to execute on " parser.add_argument('command', nargs='*', help="Commands to execute on "
"startup.", metavar=':command') "startup.", metavar=':command')
# URLs will actually be in command # URLs will actually be in command
parser.add_argument('url', nargs='*', help="URLs to open on startup.") parser.add_argument('url', nargs='*', help="URLs to open on startup "
"(empty as a window separator).")
return parser return parser