Sha256: b709e69a35b4b0df5d82b355eec0dcb7cac130fd3d466d4bfc29fca78ed05a33

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

# encoding: utf-8
require 'Context/Context'
require 'Context/Bridge'
require 'jldrill/model/Config'
require 'jldrill/contexts/FileProgressContext'

module JLDrill

    # Loads a file displaying a progress bar as it is loading.
	class LoadQuizFromEdictContext < FileProgressContext
		
		def initialize(viewBridge)
			super(viewBridge)
            @quiz = nil
            @edict = nil
		end

        def getFilename
            return "data from #{@edict.shortFilename}"
        end

        def readFile
            @quiz.reset
            size = @edict.length
            pos = 0
            @mainView.idle_add do
                limit = pos + @quiz.stepSize
                if limit > size then limit = size end
                while (pos < limit)
                    vocab = @edict.vocab(pos)
                    if !vocab.nil?
                        @quiz.contents.add(@edict.vocab(pos), 0)
                    end
                    pos += 1
                    @mainView.update(pos.to_f / size.to_f)
                end
                if pos >= size
                    exitLoadQuizFromEdictContext
                end
                pos >= size
            end
        end

        def isValid?(parent)
            return !parent.nil? && !@quiz.nil? && !@edict.nil?
        end

        def startLongEvent()
            @parent.startLongEvent()
        end

        def stopLongEvent()
            @parent.stopLongEvent()
        end

        def enter(parent, quiz, edict)
            @quiz = quiz
            @edict = edict
            super(parent)
        end

        def exitLoadQuizFromEdictContext
            self.exit
        end

        def exit
            @quiz.name = @edict.shortFilename
            super
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jldrill-0.6.0.1 lib/jldrill/contexts/LoadQuizFromEdictContext.rb