Belle II Software development
ModuleViewer Class Reference
Inheritance diagram for ModuleViewer:
IPythonWidget

Public Member Functions

def __init__ (self, module, standalone=True)
 
def get_color_code (self, param)
 
def create (self)
 

Public Attributes

 module
 The module to show.
 
 standalone
 In the standalone mode, the basic parameters of the modules are shown.
 
 table_beginning_html
 Template for the table beginning.
 
 td_html
 Template for the table cell.
 
 table_row_parameters
 Template for the row of parameters.
 
 table_row_help
 Template for the row with help.
 
 table_row_html_single
 Template for the simple row.
 
 table_title_html
 Template for the table title.
 

Detailed Description

A widget for showing module parameter with their content (not standalone)
or with their description (standalone).

Definition at line 85 of file viewer.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  module,
  standalone = True 
)
 Init with a module as a string or a registered one. 

Definition at line 91 of file viewer.py.

91 def __init__(self, module, standalone=True):
92 """ Init with a module as a string or a registered one. """
93
94
95 if isinstance(module, str):
96 import basf2.core as _basf2
97 self.module = _basf2.register_module(module)
98 else:
99 self.module = module
100
101
102 self.standalone = standalone
103
104
105 self.table_beginning_html = """<table style="margin-left: auto; margin-right: auto;
106 border-collapse: separate; border-spacing: 0px;">"""
107
108
109 self.td_html = "style=\"padding: 10px;\""
110
111
112 self.table_row_parameters = """<tr><td {td_style}>{param.name}</td>
113 <td{color_text} {td_style}>{param.values}</td>
114 <td style="color: gray; {td_style}>{param.default}</td></tr>"""
115
116
117 self.table_row_help = """<tr><td {td_style}>{param.name}</td>
118 <td {td_style}>{param.type}</td>
119 <td {td_style}>{param.values}</td>
120 <td style="color: gray; {td_style}>{param.description}</td></tr>"""
121
122
123 self.table_row_html_single = """<tr><td colspan="4" {td_style}>{text}</td></tr>"""
124
125
126 self.table_title_html = """<thead><td colspan="4" style="text-align: center;
127 font-size: 18pt;" {td_style}>{module_name} ({package})</td></thead>"""
128

Member Function Documentation

◆ create()

def create (   self)
Show the widget.

Reimplemented from IPythonWidget.

Definition at line 141 of file viewer.py.

141 def create(self):
142 """
143 Show the widget.
144 """
145 import ipywidgets as widgets
146
147 html = widgets.HTML()
148 html.value = self.table_beginning_html
149
150 if self.standalone:
151 if isinstance(self.module.name, str):
152 module_name = self.module.name
153 else:
154 module_name = self.module.name()
155
156 html.value += self.table_title_html.format(module_name=module_name, package=self.module.package(),
157 td_style=self.td_html)
158
159 html.value += self.table_row_html_single.format(text=self.module.description(), td_style=self.td_html)
160
161 if len(self.module.available_params()) == 0:
162 html.value += self.table_row_html_single.format(text="No parameters available.", td_style=self.td_html)
163 else:
164 for param in self.module.available_params():
165 color_text = self.get_color_code(param)
166
167 if self.standalone:
168 table_row_html = self.table_row_help
169 else:
170 table_row_html = self.table_row_parameters
171
172 html.value += table_row_html.format(param=param, color_text=color_text, td_style=self.td_html)
173 html.value += "</table>"
174
175 return html
176
177

◆ get_color_code()

def get_color_code (   self,
  param 
)
 Handy function for getting a color based on a parameter:
 if it has the default value, no color,
 if not, red color.

Definition at line 129 of file viewer.py.

129 def get_color_code(self, param):
130 """
131 Handy function for getting a color based on a parameter:
132 if it has the default value, no color,
133 if not, red color.
134 """
135 if str(param.values) != str(param.default) and str(param.default) != "":
136 color_text = " style='color: red;'"
137 else:
138 color_text = ""
139 return color_text
140

Member Data Documentation

◆ module

module

The module to show.

Definition at line 97 of file viewer.py.

◆ standalone

standalone

In the standalone mode, the basic parameters of the modules are shown.

Definition at line 102 of file viewer.py.

◆ table_beginning_html

table_beginning_html

Template for the table beginning.

Definition at line 105 of file viewer.py.

◆ table_row_help

table_row_help

Template for the row with help.

Definition at line 117 of file viewer.py.

◆ table_row_html_single

table_row_html_single

Template for the simple row.

Definition at line 123 of file viewer.py.

◆ table_row_parameters

table_row_parameters

Template for the row of parameters.

Definition at line 112 of file viewer.py.

◆ table_title_html

table_title_html

Template for the table title.

Definition at line 126 of file viewer.py.

◆ td_html

td_html

Template for the table cell.

Definition at line 109 of file viewer.py.


The documentation for this class was generated from the following file: