Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# widget initialization
assert isinstance(state, WidgetManager.Delayed)
if state in self.__init_queue:
self.__init_queue.remove(state)
node = state.node
widget = self.create_widget_instance(node)
self.__widgets.append(widget)
self.__widget_for_node[node] = widget
self.__node_for_widget[widget] = node
self.__initialize_widget_state(node, widget)
state = WidgetManager.Materialized(node, widget)
self.__initstate_for_node[node] = state
self.widget_for_node_added.emit(node, widget)
return state
def start(self):
"""
Start the update loop.
.. note:: The updates will not happen until the control reaches
the Qt event loop.
"""
if self.__state != SignalManager.Running:
self.__state = SignalManager.Running
self.stateChanged.emit(SignalManager.Running)
self._update()
def setScheme(self, scheme):
"""
Set the :class:`~.scheme.Scheme` instance to display/edit.
"""
if self.__scheme is not scheme:
if self.__scheme:
self.__scheme.title_changed.disconnect(self.titleChanged)
self.__scheme.removeEventFilter(self)
sm = self.__scheme.findChild(signalmanager.SignalManager)
if sm:
sm.stateChanged.disconnect(self.__signalManagerStateChanged)
self.__scheme = scheme
self.setPath("")
if self.__scheme:
self.__scheme.title_changed.connect(self.titleChanged)
self.titleChanged.emit(scheme.title)
self.__cleanProperties = node_properties(scheme)
sm = scheme.findChild(signalmanager.SignalManager)
if sm:
sm.stateChanged.connect(self.__signalManagerStateChanged)
else:
self.__cleanProperties = []
def add_node(self, node):
"""
Add a node to the scheme. An error is raised if the node is
already in the scheme.
Parameters
----------
node : :class:`.SchemeNode`
Node instance to add to the scheme.
"""
check_arg(node not in self.__nodes, "Node already in scheme.")
check_type(node, SchemeNode)
self.__nodes.append(node)
log.info("Added node %r to scheme %r." % (node.title, self.title))
self.node_added.emit(node)
def set_color(self, color):
"""
Set the fill color for the arrow as a string (`#RGB`, `#RRGGBB`,
`#RRRGGGBBB`, `#RRRRGGGGBBBB` format or one of SVG color keyword
names).
"""
check_type(color, str)
color = str(color)
if self.__color != color:
self.__color = color
self.color_changed.emit(color)
def set_font(self, font):
"""
Set the annotation's default font as a dictionary of font properties
(at the moment only family and size are used).
>>> annotation.set_font({"family": "Helvetica", "size": 16})
"""
check_type(font, dict)
font = dict(font)
if self.__font != font:
self.__font = font
self.font_changed.emit(font)
def add_annotation(self, annotation):
"""
Add an annotation (:class:`BaseSchemeAnnotation` subclass) instance
to the scheme.
"""
check_arg(
annotation not in self.__annotations,
"Cannot add the same annotation multiple times.",
)
check_type(annotation, BaseSchemeAnnotation)
self.__annotations.append(annotation)
self.annotation_added.emit(annotation)
def set_learner(self, learner):
self.learner = learner or self.default_learner
imputer = self.create_imputer(Method.Model)
button = self.default_button_group.button(Method.Model)
button.setText(imputer.name)
variable_button = self.variable_button_group.button(Method.Model)
variable_button.setText(imputer.name)
if learner is not None:
self.default_method_index = Method.Model
self.update_varview()
self.commit()
if value is not None:
self.control.setValue(self.lookup.index(value))
class CallFrontLogSlider(ControlledCallFront):
def action(self, value):
if value is not None:
if value < 1e-30:
print(
"unable to set %s to %s (value too small)" % (self.control, value)
)
else:
self.control.setValue(math.log10(value))
class CallFrontLineEdit(ControlledCallFront):
def action(self, value):
self.control.setText(str(value))
class CallFrontRadioButtons(ControlledCallFront):
def action(self, value):
if value < 0 or value >= len(self.control.buttons):
value = 0
self.control.buttons[value].setChecked(1)
class CallFrontListView(ControlledCallFront):
def action(self, values):
view = self.control
model = view.model()
sel_model = view.selectionModel()
"Return branches from `tree` in optimal order"
if tree.is_leaf:
return ()
elif is_swapped(tree):
return tree.branches
else:
return tuple(reversed(tree.branches))
# Create a new tree structure with optimally swapped branches.
T = {}
counter = count(0)
for tree in postorder(root, branches=swaped_branches):
if tree.is_leaf:
# we need to 're-enumerate' the leaves
i = next(counter)
T[tree] = Tree(tree.value._replace(range=(i, i + 1)), ())
else:
left, right = T[tree.left], T[tree.right]
if left.value.first > right.value.first:
right, left = left, right
assert left.value.first < right.value.last
assert left.value.last == right.value.first
T[tree] = Tree(
tree.value._replace(range=(left.value.first, right.value.last)),
(left, right),
)
return T[root]