added the rgb function to upiwin and started building the demo script

This commit is contained in:
Amy Bowersox 2019-12-11 12:05:53 -07:00
parent 65999084c4
commit 1088f630a0
5 changed files with 77 additions and 1 deletions

58
scripts/demo1.py Executable file
View File

@ -0,0 +1,58 @@
# Demo script that implements a simple drawing program
import upiwin
# Save off some color values.
WHITE = upiwin.rgb(255, 255, 255)
LTGRAY = upiwin.rgb(204, 204, 204)
YELLOW = upiwin.rgb(255, 255, 0)
hdc = upiwin.DevCtxt(type='screen')
# divide the screen into "drawing" and "command" areas
drawing_rect = hdc.get_clip_rect()
command_rect = drawing_rect
drawing_rect[2] -= 60;
command_rect[0] = drawing_rect[2] + 1
# further divide up the "command" area
cmd1_rect = command_rect
cmd2_rect = command_rect
cmd3_rect = command_rect
cmd4_rect = command_rect
cmd1_rect[3] = 60;
cmd2_rect[1] = 60;
cmd2_rect[3] = 120;
cmd3_rect[1] = 120;
cmd3_rect[3] = 180;
cmd4_rect[1] = 180;
def point_in_rect(rect, x, y):
return (x >= rect[0]) and (x < rect[2]) and (y >= rect[1]) and (y < rect[3])
# --- Initialize and start message loop ---
# Draw the basic layout.
hdc.set_text_color(LTGRAY)
hdc.rectangle(cmd1_rect[0], cmd1_rect[1], cmd1_rect[2], cmd1_rect[3])
hdc.rectangle(cmd2_rect[0], cmd2_rect[1], cmd2_rect[2], cmd2_rect[3])
hdc.rectangle(cmd3_rect[0], cmd3_rect[1], cmd3_rect[2], cmd3_rect[3])
hdc.rectangle(cmd4_rect[0], cmd4_rect[1], cmd4_rect[2], cmd4_rect[3])
# Main message loop
msg = {}
while upiwin.get_message(msg):
if msg['message'] == upiwin.WM_TOUCHCLICK:
if point_in_rect(cmd1_rect, msg['attrs'][0], msg['attrs'][1]):
print("Click command 1")
elif point_in_rect(cmd2_rect, msg['attrs'][0], msg['attrs'][1]):
print("Click command 2")
elif point_in_rect(cmd3_rect, msg['attrs'][0], msg['attrs'][1]):
print("Click command 3")
elif point_in_rect(cmd4_rect, msg['attrs'][0], msg['attrs'][1]):
print("Click command 4")
elif msg['message'] == upiwin.WM_HWBUTTONCLICK:
if msg['attrs'][0] == 4: # Button 4 = Exit app
upiwin.post_quit_message(0)

View File

@ -2,7 +2,7 @@ BUILDUTILS=../buildutils
RESOURCES=../resources RESOURCES=../resources
SPLASHSCREEN=splash-vmwcblk.png SPLASHSCREEN=splash-vmwcblk.png
OBJS=main.o sysinput.o ep_init.o ep_upiwin.o ep_backlight.o ep_msg.o ep_devctxt.o ep_bitmap.o \ OBJS=main.o sysinput.o ep_init.o ep_upiwin.o ep_backlight.o ep_msg.o ep_graphics.o ep_devctxt.o ep_bitmap.o \
ep_upiwin_tmp.o ep_util.o fbinit.o rect.o gfxobj.o devctxt.o dc_screen.o fontengine.o \ ep_upiwin_tmp.o ep_util.o fbinit.o rect.o gfxobj.o devctxt.o dc_screen.o fontengine.o \
bitmap.o fbprimitive.o log.o gpio.o msg_queue.o time_func.o config.o splash.o bitmap.o fbprimitive.o log.o gpio.o msg_queue.o time_func.o config.o splash.o
LIBS=-lpython3.7m -lcrypt -lfreetype -lbcm2835 -lpthread -ldl -lutil -lm LIBS=-lpython3.7m -lcrypt -lfreetype -lbcm2835 -lpthread -ldl -lutil -lm

13
src/ep_graphics.c Executable file
View File

@ -0,0 +1,13 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "wintype.h"
#include "gfxtype.h"
PyObject *Epython_rgb(PyObject *self, PyObject *args)
{
UINT32 r, g, b;
if (!PyArg_ParseTuple(args, "kkk", &r, &g, &b))
return NULL;
return PyLong_FromUnsignedLong(RGB(r, g, b));
}

View File

@ -23,6 +23,9 @@ static PyMethodDef UPIWINMethods[] = {
"Retrieves a message from the message queue, blocking if necessary."}, "Retrieves a message from the message queue, blocking if necessary."},
{"post_quit_message", Epython_post_quit_message, METH_VARARGS, {"post_quit_message", Epython_post_quit_message, METH_VARARGS,
"Posts a WM_QUIT message to the message queue, with an exit code."}, "Posts a WM_QUIT message to the message queue, with an exit code."},
/* Graphics functions */
{"rgb", Epython_rgb, METH_VARARGS,
"Creates a color value from separate red, green, and blue indexes."},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };

View File

@ -22,5 +22,7 @@ extern PyObject *Epython_set_backlight_level(PyObject *self, PyObject *args);
extern PyObject *Epython_get_message(PyObject *self, PyObject *args); extern PyObject *Epython_get_message(PyObject *self, PyObject *args);
extern PyObject *Epython_post_quit_message(PyObject *self, PyObject *args); extern PyObject *Epython_post_quit_message(PyObject *self, PyObject *args);
/* ep_graphics.c */
extern PyObject *Epython_rgb(PyObject *self, PyObject *args);
#endif /* __EP_UPIWIN_H_INCLUDED */ #endif /* __EP_UPIWIN_H_INCLUDED */