Page MenuHome

Cannot programmatically set context area to FILE_BROWSE
Closed, InvalidPublic

Description

System Information
Operating system: Arch Linux
Graphics card: GTX 1060

Blender Version
Broken:
Blender 2.80

Short description of error

import bpy
bpy.context.area.type = 'FILE_BROWSE'

produces the following error:

TypeError: bpy_struct: item.attr = val: enum "FILE_BROWSE" not found in (, 'VIEW_3D', 'IMAGE_EDITOR', 'NODE_EDITOR', 'SEQUENCE_EDITOR', 'CLIP_EDITOR', 'DOPESHEET_EDITOR', 'GRAPH_EDITOR', 'NLA_EDITOR', 'TEXT_EDITOR', 'CONSOLE', 'INFO', 'OUTLINER', 'PROPERTIES', 'FILE_BROWSE)
Error: Python script fail, look in the console for now...

Event Timeline

The problem is the message does not correctly show all the valid enum values. For example, 'CONSOLE' is truncated.

bpy.context.area.ui_type = 'FILE_BROWSER' works though. Tested on e79bb957fc3

Philipp Oeser (lichtwerk) changed the task status from Unknown Status to Invalid.Dec 10 2018, 9:42 AM
Philipp Oeser (lichtwerk) claimed this task.

Yes, the error message for not finding a string in an enum is truncated to 200 characters:

PyErr_Format(PyExc_TypeError, "%.200s enum \"%.200s\" not found in (%.200s)",

I guess this 200 char limit could be raised, but I am not sure if this could be called a bug (or has a particular reason to be clamped).
In fact, I would say it is not a bug [devs can always have a look at the documentation https://docs.blender.org/api/blender2.8/bpy.types.Area.html?#bpy.types.Area.type to get a full list of valid enum items]
(And the original report was just setting an invalid item)

Closing [unless @Campbell Barton (campbellbarton) has objections?]

Note, truncation is done because some enums are huge (icons or events for eg).

Even so, we could print all of them and accept this may exceed the default scrollback on some terminals.