Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77463
| References | (1 earlier) <mailman.13692.1409589319.18130.python-list@python.org> <5404b987$0$30001$c3e8da3$5496439d@news.astraweb.com> <mailman.13694.1409602073.18130.python-list@python.org> <zjfNv.198388$rQ.139558@fx13.am4> <CAPTjJmpPjBmtgC2dvuYmGQNc900rb=XUt5LRGHwS0--G+_xCew@mail.gmail.com> |
|---|---|
| From | Zachary Ware <zachary.ware+pylist@gmail.com> |
| Date | 2014-09-02 22:03 -0500 |
| Subject | Re: Editing text with an external editor in Python |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13724.1409713432.18130.python-list@python.org> (permalink) |
On Tue, Sep 2, 2014 at 3:45 AM, Chris Angelico <rosuav@gmail.com> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Editing text with an external editor in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-02 02:11 +1000
Re: Editing text with an external editor in Python Chris Angelico <rosuav@gmail.com> - 2014-09-02 02:35 +1000
Re: Editing text with an external editor in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-02 04:23 +1000
Re: Editing text with an external editor in Python Tim Chase <python.list@tim.thechases.com> - 2014-09-01 15:06 -0500
Re: Editing text with an external editor in Python alister <alister.nospam.ware@ntlworld.com> - 2014-09-02 08:35 +0000
Re: Editing text with an external editor in Python Chris Angelico <rosuav@gmail.com> - 2014-09-02 18:45 +1000
Re: Editing text with an external editor in Python alister <alister.nospam.ware@ntlworld.com> - 2014-09-03 08:06 +0000
Re: Editing text with an external editor in Python Terry Reedy <tjreedy@udel.edu> - 2014-09-02 17:14 -0400
Re: Editing text with an external editor in Python Chris Angelico <rosuav@gmail.com> - 2014-09-03 07:36 +1000
Re: Editing text with an external editor in Python Terry Reedy <tjreedy@udel.edu> - 2014-09-02 21:49 -0400
Re: Editing text with an external editor in Python Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-09-02 22:03 -0500
Re: Editing text with an external editor in Python Chris Angelico <rosuav@gmail.com> - 2014-09-02 08:30 +1000
Re: Editing text with an external editor in Python Roy Smith <roy@panix.com> - 2014-09-01 13:06 -0400
Re: Editing text with an external editor in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-02 04:02 +1000
Re: Editing text with an external editor in Python Cameron Simpson <cs@zip.com.au> - 2014-09-02 08:14 +1000
Re: Editing text with an external editor in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-02 13:18 +1000
Re: Editing text with an external editor in Python Chris Angelico <rosuav@gmail.com> - 2014-09-02 08:25 +1000
Re: Editing text with an external editor in Python gschemenauer3@gmail.com - 2014-09-01 19:24 -0700
csiph-web