Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'root': 0.05; 'subject:text': 0.05; 'subject:Python': 0.06; '"""': 0.07; 'sys': 0.07; 'tkinter': 0.07; '__name__': 0.09; 'deploy': 0.09; 'editor.': 0.09; 'filename': 0.09; 'git': 0.09; 'main()': 0.09; 'messing': 0.09; 'root,': 0.09; 'subject:editor': 0.09; 'def': 0.12; 'gui': 0.12; '"""simple': 0.16; "'__main__':": 0.16; "'w')": 0.16; 'committer': 0.16; 'committer:': 0.16; 'f.read())': 0.16; 'filename):': 0.16; 'main():': 0.16; 'self.root': 0.16; 'stupidity': 0.16; 'tool.': 0.16; 'skip:# 20': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'commit': 0.19; 'pointed': 0.19; 'widget': 0.19; 'import': 0.22; 'to:name:python- list@python.org': 0.22; "shouldn't": 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'assert': 0.31; 'sep': 0.31; 'class': 0.32; 'text': 0.33; 'open': 0.33; 'week.': 0.33; 'not.': 0.33; 'skip:_ 10': 0.34; 'subject:with': 0.35; 'skip:s 30': 0.35; 'editor': 0.35; 'received:google.com': 0.35; 'too': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'how': 0.40; 'easy': 0.60; 'took': 0.61; 'simple': 0.61; 'minutes': 0.67; 'ending': 0.78; 'me!': 0.84; 'sick': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=9UyZxWuIqDZU3OW+Cpy0dvT2ZD3b1KKvRSXApAUdaGc=; b=arBg8I20+c2KxtfMfTf9+SiIuxkfPYPA/VpCxQIkqhYSUoMoYHZrUYhvsKghhUigcX xYnH9zv1HPv0bKL4GMc8+19+mIdnwFQKBwy+LjH4JTQXRBsBRPfujb7C1N2mJ6HT0QPe lheOzwBNzsEeFk5ICfPfNFpzx+yIciKn1/N+4C5qC9iUIdYW2sszHHPrCwOA+HrwDC4i rQFx4GYnEfiwiGbdOrSGEnp4/5zgvyGC26jqavg9ZDGRG51AHlvK0+kAszk98G3DcYRs FYhlYpuoUQmEfj9+QCgvWSD9Jpf3sFg6BJIM0MfMY9qAUsSkBgGtnho9lTwJh4ff0Z8V 1r6g== X-Received: by 10.182.241.200 with SMTP id wk8mr35480830obc.27.1409713425083; Tue, 02 Sep 2014 20:03:45 -0700 (PDT) MIME-Version: 1.0 Sender: zachary.ware@gmail.com In-Reply-To: References: <54049ab7$0$29972$c3e8da3$5496439d@news.astraweb.com> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> From: Zachary Ware Date: Tue, 2 Sep 2014 22:03:25 -0500 X-Google-Sender-Auth: S_SYRS75l1BmgBg4H5F_HiqnTLI Subject: Re: Editing text with an external editor in Python To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409713432 news.xs4all.nl 2965 [2001:888:2000:d::a6]:36947 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77463 On Tue, Sep 2, 2014 at 3:45 AM, Chris Angelico wrote: > Considering how easy it is to deploy a multi-line edit widget in any > GUI toolkit, it shouldn't be too hard to write a GUI text editor. Coincidentally, I was annoyed enough to write the following program sometime last week. I was sick of messing with Notepad or Notepad++ as the git editor (and don't feel like learning vim just to write a commit message), so I took 10 minutes to write this, packaged it up with py2exe and pointed git at it. Works like a charm for me! #!C:/Python34/python.exe """Simple commit message tool. Dead simple tkinter GUI for writing commit messages for git without messing around with Notepad's line ending stupidity or Notepad++ being open or not. """ import os import sys import tkinter as tk class Committer: def __init__(self, root, filename): self.root = root self.root.protocol('WM_DELETE_WINDOW', self.destroy) self.filename = filename self.text = tk.Text(root) self.text['width'] = 80 self.text['height'] = 25 self.text.pack() self.text.focus() with open(self.filename) as f: self.text.insert('end', f.read()) self.text.mark_set("insert", "1.0") def destroy(self): message = self.text.get('1.0', 'end') with open(self.filename, 'w') as f: f.write(message) self.root.destroy() def main(): root = tk.Tk() assert os.path.exists(sys.argv[1]), sys.argv[1] committer = Committer(root, sys.argv[1]) root.mainloop() if __name__ == '__main__': main() -- Zach