Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d211220

Browse files
committed
checkin of Jack's original version
1 parent df804f8 commit d211220

27 files changed

Lines changed: 1525 additions & 0 deletions

Tools/modulator/EXAMPLE.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# Example input file for modulator if you don't have tk.
3+
#
4+
# You may also have to strip some imports out of modulator to make
5+
# it work.
6+
#
7+
# Generate code for a simple object with a method called sample
8+
9+
o = genmodule.object()
10+
o.name = 'simple object'
11+
o.abbrev = 'simp'
12+
o.methodlist = ['sample']
13+
o.funclist = ['new']
14+
15+
#
16+
# Generate code for an object that looks numberish
17+
#
18+
o2 = genmodule.object()
19+
o2.name = 'number-like object'
20+
o2.abbrev = 'nl'
21+
o2.typelist = ['tp_as_number']
22+
o2.funclist = ['new', 'tp_repr', 'tp_compare']
23+
24+
#
25+
# Generate code for a method with a full complement of functions,
26+
# some methods, accessible as sequence and allowing structmember.c type
27+
# structure access as well.
28+
#
29+
o3 = genmodule.object()
30+
o3.name = 'over-the-top object'
31+
o3.abbrev = 'ot'
32+
o3.methodlist = ['method1', 'method2']
33+
o3.funclist = ['new', 'tp_dealloc', 'tp_print', 'tp_getattr', 'tp_setattr',
34+
'tp_compare', 'tp_repr', 'tp_hash']
35+
o3.typelist = ['tp_as_sequence', 'structure']
36+
37+
#
38+
# Now generate code for a module that incorporates these object types.
39+
# Also add the boilerplates for functions to create instances of each
40+
# type.
41+
#
42+
m = genmodule.module()
43+
m.name = 'sample'
44+
m.abbrev = 'sample'
45+
m.methodlist = ['newsimple', 'newnumberish', 'newott']
46+
m.objects = [o, o2, o3]

Tools/modulator/README

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This is release 1.0 of modulator, a generator of boilerplate code for
2+
modules to be written in C.
3+
4+
Usage when you have tk is *reall* simple: start modulator, fill out
5+
the forms specifying all the objects and methods, tell modulator
6+
whether objects should also be accessible as sequences, etc and press
7+
'generate code'. It will write a complete skeleton module for you.
8+
9+
Usage when you don't have tk is slightly more difficult. Look at
10+
EXAMPLE.py for some details.
11+
12+
Oh yeah: you'll probably want to change Templates/copyright, or all
13+
your code ends up as being copyrighted to CWI:-)
14+
15+
Let me know what you think,
16+
Jack Jansen, [email protected]
17+

Tools/modulator/ScrolledListbox.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# A ScrolledList widget feels like a list widget but also has a
2+
# vertical scroll bar on its right. (Later, options may be added to
3+
# add a horizontal bar as well, to make the bars disappear
4+
# automatically when not needed, to move them to the other side of the
5+
# window, etc.)
6+
#
7+
# Configuration options are passed to the List widget.
8+
# A Frame widget is inserted between the master and the list, to hold
9+
# the Scrollbar widget.
10+
# Most methods calls are inherited from the List widget; Pack methods
11+
# are redirected to the Frame widget however.
12+
13+
from Tkinter import *
14+
from Tkinter import _cnfmerge
15+
16+
class ScrolledListbox(Listbox):
17+
def __init__(self, master=None, cnf={}):
18+
cnf = _cnfmerge(cnf)
19+
fcnf = {}
20+
vcnf = {'name': 'vbar',
21+
Pack: {'side': 'right', 'fill': 'y'},}
22+
for k in cnf.keys():
23+
if type(k) == ClassType or k == 'name':
24+
fcnf[k] = cnf[k]
25+
del cnf[k]
26+
self.frame = Frame(master, fcnf)
27+
self.vbar = Scrollbar(self.frame, vcnf)
28+
cnf[Pack] = {'side': 'left', 'fill': 'both', 'expand': 'yes'}
29+
cnf['name'] = 'list'
30+
Listbox.__init__(self, self.frame, cnf)
31+
self['yscrollcommand'] = (self.vbar, 'set')
32+
self.vbar['command'] = (self, 'yview')
33+
34+
# Copy Pack methods of self.frame -- hack!
35+
for m in Pack.__dict__.keys():
36+
if m[0] != '_' and m != 'config':
37+
setattr(self, m, getattr(self.frame, m))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/***********************************************************
2+
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3+
The Netherlands.
4+
5+
All Rights Reserved
6+
7+
Permission to use, copy, modify, and distribute this software and its
8+
documentation for any purpose and without fee is hereby granted,
9+
provided that the above copyright notice appear in all copies and that
10+
both that copyright notice and this permission notice appear in
11+
supporting documentation, and that the names of Stichting Mathematisch
12+
Centrum or CWI not be used in advertising or publicity pertaining to
13+
distribution of the software without specific, written prior permission.
14+
15+
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16+
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17+
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18+
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22+
23+
******************************************************************/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
#include "allobjects.h"
3+
#include "modsupport.h" /* For getargs() etc. */
4+
5+
static object *ErrorObject;
6+
7+
/* ----------------------------------------------------- */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
static object *
3+
$abbrev$_$method$(self, args)
4+
object *self; /* Not used */
5+
object *args;
6+
{
7+
8+
if (!newgetargs(args, ""))
9+
return NULL;
10+
INCREF(None);
11+
return None;
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
/* List of methods defined in the module */
3+
4+
static struct methodlist $abbrev$_methods[] = {
5+
$methodlist$
6+
{NULL, NULL} /* sentinel */
7+
};
8+
9+
10+
/* Initialization function for the module (*must* be called init$name$) */
11+
12+
void
13+
init$name$()
14+
{
15+
object *m, *d;
16+
17+
/* Create the module and add the functions */
18+
m = initmodule("$name$", $abbrev$_methods);
19+
20+
/* Add some symbolic constants to the module */
21+
d = getmoduledict(m);
22+
ErrorObject = newstringobject("$name$.error");
23+
dictinsert(d, "error", ErrorObject);
24+
25+
/* XXXX Add constants here */
26+
27+
/* Check for errors */
28+
if (err_occurred())
29+
fatal("can't initialize module $name$");
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* Declarations for objects of type $name$ */
2+
3+
typedef struct {
4+
OB_HEAD
5+
/* XXXX Add your own stuff here */
6+
} $abbrev$object;
7+
8+
staticforward typeobject $Abbrev$type;
9+
10+
#define is_$abbrev$object(v) ((v)->ob_type == &$Abbrev$type)
11+
12+
/* ---------------------------------------------------------------- */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
static object *
3+
$abbrev$_$method$(self, args)
4+
$abbrev$object *self;
5+
object *args;
6+
{
7+
if (!newgetargs(args, ""))
8+
return NULL;
9+
INCREF(None);
10+
return None;
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
static struct methodlist $abbrev$_methods[] = {
3+
$methodlist$
4+
{NULL, NULL} /* sentinel */
5+
};
6+
7+
/* ---------- */

0 commit comments

Comments
 (0)