JGUI/gtktest.py
Joey Payne 3a31732a14 Refactored a lot of code. Added a preliminary text window
Put configuration options for window so that the rendering is controlled
on initialization of window.

Improved clip function to only clip before the borders.

Added a border radius class for initializing separate border radii for
each corner.
2014-02-04 22:54:05 -07:00

68 lines
2.4 KiB
Python

from testclasses import *
import pygtk, gtk, gobject, cairo
from gtk import gdk
class JGUIWidget(gtk.DrawingArea):
buttons = {1:'mouse-left',
2:'mouse-middle',
3:'mouse-right'}
def __init__(self, width, height):
super(JGUIWidget, self).__init__()
self.surf = TestSurface([width, height])
self.connect("expose_event", self.expose)
self.connect("motion_notify_event", self.mousemoved)
self.connect("button_press_event", self.mouse_down)
self.connect("button_release_event", self.mouse_up)
self.connect("configure_event", self.resize_win)
self.add_events(gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK)
gobject.timeout_add(int((1.0/60.0)*1000), self.tick)
self.width, self.height = width, height
self.set_size_request(width, height)
def mouse_up(self, widget, event):
self.surf.inject_mouse_up(self.buttons[event.button])
def mouse_down(self, widget, event):
self.surf.inject_mouse_down(self.buttons[event.button])
def resize_win(self, widget, event):
self.surf.notify_window_resize(event.width, event.height)
def tick(self):
self.alloc = self.get_allocation()
rect = gdk.Rectangle(self.alloc.x, self.alloc.y, self.alloc.width, self.alloc.height)
self.window.invalidate_rect(rect, True)
return True
def expose(self, widget, event):
self.surf.draw()
context = widget.window.cairo_create()
#Just set the source image to be the cairo image surface of the Surface object
context.set_source_surface(self.surf.csurface, 0, 0)
context.paint()
def mousemoved(self, widget, event):
self.surf.inject_mouse_position([event.x, event.y])
class GTKJGUI(object):
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title('JGUI Test')
self.window.connect("realize", self.realize)
self.window.connect("delete_event", gtk.main_quit)
self.drawingarea = JGUIWidget(800, 800)
self.window.add(self.drawingarea)
self.drawingarea.show()
self.window.show()
gtk.main()
def realize(self, widget):
pixmap = gtk.gdk.Pixmap(None, 1, 1, 1)
color = gtk.gdk.Color()
cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0)
widget.window.set_cursor(cursor)
if __name__ == '__main__':
GTKJGUI()