Skip to content

Commit

Permalink
Merge branch 'main' into feature/poll_mask
Browse files Browse the repository at this point in the history
  • Loading branch information
c-jo committed Nov 14, 2023
2 parents 4db5803 + 582d00a commit 64d7b2b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
46 changes: 33 additions & 13 deletions riscos_toolbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,38 @@ def task_name():
return "Python Application"


def report_exception(e):
def throwback_traceback(e):
try:
type, value, tb = sys.exc_info()
stack = reversed(traceback.extract_tb(tb))
swi.swi("DDEUtils_ThrowbackStart", "s", task_name())
frame = next(stack)
swi.swi("DDEUtils_ThrowbackSend", "i.siis",
1, frame.filename, frame.lineno, 1, str(e))
for frame in stack:
swi.swi("DDEUtils_ThrowbackSend", "i.siis",
2, frame.filename, frame.lineno, 0, "called from here")
swi.swi("DDEUtils_ThrowbackEnd", "")
except Exception as e:
report_exception(e, throwback=False)


def report_exception(e, throwback):
error_block = swi.block(64)
error_block[0] = 0
# Write the error to the block at offset 4
error_block.padstring(str(e).encode('latin-1')[:250], b'\0', 4)

if swi.swi('Wimp_ReportError', 'bIs000;.I',
error_block, 0b000100000011, task_name()) == 2:
global _quit
_quit = True
if throwback:
sel = swi.swi('Wimp_ReportError', 'bIs00s;.I',
error_block, 0b000100000011, task_name(),
"Throwback")
else:
sel = swi.swi('Wimp_ReportError', 'bIs000;.I',
error_block, 0b000100000011, task_name())
if sel == 2:
sys.exit(1)
if sel == 3 and throwback:
throwback_traceback(e)


def initialise(appdir):
Expand Down Expand Up @@ -93,16 +116,13 @@ def run(application):
try:
poll_block = bytes(poll_buffer)
if reason == Wimp.ToolboxEvent:
size, reference, event_code, flags = \
struct.unpack("IIII", poll_block[0:16])
size, reference, event_code, flags = struct.unpack("IIII", poll_block[0:16])

if event_code == Toolbox.ObjectAutoCreated:
name =''.join([chr(c) for c in \
iter(lambda i=iter(poll_block[0x10:]): next(i), 0)])

name = ''.join([chr(c) for c in iter(
lambda i=iter(poll_block[0x10:]): next(i), 0)])
obj_class = swi.swi('Toolbox_GetObjectClass', '0I;I',
_id_block.self.id)

_objects[_id_block.self.id] = Object.create(
obj_class, name, _id_block.self.id)
continue
Expand All @@ -124,7 +144,7 @@ def run(application):
wimp_dispatch(reason, application, _id_block, poll_block)

except Exception as e:
report_exception(e)
report_exception(e, application.throwback)


def quit():
Expand Down
4 changes: 2 additions & 2 deletions riscos_toolbox/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def _make_poll_flags(events):


class Application(EventHandler):
def __init__(self, appdir, poll_flags=None):
def __init__(self, appdir, poll_flags=None, throwback=True):
super().__init__()
self.throwback = throwback
global _application
_application = self
if poll_flags is not None:
self.poll_flags = poll_flags
else:
Expand Down
6 changes: 3 additions & 3 deletions riscos_toolbox/user_messages/data_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Messages:
class DataTransferMessage(UserMessage):
_fields_ = [
("destination_window", ctypes.c_int32),
("estination_icon", ctypes.c_int32),
("destination_icon", ctypes.c_int32),
("destination_position", Point),
("estimated_size", ctypes.c_int32),
("file_type", ctypes.c_int32),
Expand All @@ -42,7 +42,7 @@ class DataLoadAckMessage(DataTransferMessage):
event_id = Messages.DataLoadAck


class DataSavedkMessage(UserMessage):
class DataSavedMessage(UserMessage):
event_id = Messages.DataSaved


Expand All @@ -52,7 +52,7 @@ class DataOpenMessage(UserMessage):
_fields_ = [
("window_handle", ctypes.c_int32),
("spare", ctypes.c_int32),
("pposition", Point),
("position", Point),
("zero", ctypes.c_int32),
("file_type", ctypes.c_int32),
("_path_name", ctypes.c_char * 212),
Expand Down

0 comments on commit 64d7b2b

Please sign in to comment.