如何在Pharo中显示数字时钟?和Cuis?

时间:2016-10-10 08:46:46

标签: smalltalk pharo

作为Pharo 5的初学者,我无法找到如何将数字时钟显示为" 12:25:05"在世界或/和窗口。 Pharo中没有ClockMorph?

我得到了我想要的东西!太棒了:

  • 世界上的时钟:

    |morph|     
    morph := StringMorph new.    
    morph font: (LogicalFont familyName: 'Source Sans Pro' pointSize: 20).
    morph color: Color gray.
    morph openInWorld; bounds: ((World bounds corner x)-100@0 extent: 100@20).
    [ [ true ] whileTrue: [
        morph contents: Time now print24.
        1 second wait
    ] ] fork.
    
  • 用于Morphic窗口中的时钟:

    |morph myWindow|
    myWindow := StandardWindow labelled: 'CLOCK'.
    myWindow addMorph:(morph := StringMorph new) frame: (0.1@(-0.2) corner: 0.9@0.9).
    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)-140@10 extent: 130@75.0).
    [ [ true ] whileTrue: [
            morph contents: Time now print24.
            1 second wait
    ] ] fork.
    
  • 用于具有Spec:

    的窗口中的时钟
    | view labelClock layout |
    " Configure the Spec models "    
    view := DynamicComposableModel new    
        instantiateModels: #(labelClock ButtonModel);
        extent: 128@18;
        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.
    

    感谢每个人@Peter,@ Bed,@。

  • 在坎特的变形中获得一个时钟:

    |morph string|     
    morph := LayoutMorph newRow.  
    morph morphPosition:(Display width -160)@10 extent:150@33; 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.
    

    但是有一个变形名为" UpdatingStringMorph"在项目"新变形......"在世界菜单中显示Cuis的时间!

2 个答案:

答案 0 :(得分:1)

您可以从目录中加载Pomodoro项目。 它包含一个从25分钟开始计算的时钟,你应该可以替换它。或者从Squeak导入ClockMorph,假设图像中有一个。

答案 1 :(得分:0)

您可以轻松构建自己的时钟,例如

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

openInWorld会将变形添加到左上角(您可以使用光晕点击拖动它),或者您可以使用openInWindow

可以通过标准的Morphic API进行自定义(例如,更改color:等)。