Beispiel #1
0
    def wininit(self):
        if self.__initialized:
            return
        self.__initialized = 1
        import struct
        if struct.pack('i', 1)[:1] == '\001':
            # little endian
            self.byteorder = X.LSBFirst
        else:
            # big endian
            self.byteorder = X.MSBFirst
        Xt.ToolkitInitialize()
        Xt.SetFallbackResources(resources)
        try:
            self.dpy = dpy = Xt.OpenDisplay(None, None, 'GRiNS',
                                            [], sys.argv)
        except:
            print 'Cannot open display'
            sys.exit(1)
##         dpy.Synchronize(1)
        try:
            import glX, glXconst
            visual = dpy.ChooseVisual([glXconst.GLX_RGBA,
                                       glXconst.GLX_RED_SIZE, 1,
                                       glXconst.GLX_GREEN_SIZE, 1,
                                       glXconst.GLX_BLUE_SIZE, 1])
            visuals = [visual]
        except:
            for cl, dp in tryvisuals:
                visuals = dpy.GetVisualInfo({'class': cl,
                                             'depth': dp})
                if visuals:
                    break
            else:
                raise error, 'no proper visuals available'
        self.visual = visual = visuals[0]
        self.imgformat, self.colormap, \
                        self.red_shift, self.red_mask, \
                        self.green_shift, self.green_mask, \
                        self.blue_shift, self.blue_mask = \
                                findformat(dpy, visual)
        main = Xt.CreateApplicationShell('splash', Xt.ApplicationShell,
                                         {'visual': visual,
                                          'depth': visual.depth,
                                          'colormap': self.colormap,
                                          'mappedWhenManaged': X.FALSE,
                                          'input': X.TRUE,
                                          'x': 500, 'y': 500,
                                          'width':1, 'height':1})
        main.RealizeWidget()
        self.main = main
        self.watchcursor = dpy.CreateFontCursor(Xcursorfont.watch)
Beispiel #2
0
 def canceltimer(self, id):
     if id is not None:
         tid = id.get()
         if tid is not None:
             Xt.RemoveTimeOut(tid)
         else:
             print 'canceltimer of bad timer'
         id.destroy()
Beispiel #3
0
 def select_setcallback(self, fd, func, args, mask = ReadMask):
     import Xtdefs
     if type(fd) is not IntType:
         fd = fd.fileno()
     if self._fdiddict.has_key(fd):
         id = self._fdiddict[fd]
         Xt.RemoveInput(id)
         del self._fdiddict[fd]
     if func is None:
         return
     xmask = 0
     if mask & ReadMask:
         xmask = xmask | Xtdefs.XtInputReadMask
     if mask & WriteMask:
         xmask = xmask | Xtdefs.XtInputWriteMask
     self._fdiddict[fd] = Xt.AddInput(fd, xmask,
                                      self._input_callback,
                                      (func, args))
Beispiel #4
0
 def settimer(self, sec, cb):
     if __debug__:
         # sanity check
         func, args = cb
         if not callable(func):
             raise error, 'callback function not callable'
     id = _Timer()
     tid = Xt.AddTimeOut(int(sec * 1000), id.cb, cb)
     id.set(tid)
     return id
Beispiel #5
0
def main():
	RemoteCallServer.VERBOSE = 2

	# By default, use system generated port
	port = 0

	# Create socket at port 'port' (or at system generated port
	# if port == 0).
	server = TestServer(port)

	# Register server in Xt dispatcher
	server.XtAddInput()
	server.SendAsAgent(serverdefs.StupidServer)

	print 'OK, waiting on port', server.Port(), '...'

	import Xt
	Xt.MainLoop()
Beispiel #6
0
import sys, Xt, Xm, X, img, imgformat, imgconvert
imgconvert.settrace(1)
error = 'xtestview.error'
vselect = {}
# handle arguments
i = 1
while i < len(sys.argv):
	if sys.argv[i] == '-visualid':
		del sys.argv[i]
		if i == len(sys.argv):
			raise error, '-visualid needs an argument'
		vselect['visualid'] = eval(sys.argv[i])
		del sys.argv[i]
		continue
	if sys.argv[i] == '-depth':
		del sys.argv[i]
		if i == len(sys.argv):
			raise error, '-depth needs an argument'
		vselect['depth'] = eval(sys.argv[i])
		del sys.argv[i]
		continue
	if sys.argv[i] == '-visual':
		del sys.argv[i]
		if i == len(sys.argv):
			raise error, '-visual needs an argument'
		if sys.argv[i] == 'TrueColor':
			vselect['class'] = X.TrueColor
		elif sys.argv[i] == 'PseudoColor':
			vselect['class'] = X.PseudoColor
		else:
