Esempio n. 1
0
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:]
Esempio n. 2
0
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:]
Esempio n. 3
0
 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)
Esempio n. 4
0
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:]
Esempio n. 5
0
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
Esempio n. 6
0
def create_object(template, klass=None):
    id = swi.swi('Toolbox_CreateObject', 'Is;I', 0, template)
    if klass:
        _objects[id] = klass(id)
    else:
        obj_class = swi.swi('Toolbox_GetObjectClass', '0I;I', id)
        _objects[id] = Object.create(obj_class, template, id)
    return _objects[id]
Esempio n. 7
0
 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()
Esempio n. 8
0
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
Esempio n. 9
0
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
Esempio n. 10
0
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)
Esempio n. 11
0
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))
Esempio n. 12
0
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))
Esempio n. 13
0
def exists(p):
    """
    Test whether a path exists.
    """
    try:
        return swi.swi('OS_File', '5s;i', p) != 0
    except swi.error:
        return 0
Esempio n. 14
0
def isdir(p):
    """
    Is a path a directory? Includes image files.
    """
    try:
        return swi.swi('OS_File', '5s;i', p) in (2, 3)
    except swi.error:
        return 0
Esempio n. 15
0
def isfile(p):
    """
    Test whether a path is a file, including image files.
    """
    try:
        return swi.swi('OS_File', '5s;i', p) in (1, 3)
    except swi.error:
        return 0
Esempio n. 16
0
def exists(p):
    """
  Test whether a path exists.
  """
    try:
        return swi.swi("OS_File", "5s;i", p) != 0
    except swi.error:
        return 0
Esempio n. 17
0
def isdir(p):
    """
  Is a path a directory? Includes image files.
  """
    try:
        return swi.swi("OS_File", "5s;i", p) in [2, 3]
    except swi.error:
        return 0
Esempio n. 18
0
 def fade(self):
     return swi.swi(
         'Toolbox_ObjectMiscOp',
         '0II;I',
         self.menu.id,
         3,
         self.id,
     )
Esempio n. 19
0
def exists(p):
    """
    Test whether a path exists.
    """
    try:
        return swi.swi('OS_File', '5s;i', p) != 0
    except swi.error:
        return 0
Esempio n. 20
0
def isfile(p):
    """
  Test whether a path is a file, including image files.
  """
    try:
        return swi.swi("OS_File", "5s;i", p) in [1, 3]
    except swi.error:
        return 0
Esempio n. 21
0
def isdir(p):
    """
    Is a path a directory? Includes image files.
    """
    try:
        return swi.swi('OS_File', '5s;i', p) in (2, 3)
    except swi.error:
        return 0
Esempio n. 22
0
def isfile(p):
    """
    Test whether a path is a file, including image files.
    """
    try:
        return swi.swi('OS_File', '5s;i', p) in (1, 3)
    except swi.error:
        return 0
Esempio n. 23
0
    def show(self,
             menu_semantics=False,
             submenu_semantics=False,
             type=0,
             parent=None):
        flags = 0
        if menu_semantics:
            flags |= 1
        if submenu_semantics:
            flags |= 2

        if parent:
            parent_obj, parent_comp = parent.id, parent.component
        else:
            parent_obj = parent_comp = 0

        swi.swi('Toolbox_ShowObject', 'III0II', flags, self.id, type,
                parent_obj, parent_comp)
Esempio n. 24
0
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)
Esempio n. 25
0
def _uptime_riscos():
    """Returns uptime in seconds or None, on RISC OS."""
    try:
        up = swi.swi('OS_ReadMonotonicTime', ';i')
        if up < 0:
            # Overflows after about eight months on 32-bit.
            return None
        return up / 100.
    except NameError:
        return None
Esempio n. 26
0
def _uptime_riscos():
    """Returns uptime in seconds or None, on RISC OS."""
    try:
        up = swi.swi('OS_ReadMonotonicTime', ';i')
        if up < 0:
            # Overflows after about eight months on 32-bit.
            return None
        return up / 100.
    except NameError:
        return None
Esempio n. 27
0
    def parent(self):
        id, comp_id = swi.swi('Toolbox_GetParent', '0I;Ii', self.id)
        if id in _objects:
            obj = _objects[id]
        else:
            obj = Object(id)
        if comp_id == -1:
            comp = None
        else:
            if comp_id in obj.components:
                comp = obj.components[comp_id]
            else:
                comp = Component(comp_id)

        return namedtuple('parent', ('object', 'component'))(obj, comp)
Esempio n. 28
0
 def wimp_handle(self):
     if self._wimp_handle is None:
         self._wimp_handle = swi.swi('Toolbox_ObjectMiscOp', '0II;I',
                                     self.id, 0)
     return self._wimp_handle
Esempio n. 29
0
 def _miscop_set_int(self, op, value):
     """Use Toolbox_ObjectMiscOp to set an integer."""
     swi.swi('Toolbox_ObjectMiscOp', '0IIII', self.window.id, op, self.id,
             value)
Esempio n. 30
0
 def flags(self, flags):
     """Sets the gadgets flags."""
     swi.swi('Toolbox_ObjectMiscOp', '0IIII', self.window.id, 65, self.id,
             flags)
Esempio n. 31
0
 def _miscop_set_text(self, op, text):
     """Use Toolbox_ObjectMiscOp to set a string."""
     swi.swi('Toolbox_ObjectMiscOp', '0IIIs', self.window.id, op, self.id,
             text)
Esempio n. 32
0
 def _miscop_get_int(self, op):
     """Use Toolbox_ObjectMiscOp to get an integer."""
     return swi.swi('Toolbox_ObjectMiscOp', '0III:I', self.window.id, op,
                    self.id, value)
Esempio n. 33
0
 def tick(self, val):
     swi.swi('Toolbox_ObjectMiscOp', '0IIII', self.menu.id, 0, self.id,
             1 if val else 0)
Esempio n. 34
0
 def tick(self):
     return swi.swi('Toolbox_ObjectMiscOp', '0II;I', self.menu.id, 1,
                    self.id)
Esempio n. 35
0
# Module 'riscospath' -- common operations on RISC OS pathnames.
Esempio n. 36
0
 def fade(self, val):
     swi.swi('Toolbox_ObjectMiscOp', '0IIII', self.menu.id, 2, self.id,
             1 if val else 0)
Esempio n. 37
0
 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()
Esempio n. 38
0
 def title(self, title):
     swi.swi('Toolbox_ObjectMiscOp', '0IIs', self.id, 11, title)
Esempio n. 39
0
 def add_gadget(self, block, klass):
     id = swi.swi('Toolbox_ObjectMiscOp', '0III;I', self.id, 1, block)
     obj = klass(self, id)
     self.gadgets[id] = obj
     return obj
Esempio n. 40
0
 def remove_gadget(self, gadget):
     swi.swi('Toolbox_ObjectMiscOp', '0III', self.id, 2, gadget.id)
     del self.gadgets[gadget.id]
Esempio n. 41
0
 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))