私はwxpythonアプリケーションでパスワードボックスをポップアップする機能を作った。 dialogs.pyで現在のコードは、次のようになります。私はこのようになり、いくつかのメソッドを持っている私のメインプログラムでダイアログボックスを処理する最もpythonicな方法?
class WrongPassword(Exception):
pass
class CancelDialog(Exception):
pass
:
def password_dialog(self, password):
# Only ask for password if it actually exist
if password == 'False':
return True
question = 'Put in password:'
dialog = wx.PasswordEntryDialog(self, question, 'Password...')
if dialog.ShowModal() == wx.ID_OK:
if dialog.GetValue() == password:
dialog.Destroy()
return True
else:
dialog.Destroy()
__wrong_pass()
raise WrongPassword
else:
dialog.Destroy()
raise CancelDialog
例外が同じファイル内にあります:
def on_sort_songs(self, event):
"""Renumbering the database and sort in artist and title order"""
# Check for password first
try:
dialogs.password_dialog(self, opts.generic['password'])
except dialogs.CancelDialog:
return
except dialogs.WrongPassword:
return
# Sort database and repopulate GUI
self.jbox.sort_songs()
self.populate_songlist()
問題なく動作します。しかし、それはパスワードダイアログを処理する非常に良いとpythonicのようには思われません。またはそれは?
あなたは正しいと思います... –