Beispiel #7
0
 def create_box(self,
                msg,
                callback,
                box=None,
                units=UNIT_SCREEN,
                modeless=0):
     import Xcursorfont
     if modeless:
         if not box:
             raise error, 'can only be modeless with box'
     if self._in_create_box and not self._in_create_box.is_closed():
         self._in_create_box.cancel_create_box()
     if self.is_closed():
         apply(callback, ())
         return
     _RubberBand._in_create_box = self
     self._ignore_rb = 0
     self.pop(poptop=0)
     self.__dl = self._active_displist
     if self.__dl:
         d = self.__dl.clone()
     else:
         d = self.newdisplaylist()
     self.__transparent = []
     sw = self._subwindows[:]
     sw.reverse()
     r = Xlib.CreateRegion()
     for win in sw:
         if not win._transparent:
             # should do this recursively...
             self.__transparent.append(win)
             win._transparent = 1
             d.drawfbox(win._bgcolor, win._sizes)
             apply(r.UnionRectWithRegion, win._rect)
     for win in sw:
         b = win._sizes
         if b != (0, 0, 1, 1):
             d.drawbox(b)
     self.__display = d.clone()
     if box:
         self.__drawbox(d, SELCOLOR, box, units)
     if self.__transparent:
         self._do_expose(r)
         self.__reg = r
     d.render()
     self.__curdisp = d
     if msg:
         msg = msg + '\n\n' + _rb_message
     else:
         msg = _rb_message
     self.__callback = callback
     self.__units = units
     form = self._form
     cursor = form.Display().CreateFontCursor(Xcursorfont.crosshair)
     if not modeless:
         self.__dialog = showmessage(msg,
                                     mtype='message',
                                     grab=0,
                                     callback=(self.__done, ()),
                                     cancelCallback=(self.cancel_create_box,
                                                     ()))
         self.__dialog._main.AddGrab(1, 0)
         form.AddGrab(0, 0)
         toplevel.setcursor('stop')
         self._topwindow.setcursor('')
         self.__dialog.setcursor('')
     else:
         self.__dialog = None
     form.RemoveEventHandler(X.PointerMotionMask, FALSE,
                             self._motion_handler, None)
     form.AddEventHandler(X.ButtonPressMask, FALSE, self.__start, None)
     form.AddEventHandler(X.ButtonMotionMask, FALSE, self.__do, None)
     form.AddEventHandler(X.ButtonReleaseMask, FALSE, self.__end, None)
     form.GrabButton(
         X.AnyButton, X.AnyModifier, TRUE,
         X.ButtonPressMask | X.ButtonMotionMask
         | X.ButtonReleaseMask, X.GrabModeAsync, X.GrabModeAsync, form,
         cursor)
     v = form.GetValues(['foreground', 'background'])
     v['foreground'] = v['foreground'] ^ v['background']
     v['function'] = X.GXxor
     v['line_style'] = X.LineOnOffDash
     self.__gc = form.GetGC(v)
     if box:
         x, y, w, h = self._convert_coordinates(box, units=units)
         if w < 0:
             x, w = x + w, -w
         if h < 0:
             y, h = y + h, -h
         self.__box = 1
         self.__start_x = x
         self.__start_y = y
         self.__width = w
         self.__height = h
     else:
         self.__start_x, self.__start_y, self.__width, \
                           self.__height = self._rect
         self.__box = 0
     self.__looping = 1
     toplevel.setready()
     if not modeless:
         while self.__looping:
             Xt.DispatchEvent(Xt.NextEvent())
Beispiel #8
0
    def splash(self, version = None):
        self.wininit()
        if self.visual.depth < 24:
            return 0
        try:
            import splashimg
        except ImportError:
            return 0
        import imgconvert
        try:
            rdr = imgconvert.stackreader(self.imgformat, splashimg.reader())
        except imgconvert.unsupported_error:
            return 0
        main = self.main
        data = rdr.read()
        width = rdr.width
        height = rdr.height
        swidth = main.WidthOfScreen()
        sheight = main.HeightOfScreen()
        shell = main.CreatePopupShell('splash', Xt.TopLevelShell,
                                      {'visual': self.visual,
                                       'depth': self.visual.depth,
                                       'colormap': self.colormap,
                                       'mwmDecorations': 0,
                                       'x': (swidth-width)/2,
                                       'y': (sheight-height)/2})
        self.shell = shell
