2016-10-10 5 views
0

Pharo 5의 초보자로서 세계 시계 또는/및 창에서 디지털 시계를 "12:25:05"로 표시하는 방법을 찾을 수 없습니다. Pharo에는 ClockMorph가 없습니다.Pharo에서 디지털 시계를 표시하는 방법은 무엇입니까? 그리고 Cuis?

내가 원하는 것을 얻습니다. 형태 적으로 창에

|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. 
  • 시계에 대한 : 세계 시계에 대한

    • : 그것은 위대한 사양과 창에 시계에 대한

      |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. 
      
    • :

      | 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. 
      

      모든 몸에 감사합니다 @ 피터, @ 버트, @aka.

    • 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. 
      

      을하지만 모프가이 Cuis의 시간을 보여줍니다 세계 메뉴에서 "... 새로운 모프"항목에서 "UpdatingStringMorph을"이라는!

  • 답변

    1

    카탈로그에서 Pomodoro 프로젝트를로드하여 확인할 수 있습니다. 여기에는 25 분이 경과 한 시계가 포함되어 있으므로이를 대체 할 수 있어야합니다. 또는 Squeak에서 ClockMorph를 가져옵니다. 이미지에 하나 있다고 가정합니다.

    +0

    @Stephan에게 감사드립니다. Pomodoro는 좋아 보인다. –

    0

    시계를 쉽게 만들 수 있습니다 (예 : (당신이 후광 클릭으로 주위를 드래그 할 수 있습니다), 또는 당신이 openInWindow을 사용할 수 있습니다

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

    openInWorld 왼쪽 코너 맨 위로 모프를 추가합니다.

    표준 Morphic API를 통해 맞춤 설정을 수행 할 수 있습니다 (예 : color: 변경).

    +1

    Morphic은 스레드 세이프가 아니므로 다른 프로세스에서 Morphic 코드를 실행하면 안됩니다. 스테핑은 안전합니다. UpdatingStringMorph를 시도하십시오. –

    +0

    (UpdatingStringMorph on : [시간 now print24] selector : #value) stepTime : 1000; openInWorld –

    +0

    @BertFreudenberg UpdatingStringMorph는 삐걱입니다. 하지만 제 질문은 : 스레드 안전하지 못한 위험은 무엇입니까? 모르핀 코드를 보면 깨뜨릴 수있는 것을 볼 수 없습니다. –