threads / discuss / 15739

Help with a tcl/tk gui thing..

Subject: Help with a tcl/tk gui thing..

## tl;dr

10 messages between Oct 1, 2008 and Oct 2, 2008.

replies: 9people: 4as markdown or json

Linus Torvalds· Oct 1, 2008, 19:54 UTC · lore

Ok, this is ridiculous, and has nothing to do with git apart from being hosted in it, but I thought I'd send out an email about it since the git community is the only one I know that does any GUI work at all...

I've got three girls, all wasting their time on their computer, and we set up this rule that they get to have a maximum of an hour of internet time each day. Of course, being the geek I am, I wrote a stupid time tracker for that purpose, and then totally forgot about it.

Until the harddisk in their computer broke down, and I had to re-install, and realized that I didn't have a copy of my stupid tracker sources anywhere. So I had to re-write it, and to make sure that I didn't lose it _again_, I put it in a git repo this time, and now have it on my desktop machine.

I _also_ have it on kernel.org, because I tend to change machines often enough that files get lost because I decide that switching machines is also a great way of doing "generational GC" on my home directory.

[ iow, I copy my old home directory as "old-home" when I switch machines, 
  and anything I didn't end up copying by the time I switch machines 
  again, just gets deleted. Very neat, and a great way to lose things that 
  you only care about every other year or so. ]
Whatever.

To make a long story short, I have a very small program that does all the tracking, and I have no problems with that. It doesn't have much of a admin interface, but I can do "echo 3600 > /var/log/tracker/celeste" to reset the time etc. _I_ have no need for pretty GUI's.

But I also have a UI that the kids can run to _see_ how much time they have left, so that getting thrown off the machine doesn't come as a total surprise. And yesterday Patricia asked why it has to be that ugly. And I had to admit that her dad is just not very good at UI's - and my re-implementation may in fact have been EVEN UGLIER than my original version. If that is even possible.

But hey, I'm not above impressing my kids with pretty bling if I can get somebody else who actually knows what they are doing to enhance my wish scripts to something reasonable.

Anybody?
The repository is at
	git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/tracker.git

if somebody knows how to make the text turn red when the end is near and/or make it have some nice graphical bar that fills up as time is about to expire.

And if nobody does, no worries. At least I tried. My kids can continue to watch ugly/small/monochrome fonts with just a count-down clock.

			Linus
Johannes Schindelin· Oct 1, 2008, 20:30 UTC · re: Linus Torvalds · lore

[TRACKER PATCH] Change color at specified threshold

Now the color changes when a certain threshold of remaining seconds is reached.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	On Wed, 1 Oct 2008, Linus Torvalds wrote:
	> But I also have a UI that the kids can run to _see_ how much 
	> time they have left, so that getting thrown off the machine doesn't 
	> come as a total surprise.
 tracker-ui.tcl |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/tracker-ui.tcl b/tracker-ui.tcl
index 16d00d7..1533db5 100755
--- a/tracker-ui.tcl
+++ b/tracker-ui.tcl
@@ -1,5 +1,7 @@
 #!/usr/bin/wish
 
+set red_threshold [expr 60 * 10]
+
 proc every {ms body} {
      eval $body
      after $ms [list every $ms $body]
@@ -7,14 +9,19 @@ proc every {ms body} {
 
 set user $env(USER)
 
-pack [label .tracker -textvariable time]
+pack [label .tracker -textvariable time -font "Times 36" -relief sunken]
 
 every 1000 {
-	global user
+	global user red_threshold
 	set f [open "/var/log/tracker/$user" "r"]
 	gets $f l1
 	gets $f l2
 	gets $f l3
 	close $f
 	set ::time "$l3"
+	if {[expr [lindex $l1 0] - [lindex $l1 1]] < $red_threshold} {
+		.tracker configure -foreground white -background red
+	} {
+		.tracker configure -foreground black -background white
+	}
 }
-- 
1.6.0.2.GIT
Johannes Schindelin· Oct 1, 2008, 20:41 UTC · re: Johannes Schindelin · lore

[PATCH] Make maximum surf time really per day

Earlier, when the maximum time was reached, we would block for 8 hours. The program description suggested that the maximum time should be per day instead, however. So rather check that.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	I am sure your kids will hate me.  Now the trick to surf before 
	school, after school, and then late at night does not work 
	anymore.  :-(
	Well, the "late at night" would have interfered with next day's 
	"before school" anyway.
 tracker.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/tracker.c b/tracker.c
index 1b26e7e..faa4a91 100644
--- a/tracker.c
+++ b/tracker.c
@@ -12,6 +12,9 @@
 
 #define TRACKER_FILE "/var/log/tracker/%s"
 
+/* Define this, just in case it changes some day */
+#define SECS_PER_DAY 86400
+
 enum state {
 	no_user, old_user, new_user
 };
@@ -43,7 +46,7 @@ static void update_fd(struct user *user, int fd, unsigned int s)
 	cur += s;
 
 	/* Has the user been logged out more than 8 hours? */
-	if (user->last - last >= 8*60*60)
+	if (user->last / SECS_PER_DAY != last / SECS_PER_DAY)
 		cur = 0;
 
 	left = max - cur;
-- 
1.6.0.2.GIT
Linus Torvalds· Oct 1, 2008, 23:09 UTC · re: Johannes Schindelin · lore

Re: [PATCH] Make maximum surf time really per day

On Wed, 1 Oct 2008, Johannes Schindelin wrote:
> 
> Earlier, when the maximum time was reached, we would block for 8 hours.
> The program description suggested that the maximum time should be per
> day instead, however.  So rather check that.

I actually prefer the old behavior. Your new one has a "flag time" when you get all your time back, and it's not even something logical like midnight, it is (if I read the patch right), "midnight UTC" that will do it.

So the "you have to be offline for at least 8 hours" thing is actually something that even my old tracker worked with, and at least with my kids, there is no worry that they'd wake up early just to do it both before _and_ after school ;)

		Linus
Mikael Magnusson· Oct 1, 2008, 21:03 UTC · re: Linus Torvalds · lore

Re: Help with a tcl/tk gui thing..

How's this?
git clone git://mika.l3ib.org/tracker.git

I wrote it in pygtk since I know zero to no tcl/tk, hope that's okay. It has a label with the time remaining (simply read from the daemon file), and shows the text in red if less than 10% is remaining. You'll need to change the ./ in cb_function to /var/log/tracker since I forgot to change that and I'm lazy :).

2008/10/1 Linus Torvalds <torvalds@linux-foundation.org>:
Show 62 quoted lines
>
> Ok, this is ridiculous, and has nothing to do with git apart from being
> hosted in it, but I thought I'd send out an email about it since the git
> community is the only one I know that does any GUI work at all...
>
> I've got three girls, all wasting their time on their computer, and we set
> up this rule that they get to have a maximum of an hour of internet time
> each day. Of course, being the geek I am, I wrote a stupid time tracker
> for that purpose, and then totally forgot about it.
>
> Until the harddisk in their computer broke down, and I had to re-install,
> and realized that I didn't have a copy of my stupid tracker sources
> anywhere. So I had to re-write it, and to make sure that I didn't lose it
> _again_, I put it in a git repo this time, and now have it on my desktop
> machine.
>
> I _also_ have it on kernel.org, because I tend to change machines often
> enough that files get lost because I decide that switching machines is
> also a great way of doing "generational GC" on my home directory.
>
> [ iow, I copy my old home directory as "old-home" when I switch machines,
>  and anything I didn't end up copying by the time I switch machines
>  again, just gets deleted. Very neat, and a great way to lose things that
>  you only care about every other year or so. ]
>
> Whatever.
>
> To make a long story short, I have a very small program that does all the
> tracking, and I have no problems with that. It doesn't have much of a
> admin interface, but I can do "echo 3600 > /var/log/tracker/celeste" to
> reset the time etc. _I_ have no need for pretty GUI's.
>
> But I also have a UI that the kids can run to _see_ how much time they
> have left, so that getting thrown off the machine doesn't come as a total
> surprise. And yesterday Patricia asked why it has to be that ugly. And I
> had to admit that her dad is just not very good at UI's - and my
> re-implementation may in fact have been EVEN UGLIER than my original
> version. If that is even possible.
>
> But hey, I'm not above impressing my kids with pretty bling if I can get
> somebody else who actually knows what they are doing to enhance my wish
> scripts to something reasonable.
>
> Anybody?
>
> The repository is at
>
>        git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/tracker.git
>
> if somebody knows how to make the text turn red when the end is near
> and/or make it have some nice graphical bar that fills up as time is about
> to expire.
>
> And if nobody does, no worries. At least I tried. My kids can continue to
> watch ugly/small/monochrome fonts with just a count-down clock.
>
>                        Linus
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
-- 
Mikael Magnusson
Linus Torvalds· Oct 1, 2008, 23:06 UTC · re: Mikael Magnusson · lore

Re: Help with a tcl/tk gui thing..

On Wed, 1 Oct 2008, Mikael Magnusson wrote:
Show 8 quoted lines
> 
> git clone git://mika.l3ib.org/tracker.git
> 
> I wrote it in pygtk since I know zero to no tcl/tk, hope that's okay.
> It has a label with the time remaining (simply read from the daemon file),
> and shows the text in red if less than 10% is remaining. You'll need to
> change the ./ in cb_function to /var/log/tracker since I forgot to change
> that and I'm lazy :).

Well, it doesn't do anything at all for me except change the cursor to a cross, and if I'm a n00b with tcl/tk, I'm even more of one with pygtk.

I merged the two other suggestions, though. And am open to seeing that pygtk thing too as an alternative, but only if it actually works for me ;)

		Linus
Mikael Magnusson· Oct 2, 2008, 05:18 UTC · re: Linus Torvalds · lore

Re: Help with a tcl/tk gui thing..

2008/10/2 Linus Torvalds <torvalds@linux-foundation.org>:
Show 17 quoted lines
>
>
> On Wed, 1 Oct 2008, Mikael Magnusson wrote:
>>
>> git clone git://mika.l3ib.org/tracker.git
>>
>> I wrote it in pygtk since I know zero to no tcl/tk, hope that's okay.
>> It has a label with the time remaining (simply read from the daemon file),
>> and shows the text in red if less than 10% is remaining. You'll need to
>> change the ./ in cb_function to /var/log/tracker since I forgot to change
>> that and I'm lazy :).
>
> Well, it doesn't do anything at all for me except change the cursor to a
> cross, and if I'm a n00b with tcl/tk, I'm even more of one with pygtk.
>
> I merged the two other suggestions, though. And am open to seeing that
> pygtk thing too as an alternative, but only if it actually works for me ;)

Heh, sorry, I'm an idiot. I forgot to put '#!/usr/bin/python' on the first line. I was running 'python tracker-ui.py' then did chmod +x just before committing :). So the cross is coming from running 'import time'.

-- 
Mikael Magnusson
Linus Torvalds· Oct 2, 2008, 14:49 UTC · re: Mikael Magnusson · lore

Re: Help with a tcl/tk gui thing..

On Thu, 2 Oct 2008, Mikael Magnusson wrote:
> 
> Heh, sorry, I'm an idiot. I forgot to put '#!/usr/bin/python' on the first
> line. I was running 'python tracker-ui.py' then did chmod +x just before
> committing :). So the cross is coming from running 'import time'.

