Nicer error messages for focus_tab
This commit is contained in:
parent
fce2085ea9
commit
214cda91bd
@ -330,25 +330,25 @@ class TabbedBrowser(TabWidget):
|
|||||||
self.paste(sel, True)
|
self.paste(sel, True)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs')
|
@cmdutils.register(instance='mainwindow.tabs')
|
||||||
def focus_tab(self, idx=None, count=None):
|
def focus_tab(self, index=None, count=None):
|
||||||
"""Select the tab given as argument or in count.
|
"""Select the tab given as argument or in count.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
idx: The tab index to focus, starting with 1.
|
index: The tab index to focus, starting with 1.
|
||||||
"""
|
"""
|
||||||
if ((idx is None and count is None) or
|
if ((index is None and count is None) or
|
||||||
(idx is not None and count is not None)):
|
(index is not None and count is not None)):
|
||||||
message.error("Either argument or count must be given!")
|
message.error("Either argument or count must be given!")
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
i = int(idx) if idx is not None else count
|
idx = int(index) if index is not None else count
|
||||||
except ValueError:
|
except ValueError:
|
||||||
message.error("Invalid argument: {}".format(idx))
|
message.error("Argument ({}) needs to be a number!".format(index))
|
||||||
return
|
return
|
||||||
if 1 <= i <= self.count():
|
if 1 <= idx <= self.count():
|
||||||
self.setCurrentIndex(i - 1)
|
self.setCurrentIndex(idx - 1)
|
||||||
else:
|
else:
|
||||||
message.error("Index out of bounds!")
|
message.error("There's no tab with index {}!".format(idx))
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
|
Loading…
Reference in New Issue
Block a user