##         form = shell.CreateManagedWidget('form', Xm.Form,
##                          {'allowOverlap': 1})
        w = shell.CreateManagedWidget('image', Xm.DrawingArea,
                                      {'width': width,
                                       'height': height,
                                       'x': 0, 'y': 0})
        if version is not None:
            attrs = {'labelString': version,
                     'alignment': Xmd.ALIGNMENT_CENTER,
                     'x': 10,
                     'y': 260,
                     'width': width-20,
                     'background': 0xffffff,
                     'foreground': 0x061440}
            try:
                w.LoadQueryFont(splashfont)
            except:
                # can't find the font, so don't use it
                pass
            else:
                attrs['fontList'] = splashfont
            l = w.CreateManagedWidget('version', Xm.Label, attrs)
        shell.Popup(0)
        gc = w.CreateGC({})
        descr = rdr.format.descr
        image = self.visual.CreateImage(self.visual.depth, X.ZPixmap,
                        0, data, width, height, descr['align'], 0)
        image.byte_order = self.byteorder
        w.AddCallback('exposeCallback', self.expose,
                      (gc.PutImage, (image, 0, 0, 0, 0, width, height)))
        gc.PutImage(image, 0, 0, 0, 0, width, height)
        w.DefineCursor(self.watchcursor)
        self.dpy.Flush()
        import Xtdefs
        while not self.__exposed:
            # at least wait until we were exposed
            Xt.ProcessEvent(Xtdefs.XtIMAll)
        while Xt.Pending():
            # then wait until all pending events have been
            # processed
            Xt.ProcessEvent(Xtdefs.XtIMAll)
        return 1
    def XtAddInput(self):
        "Register myself in Xt dispatcher."
        import Xt
        from Xtdefs import XtInputReadMask

        Xt.AddInput(self.fileno(), XtInputReadMask, self._XtCB, None)
Beispiel #10
0
 def mainloop(self):
     self.setready()
     Xt.MainLoop()
Beispiel #11
0
 def __init__(self,
              text,
              mtype='message',
              grab=1,
              callback=None,
              cancelCallback=None,
              name='message',
              title='message',
              parent=None,
              identity=None):
     # XXXX If identity != None the user should have the option of not
     # showing this message again
     if grab:
         dialogStyle = Xmd.DIALOG_FULL_APPLICATION_MODAL
         if parent is None:
             parent = toplevel
         while 1:
             if hasattr(parent, '_shell'):
                 parent = parent._shell
                 break
             if hasattr(parent, '_main'):
                 parent = parent._main
                 break
             if hasattr(parent, '_parent'):
                 parent = parent._parent
             else:
                 parent = toplevel
     else:
         dialogStyle = Xmd.DIALOG_MODELESS
         parent = toplevel._main
     if mtype == 'error':
         func = parent.CreateErrorDialog
     elif mtype == 'warning':
         func = parent.CreateWarningDialog
     elif mtype == 'information':
         func = parent.CreateInformationDialog
     elif mtype == 'question':
         func = parent.CreateQuestionDialog
     else:
         func = parent.CreateMessageDialog
     self._grab = grab
     w = func(
         name, {
             'messageString': text,
             'title': title,
             'dialogStyle': dialogStyle,
             'resizePolicy': Xmd.RESIZE_NONE,
             'visual': toplevel._default_visual,
             'depth': toplevel._default_visual.depth,
             'colormap': toplevel._default_colormap
         })
     w.MessageBoxGetChild(Xmd.DIALOG_HELP_BUTTON).UnmanageChild()
     if mtype == 'question' or cancelCallback:
         w.AddCallback('cancelCallback', self._callback, cancelCallback)
         w.Parent().AddWMProtocolCallback(toplevel._delete_window,
                                          self._callback, cancelCallback)
     else:
         w.MessageBoxGetChild(Xmd.DIALOG_CANCEL_BUTTON).UnmanageChild()
     w.AddCallback('okCallback', self._callback, callback)
     w.AddCallback('destroyCallback', self._destroy, None)
     w.ManageChild()
     self._main = w
     self.setcursor(_WAITING_CURSOR)
     toplevel._subwindows.append(self)
     if grab:
         toplevel.setready()
         while self._grab:
             Xt.DispatchEvent(Xt.NextEvent())
Beispiel #12
0
 def run(self):
     self.looping = TRUE
     toplevel.setready()
     while self.looping:
         Xt.DispatchEvent(Xt.NextEvent())
     return self.answer
Beispiel #13
0
def cancelidleproc(id):
    global _in_idle, _cancel_idle
    if _in_idle is not None and _idleprocdict[id] is _in_idle:
        _cancel_idle = _in_idle
    else:
        Xt.RemoveWorkProc(id)
Beispiel #14
0
def setidleproc(f):
    id = Xt.AddWorkProc(_idleproc, f)
    _idleprocdict[id] = f
    return id
Beispiel #15
0
HtmlWidgets = {}


def actionhook(widget, client_data, action, event, plist):
    if widget.Class() is not Xm.DrawingArea or \
       widget.Parent().Class() is not HTML.html:
        return
    ch = HtmlWidgets.get(widget.Parent())
    if ch is None:
        return
    ch.actionhook(client_data, action, event, plist)


import Xt, Xm
Xt.AddActionHook(actionhook, None)


class HtmlChannel(Channel.ChannelWindow):
    chan_attrs = Channel.ChannelWindow.chan_attrs + ['fgcolor']

    def __init__(self, name, attrdict, scheduler, ui):
        Channel.ChannelWindow.__init__(self, name, attrdict, scheduler, ui)
        self.want_default_colormap = 1
        self.htmlw = None
        self.play_node = None
        self.widget_name = normalize(name)
        self.backlist = []

    def do_show(self, pchan):
        #