resedit.py :  » Language-Interface » ChinesePython » chinesepython2.1.3-0.4 » Mac » Modules » res » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » ChinesePython 
ChinesePython » chinesepython2.1.3 0.4 » Mac » Modules » res » resedit.py
resource_body = """
char *buf;
int len;
Handle h;

if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
  return NULL;
h = NewHandle(len);
if ( h == NULL ) {
  PyErr_NoMemory();
  return NULL;
}
HLock(h);
memcpy(*h, buf, len);
HUnlock(h);
return ResObj_New(h);
"""

f = ManualGenerator("Resource", resource_body)
f.docstring = lambda: """Convert a string to a resource object.

The created resource object is actually just a handle,
apply AddResource() to write it to a resource file.
See also the Handle() docstring.
"""
functions.append(f)

handle_body = """
char *buf;
int len;
Handle h;
ResourceObject *rv;

if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
  return NULL;
h = NewHandle(len);
if ( h == NULL ) {
  PyErr_NoMemory();
  return NULL;
}
HLock(h);
memcpy(*h, buf, len);
HUnlock(h);
rv = (ResourceObject *)ResObj_New(h);
rv->ob_freeit = PyMac_AutoDisposeHandle;
return (PyObject *)rv;
"""

f = ManualGenerator("Handle", handle_body)
f.docstring = lambda: """Convert a string to a Handle object.

Resource() and Handle() are very similar, but objects created with Handle() are
by default automatically DisposeHandle()d upon object cleanup. Use AutoDispose()
to change this.
"""
functions.append(f)

# Convert resources to other things.

as_xxx_body = """
return %sObj_New((%sHandle)_self->ob_itself);
"""

def genresconverter(longname, shortname):

  f = ManualGenerator("as_%s"%longname, as_xxx_body%(shortname, longname))
  docstring =  "Return this resource/handle as a %s"%longname
  f.docstring = lambda docstring=docstring: docstring
  return f

resmethods.append(genresconverter("Control", "Ctl"))
resmethods.append(genresconverter("Menu", "Menu"))

# The definition of this one is MacLoadResource, so we do it by hand...

f = ResMethod(void, 'LoadResource',
    (Handle, 'theResource', InMode),
)
resmethods.append(f)

#
# A method to set the auto-dispose flag
#
AutoDispose_body = """
int onoff, old = 0;
if (!PyArg_ParseTuple(_args, "i", &onoff))
  return NULL;
if ( _self->ob_freeit )
  old = 1;
if ( onoff )
  _self->ob_freeit = PyMac_AutoDisposeHandle;
else
  _self->ob_freeit = NULL;
return Py_BuildValue("i", old);
"""
f = ManualGenerator("AutoDispose", AutoDispose_body)
f.docstring = lambda: "(int)->int. Automatically DisposeHandle the object on Python object cleanup"
resmethods.append(f)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.