def on_response(dialog, responseId, callback=callback): response = False if responseId == gtk.RESPONSE_YES: response = True callback(response) alwaysPrompt = dialog.checkbox.get_active() if alwaysPrompt == False: setattr(GlobalSettings.get(), prefName, alwaysPrompt) GlobalSettings.get().save()
def __init__(self): self.host = Globals.FTP_HOST self.port = Globals.FTP_PORT self.user = Globals.FTP_USER self.pw = Globals.FTP_PASSWORD self.submitThread = None buttons = (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dia = gtk.Dialog("Submit Error", None, 0, buttons) #username field usernameLabel = gtk.Label("Username") self.nameEntry = gtk.Entry() self.nameEntry.set_max_length(50) try: self.nameEntry.set_text(GlobalSettings.get().username) except: pass #comment field self.textbuffer = gtk.TextBuffer(table=None) self.textbuffer.set_text("Please describe the error or issue here.") textview = gtk.TextView(self.textbuffer) buffer = textview.get_buffer() textview.set_editable(True) textview.set_cursor_visible(True) textview.set_wrap_mode(gtk.WRAP_WORD) textview.show() # create a new scrolled window. scrolled_window = gtk.ScrolledWindow() scrolled_window.set_border_width(10) scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) #scrolled_window.set_size_request(300, 350) scrolled_window.add_with_viewport(textview) scrolled_window.show() #put them in a nice little table table = gtk.Table(4, 2, True) table.attach(usernameLabel, 0, 1, 0, 1) table.attach(self.nameEntry, 1, 2, 0, 1) table.attach(scrolled_window, 0, 2, 1, 4) dia.vbox.pack_start(table, True, True, 0) self.nameEntry.set_text(GlobalSettings.get().username) dia.show_all() #connect the handler: dia.connect("response", self.on_response) self.dia = dia
def __init__(self): self.host = Globals.FTP_HOST self.port = Globals.FTP_PORT self.user = Globals.FTP_USER self.pw = Globals.FTP_PASSWORD self.submitThread = None buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dia = gtk.Dialog("Submit Error", None, 0, buttons) #username field usernameLabel = gtk.Label("Username") self.nameEntry = gtk.Entry() self.nameEntry.set_max_length(50) try: self.nameEntry.set_text(GlobalSettings.get().username) except: pass #comment field self.textbuffer = gtk.TextBuffer(table=None) self.textbuffer.set_text("Please describe the error or issue here.") textview = gtk.TextView(self.textbuffer) buffer=textview.get_buffer() textview.set_editable(True) textview.set_cursor_visible(True) textview.set_wrap_mode(gtk.WRAP_WORD) textview.show() # create a new scrolled window. scrolled_window = gtk.ScrolledWindow() scrolled_window.set_border_width(10) scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) #scrolled_window.set_size_request(300, 350) scrolled_window.add_with_viewport(textview) scrolled_window.show() #put them in a nice little table table = gtk.Table(4, 2, True) table.attach(usernameLabel, 0, 1, 0, 1) table.attach(self.nameEntry, 1, 2, 0, 1) table.attach(scrolled_window, 0, 2, 1, 4) dia.vbox.pack_start(table, True, True, 0) self.nameEntry.set_text(GlobalSettings.get().username) dia.show_all() #connect the handler: dia.connect("response", self.on_response) self.dia = dia
def on_login_failure(self, err=None, text=None): """Called anytime login fails for any reason. @param err: the failure @type err: Failure, Exception, or str @param text: error message from the bank @type text: str""" if not self.startupDeferred: return log_ex(err, "Login failed", [BadLoginPasswordError]) self.loginInProgress = False if not self.isLoggedIn: #dont automatically log in if we failed last time: GlobalSettings.get().save_password = False GlobalSettings.get().save() self._trigger_event("login_failure", err, text)
def show_preference_prompt(self, text, title, callback, prefName, defaultResponse=True): """A shortcut for dialogs where we say 'Are you sure you want to X?'""" #return immediately if there is a saved setting alwaysPrompt = getattr(GlobalSettings.get(), prefName, True) if alwaysPrompt == False: callback(defaultResponse) return #otherwise, define the callback for when the user is finished with the prompt def on_response(dialog, responseId, callback=callback): response = False if responseId == gtk.RESPONSE_YES: response = True callback(response) alwaysPrompt = dialog.checkbox.get_active() if alwaysPrompt == False: setattr(GlobalSettings.get(), prefName, alwaysPrompt) GlobalSettings.get().save() #then make the dialog dia = self.show_msgbox( text, title, on_response, (gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO)) dia.checkbox = gtk.CheckButton("Always ask?") dia.checkbox.set_active(True) dia.checkbox.show() dia.vbox.pack_end(dia.checkbox) dia.set_modal(True)
def _load_settings(self): """Load global and core settings files. Deals with old format for storing settings""" #load a global config that said whether to store the last user that logged in (and his password) self.globalSettings = GlobalSettings.load() #always save, so the user can more easily edit the file for starting up from the console self.globalSettings.save() #does a settings file already exist? settingsFile = os.path.join(Globals.USER_DATA_DIR, CoreSettings.CoreSettings.defaultFile) if not Files.file_exists(settingsFile): #if not, make the folder if not Files.file_exists(Globals.USER_DATA_DIR): os.makedirs(Globals.USER_DATA_DIR) #and check that this isnt an old installation (we used to store settings on a #per username basis, which turned out to be a stupid idea). If that data exists, #copy it to the new location. if len(self.globalSettings.username) > 0: oldSettingsFilePath = os.path.join( Globals.USER_DATA_DIR, self.globalSettings.username, CoreSettings.CoreSettings.defaultFile) if os.path.exists(oldSettingsFilePath): oldFolder = os.path.join(Globals.USER_DATA_DIR, self.globalSettings.username) newFolder = Globals.USER_DATA_DIR Files.recursive_copy_folder(oldFolder, newFolder) #load the core settings: CoreSettings.start() self.coreSettings = CoreSettings.get() self.coreSettings.load(settingsFile) self.coreSettings.fileName = settingsFile
def _load_settings(self): """Load global and core settings files. Deals with old format for storing settings""" #load a global config that said whether to store the last user that logged in (and his password) self.globalSettings = GlobalSettings.load() #always save, so the user can more easily edit the file for starting up from the console self.globalSettings.save() #does a settings file already exist? settingsFile = os.path.join(Globals.USER_DATA_DIR, CoreSettings.CoreSettings.defaultFile) if not Files.file_exists(settingsFile): #if not, make the folder if not Files.file_exists(Globals.USER_DATA_DIR): os.makedirs(Globals.USER_DATA_DIR) #and check that this isnt an old installation (we used to store settings on a #per username basis, which turned out to be a stupid idea). If that data exists, #copy it to the new location. if len(self.globalSettings.username) > 0: oldSettingsFilePath = os.path.join(Globals.USER_DATA_DIR, self.globalSettings.username, CoreSettings.CoreSettings.defaultFile) if os.path.exists(oldSettingsFilePath): oldFolder = os.path.join(Globals.USER_DATA_DIR, self.globalSettings.username) newFolder = Globals.USER_DATA_DIR Files.recursive_copy_folder(oldFolder, newFolder) #load the core settings: CoreSettings.start() self.coreSettings = CoreSettings.get() self.coreSettings.load(settingsFile) self.coreSettings.fileName = settingsFile
def show_preference_prompt(self, text, title, callback, prefName, defaultResponse=True): """A shortcut for dialogs where we say 'Are you sure you want to X?'""" #return immediately if there is a saved setting alwaysPrompt = getattr(GlobalSettings.get(), prefName, True) if alwaysPrompt == False: callback(defaultResponse) return #otherwise, define the callback for when the user is finished with the prompt def on_response(dialog, responseId, callback=callback): response = False if responseId == gtk.RESPONSE_YES: response = True callback(response) alwaysPrompt = dialog.checkbox.get_active() if alwaysPrompt == False: setattr(GlobalSettings.get(), prefName, alwaysPrompt) GlobalSettings.get().save() #then make the dialog dia = self.show_msgbox(text, title, on_response, (gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO)) dia.checkbox = gtk.CheckButton("Always ask?") dia.checkbox.set_active(True) dia.checkbox.show() dia.vbox.pack_end(dia.checkbox) dia.set_modal(True)
def start(self): self.dia.show_all() self.nameEntry.grab_focus() if not self.started: self.started = True #just log in right away if we're saving the password and username anyway: if GlobalSettings.get().save_password: self.on_response(self.dia, gtk.RESPONSE_OK)
def on_login_success(self, bankApp, loginMessage=None): log_msg("Bank login succeeded!\nBank Welcome Message: %s" % (loginMessage), 2) #save all this information to the settings files if necessary: settings = GlobalSettings.get() settings.save_password = self.savePass if not settings.save_password: self.username = "" self.password = "" settings.username = self.username settings.password = self.password settings.save()
def on_login_success(self, bankApp, loginMessage=None): log_msg( "Bank login succeeded!\nBank Welcome Message: %s" % (loginMessage), 2) #save all this information to the settings files if necessary: settings = GlobalSettings.get() settings.save_password = self.savePass if not settings.save_password: self.username = "" self.password = "" settings.username = self.username settings.password = self.password settings.save()
def on_login_success(self, bankApp, text): #show the server message if there was any: if text: GUIController.get().show_msgbox(text, "Server Notice") #save all this information to the settings files if necessary: settings = GlobalSettings.get() settings.save_password = self.savePassCheck.get_active() if not settings.save_password: self.username = "" self.password = "" settings.username = self.username settings.password = self.password settings.save() self.succeeded = True self.dia.destroy()
def show_settings_cb(self, widget=None): #TODO: global and core settings creating and manipulating fake Application ojects, and settings are currently generally stupid. Change to a global settings obj apps = {} #create a fake Application wrapper for global settings: globalSettingsObj = GlobalSettings.get() apps[globalSettingsObj.settingsName] = globalSettingsObj.app coreSettingsObj = CoreSettings.get() apps[coreSettingsObj.settingsName] = coreSettingsObj.app realApplications = [self.torApp, self.btApp] # #currently no ff settings... really should use introspection, but everything is about to change # if System.IS_WINDOWS: # realApplications.append(self.ffApp) for app in realApplications: apps[app.get_settings_name()] = app self.show_settings(apps)
def do_verification_prompt(self, bankApp): #load a global config that said whether to store the last user that logged in (and his password) settings = GlobalSettings.load() #just directly login: self.username = str(settings.username) self.password = str(settings.password) self.savePass = settings.save_password while not self.username or not self.password: self.username = str(raw_input('Enter your username: '******'Enter your password: '******'Should save password? (yes/no) ')) self.savePass = shouldSave.lower() in ("yes", "y") #just directly login: Bank.get().login(self.username, self.password)
def do_verification_prompt(self, callback): #global config stores the last user that logged in (and his password) settings = GlobalSettings.get() def make_textpad(): editWindow = self.stdscr.derwin(1, curses.COLS - startX, startY + 1, startX) editWindow.clear() textpad = curses.textpad.Textbox(editWindow) return textpad, editWindow #just directly login: self.username = str(settings.username) self.password = str(settings.password) self.savePass = settings.save_password startY = 1 startX = 0 while not self.username or not self.password: self.stdscr.addstr( startY, startX, 'Enter your username- use emacs bindings (ctrl-g to enter).') curses.curs_set(1) self.stdscr.refresh() textpad, win = make_textpad() #TODO: this should be in a thread self.username = textpad.edit().rstrip() win.clear() self.stdscr.addstr( startY, startX, 'Enter your password- use emacs bindings (ctrl-g to enter).') textpad, win = make_textpad() win.clear() self.stdscr.refresh() self.password = textpad.edit().rstrip() #check that the username is possibly valid: if not Globals.USERNAME_REGEX.match(self.username): log_msg( "Usernames can only contain A-Z, a-z, 0-9, -, _, and spaces in the middle", 0) self.username = None curses.curs_set(0) callback(self.username, self.password)
def do_verification_prompt(self, callback): #global config stores the last user that logged in (and his password) settings = GlobalSettings.get() def make_textpad(): editWindow = self.stdscr.derwin(1, curses.COLS-startX, startY + 1, startX) editWindow.clear() textpad = curses.textpad.Textbox(editWindow) return textpad, editWindow #just directly login: self.username = str(settings.username) self.password = str(settings.password) self.savePass = settings.save_password startY = 1 startX = 0 while not self.username or not self.password: self.stdscr.addstr(startY, startX, 'Enter your username- use emacs bindings (ctrl-g to enter).') curses.curs_set(1) self.stdscr.refresh() textpad, win = make_textpad() #TODO: this should be in a thread self.username = textpad.edit().rstrip() win.clear() self.stdscr.addstr(startY, startX, 'Enter your password- use emacs bindings (ctrl-g to enter).') textpad, win = make_textpad() win.clear() self.stdscr.refresh() self.password = textpad.edit().rstrip() #check that the username is possibly valid: if not Globals.USERNAME_REGEX.match(self.username): log_msg("Usernames can only contain A-Z, a-z, 0-9, -, _, and spaces in the middle", 0) self.username = None curses.curs_set(0) callback(self.username, self.password)
def __init__(self, bankApp): ListenerMixin.ListenerMixin.__init__(self) self.username = None self.password = None self._start_listening_for_event("login_success", bankApp, self.on_login_success) self._start_listening_for_event("login_failure", bankApp, self.on_login_failure) dia = gtk.Dialog("Login", None, 0, None) dia.connect("destroy", self.destroy_cb) # dia.connect("expose_event", self.expose_cb) self.started = False self.succeeded = False self.loginButton = dia.add_button("Login", gtk.RESPONSE_OK) self.quitButton = dia.add_button("Quit", gtk.RESPONSE_CANCEL) #username field self.usernameLabel = gtk.Label("Username") self.nameEntry = gtk.Entry() self.nameEntry.set_max_length(50) self.nameEntry.connect("activate", self.enter_callback) #password field self.pwLabel = gtk.Label("Password") self.pwEntry = gtk.Entry() self.pwEntry.set_max_length(50) #so people cant see our password: self.pwEntry.set_visibility(False) self.pwEntry.connect("activate", self.enter_callback) resetPasswordLink = GTKUtils.make_html_link( "Forgot your password?", "%s/accounts/resetPassword/" % (ProgramState.Conf.BASE_HTTP)) makeAccountLink = GTKUtils.make_html_link( "Need an account?", "%s/accounts/register/" % (ProgramState.Conf.BASE_HTTP)) #put them in a nice little table table = gtk.Table(4, 2, True) table.attach(self.usernameLabel, 0, 1, 0, 1) table.attach(self.nameEntry, 1, 2, 0, 1) table.attach(makeAccountLink, 1, 2, 1, 2) table.attach(self.pwLabel, 0, 1, 2, 3) table.attach(self.pwEntry, 1, 2, 2, 3) table.attach(resetPasswordLink, 1, 2, 3, 4) self.savePassCheck = gtk.CheckButton("Remember Username/Password") #A text entry telling the user what to do: self.label = WrapLabel.WrapLabel() self.label.set_markup( "<span weight='bold'>Use your account name and password from the BitBlinder website!</span>" ) align = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=1.0, yscale=0.0) align.add(self.label) align.set_padding(10, 10, 5, 5) dia.vbox.pack_start(GTKUtils.add_frame(align), True, True, 10) dia.vbox.pack_start(table, True, True, 0) dia.vbox.pack_start(self.savePassCheck, True, True, 10) #load a global config that said whether to store the last user that logged in (and his password) settings = GlobalSettings.load() self.nameEntry.set_text(settings.username) self.pwEntry.set_text(settings.password) self.savePassCheck.set_active(settings.save_password) #connect the handler: dia.connect("response", self.on_response) self.dia = dia
def __init__(self, bankApp): ListenerMixin.ListenerMixin.__init__(self) self.username = None self.password = None self._start_listening_for_event("login_success", bankApp, self.on_login_success) self._start_listening_for_event("login_failure", bankApp, self.on_login_failure) dia = gtk.Dialog("Login", None, 0, None) dia.connect("destroy", self.destroy_cb) # dia.connect("expose_event", self.expose_cb) self.started = False self.succeeded = False self.loginButton = dia.add_button("Login", gtk.RESPONSE_OK) self.quitButton = dia.add_button("Quit", gtk.RESPONSE_CANCEL) #username field self.usernameLabel = gtk.Label("Username") self.nameEntry = gtk.Entry() self.nameEntry.set_max_length(50) self.nameEntry.connect("activate", self.enter_callback) #password field self.pwLabel = gtk.Label("Password") self.pwEntry = gtk.Entry() self.pwEntry.set_max_length(50) #so people cant see our password: self.pwEntry.set_visibility(False) self.pwEntry.connect("activate", self.enter_callback) resetPasswordLink = GTKUtils.make_html_link("Forgot your password?", "%s/accounts/resetPassword/" % (ProgramState.Conf.BASE_HTTP)) makeAccountLink = GTKUtils.make_html_link("Need an account?", "%s/accounts/register/" % (ProgramState.Conf.BASE_HTTP)) #put them in a nice little table table = gtk.Table(4, 2, True) table.attach(self.usernameLabel, 0, 1, 0, 1) table.attach(self.nameEntry, 1, 2, 0, 1) table.attach(makeAccountLink, 1, 2, 1, 2) table.attach(self.pwLabel, 0, 1, 2, 3) table.attach(self.pwEntry, 1, 2, 2, 3) table.attach(resetPasswordLink, 1, 2, 3, 4) self.savePassCheck = gtk.CheckButton("Remember Username/Password") #A text entry telling the user what to do: self.label = WrapLabel.WrapLabel() self.label.set_markup("<span weight='bold'>Use your account name and password from the BitBlinder website!</span>") align = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=1.0, yscale=0.0) align.add(self.label) align.set_padding(10, 10, 5, 5) dia.vbox.pack_start(GTKUtils.add_frame(align), True, True, 10) dia.vbox.pack_start(table, True, True, 0) dia.vbox.pack_start(self.savePassCheck, True, True, 10) #load a global config that said whether to store the last user that logged in (and his password) settings = GlobalSettings.load() self.nameEntry.set_text(settings.username) self.pwEntry.set_text(settings.password) self.savePassCheck.set_active(settings.save_password) #connect the handler: dia.connect("response", self.on_response) self.dia = dia