Ahh. It did _something_, so I assumed it was working, just not well. Being confused about the language would do it ;)

I fixed it up and merged it as an alternate UI. It doesn't react well to a tracker file that has just been initialized with the timeout (but without any of the extra information that gets filled out once you actually start getting tracked), but it's certainly prettier than my original one.

Thanks,
		Linus
Mikael Magnusson· Oct 2, 2008, 15:01 UTC · re: Linus Torvalds · lore

Re: Help with a tcl/tk gui thing..

2008/10/2 Linus Torvalds <torvalds@linux-foundation.org>:
Show 15 quoted lines
>
>
> On Thu, 2 Oct 2008, Mikael Magnusson wrote:
>>
>> Heh, sorry, I'm an idiot. I forgot to put '#!/usr/bin/python' on the first
>> line. I was running 'python tracker-ui.py' then did chmod +x just before
>> committing :). So the cross is coming from running 'import time'.
>
> Ahh. It did _something_, so I assumed it was working, just not well. Being
> confused about the language would do it ;)
>
> I fixed it up and merged it as an alternate UI. It doesn't react well to a
> tracker file that has just been initialized with the timeout (but without
> any of the extra information that gets filled out once you actually start
> getting tracked), but it's certainly prettier than my original one.

Ah, I didn't play around too much with the actual server part, but I guess that would get sort of annoying, so I pushed a fix for that, and also it now sets the window title right.

I should also note that I'm not exactly a python master, so if it looks ugly, blame me, not python :).

-- 
Mikael Magnusson
Björn Steinbrink· Oct 1, 2008, 21:09 UTC · re: Linus Torvalds · lore

[PATCH] GUI: Add a progressbar to visualize the time that is left

Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
---
OK, this bar doesn't fill up as you requested, but instead gets empty,
that's just how I feel it should be ;-)
Might require Tcl/Tk 8.5...
 tracker-ui.tcl |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/tracker-ui.tcl b/tracker-ui.tcl
index 16d00d7..5314c57 100755
--- a/tracker-ui.tcl
+++ b/tracker-ui.tcl
@@ -8,6 +8,7 @@ proc every {ms body} {
 set user $env(USER)
 
 pack [label .tracker -textvariable time]
+pack [ttk::progressbar .bar]
 
 every 1000 {
 	global user
@@ -17,4 +18,9 @@ every 1000 {
 	gets $f l3
 	close $f
 	set ::time "$l3"
+	set times [split "$l1" " "]
+	set max [lindex $times 0]
+	set cur [lindex $times 1]
+	set left [expr $max - $cur]
+	.bar configure -max $max -value $left
 }
-- 
1.6.0.2.307.gc427

← back to recent threads