简体   繁体   中英

Trying to find the Progressbar Morph when sending the message displayProgress

I have contribute a progress bar in PharoLauncher so that the user get information of the progress of the download of an image with this code

PharoLauncher>>displayProgress:during: (in category 'template action') -----

displayProgress: label during: workBlock
    | nextUpdateTime |
    nextUpdateTime := 0.
    ^UIManager default displayProgress: label 
        from: 0.0 to: 1.0 during:[:bar|
            [workBlock value] on: HTTPProgress do:[:ex|
                (ex total == nil or: [ex amount == nil]) ifFalse:[
                    (nextUpdateTime < Time millisecondClockValue 
                        or:[ex total = ex amount]) ifTrue:[
                            bar current: ex amount asFloat / ex total asFloat.
                            nextUpdateTime := Time millisecondClockValue + 100.
                    ].
                ].
                ex resume.
            ]
        ]

So the message is UIManager default displayProgress: from: to: during: .Now this works ok but I want to position the morph in the middle to make it more comfortable for the user to see and it scale it considerably so its much easier to do. In order to do that I need to find the Morph that acts as a container for the progress bar and scale up in its entirety.

The problem is that I hit a dead end when trying to browser the hierarchy of this messaged it sends me to

displayProgress: titleString from: minVal to: maxVal during: workBlock
    "SystemProgressMorph show: titleString from: minVal to:  during: "

    ^ workBlock asJob
            title: titleString;
            min: minVal;
            max: maxVal;
            run. 

The problem is that when I go to the Job class , as I would expect, a Morph is nowhere to be found. So how I find the Morph and how will be able to position and scale it containing all its submorphs ?

With the help of Thierry Goubier in the Pharo-dev mailing list and tinchodias at #Pharo in freenode I have found a solution

There are three announcers created , those three announcements are tied to classes JobStart , JobEnd, JobChange classes and trigger class methods startJb: endJob: and updateJob: of SystemProgressMorph. There can be only one instance of SystemProgressMorph and to capture that instance we use the uniqueInstance class method.

So to re-position and re-size the progress bar I have used the following cascade of messages

(SystemProgressMorph uniqueInstance) minWidth: 600; 
                                     minHeight: 50; 
                                     layoutInset: 30@20; 
                                     position: 150@200.

layoutInset adds some more space for the progress bar inside the SystemProgressBarMorph. It would be better to reset those values so we wont affect the progress bars that used by other pharo apps but since the PharoLauncher is contained in an independent image thats not necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM