summaryrefslogtreecommitdiff
path: root/gem
diff options
context:
space:
mode:
authorJeff Armstrong <jeffrey.armstrong@approximatrix.com>2011-07-24 22:26:32 -0400
committerJeff Armstrong <jeffrey.armstrong@approximatrix.com>2011-07-24 22:26:32 -0400
commit5eaecae93f7ba32b6bec9515dfa465130bc8b808 (patch)
tree8eccbc1aafdbffc2684b43e77cffa0f9dbe7ecbd /gem
parentfce2b435d228d240e24656d6baf47f7d6022b730 (diff)
downloadgempy-5eaecae93f7ba32b6bec9515dfa465130bc8b808.tar.gz
gempy-5eaecae93f7ba32b6bec9515dfa465130bc8b808.zip
Added VDI routines. Added proper resource handling, some menu library code, and object library code.
Diffstat (limited to 'gem')
-rw-r--r--gem/aes.py99
-rw-r--r--gem/constants.py7
-rw-r--r--gem/vdi.py55
3 files changed, 157 insertions, 4 deletions
diff --git a/gem/aes.py b/gem/aes.py
index 23f7020..7d51598 100644
--- a/gem/aes.py
+++ b/gem/aes.py
@@ -72,6 +72,7 @@ class Window:
def destroy(self):
"""Deletes an existing GEM window"""
_gem.wind_delete(self.id)
+ self.id = None
def resize(self,rect):
"""Resizes/moves a window"""
@@ -80,7 +81,6 @@ class Window:
def top(self):
"""Sets the current window to topmost"""
_gem.wind_set(self.id,WF_TOP,(self.id,0,0,0))
- print "Topped!"
def set_name(self,name):
"""Sets the name of a window"""
@@ -93,6 +93,43 @@ class Window:
def end_update(self):
window_update(END_UPDATE)
+ def get_size(self):
+ """Returns the window position and size"""
+ return _gem.wind_get(self.id,WF_CURRXYWH)
+
+ def get_work_rect(self):
+ """Returns this window's current work area rectangle"""
+ return _gem.wind_get(self.id,WF_WORKXYWH)
+
+ def get_invalid_rectangles(self):
+ """Returns a list of rectangles requiring redrawing"""
+ rects = []
+ r = _gem.wind_get(self.id,WF_FIRSTXYWH)
+ while r[2] > 0 or r[3] > 0:
+ rects.append(r)
+ r = _gem.wind_get(self.id,WF_NEXTXYWH)
+
+ return rects
+
+ def intersect_work_area(self,rect):
+ """Returns the intersecting region of a rectangle and the window's workspace"""
+ wrect = self.get_work_rect()
+
+ tw = min(wrect[0]+wrect[2], rect[0]+rect[2])
+ th = min(wrect[1]+wrect[3], rect[1]+rect[3])
+ tx = max(wrect[0], rect[0])
+ ty = max(wrect[1], rect[1])
+
+ if (tw > tx) and (th > ty):
+ return (tx, ty, tw-tx, th-ty)
+ else:
+ return None
+
+ def graphics_handle(self):
+ """Returns a VDI handle to the screen"""
+ vh,ignore = _gem.graf_handle()
+ return vh
+
class Event:
def __init__(self):
pass
@@ -198,14 +235,35 @@ class Application:
except:
self.resource = False
raise GEMError("Could not load the resource file {0}".format(file))
+
+ def get_resource_item(self,type,index):
+ """Returns a capsule containing a resource item"""
+ return _gem.rsrc_gaddr(type,index)
+
+ def set_menu(self,item,show=True):
+ """Sets the application menu"""
+ if type(item) is int:
+ capsule = self.get_resource_address(R_OBJECT,item)
+ else:
+ capsule = item
+
+ action = MENU_SHOW
+ if type(show) is int:
+ action = show
+ elif not show:
+ action = MENU_HIDE
+ window_update(BEG_UPDATE)
+ _gem.menu_bar(capsule, action)
+ window_update(END_UPDATE)
+
def get_resource_address(self,type,index):
"""Retrieves the address of a resource element in a Python capsule.
The returned object should never be directly modified."""
if not self.resource:
raise GEMError("A resource has not yet be loaded")
- return _gem.rsrc.gaddr(type, index)
+ return _gem.rsrc_gaddr(type, index)
def new_window(self, rect, name=None):
"""Opens an application-managed window"""
@@ -283,4 +341,39 @@ class Application:
self.keyboard_event.keycode = ret['key']
self.keyboard_event.process()
- \ No newline at end of file
+ def graphics_handle(self):
+ """Returns a VDI handle to the screen"""
+ vh,ignore = _gem.graf_handle()
+ return vh
+
+ def send_message(self, data, target=None):
+ """Send a message to a gem application (self if target is None)"""
+ xmsg = data
+ if len(data) > 8:
+ raise ValueError("Message may only be 8 words long")
+ else:
+ while len(xmsg) < 8:
+ xmsg = xmsg + (0,)
+
+ bytemsg = struct.pack("@hhhhhhhh",*xmsg)
+
+ if target is None:
+ ret = _gem.appl_write(self.id, 16, bytemsg)
+ elif type(target) is int:
+ ret = _gem.appl_write(target, 16, bytemsg)
+ else:
+ ret = _gem.appl_write(target.id, 16, bytemsg)
+
+ return ret
+
+ def draw_object(self,object,depth,position=None,center=True):
+ """Draws an AES object (usually from a resource)"""
+ xpos = position
+ if center:
+ position = _gem.form_center(object)
+
+ _gem.objc_draw(object,0,depth,position)
+
+ def form_do(self,object):
+ """Executes a form (dialog)"""
+ return _gem.form_do(object,0) \ No newline at end of file
diff --git a/gem/constants.py b/gem/constants.py
index f4512eb..078818b 100644
--- a/gem/constants.py
+++ b/gem/constants.py
@@ -145,4 +145,9 @@ MB_CENTER = 0x0004
MB_KRSHIFT = 0x0001
MB_KLSHIFT = 0x0002
MB_KCONTROL = 0x0004
-MB_KALT = 0x0008 \ No newline at end of file
+MB_KALT = 0x0008
+
+# Menu menu_bar() definitions
+MENU_HIDE = 0
+MENU_SHOW = 1
+MENU_INSTL = 100
diff --git a/gem/vdi.py b/gem/vdi.py
new file mode 100644
index 0000000..581ab2d
--- /dev/null
+++ b/gem/vdi.py
@@ -0,0 +1,55 @@
+from error import GEMError
+from constants import *
+
+import _gem
+
+def get_screen_handle():
+ """Returns a VDI handle for the current screen"""
+ return _gem.v_open_screen()
+
+def close(handle):
+ """Closes the passed VDI handle"""
+ _gem.v_clsvwk(handle)
+
+
+# Drawing primitives
+def bar(handle,pt1,pt2=None):
+ """Draw a filled rectangle"""
+
+ xpt1 = pt1
+ if pt2 is None and len(pt1) == 4:
+ xpt1 = (pt1[0],pt1[1])
+ xpt2 = (pt1[0]+pt1[2],pt1[1]+pt1[3])
+ elif len(pt2) == 2 and len(pt1) == 2:
+ xpt2 = pt2
+ else:
+ raise ArgumentError('Points should be one (x,y,w,h) tuple or an (x,y) pair of tuples')
+
+ _gem.v_bar(handle,xpt1,xpt2)
+
+def ellipse(handle,center,radii):
+ """Draw eclipse"""
+ _gem.v_ellipse(handle,center,radii)
+
+def vsf_color(handle,index):
+ """Set the fill color index"""
+ _gem.vsf_color(handle,index)
+
+def vs_clip(handle, enable, pt1, pt2=None):
+ """Set the clipping region"""
+ xpt1 = pt1
+ if pt2 is None and len(pt1) == 4:
+ xpt1 = (pt1[0],pt1[1])
+ xpt2 = (pt1[0]+pt1[2],pt1[1]+pt1[3])
+ elif len(pt2) == 2 and len(pt1) == 2:
+ xpt2 = pt2
+ else:
+ raise ArgumentError('Point should be one (x,y,w,h) tuple or an (x,y) pair of tuples')
+
+ if enable:
+ xenable = 1
+ else:
+ xenable = 0
+
+ _gem.vs_clip(handle,xenable, xpt1, xpt2)
+ \ No newline at end of file