Allow commands/URLs to be passed as arguments.

This commit is contained in:
Florian Bruhin 2014-01-30 20:41:54 +01:00
parent c6b21b27b5
commit c3ce167926
3 changed files with 29 additions and 2 deletions

View File

@ -83,6 +83,29 @@ class QuteBrowser(QApplication):
self.mainwindow.show()
self._python_hacks()
self._process_init_args()
def _process_init_args(self):
"""Process initial positional args.
URLs to open have no prefix, commands to execute begin with a colon.
"""
opened_urls = False
for e in self.args.command:
if e.startswith(':'):
logging.debug('Startup cmd {}'.format(e))
self.commandparser.run(e.lstrip(':'))
else:
logging.debug('Startup url {}'.format(e))
opened_urls = True
self.mainwindow.tabs.tabopen(e)
if not opened_urls:
logging.debug('Opening startpage')
for url in config.config.get('general', 'startpage',
fallback='http://ddg.gg/').split(','):
self.mainwindow.tabs.tabopen(url)
def _tmp_exception_hook(self, exctype, value, traceback):
"""Handle exceptions while initializing by simply exiting.
@ -132,6 +155,10 @@ class QuteBrowser(QApplication):
help='Set loglevel', default='info')
parser.add_argument('-c', '--confdir', help='Set config directory '
'(empty for no config storage)')
parser.add_argument('command', nargs='*', help='Commands to execute '
'on startup.', metavar=':command')
# URLs will actually be in command
parser.add_argument('url', nargs='*', help='URLs to open on startup.')
self.args = parser.parse_args()
def _initlog(self):

View File

@ -20,6 +20,7 @@ default_config = """
space_scroll = 200
ignorecase = true
wrapsearch = true
startpage = http://www.duckduckgo.com/
[keybind]
o = open

View File

@ -8,7 +8,7 @@ containing BrowserTabs).
import logging
from PyQt5.QtWidgets import QShortcut, QApplication
from PyQt5.QtCore import QUrl, pyqtSignal, Qt, QEvent
from PyQt5.QtCore import pyqtSignal, Qt, QEvent
from PyQt5.QtGui import QClipboard
from PyQt5.QtPrintSupport import QPrintPreviewDialog
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
@ -39,7 +39,6 @@ class TabbedBrowser(TabWidget):
def __init__(self, parent):
super().__init__(parent)
self.currentChanged.connect(self._currentChanged_handler)
self.tabopen(QUrl("http://ddg.gg/"))
space = QShortcut(self)
space.setKey(Qt.Key_Space)
space.setContext(Qt.WidgetWithChildrenShortcut)