Tablet Pressure Testing via Python

For questions about using Classic.

Post » Sun Jan 24, 2010 11:55 am

Morning!

I am attempting to use the wintab libraries for Python, that I may access tablet packet information. In order to open the packet stream, one needs designate the hwnd or console window handle for the application. I'm not exactly sure what this is, since I'm not much of a programmer, but I can't figure out if it's possible to acquire this integer (it is an integer, right?) from within Construct.

This guy uses pygame to acquire it in his example, but that doesn't really work for me, and seems a bit far-reaching anyway, since Construct is generating the application, not Python. I also found it's possible with another library called wxPython, but have not tried it for the same reason.

Is hwnd accessible within Construct?
B
4
S
2
G
6
Posts: 161
Reputation: 2,597

Post » Sun Jan 24, 2010 6:58 pm

Use the 'window' object, it has an expression 'get application window' which i think returns a window handle. Hope that helps.
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Sun Jan 24, 2010 9:45 pm

That seems right!

I got it working. ^^; Thanks.
B
4
S
2
G
6
Posts: 161
Reputation: 2,597

Post » Sun Jan 24, 2010 10:56 pm

Why even use Construct then?
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun Jan 24, 2010 11:05 pm

Why even use anything? Nothing really matters. Abandon all hope.



This cheerful message brought to you by deadeye, brightening your days since 2007.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sun Jan 24, 2010 11:27 pm

construct and tablets? I wanna know what comes out of this =)
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Mon Jan 25, 2010 2:27 am

Good to know at least one person is supportive. :P I don't really understand newt's comment.

So far I've got pressure sensitivity reading fine, and it even works on other computers (took a while to figure out where to store the libraries, am learning). At the moment I am in my newbish way attempting to pull further packet data from the tablet driver connection, and will likely make a thread in Tutorials about tablet support when the methods become clear.
B
4
S
2
G
6
Posts: 161
Reputation: 2,597

Post » Mon Jan 25, 2010 5:31 am

storing external python libraries is something no one has explained (or done at all?) yet.
Could you post details about this?
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Mon Jan 25, 2010 7:18 am

[quote="Vrav":34sjgldl]Good to know at least one person is supportive. :P I don't really understand newt's comment.

So far I've got pressure sensitivity reading fine, and it even works on other computers (took a while to figure out where to store the libraries, am learning). At the moment I am in my newbish way attempting to pull further packet data from the tablet driver connection, and will likely make a thread in Tutorials about tablet support when the methods become clear.[/quote:34sjgldl]

You cant draw to the Construct window. At least thats the way I understand it.

[quote="Madster":34sjgldl]storing external python libraries is something no one has explained (or done at all?) yet.
Could you post details about this?[/quote:34sjgldl]

According to David everything should be exported to the exe. You will, however have to place the modules used into the folder construct\data\python... when everything works correctly.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Jan 25, 2010 8:00 am

"can't draw to the construct window" -> Certainly you can! Here's what I had back in May '09:



That wasn't even with pressure sensitivity.

[quote:2mapg3b3]storing external python libraries is something no one has explained (or done at all?) yet.[/quote:2mapg3b3]

It was not very difficult. What newt says about exporting the scripts to exe is correct - but only for scripts. If the scripts in question reference any other files, in my case a compiled .pyd file, you don't want to pack those in the same way as the scripts, because the bundled .py files are read from a zip within the Temp directory at runtime, and the scripts can't seem to reference the contents of that zip.

At first this had me confused, but as soon as I looked at what it was doing, everything made sense. The test app was functional within Construct, because it could read the libraries the scripts were using from various locations - Construct\Data\Python, where I'd placed them manually, but also from the Python26\Lib\etc directories. Of course, for distribution, you are not going to want to require that the user install Python and a special library just to run your program. So what I did was tossed the extra, non-.py libraries in the exe's directory.

It seems that simple!

I've only had one friend try it, though, so if anyone with a tablet wants to help - it's rather featureless, but - here is a 7z and a zip of the test application. They are identical. In reality, people without tablets should be able to test it as well. If it's all bundled correctly, it should not pop up any errors when loading the exe.

http://dl.dropbox.com/u/398143/Files/PressureTest.7z (1,324 KB)
http://dl.dropbox.com/u/398143/Files/PressureTest.zip (1,906 KB)

There is a boost_python-vc90-mt-1_39.dll in there that I don't think is actually being used. It seems to work fine without it at the moment. Wintab uses it for something, presumably - I have simply not accessed many features just yet. Also! Since I have it reading sensitivity, but not delivering any other actual information about the tablet to Construct, this is hardcoded to function properly with tablets that possess 1024 levels of pressure sensitivity alone. If tablets with different sensitivity levels exist, it will probably behave unusually.

If you are going to bundle libraries and such accessed by your python scripts in your own project, but aren't writing all your imported scripts from scratch (such as wintab, which communicates with tablet drivers), you may need to fiddle with the directory context of the various 'import' calls within the scripts. For example, wintab is stored within cgkit in Python, but I am using it outside of cgkit, and therefore simplified the file organization. I am not really sure how intuitive Python is when it comes to importing resources (where it will look, and how deep) but the error reporting in Construct proved invaluable for rooting out which scripts needed tweaking where.
B
4
S
2
G
6
Posts: 161
Reputation: 2,597

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests