<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dammit Jim! &#187; Python</title>
	<atom:link href="http://scott.sherrillmix.com/blog/category/programmer/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://scott.sherrillmix.com/blog</link>
	<description>I'm a biologist not a...</description>
	<lastBuildDate>Tue, 12 Jan 2010 05:09:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Active Window Logger</title>
		<link>http://scott.sherrillmix.com/blog/programmer/active-window-logger/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/active-window-logger/#comments</comments>
		<pubDate>Sun, 24 Sep 2006 18:32:57 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Programmer]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[active window]]></category>
		<category><![CDATA[attention]]></category>
		<category><![CDATA[idle]]></category>
		<category><![CDATA[idle time]]></category>
		<category><![CDATA[logger]]></category>
		<category><![CDATA[taskbar]]></category>
		<category><![CDATA[time tracker]]></category>
		<category><![CDATA[wxPython]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/uncategorized/active-window-logger/</guid>
		<description><![CDATA[I was curious how I spend my time and wanted something simple to log which window was active on my computer. I couldn't see anything that did this easily on the internet, although there is a (more sophisticated/complicated) browsing history tracker, and I needed to relax for an hour or two so I thought I'd [...]]]></description>
			<content:encoded><![CDATA[<p>I was curious how I spend my time and wanted something simple to log which window was active on my computer. I couldn't see anything that did this easily on the internet, although there is a (more sophisticated/complicated) <a href="http://www.wynia.org/wordpress/2006/03/03/recording-your-attention-spying-on-yourself/">browsing history tracker</a>, and I needed to relax for an hour or two so I thought I'd give it a shot in Python and see what came out. After looking at the <a href="http://wiki.wxpython.org/index.cgi/FlashingTaskbarIcon">flashing taskbar icon tutorial</a>, <a href="http://mail.python.org/pipermail/python-list/2001-December/077001.html">how to get the currently active window</a>, <a href="http://www.mail-archive.com/python-win32@python.org/msg00669.html"> how to detect if Windows is idle</a> and <a href="http://scott.sherrillmix.com/blog/programmer/getting-rid-of-the-python-console-window/">how to get rid of the console window</a>, I could finally start programming. I really don't know how people programmed before Google.</p>

<p>Python really makes things easy. It took less than 90 lines of code and just a couple hours to write this. So here is the code for it if you want to build it yourself:</p>
<div class="syntax_hilite"><span class="langName">PYTHON:</span><br /><div id="python-2">
<div class="python"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">import</span> wx</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> win32gui <span style="color: #ff7700;font-weight:bold;">import</span> GetWindowText, GetForegroundWindow</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">time</span> <span style="color: #ff7700;font-weight:bold;">import</span> sleep, strftime, localtime</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> ctypes <span style="color: #ff7700;font-weight:bold;">import</span> windll, Structure, c_uint, sizeof, byref</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">class</span> TaskBarApp<span style="color: black;">&#40;</span>wx.<span style="color: black;">Frame</span><span style="color: black;">&#41;</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, parent, <span style="color: #008000;">id</span>, title<span style="color: black;">&#41;</span>:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; wx.<span style="color: black;">Frame</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, parent, -<span style="color: #ff4500;color:#800000;">1</span>, title, size = <span style="color: black;">&#40;</span><span style="color: #ff4500;color:#800000;">1</span>, <span style="color: #ff4500;color:#800000;">1</span><span style="color: black;">&#41;</span>, style=wx.<span style="color: black;">FRAME_NO_TASKBAR</span>|wx.<span style="color: black;">NO_FULL_REPAINT_ON_RESIZE</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">ICON_STATE</span> = <span style="color: #ff4500;color:#800000;">1</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">ID_ICON_TIMER</span>=wx.<span style="color: black;">NewId</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">tbicon</span> = wx.<span style="color: black;">TaskBarIcon</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; icon = wx.<span style="color: black;">Icon</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'logon.ico'</span>, wx.<span style="color: black;">BITMAP_TYPE_ICO</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">tbicon</span>.<span style="color: black;">SetIcon</span><span style="color: black;">&#40;</span>icon, <span style="color: #483d8b;">'Logging'</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">tbicon</span>.<span style="color: black;">Bind</span><span style="color: black;">&#40;</span>wx.<span style="color: black;">EVT_TASKBAR_LEFT_DCLICK</span>, <span style="color: #008000;">self</span>.<span style="color: black;">OnTaskBarLeftDClick</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">tbicon</span>.<span style="color: black;">Bind</span><span style="color: black;">&#40;</span>wx.<span style="color: black;">EVT_TASKBAR_RIGHT_UP</span>, <span style="color: #008000;">self</span>.<span style="color: black;">OnTaskBarRightClick</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">Bind</span><span style="color: black;">&#40;</span>wx.<span style="color: black;">EVT_TIMER</span>, <span style="color: #008000;">self</span>.<span style="color: black;">Log</span>, <span style="color: #008000;">id</span>=<span style="color: #008000;">self</span>.<span style="color: black;">ID_ICON_TIMER</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">SetIconTimer</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">Show</span><span style="color: black;">&#40;</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">lastInputInfo</span> = <span style="color: #008000;">self</span>.<span style="color: black;">LASTINPUTINFO</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">lastInputInfo</span>.<span style="color: black;">cbSize</span> = sizeof<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">lastInputInfo</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">Write</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">Now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">"&lt;|&gt;__LOGGERSTART__&lt;|&gt;0<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> OnTaskBarLeftDClick<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, evt<span style="color: black;">&#41;</span>:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">ICON_STATE</span> == <span style="color: #ff4500;color:#800000;">0</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">Write</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">Now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">"&lt;|&gt;__LOGGERUNPAUSE__&lt;|&gt;0<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">StartIconTimer</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; icon = wx.<span style="color: black;">Icon</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'logon.ico'</span>, wx.<span style="color: black;">BITMAP_TYPE_ICO</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">tbicon</span>.<span style="color: black;">SetIcon</span><span style="color: black;">&#40;</span>icon, <span style="color: #483d8b;">'Logging'</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">ICON_STATE</span> = <span style="color: #ff4500;color:#800000;">1</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">StopIconTimer</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">Write</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">Now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">"&lt;|&gt;__LOGGERPAUSE__&lt;|&gt;0<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; icon = wx.<span style="color: black;">Icon</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'logoff.ico'</span>, wx.<span style="color: black;">BITMAP_TYPE_ICO</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">tbicon</span>.<span style="color: black;">SetIcon</span><span style="color: black;">&#40;</span>icon, <span style="color: #483d8b;">'Not Logging'</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">ICON_STATE</span> = <span style="color: #ff4500;color:#800000;">0</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> OnTaskBarRightClick<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, evt<span style="color: black;">&#41;</span>:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">StopIconTimer</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">Write</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">Now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">"&lt;|&gt;__LOGGERSTOP__&lt;|&gt;0<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">tbicon</span>.<span style="color: black;">Destroy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">Close</span><span style="color: black;">&#40;</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; wx.<span style="color: black;">GetApp</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">ProcessIdle</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> SetIconTimer<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">icontimer</span> = wx.<span style="color: black;">Timer</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #008000;">self</span>.<span style="color: black;">ID_ICON_TIMER</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">icontimer</span>.<span style="color: black;">Start</span><span style="color: black;">&#40;</span><span style="color: #ff4500;color:#800000;">10000</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> StartIconTimer<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">try</span>:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">icontimer</span>.<span style="color: black;">Start</span><span style="color: black;">&#40;</span><span style="color: #ff4500;color:#800000;">10000</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">except</span>:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">pass</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> StopIconTimer<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">try</span>:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">icontimer</span>.<span style="color: black;">Stop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">except</span>:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">pass</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> Log<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, evt<span style="color: black;">&#41;</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; windll.<span style="color: black;">user32</span>.<span style="color: black;">GetLastInputInfo</span><span style="color: black;">&#40;</span>byref<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">lastInputInfo</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; idleDelta = <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>windll.<span style="color: black;">kernel32</span>.<span style="color: black;">GetTickCount</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - <span style="color: #008000;">self</span>.<span style="color: black;">lastInputInfo</span>.<span style="color: black;">dwTime</span><span style="color: black;">&#41;</span> / <span style="color: #ff4500;color:#800000;">1000</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">Write</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">Now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">"&lt;|&gt;"</span>+GetWindowText<span style="color: black;">&#40;</span>GetForegroundWindow<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">"&lt;|&gt;"</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>idleDelta<span style="color: black;">&#41;</span>+<span style="color: #483d8b;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> Write<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, text<span style="color: black;">&#41;</span>:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; f=<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'log.tmp'</span>, <span style="color: #483d8b;">'a'</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: black;">write</span> <span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> Now<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> strftime<span style="color: black;">&#40;</span><span style="color: #483d8b;">"%Y-%m-%d %H:%M:%S"</span>, localtime<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">class</span> LASTINPUTINFO<span style="color: black;">&#40;</span>Structure<span style="color: black;">&#41;</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; _fields_ = <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">"cbSize"</span>, c_uint<span style="color: black;">&#41;</span>,<span style="color: black;">&#40;</span><span style="color: #483d8b;">"dwTime"</span>, c_uint<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">class</span> MyApp<span style="color: black;">&#40;</span>wx.<span style="color: black;">App</span><span style="color: black;">&#41;</span>:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> OnInit<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; frame = TaskBarApp<span style="color: black;">&#40;</span><span style="color: #008000;">None</span>, -<span style="color: #ff4500;color:#800000;">1</span>, <span style="color: #483d8b;">' '</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; frame.<span style="color: black;">Center</span><span style="color: black;">&#40;</span>wx.<span style="color: black;">BOTH</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; frame.<span style="color: black;">Show</span><span style="color: black;">&#40;</span><span style="color: #008000;">False</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; app = MyApp<span style="color: black;">&#40;</span><span style="color: #ff4500;color:#800000;">0</span><span style="color: black;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; app.<span style="color: black;">MainLoop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> </div></li></ol></div>
</div></div><br />

<p>It's not too pretty but it seems to work. If you try it, it should begin putting an entry in <code>log.tmp</code> every ten seconds of 'datetime&lt;|&gt;program title&lt;|&gt;idle time'. Unfortunately, it takes 16 megs of RAM. I guess there's a lot going on in the background in the imported stuff. I think it would be much more efficient if programmed from scratch but I'm no programmer. Also, I would make an .exe for people without Python but the .dll files that would have to go along with it would take up more than 10 megs. Must be all the stuff going on in the background again. So it's inefficient but it would get the job done if you want something quick for a day or two or maybe it could form the base of a more optimized program. Next time I have a little free time, I might write a program to read the log and make a summary.</p>
<p>Oh you'll also need 2 32x32 .ico files called logon.ico and logoff.ico. You can use these or <a href="http://www.winterdrache.de/freeware/png2ico/">make your own icons</a>.</p>
<a href="/res/images/logon.ico"><img src="/res/images/logon.png" alt="A logon icon" /></a> <a href="/res/images/logoff.ico"><img src="/res/images/logoff.png" alt="A logoff icon" /></a>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/active-window-logger/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting Rid of the Python Console Window</title>
		<link>http://scott.sherrillmix.com/blog/programmer/getting-rid-of-the-python-console-window/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/getting-rid-of-the-python-console-window/#comments</comments>
		<pubDate>Thu, 21 Sep 2006 13:45:56 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Programmer]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[black]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[window]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/programmer/getting-rid-of-the-python-console-window/</guid>
		<description><![CDATA[Python sure is handy. I just found out that if you make a program that uses wxPython or something to generate windows and don't want the  big (somewhat ugly) black console window, all you have to do is change the program name from program.py to program.pyw or run pythonw.exe instead of python.exe. Pretty obvious [...]]]></description>
			<content:encoded><![CDATA[<p>Python sure is handy. I just found out that if you make a program that uses <a href="http://www.wxpython.org/">wxPython</a> or something to generate windows and don't want the  big (somewhat ugly) black console window, all you have to do is change the program name from <code>program.py</code> to <code>program.pyw</code> or run <code>pythonw.exe</code> instead of <code>python.exe</code>. Pretty obvious now but took me a few minutes to come up with the right google. Now I just wish it wasn't using 16 megs of RAM for a 30 line program...</p>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/getting-rid-of-the-python-console-window/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
