Top-rated recipes tagged "ctypes" but not "threading" and "remove"http://code.activestate.com/recipes/tags/-threading+ctypes-remove/top/2016-05-09T18:00:44-07:00ActiveState Code RecipesCalling Windows API using ctypes and win32con (Python)
2008-07-25T20:01:50-07:00Gary Eakinshttp://code.activestate.com/recipes/users/470921/http://code.activestate.com/recipes/208699-calling-windows-api-using-ctypes-and-win32con/
<p style="color: grey">
Python
recipe 208699
by <a href="/recipes/users/470921/">Gary Eakins</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/windows_api/">windows_api</a>).
Revision 4.
</p>
<p>It is easy to call Windows API dlls using the
ctypes module with win32con defining the
constant values for message identifiers and
parameter flags. The demo code shows a simple
but complete application that registers a
window class and a Python WndProc callback function,
creates the window and pumps messages.</p>
C function decorator (Python)
2009-04-29T23:55:03-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576731-c-function-decorator/
<p style="color: grey">
Python
recipe 576731
by <a href="/recipes/users/4170000/">geremy condra</a>
(<a href="/recipes/tags/cpp/">cpp</a>, <a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/function/">function</a>).
Revision 6.
</p>
<p>This recipe provides an easy-to-use, decorator-based solution to the problem of using functions from other languages, especially C, in Python. It takes advantage of Python's new annotations to provide simple type checking and automatic conversion. If you like it, you may also want to check out my <a href="http://code.activestate.com/recipes/576734/">C structure decorator</a></p>
Windows directory walk using ctypes (Python)
2013-08-09T00:17:00-07:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/578629-windows-directory-walk-using-ctypes/
<p style="color: grey">
Python
recipe 578629
by <a href="/recipes/users/4168519/">Shao-chuan Wang</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/system/">system</a>).
</p>
<p>Windows shell/explorer has a limit size of full path, but both NTFS and ReFS can support full path longer than the limit; this is making os.walk on Windows bad if files are in deeply nested folders, and therefore this recipe.</p>
Get memory usage of Windows processes using GetProcessMemoryInfo (via ctypes) (Python)
2013-04-25T01:26:19-07:00Ben Hoythttp://code.activestate.com/recipes/users/4170919/http://code.activestate.com/recipes/578513-get-memory-usage-of-windows-processes-using-getpro/
<p style="color: grey">
Python
recipe 578513
by <a href="/recipes/users/4170919/">Ben Hoyt</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/win32/">win32</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>These functions call the Win32 function GetProcessMemoryInfo() using ctypes to get the memory usage of the current process. Works on both 32-bit and 64-bit Windows and Python 2.6+ (including Python 3.x).</p>
Calling (C-level) finalizers without __del__ (Python)
2011-07-02T18:42:08-07:00Benjamin Petersonhttp://code.activestate.com/recipes/users/4170802/http://code.activestate.com/recipes/577242-calling-c-level-finalizers-without-__del__/
<p style="color: grey">
Python
recipe 577242
by <a href="/recipes/users/4170802/">Benjamin Peterson</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/finalization/">finalization</a>, <a href="/recipes/tags/weakref/">weakref</a>).
Revision 3.
</p>
<p>This recipe is meant for Python classes wrapping ctypes bindings where a C-level finalizer must be invoked when the wrapper is destroyed. It uses weakref callbacks to avoid problems with <code>__del__</code>.</p>
Thinkpad Turtle (Python)
2010-03-26T20:04:05-07:00Michael Grünewaldhttp://code.activestate.com/recipes/users/4172244/http://code.activestate.com/recipes/576985-thinkpad-turtle/
<p style="color: grey">
Python
recipe 576985
by <a href="/recipes/users/4172244/">Michael Grünewald</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/thinkpad/">thinkpad</a>, <a href="/recipes/tags/win32/">win32</a>, <a href="/recipes/tags/windows/">windows</a>).
Revision 4.
</p>
<p>A small program utilizing the <code>ctypes</code> and <code>turtle</code> modules. You can <em>drive</em> the little turtle by turning your Thinkpad (which must have APS).</p>
<p><em>Requirements:</em></p>
<p>You need a newer Thinkpad (T41, T42, T43, T6x, R5x, R6x or any newer) and need to have the Active Protection System drivers (now called Lenovo Airbag Protection) installed.</p>
Shutdown your PC by using ctypes (Win32 Platform) (Python)
2009-08-03T10:05:38-07:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/576865-shutdown-your-pc-by-using-ctypes-win32-platform/
<p style="color: grey">
Python
recipe 576865
by <a href="/recipes/users/4168519/">Shao-chuan Wang</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/reboot/">reboot</a>, <a href="/recipes/tags/shutdown/">shutdown</a>, <a href="/recipes/tags/system_programming/">system_programming</a>, <a href="/recipes/tags/win32/">win32</a>).
</p>
<p>It is true that by using win32 extension python modules, such as win32api, win32con, and win32security, we can easily shutdown the computer with a few steps. However, sometimes your python's runtime environment does not provide win32com module (because it is not a build-in module), we may have to shutdown the pc on our own.</p>
<p>By using ctypes, we are still able to shutdown or reboot the PC easily.</p>
Control CPU Usage by using ctypes (Win32 Platform) (Python)
2009-01-26T09:32:34-08:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/576634-control-cpu-usage-by-using-ctypes-win32-platform/
<p style="color: grey">
Python
recipe 576634
by <a href="/recipes/users/4168519/">Shao-chuan Wang</a>
(<a href="/recipes/tags/cpu_usage/">cpu_usage</a>, <a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/system_programming/">system_programming</a>, <a href="/recipes/tags/win32/">win32</a>).
Revision 3.
</p>
<p>This program will make your cpu work at a given cpu usage. It should be also able to work on machines with multi-processors. The program has been tested on Windows xp sp2 with python of version 2.5.4.</p>
<p>The implementation is based on the fact that it will adjust the ratio of being busy over being idle in the main process to approach the target cpu usage rate. </p>
Using ctypes to call C code from Python (Python)
2016-05-09T18:00:44-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580660-using-ctypes-to-call-c-code-from-python/
<p style="color: grey">
Python
recipe 580660
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/ffi/">ffi</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/time/">time</a>).
</p>
<p>This recipe shows basic usage of the ctypes module to call C code from Python code.</p>
Simple video with ctypes and Xvid (Tkinter,pygame,...) (Python)
2015-06-29T13:59:38-07:00Jiri Justrahttp://code.activestate.com/recipes/users/4192188/http://code.activestate.com/recipes/579073-simple-video-with-ctypes-and-xvid-tkinterpygame/
<p style="color: grey">
Python
recipe 579073
by <a href="/recipes/users/4192188/">Jiri Justra</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/video/">video</a>, <a href="/recipes/tags/xvid/">xvid</a>).
</p>
<p>This is simple library for playing avi video clips. Videos must be SOUNDLESS (and maybe Xvid encoded wont hurt), to work it properly. I am using it to play intro. It suites good to this purpose, since it can play one clip at a time only.</p>
car.py (Ctypes ARchiver in PYthon [libarchive ffi wrapper]) (Python)
2013-05-28T04:02:15-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578531-carpy-ctypes-archiver-in-python-libarchive-ffi-wra/
<p style="color: grey">
Python
recipe 578531
by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a>
(<a href="/recipes/tags/bzip2/">bzip2</a>, <a href="/recipes/tags/cpio/">cpio</a>, <a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/ffi/">ffi</a>, <a href="/recipes/tags/gzip/">gzip</a>, <a href="/recipes/tags/lzma/">lzma</a>, <a href="/recipes/tags/pax/">pax</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tar/">tar</a>).
Revision 3.
</p>
<p>CTypes libarchive wrapper, handles extraction only with no arguments.</p>
POSIX Semaphore (FreeBSD) (Python)
2011-04-14T17:54:16-07:00David Naylorhttp://code.activestate.com/recipes/users/4177661/http://code.activestate.com/recipes/577655-posix-semaphore-freebsd/
<p style="color: grey">
Python
recipe 577655
by <a href="/recipes/users/4177661/">David Naylor</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/freebsd/">freebsd</a>, <a href="/recipes/tags/semaphores/">semaphores</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/threads/">threads</a>).
</p>
<p>POSIX Semaphore bindings for FreeBSD. </p>
DDE Client (Python)
2011-04-14T16:33:19-07:00David Naylorhttp://code.activestate.com/recipes/users/4177661/http://code.activestate.com/recipes/577654-dde-client/
<p style="color: grey">
Python
recipe 577654
by <a href="/recipes/users/4177661/">David Naylor</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/dde/">dde</a>, <a href="/recipes/tags/win32/">win32</a>).
</p>
<p>A DDE Client using ctypes for Windows. Unlike the pywin32 implementation this code supports advice requests. </p>
Altering immutable string object. (Python)
2010-01-11T06:11:05-08:00Pepe Aracilhttp://code.activestate.com/recipes/users/4171769/http://code.activestate.com/recipes/577000-altering-immutable-string-object/
<p style="color: grey">
Python
recipe 577000
by <a href="/recipes/users/4171769/">Pepe Aracil</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/immutable/">immutable</a>).
Revision 3.
</p>
<p>"Useless" alteration of immutable string object in 100% pure python. :) </p>
Detect when system is idle (Python)
2009-05-31T01:18:03-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/576786-detect-when-system-is-idle/
<p style="color: grey">
Python
recipe 576786
by <a href="/recipes/users/924636/">Gabriel Genellina</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/idle/">idle</a>, <a href="/recipes/tags/idle_time/">idle_time</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/user_input/">user_input</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>Detect when system is idle, globally. That is, the user is not moving the mouse nor typing anything, in any application (not just our program).</p>
Get CPU Usage by using ctypes (Win32 Platform) (Python)
2009-01-26T06:43:38-08:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/576631-get-cpu-usage-by-using-ctypes-win32-platform/
<p style="color: grey">
Python
recipe 576631
by <a href="/recipes/users/4168519/">Shao-chuan Wang</a>
(<a href="/recipes/tags/cpu_usage/">cpu_usage</a>, <a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/system_programming/">system_programming</a>, <a href="/recipes/tags/win32/">win32</a>).
Revision 2.
</p>
<p>The following code has been tested at Windows XP sp2 with Python of version 2.5.4.</p>
Low level inotify wrapper (Python)
2013-08-12T14:39:57-07:00Louis RIVIEREhttp://code.activestate.com/recipes/users/4035877/http://code.activestate.com/recipes/576375-low-level-inotify-wrapper/
<p style="color: grey">
Python
recipe 576375
by <a href="/recipes/users/4035877/">Louis RIVIERE</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/inotify/">inotify</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/system/">system</a>).
Revision 10.
</p>
<p>This module is meant to be as simple and straightforward as it gets.</p>
How to Mutate a Float (Python)
2012-05-14T16:49:13-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578132-how-to-mutate-a-float/
<p style="color: grey">
Python
recipe 578132
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/experiment/">experiment</a>, <a href="/recipes/tags/float/">float</a>, <a href="/recipes/tags/structure/">structure</a>).
</p>
<p>This is just an experiment to test my mental understanding of Python. It should not be used in any code as is violates the design principle that floats are to be immutable. The code also abuses <code>ctypes</code> and an understanding of how <code>floats</code> are currently arranged in memory. <code>set_float</code> is not guaranteed to work properly on any system, and may fail to work in the future if the data's arrangement changes.</p>
ctype Enumeration class (Python)
2008-08-10T16:45:46-07:00Devan L Devan Lhttp://code.activestate.com/recipes/users/4166311/http://code.activestate.com/recipes/576415-ctype-enumeration-class/
<p style="color: grey">
Python
recipe 576415
by <a href="/recipes/users/4166311/">Devan L Devan L</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>).
</p>
<p>An example Enumeration class and metaclass to declare an enumeration in ctypes.</p>