Insert Date and Time

master
Yevgen Muntyan 2007-11-26 02:45:23 -06:00
parent 103b32915d
commit b63da1d89e
4 changed files with 107 additions and 1 deletions

View File

@ -124,3 +124,18 @@ accel=<alt>M
Left() Left()
Select(-1) Select(-1)
end end
[tool]
id=InsertDateAndTime
type=python
name=Insert Date and Time
options=need-doc
# insert_date_and_time.py is installed in
# $prefix/lib/moo/plugins/lib
from insert_date_and_time import get_format
import time
fmt = get_format(window)
if fmt is not None:
buffer.insert_at_cursor(time.strftime(fmt))

View File

@ -29,8 +29,11 @@ moopython_plugins_DATA = \
$(ini_files) \ $(ini_files) \
$(plugins) $(plugins)
plugins_lib_DATA = \
lib/pyconsole.py \
lib/insert_date_and_time.py
nobase_plugins_lib_DATA = \ nobase_plugins_lib_DATA = \
pyconsole.py \
medit/__init__.py \ medit/__init__.py \
medit/runpython.py medit/runpython.py

View File

@ -0,0 +1,88 @@
import gtk
import time
import moo
# List of formats is shamelessly stolen from gedit
formats = [
"%c",
"%x",
"%X",
"%x %X",
"%Y-%m-%d %H:%M:%S",
"%a %b %d %H:%M:%S %Z %Y",
"%a %b %d %H:%M:%S %Y",
"%a %d %b %Y %H:%M:%S %Z",
"%a %d %b %Y %H:%M:%S",
"%d/%m/%Y",
"%d/%m/%y",
"%D",
"%A %d %B %Y",
"%A %B %d %Y",
"%Y-%m-%d",
"%d %B %Y",
"%B %d, %Y",
"%A %b %d",
"%H:%M:%S",
"%H:%M",
"%I:%M:%S %p",
"%I:%M %p",
"%H.%M.%S",
"%H.%M",
"%I.%M.%S %p",
"%I.%M %p",
"%d/%m/%Y %H:%M:%S",
"%d/%m/%y %H:%M:%S",
]
moo.utils.prefs_new_key_string('Tools/InsertDateAndTime', '%c')
def populate_tree_view(treeview):
model = gtk.ListStore(str, str)
curtime = time.localtime()
default_iter = None
default_fmt = moo.utils.prefs_get_string('Tools/InsertDateAndTime')
for fmt in formats:
iter = model.append([time.strftime(fmt, curtime), fmt])
if default_fmt == fmt:
default_iter = iter
cell = gtk.CellRendererText()
column = gtk.TreeViewColumn(None, cell, text=0)
treeview.append_column(column)
treeview.set_model(model)
if default_iter is not None:
treeview.get_selection().select_iter(default_iter)
def get_format_from_list(treeview):
model, row = treeview.get_selection().get_selected()
fmt = model[row][1]
moo.utils.prefs_set_string('Tools/InsertDateAndTime', fmt)
return fmt
def get_format(parent=None):
window = gtk.Dialog("Select Format", parent, 0,
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
window.set_size_request(250, 300)
swindow = gtk.ScrolledWindow()
treeview = gtk.TreeView()
swindow.add(treeview)
swindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
swindow.show_all()
window.vbox.pack_start(swindow)
populate_tree_view(treeview)
treeview.set_headers_visible(False)
treeview.connect('row-activated', lambda tv, path, clmn, dlg:
dlg.response(gtk.RESPONSE_ACCEPT), window)
fmt = None
if window.run() == gtk.RESPONSE_ACCEPT:
fmt = get_format_from_list(treeview)
window.destroy()
return fmt
if __name__ == '__main__':
print get_format()