44
55from mathics .core .expression import (Symbol , Atom , String , Expression )
66from mathics .builtin .base import BoxConstruct , AtomBuiltin , Predefined
7+ from mathics .builtin .graphics import GRAPHICS_OPTIONS
78
89class CustomBoxConstruct (BoxConstruct ):
910 def __init__ (self , evaluation ):
@@ -36,6 +37,39 @@ def apply_to_boxes(self, evaluation):
3637 'System`MakeBoxes[System`CustomAtom, StandardForm|TraditionalForm|OutputForm|InputForm]'
3738 return CustomBoxConstruct (evaluation = evaluation )
3839
40+
41+ class CustomGraphicsBox (BoxConstruct ):
42+ """
43+
44+ """
45+ options = GRAPHICS_OPTIONS
46+ attributes = ("HoldAll" , "ReadProtected" )
47+
48+
49+ def apply_box (self , elems , evaluation , options ):
50+ """System`MakeBoxes[System`Graphics[elems_, System`OptionsPattern[System`Graphics]],
51+ System`StandardForm|System`TraditionalForm|System`OutputForm]"""
52+ instance = CustomGraphicsBox (* (elems ._leaves ), evaluation = evaluation )
53+ return instance
54+
55+ def boxes_to_text (self , leaves = None , ** options ):
56+ if leaves :
57+ self ._leaves = leaves
58+ return "--custom graphics--: I should plot " + self ._leaves .__str__ () + " items"
59+
60+ def boxes_to_tex (self , leaves = None , ** options ):
61+ return "--custom graphics--: I should plot " + self ._leaves .__str__ () + " items"
62+
63+ def boxes_to_xml (self , leaves = None , ** options ):
64+ return "--custom graphics--: I should plot " + self ._leaves .__str__ () + " items"
65+
66+ def boxes_to_svg (self , evaluation ):
67+ return "--custom graphics--: I should plot " + self ._leaves .__str__ () + " items"
68+
69+
70+
71+
72+
3973def test_custom_boxconstruct ():
4074 defs = session .evaluation .definitions
4175 instance_custom_atom = CustomAtom (expression = False )
@@ -44,3 +78,12 @@ def test_custom_boxconstruct():
4478 formatted = session .format_result ().boxes_to_xml ()
4579 assert formatted == "CustomBoxConstruct<<[1, 2, 3]>>"
4680
81+
82+
83+ def test_custom_graphicsbox_constructor ():
84+ defs = session .evaluation .definitions
85+ instance_customgb_atom = CustomGraphicsBox (expression = False , evaluation = session .evaluation )
86+ instance_customgb_atom .contribute (defs , is_pymodule = True )
87+ expr = session .evaluate ("MakeBoxes[Graphics[{Circle[{0,0},1]}], OutputForm]" )
88+ formatted = session .format_result ().boxes_to_xml ()
89+ assert formatted == "--custom graphics--: I should plot (<Expression: System`Circle[System`List[0, 0], 1]>,) items"
0 commit comments