⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statusgui.tcl

📁 SMC takes a state machine stored in a .sm file and generates a State pattern in twelve programming l
💻 TCL
📖 第 1 页 / 共 2 页
字号:
            # The coordinates are in relation to the task row.            # But tk_popup uses screen coordinates. Convert             # So add the row's X1 and Y1 to the coordinates.            $widget(TaskMenu) post \                    [expr [winfo rootx $window] + $x] \                    [expr [winfo rooty $window] + $y];        }        return -code ok;    }    # DisplayTask --    #    #   Update a task's display. If the task is new, then    #   put the entire task on the canvas. If just one part    #   of the task is being updated, then update just that    #   part.    #    # Arguments:    #   name         The task's name.    #   updateType   new, state, time, moveup or remove. If new,    #                then put the task on the display. If status,    #                then update the status field. If time, then    #                update the complete slider and time left    #                fields. If moveup, then move the row up one.    #                If remove, then remove the task's display.    #    # Results:    #   None.    private method DisplayTask {name updateType} {        # Is this a known task?        if {[string length [array names _taskTable $name]] != 0} {            switch -exact -- $updateType {                new {                    # Figure out where the task goes on the                    # canvas. Each row is 15 pixels high and                    # there are 4 pixels between rows. First,                    # figure out how many rows are displayed.                    # The rows upper Y coordinate is 19n + the                    # initial offset from the canvas edge. The                    # lower Y coordinate is the upper Y coordinate                    # plus the row height. The X coordinates are                    # fixed. Rows are number starting at 0.                    array set TaskInfo $_taskTable($name);                    set TaskInfo(Y1) \                            [expr [expr $TaskInfo(row) * \                                        $_rowPaddedHeight] + \                                  $_initialYOffset];                    set TaskInfo(Y2) [expr $TaskInfo(Y1) + $_rowHeight];                    # Put the updated task info back into the                    # task table.                    set _taskTable($name) [array get TaskInfo];                    # Now display the entire row.                    DisplayTaskInfo $name [list name state priority time percentComplete];                }                state {                    DisplayTaskInfo $name [list state];                }                time {                    DisplayTaskInfo $name [list percentComplete];                }                moveup {                    # First, remove the task from the display.                    RemoveTaskInfo $name;                    array set TaskInfo $_taskTable($name);                    # Update the task's row number and                    # {X1, Y1} coordinates.                    unset _displayTable($TaskInfo(row));                    incr TaskInfo(row) -1;                    set TaskInfo(Y1) \                            [expr [expr $TaskInfo(row) * \                                        $_rowPaddedHeight] + \                                  $_initialYOffset];                    set TaskInfo(Y2) [expr $TaskInfo(Y1) + $_rowHeight];                    set _displayTable($TaskInfo(row)) $name;                    # Put the update task information back into                    # the task table                    set _taskTable($name) [array get TaskInfo];                    # Now put the task back on display.                    DisplayTaskInfo $name [list name state priority time percentComplete];                }                remove {                    RemoveTaskInfo $name;                }            }        }        # Else an unknown task was specified. Ignore request.        return -code ok;    }    # DisplayTaskInfo --    #    #   Display the specified task info on the canvas.    #    # Arguments:    #   name      The task's name.    #   infoList  The task information to be displayed.    #    # Results:    #   None.    private method DisplayTaskInfo {name infoList} {        global widget;        # Is this a known task?        if {[string length [array names _taskTable $name]] != 0} {            # Get the task info.            array set TaskInfo $_taskTable($name);            foreach InfoName $infoList {                switch -exact -- $InfoName {                    name {                        # Since task names can be very long. Use                        # the entry widget to display them.                        if {$TaskInfo(nameID) < 0} {                            set TaskInfo(nameID) \                                    [$_canvas create window \                                        $_nameX1 \                                        $TaskInfo(Y1) \                                        -height $_rowHeight \                                        -width $_nameWidth \                                        -anchor nw \                                        -window $TaskInfo(nameEntry)];                            # Put the update task information                            # back into the task table.                            set _taskTable($name) [array get TaskInfo];                        }                        # The task name should never be updated.                        # If the name is already displayed, then                        # do nothing.                    }                    state -                    priority -                    time {                        # These are text fields and use the same                        # display code.                        # If the text is already displayed, remove it.                        set FieldName ${InfoName}ID;                        if {$TaskInfo($FieldName) < 0} {                            set X1VarName "_${InfoName}X1";                            set JustifyVarName "_${InfoName}Justify";                            set TaskInfo($FieldName) \                                    [$_canvas create text \                                              [eval "set $X1VarName"] \                                              $TaskInfo(Y1) \                                              -text $TaskInfo($InfoName) \                                              -anchor nw \                                              -justify [eval "set $JustifyVarName"]];                            $_canvas bind $TaskInfo($FieldName) \                                    <ButtonPress-1> \                                    [list $this displayTaskMenu $name %W %x %y];                            # Put the update task information                            # back into the task table.                            set _taskTable($name) [array get TaskInfo];                        } else {                            $_canvas itemconfigure \                                    $TaskInfo($FieldName) \                                    -text $TaskInfo($InfoName);                        }                    }                    percentComplete {                        # This display uses rectangles and text.                        if {$TaskInfo(rect1ID) < 0} {                            # Draw the background grey rectangle.                            set TaskInfo(rect1ID) \                                    [$_canvas create rect \                                        $_rect1X1 \                                        $TaskInfo(Y1) \                                        $_rect1X2 \                                        $TaskInfo(Y2) \                                        -fill grey \                                        -width 2];                            $_canvas bind $TaskInfo(rect1ID) \                                    <ButtonPress-1> \                                    [list $this displayTaskMenu $name %W %x %y];                            # Put the update task information                            # back into the task table.                            set _taskTable($name) [array get TaskInfo];                        }                        # Draw the blue bar only if the percent                        # complete is greater than 0.                        if {$TaskInfo(percentComplete) > 0} {                            # Figure out how the blue rectangle's                            # coordinates based on percent completion.                            # Remember: the inside rectangle's                            # length is smaller than the grey                            # rectangle's.                            set Rect2X2 [expr $_rect1X1 + \                                    [expr $_rect2Width * \                                        [expr $TaskInfo(percentComplete) / 100.0]]];                            set Rect2Y1 [expr $TaskInfo(Y1) + $_rectSeparation];                            set Rect2Y2 [expr $TaskInfo(Y2) - $_rectSeparation];                            # The only way to update the blue rectangle                            # is to delete it and redraw it. Also                            # delete the percent text as well.                            if {$TaskInfo(percentID) >= 0} {                                $_canvas delete $TaskInfo(percentID);                                set TaskInfo(percentID) -1;                            }                            if {$TaskInfo(rect2ID) >= 0} {                                $_canvas delete $TaskInfo(rect2ID);                                set TaskInfo(rect2ID) -1;                            }                            # Now draw the blue rectangle.                            set TaskInfo(rect2ID) \                                    [$_canvas create rect \                                        $_rect2X1 \                                        $Rect2Y1 \                                        $Rect2X2 \                                        $Rect2Y2 \                                        -fill blue \                                        -outline ""];                            $_canvas bind $TaskInfo(rect2ID) \                                    <ButtonPress-1> \                                    [list $this displayTaskMenu $name %W %x %y];                        }                        # Always draw the % complete text.                        # But first change it from a float to                        # an integer.                        if {$TaskInfo(percentID) < 0} {                            set TaskInfo(percentID) \                                    [$_canvas create text \                                        $_percentX1 \                                        $TaskInfo(Y1) \                                        -text "[expr int($TaskInfo(percentComplete))]%" \                                        -fill white \                                        -anchor nw];                            $_canvas bind $TaskInfo(percentID) \                                    <ButtonPress-1> \                                    [list $this displayTaskMenu $name %W %x %y];                        } else {                            $_canvas itemconfigure $TaskInfo(percentID) \                                    -text "[expr int($TaskInfo(percentComplete))]%";                        }                        # Put the update task information                        # back into the task table.                        set _taskTable($name) [array get TaskInfo];                    }                }            }        }        # Else this task is unknown. Ignore request.        return -code ok;    }    # RemoveTaskInfo --    #    #   Remove the task's row from the display.    #    # Arguments:    #   name   The task's name.    #    # Results:    #   None.    private method RemoveTaskInfo {name} {        # Is this a known task?        if {[string length [array names _taskTable $name]] != 0} {            # Yes. Get the task information.            array set TaskInfo $_taskTable($name);            if {$TaskInfo(nameID) >= 0} {                $_canvas delete $TaskInfo(nameID);                set TaskInfo(nameID) -1;            }            if {$TaskInfo(stateID) >= 0} {                $_canvas delete $TaskInfo(stateID);                set TaskInfo(stateID) -1;            }            if {$TaskInfo(priorityID) >= 0} {                $_canvas delete $TaskInfo(priorityID);                set TaskInfo(priorityID) -1;            }            if {$TaskInfo(timeID) >= 0} {                $_canvas delete $TaskInfo(timeID);                set TaskInfo(timeID) -1;            }            if {$TaskInfo(rect1ID) >= 0} {                $_canvas delete $TaskInfo(rect1ID);                set TaskInfo(rect1ID) -1;            }            if {$TaskInfo(rect2ID) >= 0} {                $_canvas delete $TaskInfo(rect2ID);                set TaskInfo(rect2ID) -1;            }            if {$TaskInfo(percentID) >= 0} {                $_canvas delete $TaskInfo(percentID);                set TaskInfo(percentID) -1;            }            # Put the update task information back into the task            # table.            set _taskTable($name) [array get TaskInfo];        }        # Else unknown task. Ignore request.        return -code ok;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -