Menu

[62a5d4]: / pyedit.py  Maximize  Restore  History

Download this file

172 lines (128 with data), 5.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python
# ------------------------------------------------------------------------
# This is open source editor. Written on python. The motivation for
# this project was to create a modern multi-platform editor.
# Simple, powerful, configurable, extendable.
#
# Pyedit has:
#
# o macro recording/play,
# o search/replace,
# o functional navigation,
# o comment/string spell check,
# o auto backup,
# o persistent undo/redo,
# o auto complete, auto correct,
# o ... and a lot more.
#
# It is fast, it is extendable, as python lends itself to easy tinkering.
# The editor has a table driven key mapping. One can easily edit the key
# map in keyhand.py, and the key actions in acthand.py The default key map
# resembles gedit / wed / etp / brief
# ASCII only, fixed font only. For now ... Requires pygtk.
import os, sys, getopt, signal
import gobject, gtk
import pyedlib.keyhand, pyedlib.acthand
import pyedlib.pedutil, pyedlib.pedwin
import pyedlib.pedconfig, pyedlib.pedsql
import pyedlib.log
from pyedlib.pedutil import *
mainwin = None
show_timing = 0
show_config = 0
clear_config = 0
# ------------------------------------------------------------------------
def main(strarr):
if(pyedlib.pedconfig.conf.verbose):
print "PyEdit running on", "'" + os.name + "'", \
"GTK", gtk.gtk_version, "PyGtk", gtk.pygtk_version
signal.signal(signal.SIGTERM, terminate)
mainwin = pyedlib.pedwin.EdMainWindow(None, None, strarr)
pyedlib.pedconfig.conf.pedwin = mainwin
gtk.main()
def help():
print
print "PyEdit version: ", pyedlib.pedconfig.conf.version
print "Usage: " + os.path.basename(sys.argv[0]) + " [options] [[filename] ... [filenameN]]"
print "Options:"
print " -d level - Debug level 1-10. (Limited implementation)"
print " -v - Verbose (to stdout and log)"
print " -f - Start Full screen"
print " -c - Dump Config"
print " -x - Clear (eXtinguish) config (will prompt)"
print " -h - Help"
print
# ------------------------------------------------------------------------
def terminate(arg1, arg2):
if(pyedlib.pedconfig.conf.verbose):
print "Terminating pyedit.py, saving files to ~/pyedit"
# Save all
pyedlib.pedconfig.conf.pedwin.activate_quit(None)
#return signal.SIG_IGN
# Start of program:
if __name__ == '__main__':
# Redirect stdout to a fork to real stdout and log. This way messages can
# be seen even if pyedit is started without a terminal (from the GUI)
sys.stdout = pyedlib.log.fake_stdout()
opts = []; args = []
try:
opts, args = getopt.getopt(sys.argv[1:], "d:hfvxct")
except getopt.GetoptError, err:
print "Invalid option(s) on command line:", err
sys.exit(1)
#print "opts", opts, "args", args
pyedlib.pedconfig.conf.version = 0.23
for aa in opts:
if aa[0] == "-d":
try:
pgdebug = int(aa[1])
except:
pgdebug = 0
if aa[0] == "-h": help(); exit(1)
if aa[0] == "-f": pyedlib.pedconfig.conf.full_screen = True
if aa[0] == "-v": pyedlib.pedconfig.conf.verbose = True
if aa[0] == "-x": clear_config = True
if aa[0] == "-c": show_config = True
if aa[0] == "-t": show_timing = True
try:
if not os.path.isdir(pyedlib.pedconfig.conf.config_dir):
if(pyedlib.pedconfig.conf.verbose):
print "making", pyedlib.pedconfig.con.config_dir
os.mkdir(pyedlib.pedconfig.conf.config_dir)
except: pass
# Let the user know it needs fixin'
if not os.path.isdir(pyedlib.pedconfig.conf.config_dir):
print "Cannot access config dir:", pyedlib.pedconfig.conf.config_dir
sys.exit(1)
if not os.path.isdir(pyedlib.pedconfig.conf.data_dir):
if(pyedlib.pedconfig.conf.verbose):
print "making", pyedlib.pedconfig.con.data_dir
os.mkdir(pyedlib.pedconfig.conf.data_dir)
if not os.path.isdir(pyedlib.pedconfig.conf.macro_dir):
if(pyedlib.pedconfig.conf.verbose):
print "making", pyedlib.pedconfig.con.macro_dir
os.mkdir(pyedlib.pedconfig.conf.macro_dir)
# Initialize sqlite to load / save preferences & other info
sql = pyedlib.pedsql.pedsql(pyedlib.pedconfig.conf.sql_data)
# Initialize pedconfig for use
pyedlib.pedconfig.conf.sql = sql
pyedlib.pedconfig.conf.keyh = pyedlib.keyhand.KeyHand()
# To clear all config vars
if clear_config:
print "Are you sure you want to clear config ? (y/n)"
aa = sys.stdin.readline()
if aa[0] == "y":
print "Removing configuration ... ",
sql.rmall()
print "OK"
sys.exit(0)
# To check all config vars
if show_config:
print "Dumping configuration:"
ss = sql.getall();
for aa in ss:
print aa
sys.exit(0)
#pyedlib.log.printx("Started pyedit")
main(args[0:])
# EOF
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.