def initialise(appdir): msgtrans_block = block(4) wimp_messages = block(1) toolbox_events = block(1) wimp_messages[0] = 0 toolbox_events[0] = 0 swi('MessageTrans_OpenFile', 'bsi', msgtrans_block, appdir + '.Messages', 0) wimp_ver,task_handle,sprite_area = \ swi('Toolbox_Initialise','0Ibbsbb;III', 560, wimp_messages, toolbox_events, appdir, msgtrans_block, _id_block.block)
def expandvars(p): """ Expand environment variables using OS_GSTrans. """ l = 512 b = swi.block(l) return b.tostring(0, swi.swi('OS_GSTrans', 'sbi;..i', p, b, l))
def expanduser(p): fs, drive, path = _split(p) l = 512 b = swi.block(l) if path[:1] != '@': return p if fs == '': fsno = swi.swi('OS_Args', '00;i') swi.swi('OS_FSControl', 'iibi', 33, fsno, b, l) fsname = b.ctrlstring() else: if fs[:1] == '-': fsname = fs[1:-1] else: fsname = fs[:-1] fsname = string.split(fsname, '#', 1)[0] x = swi.swi('OS_FSControl', 'ib2s.i;.....i', 54, b, fsname, l) if x < l: urd = b.tostring(0, l - x - 1) else: x = swi.swi('OS_FSControl', 'ib0s.i;.....i', 54, b, fsname, l) if x < l: urd = b.tostring(0, l - x - 1) else: urd = '$' return fsname + ':' + urd + path[1:]
def expanduser(p): (fs, drive, path) = _split(p) l = 512 b = swi.block(l) if path[:1] != "@": return p if fs == "": fsno = swi.swi("OS_Args", "00;i") swi.swi("OS_FSControl", "iibi", 33, fsno, b, l) fsname = b.ctrlstring() else: if fs[:1] == "-": fsname = fs[1:-1] else: fsname = fs[:-1] fsname = string.split(fsname, "#", 1)[0] # remove special field from fs x = swi.swi("OS_FSControl", "ib2s.i;.....i", 54, b, fsname, l) if x < l: urd = b.tostring(0, l - x - 1) else: # no URD! try CSD x = swi.swi("OS_FSControl", "ib0s.i;.....i", 54, b, fsname, l) if x < l: urd = b.tostring(0, l - x - 1) else: # no CSD! use root urd = "$" return fsname + ":" + urd + path[1:]
def extent(self, extent): extent_block = swi.block(4) extent_block.signed(0, extent[0]) extent_block.signed(1, extent[1]) extent_block.signed(2, extent[2]) extent_block.signed(3, extent[3]) swi.swi('Toolbox_ObjectMiscOp', '0Iib', self.id, 15, extent_block)
def samefile(fa, fb): l = 512 b = swi.block(l) swi.swi('OS_FSControl', 'isb..i', 37, fa, b, l) fa = b.ctrlstring() swi.swi('OS_FSControl', 'isb..i', 37, fb, b, l) fb = b.ctrlstring() return fa == fb
def _miscop_get_text(self, op): """Use Toolbox_ObjectMiscOp to get a string. This call will allocate a suitably-sized buffer, read the string and return it.""" buf_size = swi.swi('Toolbox_ObjectMiscOp', '0IIII00;....I', self.window.id, op, self.id) buffer = swi.block((buf_size + 3) / 4) swi.swi('Toolbox_ObjectMiscOp', '0IIIIbI', self.window.id, op, self.id, buffer, buf_size) return block.nullstring()
def samefile(fa, fb): """ Test whether two pathnames reference the same actual file. """ l = 512 b = swi.block(l) swi.swi('OS_FSControl', 'isb..i', 37, fa, b, l) fa = b.ctrlstring() swi.swi('OS_FSControl', 'isb..i', 37, fb, b, l) fb = b.ctrlstring() return fa == fb
def run(): poll_block = block(64) global _quit while not _quit: reason, sender = swi('Wimp_Poll', 'Ib;I.I', 0b1, poll_block) if reason == 0x200: # Toolbox Event size = poll_block[0] reference = poll_block[1] event_code = poll_block[2] flags = poll_block[3] if event_code == 0x44ec1: # Object_AutoCreated name = poll_block.nullstring(0x10, size) obj_class = swi('Toolbox_GetObjectClass', '0I;I', _id_block.self_id) _objects[_id_block.self_id] = \ Object.create(obj_class, name, _id_block.self_id) continue object = get_object(_id_block.self_id) component = _id_block.self_component if object: if isinstance(object, Window) and component in object.gadgets: gadget = object.gadgets[component] gadget.event_handler(event_code, _id_block, poll_block) else: object.event_handler(event_code, _id_block, poll_block) if reason == 2: # Open Window if _id_block.self_id in _objects: object = _objects[_id_block.self_id] object.wimp_handler(reason, _id_block, poll_block) if reason == 17 or reason == 18: # Wimp Message message = poll_block[4] if message == 0: _quit = True else: if message in _message_handlers: _message_handlers[message](poll_block)
def extent(self): extent_block = swi.block(4) swi.swi('Toolbox_ObjectMiscOp', '0Iib', self.id, 16, extent_block) return (extent_block.tosigned(0), extent_block.tosigned(1), extent_block.tosigned(2), extent_block.tosigned(3))
def title(self): buf_size = swi.swi('Toolbox_ObjectMiscOp', '0II0;....I', self.id, 12) buffer = swi.block(int((buf_size + 3) / 4)) swi.swi('Toolbox_ObjectMiscOp', '0IIbI', self.id, 12, buffer, buf_size) return buffer.nullstring()
# Module 'riscospath' -- common operations on RISC OS pathnames.
def expandvars(p): l = 512 b = swi.block(l) return b.tostring(0, swi.swi('OS_GSTrans', 'sbi;..i', p, b, l))
def __init__(self): self.block = block(6)
def file_name(self): buf_size = swi.swi('Toolbox_ObjectMiscOp', '0II00;....I', self.id, 4) buf = swi.block((buf_size+3)/4) swi.swi('Toolbox_ObjectMiscOp', '0IIbI', self.id, 4, buf, buf_size) return buf.nullstring()