-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerDialog.cs
More file actions
141 lines (118 loc) · 2.86 KB
/
TimerDialog.cs
File metadata and controls
141 lines (118 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using Gtk;
using GLib;
namespace workflow
{
public partial class TimerDialog : Gtk.Dialog
{
static string timerMessage;
static bool theTimerIsStopwatch;
static bool timerPause;
static bool timesUp;
static int timerSeconds;
static int timerTargetSeconds;
public TimerDialog ()
{
this.Build ();
InitializeTimer ();
}
public void InitializeTimer ()
{
GLib.Timeout.Add(1000, new GLib.TimeoutHandler(update_timer));
timerSeconds = 0;
timesUp = false;
timerPause = true;
theTimerIsStopwatch = true;
getTimerDigits ();
Pango.FontDescription fontDescription = Pango.FontDescription.FromString("Roman 48");
TimerEntry.ModifyFont ( fontDescription );
UpdateTimerDisplay ();
}
bool update_timer ()
{
// entryStatusBarLeft.Text=DateTime.Now.ToString ();
if (timerPause == false) {
if (theTimerIsStopwatch == true) {
timerSeconds++;
if (timerSeconds == timerTargetSeconds) {
timesUp = true;
}
}
else {
timerSeconds--;
if (timerSeconds == 0) {
timesUp = true;
}
}
if (timesUp == true) {
stopTimer();
timerMessage = "Time's up!";
TimerDialog timeDone = new TimerDialog ();
timeDone.Run ();
timeDone.Destroy ();
}
else {
timerMessage = string.Format("{0:00}:{1:00}:{2:00}",timerSeconds/3600,
(timerSeconds/60)%60,
timerSeconds%60);
}
UpdateTimerDisplay ();
}
return true;
}
protected void UpdateTimerDisplay ()
{
TimerEntry.Text = timerMessage;
}
protected void resetTimer (object sender, System.EventArgs e)
{
timerSeconds = 0;
timesUp = false;
getTimerDigits ();
}
protected void stopwatchSelected (object sender, System.EventArgs e)
{
timerSeconds = 0;
theTimerIsStopwatch = true;
}
protected void countdownSelected (object sender, System.EventArgs e)
{
timerSeconds = timerTargetSeconds;
theTimerIsStopwatch = false;
}
protected void getTimerDigits()
{
timerTargetSeconds = (int)spinbuttonHours.Value * 3600 +
(int)spinbuttonMinutes.Value * 60 +
(int)spinbuttonSeconds.Value;
timerMessage = string.Format("{0:00}:{1:00}:{2:00}",timerTargetSeconds/3600,
(timerTargetSeconds/60)%60,
timerTargetSeconds%60);
if (theTimerIsStopwatch == true) {
timerSeconds = 0;
}
else {
timerSeconds = timerTargetSeconds;
}
UpdateTimerDisplay ();
}
protected void PauseToggle (object sender, System.EventArgs e)
{
if (timerPause == true)
timerPause = false;
else {
timerPause = true;
}
}
protected void setTimer (object sender, System.EventArgs e)
{
timesUp = false;
getTimerDigits ();
}
protected void stopTimer ()
{
timerSeconds = 0;
timerPause = true;
}
}
}