📄 statusgui.tcl
字号:
# # The contents of this file are subject to the Mozilla Public# License Version 1.1 (the "License"); you may not use this file# except in compliance with the License. You may obtain a copy of# the License at http://www.mozilla.org/MPL/# # Software distributed under the License is distributed on an "AS# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or# implied. See the License for the specific language governing# rights and limitations under the License.# # The Original Code is State Machine Compiler (SMC).# # The Initial Developer of the Original Code is Charles W. Rapp.# Portions created by Charles W. Rapp are# Copyright (C) 2000 - 2003 Charles W. Rapp.# All Rights Reserved.# # Contributor(s):## StatusGUI --## For each existing tasks, display the task name, priority,# total time and percent completion (as a scale).## RCS ID# $Id: statusGUI.tcl,v 1.4 2005/05/28 18:02:56 cwrapp Exp $## CHANGE LOG# $Log: statusGUI.tcl,v $# Revision 1.4 2005/05/28 18:02:56 cwrapp# Updated Tcl examples, removed EX6.## Revision 1.0 2003/12/14 20:32:48 charlesr# Initial revision#class StatusGUI {# Member data. # Put the information on this canvas. private variable _canvas; # This array contains all the currently displayed tasks. private variable _taskTable; # This array associates task names with rows. private variable _displayTable; # There static variables store the display field # widths and each row's height. They are needed to # calculate coordinates. All values specified in pixels. private common _initialXOffset 8; private common _initialYOffset 8; private common _rowHeight 15; private common _rowSeparation 4; private common _rowPaddedHeight [expr $_rowHeight + $_rowSeparation]; private common _colSeparation 4; private common _nameWidth 180; private common _nameJustify left; private common _nameX1 $_initialXOffset; private common _nameX2 [expr $_nameX1 + $_nameWidth]; private common _stateWidth 100; private common _stateJustify left; private common _stateX1 [expr $_nameX2 + $_colSeparation]; private common _stateX2 [expr $_stateX1 + $_stateWidth]; private common _priorityWidth 50; private common _priorityJustify right; private common _priorityX1 [expr $_stateX2 + $_colSeparation]; private common _priorityX2 [expr $_priorityX1 + $_priorityWidth]; private common _timeWidth 50; private common _timeJustify right; private common _timeX1 [expr $_priorityX2 + $_colSeparation]; private common _timeX2 [expr $_timeX1 + $_timeWidth]; private common _rectSeparation 2; private common _rect1Width 100; private common _rect1X1 [expr $_timeX2 + $_colSeparation]; private common _rect1X2 [expr $_rect1X1 + $_rect1Width]; private common _rect2Width [expr $_rect1Width - \ [expr $_rectSeparation * 2]]; private common _rect2X1 [expr $_rect1X1 + $_rectSeparation]; private common _percentX1 [expr $_rect1X1 + [expr $_rect1Width / 2]]; private common _X1 $_initialXOffset; private common _X2 $_rect1X2;# Member methods. constructor {canvas} { set _canvas $canvas; } destructor {}; # taskCreated -- # # Place a new task on the display. # # Arguments: # name Task's print name (not object name). # state Task's current state. # priority Task's static priority # time Task's total run time. # # Results: # None. public method taskCreated {name state priority time} { global widget; # Put this information into the task array. set TaskInfo(name) $name; set TaskInfo(state) $state; set TaskInfo(priority) $priority; set TaskInfo(time) $time; set TaskInfo(timeLeft) [expr $time * 1000]; set TaskInfo(percentComplete) 0; # Create the entry widget which contains the task name. set TaskInfo(nameEntry) \ [entry $widget(TaskCanvas).entry$name \ -relief flat \ -borderwidth 0 \ -justify $_nameJustify \ -background [$_canvas cget -background]]; # Put the task name into the widget. $TaskInfo(nameEntry) \ insert 0 $name; # Make the entry widget read only. $TaskInfo(nameEntry) configure \ -state disabled; # bind $TaskInfo(nameEntry) \ # <ButtonPress-1> \ # [list $this displayTaskMenu $name %W %x %y]; # Set the canvas IDs to empty strings since this # task is not yet displayed. set TaskInfo(nameID) -1; set TaskInfo(stateID) -1; set TaskInfo(priorityID) -1; set TaskInfo(timeID) -1; set TaskInfo(rect1ID) -1; set TaskInfo(rect2ID) -1; set TaskInfo(percentID) -1; # Have the display method figure out where the task # goes on the display. set RowCount [array size _taskTable]; set TaskInfo(row) $RowCount; # Store the task in the task table. set _taskTable($name) [array get TaskInfo]; set _displayTable($TaskInfo(row)) $name; DisplayTask $name new; return -code ok; } # taskStateUpdate -- # # Update the specified task's state. # # Arguments: # name Task's print name (not object name). # state Task's current state. # # Results: # None. public method taskStateUpdate {name state} { # Is this task already being displayed. if {[string length [array names _taskTable $name]] > 0} { # Yes, it does exist. Update the display but only # if different. Note: the task priority and time do # not change, only state and percent complete do. array set TaskInfo $_taskTable($name); if {[string compare $TaskInfo(state) $state] != 0} { set TaskInfo(state) $state; set _taskTable($name) [array get TaskInfo]; # Update the task's display. DisplayTask $name state; # If the task has completed (Done state) or been # deleted, then set up a timer to remove the task # from the display. if {[string compare $state "Done"] == 0 || \ [string compare $state "Deleted"] == 0} { after 1500 [list $this removeTask $name]; } } } return -code ok; } # taskTimeUpdate -- # # Update the specified task's percent complete. # # Arguments: # name Task's print name (not object name). # timeLeft Task's time remaining to run. # # Results: # None. public method taskTimeUpdate {name timeLeft} { # Is this task already being displayed. if {[string length [array names _taskTable $name]] > 0} { # Yes, it does exist. Update the display but only # if different. array set TaskInfo $_taskTable($name); set TotalTime [expr $TaskInfo(time) * 1000.0]; set NewPercentComplete \ [expr [expr [expr $TotalTime - $timeLeft] / \ $TotalTime] * \ 100.0]; if {$TaskInfo(percentComplete) != $NewPercentComplete} { set TaskInfo(percentComplete) $NewPercentComplete; set _taskTable($name) [array get TaskInfo]; # Update the task's display. DisplayTask $name time; } } return -code ok; } # removeTask -- # # Remove the task from the display. Simply delete the # canvas objects associated with the task. If the task # is the last row, then do nothing more. If not, then # move all the rows below the task up one row. # # Arguments: # name The task's name. # # Results: # None. public method removeTask {name} { # Is this a known task? if {[string length [array names _taskTable $name]] != 0} { DisplayTask $name remove; array set TaskInfo $_taskTable($name); # First, get the current table size and then remove # the task from the table. set LastRow [expr [array size _taskTable] - 1]; unset _taskTable($name); unset _displayTable($TaskInfo(row)); # Delete the task name's entry widget. destroy $TaskInfo(nameEntry); # Before deleting the task from the table, # figure out where it was in the display. if {$TaskInfo(row) < $LastRow} { # Since the display table will be updated by # the move up process, make a list of tasks # to be updated first. set TaskList {}; for {set i [expr $TaskInfo(row) + 1]} {$i <= $LastRow} {incr i} { lappend TaskList $_displayTable($i); } foreach Task $TaskList { DisplayTask $Task moveup; } } } } # displayTaskMenu -- # # Put up the task pop-up menu at the specified coordinates. # The menu consists of three items: Block, Unblock and # Delete. If the task in not in the blocked state, then # the Unblock item is disabled. If the task is in the # blocked state, then Block is disabled. A task can # always be deleted. # # Arguments: # name The task's name. # window The window reporting the click. # x The menu's upper left x coordinate. # y The menu's upper left y coordinate. # # Results: # None. public method displayTaskMenu {name window x y} { if {[string length [array names _taskTable $name]] != 0} { global widget; array set TaskInfo $_taskTable($name); # Figure out whether Blocked and Unblocked are normal # or disabled. Also, configure the entry commands # since the commands need to access the task name. if {[string compare $TaskInfo(state) "Blocked"] == 0} { $widget(TaskMenu) entryconfigure \ $widget(BlockMenuEntry) \ -state disabled \ -command ""; $widget(TaskMenu) entryconfigure \ $widget(UnblockMenuEntry) \ -state normal \ -command [list guiController postMessage \ taskManager unblockTask $name]; } else { $widget(TaskMenu) entryconfigure \ $widget(BlockMenuEntry) \ -state normal \ -command [list guiController postMessage \ taskManager blockTask $name]; $widget(TaskMenu) entryconfigure \ $widget(UnblockMenuEntry) \ -state disabled \ -command ""; } $widget(TaskMenu) entryconfigure \ $widget(DeleteMenuEntry) \ -command [list guiController postMessage \ taskManager deleteTask $name];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -