Forum Archive

keychain.master_password dialog and ui.View subclass issue

userista

If I have a call to keychain.get_password in a delegate and have a master_password set it will lock up the ui even if using a @ui.in_background function decorator. What am I doing wrong here?

(Don't mind the messed up indentation - posting on mobile...)


    import keychain, ui, console

    class Test (ui.View):
      def __init__(self):
        tv = ui.TableView()
        tv.frame = self.bounds
        tv.flex = 'WH'
        ds = ui.ListDataSource(['foo','bar','baz'])
        ds.action = self.item_selected
        tv.data_source = ds
        tv.delegate = ds
        self.tableview = tv
        self.add_subview(self.tableview)

      @ui.in_background
      def item_selected(self,sender):
        #this will lock up bec of the keychain.master_password alert 
        #(make sure that u have an entry in the keychain 'name'/'user'/'foobar')
        print keychain.get_password('name','user')
        #if you comment out the line above, you can see that the @ui.in_background is working 
        #bec the next line does not lock up the ui
        console.alert('test')

    test = Test()
    test.present('sheet')

This only happens when subclassing ui.View. When making a "standalone" view there's no lock up:

import keychain, ui
@ui.in_background
def cell_tapped(sender):
    print keychain.get_password('name','user')

tv = ui.TableView()
tv.flex = 'WH'
ds = ui.ListDataSource({'title':x,'accessory_type':'detail_button'} for x in ['foo','bar','baz'])
ds.action = cell_tapped
tv.data_source = tv.delegate = ds
tv.present('sheet')

userista

So it seems like it's either an issue with ui.View or the keychain.master_password dialog. (It only happens when subclassing ui.View).
@omz is this a bug?

# to reproduce:
# set a master_password;
# set a service in the keychain: 
# name=foo, username=bar, password=whatever 
# (so that the master_password dialog will be called)
# Issue: The ui locks up

import keychain, ui

class GetPassword (ui.View):
    #this doesn't make a difference
    #@ui.in_background
    def get_password(self,name,user):
        return keychain.get_password(name,user)

gp  = GetPassword()

print gp.get_password('foo','bar')


omz

Looks like a bug. Thanks, I'll look into it.

userista

Thanks so much!

[deleted]

@omz I have a similar problem I think. This works fine the first time it's run. However the second time through... the second script hangs the ui when it's run.

Test.py

import ui, console, editor

class Test (ui.View):
    def __init__(self):
        tv = ui.TableView()
        tv.frame = self.bounds
        tv.flex = 'WH'
        ds = ui.ListDataSource(['foo','bar','baz'])
        ds.action = self.item_selected
        tv.data_source = ds
        tv.delegate = ds
        self.tableview = tv
        self.add_subview(self.tableview)

    @ui.in_background
    def item_selected(self,sender):
        #console.alert('Test')
        self.close()
        editor.open_file('Test2')

Test().present('popover')

Test2.py

import console
console.alert('Test2')