Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def send_access_state(self):
if data_plugins.is_read_only():
self.write_access_signal.emit(False)
return
self.write_access_signal.emit(self.write_access)
def update_window_title(self):
if self.showing_file_path_in_title_bar:
title = self.current_file()
else:
title = self._display_widget.windowTitle()
title += " - PyDM"
if data_plugins.is_read_only():
title += " [Read Only Mode]"
self.setWindowTitle(title)
def plugin_changed(self, plugin):
def cleanup():
try:
if self.plugin_param_widget:
self.param_layout.removeWidget(self.plugin_param_widget)
self.plugin_param_widget.setVisible(False)
self.plugin_param_widget.deleteLater()
except RuntimeError:
pass
module = data_plugins.plugin_modules.get(plugin, None)
cleanup()
if module:
self.plugin_param_widget = module.param_editor(self)
self.param_layout.addWidget(self.plugin_param_widget)
def connect(self):
"""
Connect a PyDMChannel to the proper PyDMPlugin
"""
if not self.address:
return
if is_qt_designer() and not config.DESIGNER_ONLINE:
return
logger.debug("Connecting %r", self.address)
# Connect to proper PyDMPlugin
try:
pydm.data_plugins.establish_connection(self)
except Exception:
logger.exception("Unable to make proper connection "
"for %r", self)
self.ui.actionBack.setEnabled(len(self.back_stack) > 1)
if self.home_file is None:
self.home_file = (filename, merged_macros, command_line_args)
# Update here the Menu Editor text...
ui_file, py_file = self.get_files_in_display()
edit_in_text = "Open in "
editors = []
if ui_file is not None and ui_file != "":
editors.append("Designer")
if py_file is not None and py_file != "":
editors.append("Text Editor")
edit_in_text += ' and '.join(editors)
self.ui.actionEdit_in_Designer.setText(edit_in_text)
if self.designer_path:
self.ui.actionEdit_in_Designer.setEnabled(True)
data_plugins.establish_queued_connections()
w = self.open_template_file(variables)
if w is None:
w = QLabel()
w.setText("No Template Loaded. Data: {}".format(variables))
w.setParent(self)
self.layout().addWidget(w)
except:
logger.exception('Template repeater failed to rebuild.')
finally:
# If issues happen during the rebuild we should still enable
# updates and establish connection for the widgets added.
# Moreover, if we dont call establish_queued_connections
# the queue will never be emptied and new connections will be
# staled.
self.setUpdatesEnabled(True)
pydm.data_plugins.establish_queued_connections()
def get_plugin_repr(address):
plugin = data_plugins.plugin_for_address(address)
plugin_repr = plugin.get_repr(address)
return plugin_repr
hide_status_bar: bool, optional
Whether or not to display the status bar (general messages and errors)
when the main window is first displayed.
read_only: bool, optional
Whether or not to launch PyDM in a read-only state.
macros : dict, optional
A dictionary of macro variables to be forwarded to the display class
being loaded.
use_main_window : bool, optional
If ui_file is note given, this parameter controls whether or not to
create a PyDMMainWindow in the initialization (Default is True).
fullscreen : bool, optional
Whether or not to launch PyDM in a full screen mode.
"""
# Instantiate our plugins.
plugins = data_plugins.plugin_modules
def __init__(self, ui_file=None, command_line_args=[], display_args=[],
perfmon=False, hide_nav_bar=False, hide_menu_bar=False,
hide_status_bar=False, read_only=False, macros=None,
use_main_window=True, stylesheet_path=None, fullscreen=False):
super(PyDMApplication, self).__init__(command_line_args)
# Enable High DPI display, if available.
if hasattr(Qt, 'AA_UseHighDpiPixmaps'):
self.setAttribute(Qt.AA_UseHighDpiPixmaps)
# The macro and directory stacks are needed for nested displays (usually PyDMEmbeddedDisplays).
# During the process of loading a display (whether from a .ui file, or a .py file), the application's
# 'open_file' method will be called recursively. Inside open_file, the last item on the stack represents
# the parent widget's file path and macro variables. Any file paths are joined to the end of the parent's
# file path, and any macros are merged with the parent's macros. This system depends on open_file always
# being called hierarchially (i.e., parent calls it first, then on down the ancestor tree, with no unrelated
# calls in between). If something crazy happens and PyDM somehow gains the ability to open files in a
"open_relative. The connection is now handled by the"
" widgets.")
# First split the ui_file string into a filepath and arguments
args = command_line_args if command_line_args is not None else []
dir_name, file_name, extra_args = path_info(ui_file)
args.extend(extra_args)
filepath = os.path.join(dir_name, file_name)
self.directory_stack.append(dir_name)
(filename, extension) = os.path.splitext(file_name)
if macros is None:
macros = {}
merged_macros = self.macro_stack[-1].copy()
merged_macros.update(macros)
self.macro_stack.append(merged_macros)
with data_plugins.connection_queue(defer_connections=defer_connections):
if extension == '.ui':
widget = load_ui_file(filepath, merged_macros)
elif extension == '.py':
widget = load_py_file(filepath, args, merged_macros)
else:
self.directory_stack.pop()
self.macro_stack.pop()
raise ValueError("Invalid file type: {}".format(extension))
# Add on the macros to the widget after initialization. This is
# done for both ui files and python files.
widget.base_macros = merged_macros
self.directory_stack.pop()
self.macro_stack.pop()
return widget
def setup_hooks(self):
sys.excepthook = self.__handle_exceptions
# Set PyDM to be read-only
data_plugins.set_read_only(True)
if self.form_editor:
fwman = self.form_editor.formWindowManager()
if fwman:
fwman.formWindowAdded.connect(
self.__new_form_added
)