Hi!
I’m pretty new to programming and I’m working on an addon.
My addon processes the user input from several “Edit”-s (xbmcgui.ControlEdit), and it has to make sure, none of the “Edit”-s are empty, before calling a function.
I’ve tried it two ways, both of them were working, but which is the right way to implement it?
The addon should notify the user and terminate the execution without closing the window, so the user can try again.
First I’ve tried it without catching the Exception:
PHP Code:
import xbmcgui
dialog
= xbmcgui.Dialog()
class
EmptyEditException(Exception):
def __init__(self):
msg = "Some edits are empty."
xbmc.log(msg)
dialog.notification("Alert", msg)
def check_if_empty(s):
if s == "":
raise EmptyEditException
edit0
= xbmcgui.ControlEdit (100, 250, 125, 75, 'Status')
def some_function():
input = edit0.getText()
check_if_empty(input)
some_other_func(input)
So the execution will be terminated, because of the exception.
The other way:
PHP Code:
import xbmcgui
dialog
= xbmcgui.Dialog()
class
EmptyEditException(Exception):
def __init__(self):
msg = "Some edits are empty."
xbmc.log(msg)
def check_if_empty(s):
if s == "":
raise EmptyEditException
edit0
= xbmcgui.ControlEdit (100, 250, 125, 75, 'Status')
def some_function():
input = edit0.getText()
check_if_empty(input)
some_other_func(input)
def button_handler():
try:
some_function()
except EmptyEditException:
dialog.notification("Alert", "Fill all the edits!")
How would you implement it?
Thanks!