2016-10-10 1 views
0

En tant que débutant dans Pharo 5, je ne peux pas trouver comment afficher une horloge numérique comme "12:25:05" dans le monde et/ou une fenêtre. Il n'y a pas ClockMorph dans Pharo?Comment afficher une horloge numérique dans Pharo? et Cuis?

Je reçois ce que je veux! Il est grand:

  • pour une horloge dans le monde:

    |morph|  
    morph := StringMorph new.  
    morph font: (LogicalFont familyName: 'Source Sans Pro' pointSize: 20). 
    morph color: Color gray. 
    morph openInWorld; bounds: ((World bounds corner x)[email protected] extent: [email protected]). 
    [ [ true ] whileTrue: [ 
        morph contents: Time now print24. 
        1 second wait 
    ] ] fork. 
    
  • pour une horloge dans une fenêtre avec morphique:

    |morph myWindow| 
    myWindow := StandardWindow labelled: 'CLOCK'. 
    myWindow addMorph:(morph := StringMorph new) frame: ([email protected](-0.2) corner: [email protected]). 
    myWindow beUnresizeable ; removeCloseBox ; removeCollapseBox ; 
    removeExpandBox ; removeMenuBox. 
    "meta-click to activate the ""morphic halo"" and close window" 
    morph font: (LogicalFont familyName: 'Source Sans Pro' pointSize: 20). 
    morph color: Color white. 
    myWindow openInWorld; bounds: ((World bounds corner x)[email protected] extent: [email protected]). 
    [ [ true ] whileTrue: [ 
         morph contents: Time now print24. 
         1 second wait 
    ] ] fork. 
    
  • pour une horloge dans une fenêtre avec Spec:

    | view labelClock layout | 
    " Configure the Spec models "  
    view := DynamicComposableModel new  
        instantiateModels: #(labelClock ButtonModel); 
        extent: [email protected]; 
        title: 'CLOCK' 
        yourself. 
    " Configure the Spec layout " 
    layout := SpecLayout composed 
        newColumn: [ : r | r add: #labelClock]; 
        yourself. 
    " Set up the widgets " 
    view labelClock font: (LogicalFont familyName: 'Source Sans Pro' pointSize: 20). 
        [ [ true ] whileTrue: [ 
         view labelClock label: Time now print24. 
         1 second wait 
    ] ] fork. 
    " Open the Window " 
    (view openWithSpecLayout: layout) 
        centered; 
        modalRelativeTo: World. 
    

    Merci à tout le monde @Peter, @Bert, @aka.

  • pour une horloge dans un Morph Cuis:

    |morph string|  
    morph := LayoutMorph newRow. 
    morph morphPosition:(Display width -160)@10 extent:[email protected]; color:Color skyBlue; padding:#center. 
    string := StringMorph new. 
    string font: (AbstractFont familyName: 'DejaVu' pointSize: 22). 
    [ [ true ] whileTrue: [ 
        string contents: Time now print24. 
        (Delay forSeconds:1) wait 
    ] ] fork. 
    morph addMorph: string. 
    morph openInWorld. 
    

    Mais il y a un Morph appelé "UpdatingStringMorph" dans la rubrique "Nouveau Morph ..." dans le menu mondial qui affiche l'heure à Cuis!

Répondre

1

Vous pouvez vous renseigner en chargeant le projet Pomodoro du catalogue. Qui contient une horloge qui compte depuis 25 minutes, et vous devriez pouvoir le remplacer. Ou importez un ClockMorph à partir de Squeak, en supposant qu'il y en ait un dans l'image.

+0

Merci beaucoup @Stephan. Pomodoro a l'air bien. –

0

Vous pouvez facilement créer votre propre horloge, par ex.

morph := StringMorph new. 
morph openInWorld. 
[ [ true ] whileTrue: [ 
     morph contents: Time now print24. 
     1 second wait 
] ] fork. 

openInWorld ajoutera le morphing à l'angle supérieur gauche (vous pouvez le faire glisser autour avec un clic halo), Vous pouvez également utiliser openInWindow.

La personnalisation peut être effectuée via l'API Morphic standard (par exemple en changeant color: etc.).

+1

Morphic n'est pas threadsafe, vous ne devriez pas exécuter le code Morphic d'un processus différent. Le pas est sûr. Essayez UpdatingStringMorph. –

+0

(UpdatingStringMorph activé: [Time now print24] selector: #value) stepTime: 1000; openInWorld –

+0

@BertFreudenberg UpdatingStringMorph est un grincement seulement. Mais ma question est: quel est le danger de fil imprudent ici? En regardant le code morphique, je ne vois rien qui pourrait casser. –