Пример #1
0
    def get_history(self, k):
        r = gui.defer_bg(self.langmodel.get_history, k)

        def history_ok(result):
            i = result[0]
            h = result[1]
            print 'history ok ', i, h
            status = ''
            feedback = ''
            if h:
                words = self.__makeWords(h[0])
                if len(h) > 1:
                    status = h[1]
                if len(h) > 2:
                    feedback = h[2]
                if len(h) > 3:
                    speaker = h[3]
                if words:
                    if not self.__repeat(i, words, status):
                        self.__lasti = i
                        self.__lastwords = []
                        for w in words:
                            self.__lastwords.append(w)
                        self.__laststatus = status
                        self.__input_phrase(i, words, status, feedback,
                                            speaker)

        def history_failed():
            print 'history failed'

        r.setCallback(history_ok).setErrback(history_failed)
Пример #2
0
    def __get_current(self, id):
        if self.proxy is None:
            return

        r = gui.defer_bg(self.proxy.current, id)

        yield r

        if not r.status():
            print 'browse current:notok', r.args()
            yield async .Coroutine.success()

        (current, ) = r.args()

        if current:
            (cookie, categories) = current[0]
            print 'current ok', cookie, categories
            if self.current != cookie:
                self.current = cookie
                self.add_update(upd_list)
            if self.current_categories != categories:
                self.current_categories = categories
                self.add_update(upd_list)
        else:
            self.current = None
            self.current_categories = ()
            self.add_update(upd_list)
Пример #3
0
    def __get_dinfo(self, id, path):
        if self.proxy is None:
            return

        r = gui.defer_bg(self.proxy.dinfo, id, path)

        yield r

        if not r.status():
            print 'dinfo failed', r.args()
            #picross.to_front()
            self.keyval = []
            self.add_update(upd_info)
            yield async .Coroutine.success()

        (dlist, ) = r.args()

        print 'got_dinfo', dlist, logic.is_term(dlist)
        #picross.to_front()
        self.keyval = []
        if logic.is_term(dlist):
            if logic.is_pred(dlist, 'keyval'):
                dinfo = dlist.args[0]
                if self.dinfoTarget != dinfo[0][1]:
                    self.dinfoTarget = dinfo[0][1]
                    if self.infoListener:
                        self.infoListener.targetChanged()

                if len(dinfo) > 1:
                    for k, v in dinfo[1:]:
                        print k, v
                        self.keyval.append((k, v))

            self.add_update(upd_info)
Пример #4
0
    def __get_finfo(self, id, path):
        if self.proxy is None:
            return

        r = gui.defer_bg(self.proxy.finfo, id, path)

        yield r

        if not r.status():
            print 'browse get_finfo:notok', r.args()
            self.finfo = []
            self.numFiles = len(self.finfo)
            self.finfo_for_new_category = False
            self.add_update(upd_list)
            yield async .Coroutine.success()

        (files, total) = r.args()

        resultlist = files
        if self.finfo != resultlist:
            self.finfo = resultlist
            self.numFiles = len(self.finfo)
            self.add_update(upd_list)

        if self.category_changed:
            self.category_changed = False
            self.finfo_for_new_category = True
            self.add_update(upd_list)

        print 'browse get_finfo:ok'
Пример #5
0
    def ready(self, id):
        print 'BrowseModel:ready id=', id
        r = gui.defer_bg(self.new_proxy.enumerate, id, [])
        yield r

        if not r.status():
            print 'Enumerate check failed on', id, '- browse target unchanged'
            self.__updating = False
        else:
            print 'Enumerate check suceeded on', id

            db = self.proxy
            if db:
                self.proxy = None
                gui.call_bg_sync(db.removeAllListeners)
                gui.call_bg_sync(db.shutdown)

            self.proxy = self.new_proxy
            self.setTargetId(id)
            self.path = []
            self.add_update(upd_path)
            yield self.__get_name(id)
            yield self.__get_icon()
            yield self.__get_directory_details(True)
            self.flush_updates()
            self.__updating = False
Пример #6
0
    def __get_cinfo(self, id, path, start, ncolls):
        if self.proxy is None:
            return

        r = gui.defer_bg(self.proxy.cinfo, id, path, start, ncolls)

        yield r

        if not r.status():
            print 'browse get_cinfo:notok', r.args()
            self.cinfo = []
            count = 0
            self.add_update(upd_list)
            yield async .Coroutine.success()

        (colls, total) = r.args()

        cinfo = colls
        cinfo.sort()
        self.cinfo = []
        count = 0

        if path:
            self.cinfo.append(('!control' + str(count), 'Up one level'))
            self.numCollections = self.numCollections + 1
            count = count + 1

        for c in cinfo:
            self.cinfo.append(('!collection' + str(count), c))
            count = count + 1

        self.category_changed = True
        print 'get_cinfo ok'
        yield self.__get_finfo(self.getTargetId(), self.path)
Пример #7
0
 def __get_icon(self):
     r = gui.defer_bg(self.proxy.get_icon)
     yield r
     self.icon = None
     if r.status():
         (self.icon, ) = r.args()
     self.add_update(upd_list)
Пример #8
0
 def __get_name(self, targetId):
     db = self.proxy
     r = gui.defer_bg(db.getName, targetId)
     yield r
     self.targetName = ''
     if r.status():
         (self.targetName, ) = r.args()
     self.add_update(upd_title)
Пример #9
0
    def __get_name(self, targetId):
        if self.proxy is None:
            print '__get_name: proxy is None - returning'
            return

        db = self.proxy
        r = gui.defer_bg(db.getName, targetId)
        yield r
        self.targetName = ''
        if r.status():
            (self.targetName, ) = r.args()
        self.add_update(upd_title)
        print 'get_name', self.targetName
Пример #10
0
    def __change_target(self, targetId):
        print 'browseModel.change_target', targetId

        self.__updating = True

        if targetId == '':
            if self.agent.getTargetId() == '':
                self.targetName = ''
                self.path = []
                self.cinfo = []
                self.finfo = []
                self.keyval = []
                self.numFiles = 0
                self.numCollections = 0
                self.icon = None
                self.add_update(upd_all)
                self.flush_updates()
                self.__updating = False
                yield async .Coroutine.success()

            targetId = self.agent.getTargetId()

        print 'BrowseModel: Attempt target change to', targetId, 'from', self.getTargetId(
        )

        if self.proxy is None or (targetId != self.getTargetId()):
            proxy = gui.call_bg_sync(self.__create_browse_proxy, targetId)
            r = gui.defer_bg(proxy.enumerate, targetId, [])
            yield r

            if not r.status():
                print 'Enumerate check failed on', targetId, '- browse target unchanged'
                self.__updating = False
            else:

                db = self.proxy
                if db:
                    self.proxy = None
                    gui.call_bg_sync(db.removeAllListeners)
                    gui.call_bg_sync(db.shutdown)

                self.proxy = proxy
                self.setTargetId(targetId)
                self.path = []
                yield self.__get_directory_details(True)
                self.__updating = False

        else:
            self.path = []
            yield self.__get_directory_details(True)
            self.__updating = False
Пример #11
0
    def __check_enumerate(self, id, path):
        r = gui.defer_bg(self.proxy.enumerate, id, path)

        yield r

        if not r.status():
            print 'browse check_enumerate:notok', arg
            yield async .Coroutine.success()

        (numFiles, numColl) = r.args()

        if numFiles == self.numFiles:
            print 'check_enumerate ok:'
            yield self.__get_finfo(self.getTargetId(), path)
            yield self.__get_dinfo(self.getTargetId(), path)
        else:
            print 'check_enumerate ok: number of files', numFiles, 'changed'
            self.path = []
            yield self.__get_directory_details(False)
Пример #12
0
    def __enumerate(self, id, path):
        r = gui.defer_bg(self.proxy.enumerate, id, path)

        yield r

        if not r.status():
            print 'browse enumerate:notok', r.args()
            yield async .Coroutine.success()

        (numFiles, numColl) = r.args()

        self.numFiles = numFiles
        self.numCollections = numColl

        if self.path == []:
            self.rootNumFiles = self.numFiles
            self.rootNumCollections = self.numCollections

        self.listListener.resetVScroller(1)
        self.listListener.offset = 0
Пример #13
0
    def get_history(self,k):
        r=gui.defer_bg(self.langmodel.get_history,k)
        def history_ok(result):
            i=result[0]
            h=result[1]
            status=''
            feedback=''
            if h:
                words=self.__makeWords(h[0])
                if len(h)>1:
                    status=h[1]
                if len(h)>2:
                    feedback=h[2]
                if len(h)>3:
                    speaker=h[3]
                if words:
                    self.words=words
                self.update()

        def history_failed():
            print 'history failed'
        r.setCallback(history_ok).setErrback(history_failed)
Пример #14
0
    def resolve(self, arg):
        (a, o) = logic.parse_clause(arg)

        print 'resolving virtual', arg, (a, o)

        if not self.getTargetId():
            return '[]'

        if a:
            return '[]'

        if not o:
            o = self.selected_file
        else:
            o = int(o)

        if o < 1:
            return '[]'

        print 'resolving', o
        return gui.defer_bg(self.__resolve1, self.getTargetId(), self.path, o,
                            True)