Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10593

Windows: setting title of console window

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'sys': 0.05; 'python': 0.08; 'scripts': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'oh,': 0.09; 'received:gator410.hostgator.com': 0.09; 'subject:setting': 0.09; 'to:name:python list': 0.09; '~ethan~': 0.09; 'gui': 0.13; 'track.': 0.16; 'folks': 0.16; 'this:': 0.16; 'def': 0.16; 'command': 0.19; 'subject:Windows': 0.19; '(which': 0.20; 'work,': 0.20; 'says': 0.25; 'modules': 0.25; 'import': 0.29; 'skip:- 30': 0.30; 'ctypes': 0.30; 'occasional': 0.30; 'class': 0.31; "skip:' 10": 0.32; 'setting': 0.32; 'to:addr:python-list': 0.34; 'header :User-Agent:1': 0.34; 'quite': 0.34; 'question': 0.35; '(for': 0.36; 'some': 0.37; 'perform': 0.37; 'but': 0.37; 'using': 0.37; 'subject:: ': 0.38; 'portion': 0.38; 'something': 0.38; 'easier': 0.39; 'help': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'received:websitewelcome.com': 0.65; 'received:184': 0.67; 'skip:w 40': 0.67; 'received:69.41.242': 0.84
Date Sat, 30 Jul 2011 10:23:40 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version 1.0
To python list <python-list@python.org>
Subject Windows: setting title of console window
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender c-67-170-168-84.hsd1.or.comcast.net ([192.168.74.5]) [67.170.168.84]:3121
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1667.1312046688.1164.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1312046688 news.xs4all.nl 23974 [2001:888:2000:d::a6]:57512
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10593

Show key headers only | View raw


I came across question http://stackoverflow.com/questions/6485678/ which 
has to do with setting the console title from sitecustomize.py.  With 
some help from the folks on python-win32 (for the title portion ;) I 
came up with this:

8<-- sitecustomize.py ---------------------------------
import sys
import time
from ctypes import windll

class SetTitle(object):
     def __del__(self):
         time.sleep(.1)
         command = ' '.join(sys.argv)
         windll.kernel32.SetConsoleTitleA(command)

sys.argv = SetTitle()
8<-----------------------------------------------------

I have a good number of python scripts being called to perform work, and 
even the GUI modules have a console window -- no, it's not very 
polished, but it's internal use only and it make the occasional bug 
easier to track.

Having the python script's name in the console window (which otherwise 
just says something like 'c:\windows\cmd.exe') is quite nice.

Oh, and if you're using Python 3, change SetConsoleTitleA to 
SetConsoleTitleW.

~Ethan~

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Windows: setting title of console window Ethan Furman <ethan@stoneleaf.us> - 2011-07-30 10:23 -0700

csiph-web