### Device Server PyAlarm Configuration Example Source: https://pythonhosted.org/panic/_sources/PyAlarmUserGuide.txt Example configuration for a PyAlarm device server, including alarm descriptions, receivers, and alarm list definitions. ```python #--------------------------------------------------------- # SERVER PyAlarm/AssemblyArea, PyAlarm device declaration #--------------------------------------------------------- PyAlarm/AssemblyArea/DEVICE/PyAlarm: "LAB/VC/Alarms" # --- LAB/VC/Alarms properties LAB/VC/Alarms->AlarmDescriptions: "OVENPRESSURE:The pressure in the Oven exceeds Range",\ "ADIXENPRESSURE:The pressure in the Roughing Station exceeds Range",\ "OVENTEMPERATURE:The Temperature of the Oven exceeds Range",\ "DEBUG:Just for debugging purposes" LAB/VC/Alarms->AlarmReceivers: OVENPRESSURE:somebody@cells.es,someone_else@cells.es,SMS:+34999666333,\ ADIXENPRESSURE:somebody@cells.es,someone_else@cells.es,SMS:+34999666333,\ OVENTEMPERATURE:somebody@cells.es,someone_else@cells.es,SMS:+34999666333,\ DEBUG:somebody@cells.es LAB/VC/Alarms->AlarmsList: "OVENPRESSURE:LAB/VC/BestecOven-1/Pressure_mbar > 5e-4",\ "OVENRUNNING:LAB/VC/BestecOven-1/MaxValue > 70",\ "ADIXENPRESSURE:LAB/VC/Adixen-01/P1 > 1e-4 and OVENRUNNING",\ "OVENTEMPERATURE:LAB/VC/BestecOven-1/MaxValue > 220",\ "DEBUG:OVENRUNNING and not PCISDOWN" LAB/VC/Alarms->PollingPeriod: 30 LAB/VC/Alarms->SMSConfig: ... ``` -------------------------------- ### Start Device Server Source: https://pythonhosted.org/panic/_sources/recipes/CustomAlarms.txt Launch the device server using Astor. ```python import fandango as fn fn.Astor('test/pyalarm/clock').start_servers(host='your_hostname') ``` -------------------------------- ### Start PyAlarm Device Server with Astor Source: https://pythonhosted.org/panic/_sources/recipes/UseEventsWithTaurus.txt This code starts the PyAlarm device server using Astor. Replace 'your_hostname' with the actual hostname where the server will run. This is necessary before configuring device properties. ```python import fandango as fn fn.Astor('test/pyalarm/events').start_servers(host='your_hostname') ``` -------------------------------- ### Setup Toolbar Source: https://pythonhosted.org/panic/_modules/panic/widgets.html Configures the toolbar, initializes the API, and applies filters. ```python def setup(self,filters=None,api=None):#, alarms=None): print "In PanicToolbar.setup(%s)"%filters self.setMovable(True) self.setFloatable(True) filters = filters or self.filters if not self.api: self.api = api or AlarmAPI(filters) else: self.api.load(filters) self.alarms = [] #dict((a,) for a in self.api) #Alarms must be set here and not in refresh; #We should never clear this list again if filters and filters not in self.filters: if isinstance(filters,basestring): self.filters.append(filters) else: self.filters.extend(filters) self.filter_alarms() return ``` -------------------------------- ### Create a TEST_ALARM using PANIC API Source: https://pythonhosted.org/panic/_sources/recipes/InstallPanic.txt Create a new alarm using the PANIC API. This example sets up a test alarm that monitors a simulated device attribute. Ensure the 'panic' library is installed and accessible. ```python import panic alarms = panic.api() alarms.add('TEST_ALARM',formula='(test/sim/1/A%15 > 5)',description='test',receivers='your@mail') ``` -------------------------------- ### Start Alarm Servers Source: https://pythonhosted.org/panic/_modules/panic/panic.html Starts alarm servers matching the provided filters. ```python def start_servers(self,tag='',device='',host=''): "" Starts Alarm Servers matching the filters "" self.servers.start_servers(set(self.servers.get_device_server(a.device) for a in self.get_alarms(tag,device)),host=host) ``` -------------------------------- ### Basic PyQt Application Setup Source: https://pythonhosted.org/panic/_modules/panic/gui/core.html Initializes a PyQt application instance. This is the entry point for any PyQt application. ```python import sys app = QtGui.QApplication(sys.argv) ``` -------------------------------- ### Start the PyAlarm Server Source: https://pythonhosted.org/panic/Install.html Execute the PyAlarm server instance from the command line with verbose logging enabled. ```bash python ds/PyAlarm.py TEST -v4 ``` -------------------------------- ### Print Formula Rows (Example) Source: https://pythonhosted.org/panic/_modules/panic/gui/editor.html An example method to iterate through the current formula rows and print their children. This is likely for debugging or demonstration purposes. ```python def PrintText(self): # just egzample self.rows = self._rowList print "PRINT" for i in self.rows: print "childrens: ", self.rows[i] self.targets = ('variableCombo','valueCombo','operatorCombo') for t in self.targets: ``` -------------------------------- ### PanicToolbar Initialization and Setup Source: https://pythonhosted.org/panic/_modules/panic/widgets.html Details the initialization of the PanicToolbar, including setting up timers, filters, and the API connection. ```APIDOC ## PanicToolbar Class ### Description Represents a toolbar for managing and displaying alarms, with features for filtering and refreshing alarm data. ### Methods #### `__init__(self, parent=None, container=None, filters=None, max_visible=16, refresh=10000)` Initializes the PanicToolbar. - **parent** (QWidget, optional): The parent widget. - **container** (QWidget, optional): The container widget. - **filters** (list, optional): A list of filters to apply to alarms. - **max_visible** (int, optional): Maximum number of alarms to display. - **refresh** (int, optional): The refresh interval in milliseconds. #### `setup(self, filters=None, api=None)` Configures the toolbar, setting up filters and the AlarmAPI. - **filters** (list, optional): Filters to apply. Defaults to existing filters. - **api** (AlarmAPI, optional): An instance of AlarmAPI. If not provided, a new one is created. ### Attributes - **api**: An instance of AlarmAPI used for retrieving alarm data. - **filters**: A list of filters applied to the alarms. - **buttons**: A dictionary to store toolbar buttons. - **gui**: An instance of GuiWidget for displaying the GUI. - **refreshTimer**: A QTimer object for periodic refreshing. ``` -------------------------------- ### Launch PANIC GUI Source: https://pythonhosted.org/panic/recipes/InstallPanic.html Command to start the PANIC user interface application. ```bash python Panic/gui.py ``` -------------------------------- ### Alarm Object Initialization and Setup Source: https://pythonhosted.org/panic/_modules/panic/panic.html Details on how to initialize and set up an Alarm object with various parameters. ```APIDOC ## Alarm Object ### Description Represents an alarm within the system, used by the API to manage and monitor alarm states. ### Method `__init__` ### Parameters - **tag** (string) - Required - The unique tag identifying the alarm. - **device** (string) - Optional - The device associated with the alarm. - **formula** (string) - Optional - The formula used for alarm evaluation. - **description** (string) - Optional - A description of the alarm. - **receivers** (string) - Optional - Information about alarm receivers. - **config** (string) - Optional - Configuration settings for the alarm. - **severity** (string) - Optional - The severity level of the alarm. - **api** (object) - Optional - The API object instance. ### Method `setup` ### Description Assigns or updates values for the Alarm object's attributes. ### Parameters - **tag** (string) - Optional - The unique tag identifying the alarm. - **device** (string) - Optional - The device associated with the alarm. - **formula** (string) - Optional - The formula used for alarm evaluation. - **description** (string) - Optional - A description of the alarm. - **receivers** (string) - Optional - Information about alarm receivers. - **config** (string) - Optional - Configuration settings for the alarm. - **severity** (string) - Optional - The severity level of the alarm. - **write** (boolean) - Optional - If True, writes the changes to the system. ``` -------------------------------- ### Launch the PANIC GUI Source: https://pythonhosted.org/panic/Install.html Run the GUI directly from the source directory without performing a full system installation. ```bash python panic/gui/gui.py ``` -------------------------------- ### PanicToolbar setup Method Source: https://pythonhosted.org/panic/panic.widgets.html Sets up the PanicToolbar with filters and an API. This method is part of the PanicToolbar class. ```python def setup(_filters=None, _api=None): pass ``` -------------------------------- ### Import and Initialize PANIC API Source: https://pythonhosted.org/panic/_sources/recipes/PanicAPI.txt Import the panic module and get an instance of the AlarmAPI to manage PyAlarm devices. ```python import panic alarms = panic.api() ``` -------------------------------- ### Get Alarm Timestamp Function Source: https://pythonhosted.org/panic/panic.gui.widgets.html Gets the activation timestamp of an alarm. Optionally uses Taurus. ```python panic.gui.widgets.getAlarmTimestamp(_alarm_ , _attr_value=None_ , _use_taurus=True_) ``` -------------------------------- ### Initialize Application Source: https://pythonhosted.org/panic/_modules/panic/gui/editor.html Entry point for the application, initializing the Qt environment and displaying the AlarmForm. ```python if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = AlarmForm() if sys.argv[1:]: myapp.setAlarmData(*sys.argv[1:]) else: myapp.onNew() myapp.show() sys.exit(app.exec_()) ``` -------------------------------- ### Get and Set Alarm Device Properties Source: https://pythonhosted.org/panic/_modules/panic/panic.html Utility functions to get or set specific properties on a Tango alarm device. ```python def getAlarmDeviceProperty(device, prop): """ Gets the value of pointed property from the device """ return _TANGO.get_device_property(device,[prop])[prop] ``` ```python def setAlarmDeviceProperty(device, prop, value): """ Sets property of the device """ _TANGO.put_device_property(device,{prop:[value]}) ``` -------------------------------- ### Application Entry Point Source: https://pythonhosted.org/panic/_modules/panic/gui/devattrchange.html Standard Python application entry point using PyQt. Initializes the QApplication, creates a main widget, sets up the UI, shows the widget, and starts the application's event loop. ```Python if __name__ == "__main__": import sys app=QtGui.QApplication(sys.argv) Form=QtGui.QWidget() ui=devattrchangeForm() ui.devattrchangeSetupUi(Form) Form.show() ui.setDevCombo() sys.exit(app.exec_()) ``` -------------------------------- ### Initialize UI for Alarm List Source: https://pythonhosted.org/panic/_modules/panic/gui/core.html Sets up the main window and its basic properties like size policy and minimum size. This is the entry point for the UI setup. ```python from widgets import Qt, QtCore, QtGui import taurus from taurus.qt.qtgui.panel import TaurusForm from widgets import getThemeIcon [docs]class Ui_AlarmList(object): [docs] def setupUi(self, Form): self.Form=Form Form.setObjectName("Form") #Form.resize(QtCore.QSize(900, 900)) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) #sizePolicy.setHorizontalStretch(100) #sizePolicy.setVerticalStretch(100) sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth()) Form.setSizePolicy(sizePolicy) Form.setMinimumSize(QtCore.QSize(250, 250)) Form.setSizeIncrement(QtCore.QSize(1, 1)) ``` -------------------------------- ### iValidatedWidget Usage Example Source: https://pythonhosted.org/panic/panic.gui.widgets.html Example of using iValidatedWidget, which requires a PanicAPI member and specific PyAlarm properties. It demonstrates conditional logic based on validation and user permissions. ```python self.setAllowedUsers(self.api.get_admins_for_alarm(len(items)==1 and items[0].get_alarm_tag())) if not self.validate('onDisable/Enable(%s,%s)'%(checked,[a.get_alarm_tag() for a in items])): return ``` -------------------------------- ### Create Periodic Self-Reset Alarm Source: https://pythonhosted.org/panic/_sources/recipes/AlarmExamples.txt Example of a periodic alarm that uses the current time and sets 'AlarmThreshold', 'PollingPeriod', and 'AutoReset' properties. This specific example executes a command within its own formula. ```python PERIODIC:(FrontEnds/VC/Elotech-01/Temperature and FrontEnds/VC/VGCT-01/P1 \ and (1920<(now%3600)<3200)) or (ResetAlarm('PERIODIC') and False) ``` -------------------------------- ### Application Entry Point Source: https://pythonhosted.org/panic/_modules/panic/gui/alarmhistory.html Sets up and runs the main application window for the alarm history form. It initializes the Qt application, creates the main form widget, sets up the UI, shows the form, performs an initial refresh, and starts the application event loop. ```python if __name__ == "__main__": import sys app=QtGui.QApplication(sys.argv) Form=QtGui.QWidget() ui=alarmhistoryForm() ui.alarmhistorySetupUi(Form) Form.show() ui.onRefresh() sys.exit(app.exec_()) ``` -------------------------------- ### List Comprehension Examples with FIND Source: https://pythonhosted.org/panic/_sources/recipes/AlarmExamples.txt Demonstrates various ways to use list comprehensions with the 'FIND' function for filtering and evaluating attributes. These examples show how to check for the existence of errors or specific conditions within a set of found attributes. ```python any([s for s in FIND(SR/ID/SCW01/Cooler*Err*)]) ``` ```python any(FIND(SR/ID/SCW01/Cooler*Err*)) ``` ```python any([s==0 for s in FIND(SR/ID/SCW01/Cooler*Err*)]) ``` ```python any(not s for s in FIND(SR/ID/SCW01/Cooler*Err*)) ``` ```python not all(FIND(SR/ID/SCW01/Cooler*Err*)) ``` ```python [s for s in FIND(SR/ID/SCW01/Cooler*Err*) if not s] ``` -------------------------------- ### Configure context menu actions Source: https://pythonhosted.org/panic/_modules/panic/gui/gui.html Sets up menu actions for device testing and configuration within a Qt popup menu. ```python act.setEnabled(len(items)==1) self.popMenu.addAction(getThemeIcon("applications-system"), "Advanced Config",self.onConfig) self.popMenu.addSeparator() act = self.popMenu.addAction(getThemeIcon("accessories-text-editor"), "TestDevice",lambda d=row.alarm.device:os.system('tg_devtest %s &'%d)) act.setEnabled(len(items)==1) #self.popMenu.addSeparator() #self.popMenu.addAction(getThemeIcon("process-stop"), "close App",self.close) self.popMenu.exec_(self._ui.listWidget.mapToGlobal(point)) ``` -------------------------------- ### Alarm Preview Window Execution Source: https://pythonhosted.org/panic/_modules/panic/gui/widgets.html Example of how to instantiate and show the AlarmPreview window when the script is run directly. Sets up the Qt application event loop. ```python if __name__ == '__main__': import sys qapp = Qt.QApplication(sys.argv) form = AlarmPreview(*sys.argv[1:]) form.show() qapp.exec_() ``` -------------------------------- ### get_bold_font Function Source: https://pythonhosted.org/panic/panic.gui.widgets.html Gets a bold font object. ```APIDOC ## Function: get_bold_font ### Description Returns a font object configured for bold text. ### Parameters - **points_** (int) - The font size in points. Defaults to 8. ``` -------------------------------- ### getAlarmTimestamp Function Source: https://pythonhosted.org/panic/panic.gui.widgets.html Gets the activation timestamp of an alarm. ```APIDOC ## Function: getAlarmTimestamp ### Description Retrieves the activation timestamp of a given alarm object. ### Parameters - **alarm_** (any) - The alarm object. - **attr_value** (any) - Optional attribute value. - **use_taurus** (bool) - Whether to use Taurus for timestamp retrieval. Defaults to True. ### Returns The alarm activation timestamp, or 0 if not available. ``` -------------------------------- ### Get User Source: https://pythonhosted.org/panic/panic.gui.widgets.html Retrieves the current user information. ```python get_user() ``` -------------------------------- ### GET /api/alarms/configurations Source: https://pythonhosted.org/panic/_modules/panic/panic.html Retrieves alarm configurations for specified tags. ```APIDOC ## GET /api/alarms/configurations ### Description Retrieves the configuration details for alarms, optionally filtered by a tag pattern. ### Method GET ### Endpoint /api/alarms/configurations ### Parameters #### Query Parameters - **tag** (string) - Optional - A tag pattern to filter alarms (default: '*'). ### Response #### Success Response (200) - **configurations** (object) - A dictionary where keys are alarm tags and values are their configuration objects, including device, severity, and notification settings (Snap, Email, Action, SMS). #### Response Example ```json { "alarm_tag_1": { "Device": "server_1", "Severity": "WARNING", "Snap": true, "Email": false, "Action": true, "SMS": false, "threshold": 80, "unit": "C" } } ``` ``` -------------------------------- ### Initialize PANIC GUI Application Source: https://pythonhosted.org/panic/_modules/panic/gui/gui.html The main function configures the TaurusApplication, sets up the main window with menus and toolbars, and initializes various alarm-related widgets. ```python def main(args=[]): import widgets from taurus.qt.qtgui.application import TaurusApplication opts = [a for a in args if a.startswith('-')] args = [a for a in args if not a.startswith('-')] URL = 'http://www.cells.es/Intranet/Divisions/Computing/Controls/Help/Alarms/panic' #uniqueapp = Qt.QApplication([]) uniqueapp = TaurusApplication(opts) print '='*80 trace(' Launching Panic ...') print '='*80 if '--calc' in opts: args = args or [''] form = AlarmPreview(*args) form.show() uniqueapp.exec_() return tmw = CleanMainWindow() tmw.setWindowTitle('PANIC') #str(os.getenv('TANGO_HOST')).split(':',1)[0]+' ) tmw.menuBar = Qt.QMenuBar(tmw) tmw.toolsMenu = Qt.QMenu('Tools',tmw.menuBar) tmw.fileMenu = Qt.QMenu('File',tmw.menuBar) tmw.viewMenu = Qt.QMenu('View',tmw.menuBar) tmw.helpMenu = Qt.QMenu('Help',tmw.menuBar) trace('\tlaunching AlarmGUI ... %s'%sys.argv) alarmApp = AlarmGUI(filters='|'.join(args),options=opts,mainwindow=tmw) tmw.setCentralWidget(alarmApp) tmw.setMenuBar(tmw.menuBar) [tmw.menuBar.addAction(a.menuAction()) for a in (tmw.fileMenu,tmw.toolsMenu,tmw.helpMenu,tmw.viewMenu)] toolbar = Qt.QToolBar(tmw) toolbar.setIconSize(Qt.QSize(20,20)) tmw.helpMenu.addAction(getThemeIcon("applications-system"),"Webpage",lambda : os.system('konqueror %s &'%URL)) tmw.toolsMenu.addAction(getThemeIcon("applications-system"),"Jive",lambda : os.system('jive &')) tmw.toolsMenu.addAction(getThemeIcon("applications-system"),"Astor",lambda : os.system('astor &')) tmw.fileMenu.addAction(getThemeIcon(":/designer/back.png"),"Export to CSV file",alarmApp.saveToFile) tmw.fileMenu.addAction(getThemeIcon(":/designer/forward.png"),"Import from CSV file",alarmApp.loadFromFile) tmw.fileMenu.addAction(getThemeIcon(":/designer/filereader.png"),"Use external editor",alarmApp.editFile) tmw.fileMenu.addAction(getThemeIcon("applications-system"),"Exit",tmw.close) tmw.viewMenu.connect(tmw.viewMenu,Qt.SIGNAL('aboutToShow()'),alarmApp.setViewMenu) from phonebook import PhoneBook alarmApp.tools['bookApp'] = WindowManager.addWindow(PhoneBook(container=tmw)) tmw.toolsMenu.addAction(getThemeIcon("x-office-address-book"), "PhoneBook", alarmApp.tools['bookApp'].show) toolbar.addAction(getThemeIcon("x-office-address-book") ,"PhoneBook",alarmApp.tools['bookApp'].show) trend_action = (getThemeIcon(":/designer/qwtplot.png"), 'Trend', lambda:WindowManager.addWindow(widgets.get_archive_trend(show=True)) ) tmw.toolsMenu.addAction(*trend_action) toolbar.addAction(*trend_action) alarmApp.tools['config'] = WindowManager.addWindow(widgets.dacWidget(container=tmw)) tmw.toolsMenu.addAction(getThemeIcon("applications-system"),"Advanced Configuration", alarmApp.tools['config'].show) toolbar.addAction(getThemeIcon("applications-system") ,"Advanced Configuration",alarmApp.tools['config'].show) toolbar.setMovable(False) toolbar.setFloatable(False) tmw.addToolBar(toolbar) if SNAP_ALLOWED: alarmApp.tools['history'] = WindowManager.addWindow(widgets.ahWidget(container=tmw)) tmw.toolsMenu.addAction(getThemeIcon("office-calendar"),"Alarm History Viewer",alarmApp.tools['history'].show) toolbar.addAction(getThemeIcon("office-calendar") ,"Alarm History Viewer",alarmApp.tools['history'].show) else: trace("Unable to load SNAP",'History Viewer Disabled!') alarm_preview_action = (getThemeIcon("accessories-calculator"),"Alarm Calculator", lambda g=alarmApp:WindowManager.addWindow(AlarmPreview.showEmptyAlarmPreview(g))) [o.addAction(*alarm_preview_action) for o in (tmw.toolsMenu,toolbar)] tmw.show() return uniqueapp #.exec_() ``` -------------------------------- ### GET /api/alarms/filter_severity Source: https://pythonhosted.org/panic/_modules/panic/panic.html Filters alarms based on severity level. ```APIDOC ## GET /api/alarms/filter_severity ### Description Filters a list of alarms based on a specified severity level. It returns alarms with the given severity or higher, depending on the input severity. ### Method GET ### Endpoint /api/alarms/filter_severity ### Parameters #### Query Parameters - **sev** (string) - Required - The severity level to filter by (e.g., 'WARNING', 'ALARM', 'ERROR'). - **alarms** (array) - Optional - A list of alarms to filter. If not provided, all alarms are considered. ### Response #### Success Response (200) - **alarms** (array) - A list of alarms matching the specified severity criteria. #### Response Example ```json [ { "tag": "high_temp_alarm", "severity": "ERROR", "device": "server_1", "formula": "temp > 90", "description": "High temperature detected." } ] ``` ``` -------------------------------- ### Initialize and display PyQt UI Source: https://pythonhosted.org/panic/_modules/panic/gui/core.html Use this pattern to launch a window defined by a generated Ui_AlarmList class. Ensure the QApplication instance is initialized before calling app.exec_(). ```python Form = QtGui.QWidget() ui = Ui_AlarmList() ui.setupUi(Form) Form.show() sys.exit(app.exec_()) ``` -------------------------------- ### GET /device/state Source: https://pythonhosted.org/panic/_modules/panic/panic.html Retrieves the current operational state of the device. ```APIDOC ## GET /device/state ### Description Returns the current state of the device. ### Method GET ``` -------------------------------- ### PyAlarm Main Execution Function Source: https://pythonhosted.org/panic/_modules/panic/ds/PyAlarm.html Sets up and runs the PyTango server for the PyAlarm class. It initializes PyTango, adds the PyAlarm class, and starts the server loop. Includes error handling for PyTango DevFailed exceptions and other unforeseen errors. ```python def main(args=None): import sys if args is None: args = sys.argv try: py = PyTango.Util(args) py.add_TgClass(PyAlarmClass,PyAlarm,'PyAlarm') try: import sys from fandango.device import DDebug DDebug.addToServer(py,'PyAlarm',args[1]) except Exception,e: print('Unable to add DDebug class to PyAlarm: ',e) U = PyTango.Util.instance() U.server_init() U.server_run() except PyTango.DevFailed,e: print '-------> Received a DevFailed exception:',traceback.format_exc() except Exception,e: print '-------> An unforeseen exception occured....',traceback.format_exc() ``` -------------------------------- ### Get Device Status Source: https://pythonhosted.org/panic/_modules/panic/panic.html Retrieves the current status of the device. ```python def status(self): """ Returns device status """ return self.get().Status() ``` -------------------------------- ### Setup Main Layout and Frame Source: https://pythonhosted.org/panic/_modules/panic/gui/core.html Configures the main horizontal layout and a styled frame within the form. The frame is set to have a minimum size. ```python self.horizontalLayout_3 = QtGui.QHBoxLayout(Form) self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.Form.setLayout(self.horizontalLayout_3) self.verticalLayout_2 = QtGui.QVBoxLayout() self.verticalLayout_2.setObjectName("verticalLayout_2") self.frame = QtGui.QFrame(Form) self.frame.setFrameShape(QtGui.QFrame.StyledPanel) self.frame.setFrameShadow(QtGui.QFrame.Raised) self.frame.setObjectName("frame") self.frame.setMinimumSize(QtCore.QSize(300, 200)) ``` -------------------------------- ### Get User Function Source: https://pythonhosted.org/panic/panic.gui.widgets.html Retrieves the current user information. ```python panic.gui.widgets.get_user() ``` -------------------------------- ### Get Alarm Report Function Source: https://pythonhosted.org/panic/panic.gui.widgets.html Retrieves an alarm report. ```python panic.gui.widgets.getAlarmReport(_alarm_ , _parent=None_) ``` -------------------------------- ### Configure SNAP Database Logging Source: https://pythonhosted.org/panic/recipes/ReceiversLoggingAndActions.html Enable logging to a SNAP database by setting PyAlarm's CreateNewContexts property to True or manually creating contexts. Set UseSnap=True to trigger snapshots for all alarms, or add the SNAP receiver directly. ```text # UseSnap=True to trigger snapshots for all alarms # Or simply add the SNAP receiver. ``` -------------------------------- ### Get Alarm Report Source: https://pythonhosted.org/panic/panic.gui.widgets.html Generates a report for a given alarm. ```python getAlarmReport(alarm, parent=None) ``` -------------------------------- ### Get SNAP API Source: https://pythonhosted.org/panic/panic.gui.widgets.html Retrieves the SNAP API object. ```python get_snap_api() ``` -------------------------------- ### Prepare Line Widget Source: https://pythonhosted.org/panic/_modules/panic/gui/editor.html Initializes the UI components for the State/Details/Reset line. ```python def prepareLineWidget(self): #Setup of the State/Details/Reset line in the editor widget self.w = Qt.QWidget() self.w.setLayout(Qt.QHBoxLayout()) self._tvl = AlarmValueLabel(self.w) self._tvl.setShowQuality(False) self._detailsButton = Qt.QPushButton(self.w) self._detailsButton.setText('Last Report') self._detailsButton.setIcon(getThemeIcon("edit-find")) self._detailsButton.connect(self._detailsButton,Qt.SIGNAL("clicked()"),self.showAlarmReport) self._detailsButton.setEnabled(False) self._resetButton = Qt.QPushButton(self.w) self._resetButton.setText('Reset') self._resetButton.setIcon(getThemeIcon("edit-undo")) self._resetButton.connect(self._resetButton,Qt.SIGNAL("clicked()"),self.ResetAlarm) self._resetButton.setEnabled(False) self.w.layout().addWidget(self._tvl) self.w.layout().addWidget(self._detailsButton) self.w.layout().addWidget(self._resetButton) self._dataWidget._wi.horizontalLane.addWidget(self.w) ``` -------------------------------- ### Add New PyAlarm Device UI Source: https://pythonhosted.org/panic/_modules/panic/gui/devattrchange.html Creates a PyQt GUI window to add a new PyAlarm device. It includes input fields for server instance and device name, and a button to apply changes. ```Python w.setWindowTitle('Add New PyAlarm Device') w.setLayout(Qt.QGridLayout()) server,device = Qt.QLineEdit(w),Qt.QLineEdit(w) server.setText('TEST') device.setText('test/pyalarm/1') w.layout().addWidget(Qt.QLabel('Server Instance'),0,0,1,1) w.layout().addWidget(server,0,1,1,1) w.layout().addWidget(Qt.QLabel('Device Name'),1,0,1,1) w.layout().addWidget(device,1,1,1,1) doit = Qt.QPushButton('Apply') w.layout().addWidget(doit,2,0,2,2) def create(s=server,d=device,p=w): try: s,d = str(s.text()),str(d.text()) if '/' not in s: s = 'PyAlarm/%s'%s import fandango.tango as ft ft.add_new_device(s,'PyAlarm',d) print('%s - %s: created!'%(s,d)) except: traceback.print_exc() self.api.load() p.close() QtCore.QObject.connect(doit, QtCore.SIGNAL("clicked()", create) w.exec_() self.setDevCombo() ``` -------------------------------- ### GET /api/alarms/{alarm}/admins Source: https://pythonhosted.org/panic/_modules/panic/panic.html Retrieves administrators for a specific alarm. ```APIDOC ## GET /api/alarms/{alarm}/admins ### Description Retrieves a list of administrators for a specific alarm. This includes globally defined admin users and any specific users associated with the alarm's receivers. ### Method GET ### Endpoint /api/alarms/{alarm}/admins ### Parameters #### Path Parameters - **alarm** (string) - Required - The tag of the alarm. ### Response #### Success Response (200) - **admins** (array) - A list of administrator usernames. #### Response Example ```json [ "admin_user_1", "admin_user_2", "specific_user_for_alarm" ] ``` ``` -------------------------------- ### Launch PyAlarm and Simulator Devices Source: https://pythonhosted.org/panic/_sources/recipes/InstallPanic.txt Launch the PyAlarm and Simulator devices from the shell. Ensure the Python scripts are in your PYTHONPATH. ```shell # python PyAlarm/PyAlarm.py 1 & # python PySignalSimulator/PySignalSimulator.py 1 & ``` -------------------------------- ### GET /db_properties Source: https://pythonhosted.org/panic/_modules/panic/panic.html Retrieves configuration or specific properties for a device from the database. ```APIDOC ## GET /db_properties ### Description Retrieves the configuration or specific properties associated with a device. ### Method GET ### Parameters #### Query Parameters - **update** (boolean) - Optional - If true, forces a refresh of the configuration from the database. - **prop** (string/sequence) - Required - The property name or list of property names to retrieve. ``` -------------------------------- ### POST /init Source: https://pythonhosted.org/panic/_modules/panic/panic.html Forces the device to reload its configuration. ```APIDOC ## POST /init ### Description Forces the device to reload its configuration by reading the device state and re-initializing. ### Method POST ``` -------------------------------- ### Get Current Alarms Source: https://pythonhosted.org/panic/_modules/panic/gui/gui.html Returns the currently ordered list of alarms. ```python def getCurrents(self): return self._ordered ``` -------------------------------- ### Get Snap API Function Source: https://pythonhosted.org/panic/panic.gui.widgets.html Retrieves the Snap API object. ```python panic.gui.widgets.get_snap_api() ``` -------------------------------- ### POST /init_device Source: https://pythonhosted.org/panic/_modules/panic/ds/PyAlarm.html Initializes a device, optionally updating properties and allowing the operation. ```APIDOC ## POST /init_device ### Description Initializes a device. This method can be called first for creating the device or afterwards to force a reloading of Alarms or Properties. ### Method POST ### Endpoint /init_device ### Parameters #### Query Parameters - **update_properties** (boolean) - Optional - If true, properties will be updated. - **allow** (boolean) - Optional - If true, the initialization is allowed. Defaults to true. ### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example { "status": "Device initialized successfully" } #### Error Response (400) - **error** (string) - Description of the error if initialization is not allowed. #### Error Example { "error": "init_device() is not allowed, please restart the server" } ``` -------------------------------- ### Device Initialization and Acknowledgment Source: https://pythonhosted.org/panic/_modules/panic/panic.html Methods for reloading device configurations and acknowledging active alarms. ```python def init(self): """ forces the device to reload its configuration""" try: self.read() self.get().init() self.config = None except: print 'Device %s is not running' % self.name ``` ```python def acknowledge(self,alarm,comment): """ Acknowledge of an active Alarm Returns True if there's no more active alarms, else returns False """ args=[] args.append(str(alarm)) args.append(str(comment)) try: return (False if self.get().ResetAlarm(args) else True) except: print 'Device %s is not running' % self.name print traceback.format_exc() return None ``` -------------------------------- ### Alarm Server Control Source: https://pythonhosted.org/panic/panic.panic.html Methods to start, stop, and update alarm servers. ```APIDOC ## POST /start_servers ### Description Starts Alarm Servers matching the provided filters. ### Method POST ### Parameters #### Request Body - **tag** (string) - Optional - Filter by tag - **device** (string) - Optional - Filter by device - **host** (string) - Optional - Filter by host ## POST /stop_servers ### Description Stops Alarm Servers matching the provided filters. ### Method POST ### Parameters #### Request Body - **tag** (string) - Optional - Filter by tag - **device** (string) - Optional - Filter by device ``` -------------------------------- ### Configure UI Layout Elements Source: https://pythonhosted.org/panic/_modules/panic/gui/ui_data.html Initializes widgets and adds them to a grid layout. Requires an existing Data object and gridLayout instance. ```python self.descriptionTextEdit.setMinimumSize(QtCore.QSize(0, 25)) self.descriptionTextEdit.setReadOnly(True) self.descriptionTextEdit.setObjectName("descriptionTextEdit") self.gridLayout.addWidget(self.descriptionTextEdit, 6, 1, 1, 3) self.receiversLabel = QtGui.QLabel(Data) self.receiversLabel.setObjectName("receiversLabel") self.gridLayout.addWidget(self.receiversLabel, 7, 0, 1, 1) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.receiversStackedLayout = QtGui.QStackedLayout() self.receiversStackedLayout.setObjectName("receiversStackedLayout") self.receiversLineEdit = clickableQLineEdit(Data) self.receiversLineEdit.setReadOnly(True) self.receiversLineEdit.setObjectName("receiversLineEdit") self.receiversLineEdit.setSizePolicy(sizePolicy) self.receiversStackedLayout.addWidget(self.receiversLineEdit) self.receiversWidget = QtGui.QWidget(Data) self.receiversWidget.setObjectName("receiversWidget") ``` -------------------------------- ### Build and Display Alarm Toolbar Source: https://pythonhosted.org/panic/_modules/panic/widgets.html This code initializes the Qt application, processes command-line arguments to determine filters, and constructs the main window with a Taurus form and a custom PanicToolbar. It handles cases where specific attributes are provided or when a general filter is used. ```python if __name__ == '__main__': qapp = Qt.QApplication([]) devices = sys.argv[1:] if any('/' in d for d in devices): filters = None attr_list = ['%s/%s'%(d,a) for d in devices for a in PyTango.DeviceProxy(d).get_attribute_list()] else: filters = devices attr_list = [] if attr_list: import taurus taurus.setLogLevel('WARNING') tmw = TaurusMainWindow() taurusForm = TaurusForm(tmw) taurusForm.setModel(attr_list) tmw.setCentralWidget(taurusForm) tmw.statusBar().showMessage('Ready') tmw.show() s=tmw.splashScreen() s.finish(tmw) else: tmw = Qt.QMainWindow() label = Qt.QLabel('Select any alarm from the toolbar') tmw.setCentralWidget(label) tmw.show() tmw.setMinimumWidth(600) print '*'*80 tmw.setWindowTitle('Alarm Toolbar') toolbar = PanicToolbar(tmw,filters=filters) tmw.addToolBar(toolbar) sys.exit(qapp.exec_()) ``` -------------------------------- ### Get Active Alarms Source: https://pythonhosted.org/panic/_modules/panic/ds/PyAlarm.html Retrieves a list of all currently active alarm tags. ```python def get_active_alarms(self): return [k for k,v in self.Alarms.items() if v.active] ``` -------------------------------- ### Get Last Values Source: https://pythonhosted.org/panic/_modules/panic/ds/PyAlarm.html Retrieves the most recent values for variables associated with an alarm. ```python def get_last_values(self,alarm='',variables=None): if self.worker: # Getting the values of variables previous = self.worker.get('previous') try: #self.debug('previous values: %s'%previous.keys()) if variables is None: variables = self.Eval.parse_variables(self.Alarms[alarm].formula) formula = self.Alarms[alarm].formula if alarm in self.Alarms else '' VALUE = dict((k,v) for k,v in previous.items() if any(fun.searchCl(self.Eval.parse_tag(v[0]+'/'+v[1],'.'),k) for v in variables)) VALUE.update((a,bool(v.active)) for a,v in self.Alarms.items() if a in formula) ``` -------------------------------- ### Declare PyAlarm Device Server Properties Source: https://pythonhosted.org/panic/PyAlarmUserGuide.html Example of a typical PyAlarm device server configuration including alarm descriptions, receivers, and logic. ```text #--------------------------------------------------------- # SERVER PyAlarm/AssemblyArea, PyAlarm device declaration #--------------------------------------------------------- PyAlarm/AssemblyArea/DEVICE/PyAlarm: "LAB/VC/Alarms" # --- LAB/VC/Alarms properties LAB/VC/Alarms->AlarmDescriptions: "OVENPRESSURE:The pressure in the Oven exceeds Range",\ "ADIXENPRESSURE:The pressure in the Roughing Station exceeds Range",\ "OVENTEMPERATURE:The Temperature of the Oven exceeds Range",\ "DEBUG:Just for debugging purposes" LAB/VC/Alarms->AlarmReceivers: OVENPRESSURE:somebody@cells.es,someone_else@cells.es,SMS:+34999666333,\ ADIXENPRESSURE:somebody@cells.es,someone_else@cells.es,SMS:+34999666333,\ OVENTEMPERATURE:somebody@cells.es,someone_else@cells.es,SMS:+34999666333,\ DEBUG:somebody@cells.es LAB/VC/Alarms->AlarmsList: "OVENPRESSURE:LAB/VC/BestecOven-1/Pressure_mbar > 5e-4",\ "OVENRUNNING:LAB/VC/BestecOven-1/MaxValue > 70",\ "ADIXENPRESSURE:LAB/VC/Adixen-01/P1 > 1e-4 and OVENRUNNING",\ "OVENTEMPERATURE:LAB/VC/BestecOven-1/MaxValue > 220",\ "DEBUG:OVENRUNNING and not PCISDOWN" LAB/VC/Alarms->PollingPeriod: 30 LAB/VC/Alarms->SMSConfig: ... ``` -------------------------------- ### GET /load Source: https://pythonhosted.org/panic/_modules/panic/panic.html Reloads all alarm properties from the database based on provided filters. ```APIDOC ## GET /load ### Description Reloads all alarm properties from the database. Allows filtering by device or server name. ### Method GET ### Parameters #### Query Parameters - **filters** (string) - Optional - Specifies which devices to be loaded (default: '*'). - **exported** (boolean) - Optional - If True, only loads exported devices. ``` -------------------------------- ### Initialize AlarmGUI Source: https://pythonhosted.org/panic/_modules/panic/gui/gui.html Initializes the GUI components and sets up initial combo box states. ```python trace('Setting combos ...') self.source = "" #Value in first comboBox self.setFirstCombo() self.setSecondCombo() self._ui.infoLabel0_1.setText(self._ui.contextComboBox.currentText()) self.updateStatusLabel() trace('AlarmGUI(): done') ``` -------------------------------- ### Configure PyQt Layouts and Widgets Source: https://pythonhosted.org/panic/_modules/panic/gui/ui_data.html Initializes stacked layouts, frames, and buttons within a PyQt interface. Requires an existing Data object context. ```python # self.receiversStackedLayout.addWidget(self.receiversWidget) self.receiversStackedLayout.setCurrentIndex(0) self.horizontalLayout.addLayout(self.receiversStackedLayout) self.addReceiversButton = QtGui.QPushButton(Data) self.addReceiversButton.setObjectName("addReceiversButton") self.addReceiversButton.setIcon(getThemeIcon("list-add")) self.horizontalLayout.addWidget(self.addReceiversButton) self.addReceiversButton.setEnabled(False) self.gridLayout.addLayout(self.horizontalLayout, 7, 1, 1, 1) self.verticalLayout_3.addLayout(self.gridLayout) self.frame = QtGui.QFrame(Data) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth()) self.frame.setSizePolicy(sizePolicy) self.frame.setFrameShape(QtGui.QFrame.StyledPanel) self.frame.setFrameShadow(QtGui.QFrame.Raised) self.frame.setObjectName("frame") self.formulaStacked = QtGui.QStackedLayout(self.frame) self.formulaStacked.setObjectName("stackedLayout") self.formulaWidget = QtGui.QWidget(self.frame) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.formulaWidget.sizePolicy().hasHeightForWidth()) self.formulaWidget.setSizePolicy(sizePolicy) self.formulaWidget.setObjectName("formulaWidget") self.formulaStacked.addWidget(self.formulaWidget) # ad widget to stacked self.verticalLayout_2 = QtGui.QVBoxLayout(self.formulaWidget) self.verticalLayout_2.setObjectName("verticalLayout_2") self.formulaLabel = QtGui.QLabel()#self.formulaWidget) #self.font = QtGui.QFont() #self.font.setPointSize(8) #self.font.setWeight(75) #self.font.setBold(True) #self.formulaLabel.setFont(self.font) #self.formulaLabel.setObjectName("formulaLabel") #self.verticalLayout_2.addWidget(self.formulaLabel) from widgets import AlarmFormula self.formulaTextEdit = AlarmFormula() #clickableQTextEdit(self.formulaWidget) self.formulaTextEdit.setReadOnly(True) self.formulaTextEdit.setObjectName("formulaTextEdit") self.verticalLayout_2.addWidget(self.formulaTextEdit) self.verticalLayout_3.addWidget(self.frame) self.gridLayout_2 = QtGui.QGridLayout() self.gridLayout_2.setObjectName("gridLayout_2") self.spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout_2.addItem(self.spacerItem, 0, 2, 1, 1) self.editButton = QtGui.QPushButton(Data) self.font = QtGui.QFont() self.font.setPointSize(8) self.editButton.setFont(self.font) self.editButton.setObjectName("editButton") self.editButton.setIcon(getThemeIcon("accessories-text-editor")) self.gridLayout_2.addWidget(self.editButton, 0, 0, 1, 1) self.previewButton = QtGui.QPushButton(Data) self.font = QtGui.QFont() self.font.setPointSize(8) self.previewButton.setFont(self.font) self.previewButton.setObjectName("previewButton") self.previewButton.setIcon(getThemeIcon("face-glasses")) self.gridLayout_2.addWidget(self.previewButton, 0, 1, 1, 1) self.cancelButton = QtGui.QPushButton(Data) self.font = QtGui.QFont() self.font.setPointSize(8) self.cancelButton.setFont(self.font) self.cancelButton.setObjectName("cancelButton") self.cancelButton.setIcon(getThemeIcon("edit-delete")) self.gridLayout_2.addWidget(self.cancelButton, 0, 4, 1, 1) self.saveButton = QtGui.QPushButton(Data) self.font = QtGui.QFont() self.font.setPointSize(8) self.saveButton.setFont(self.font) self.saveButton.setObjectName("saveButton") self.saveButton.setIcon(getThemeIcon("document-save")) self.gridLayout_2.addWidget(self.saveButton, 0, 3, 1, 1) self.verticalLayout_3.addLayout(self.gridLayout_2) self.retranslateUi(Data) QtCore.QMetaObject.connectSlotsByName(Data) ``` -------------------------------- ### Access PyAlarm CACHE Source: https://pythonhosted.org/panic/_sources/recipes/CustomAlarms.txt Examples of querying the CACHE dictionary for attribute history. ```python PASS_BY_0=[(k,v.time.tv_sec,str(v.value)) for k,t in CACHE.items() for v in t if v.value==0] ``` ```python not (lambda l:max(l)-min(l))([v.value for v in CACHE['wr/rf/circ-1/heartbeat']]) ``` -------------------------------- ### Manage Alarm Thread Source: https://pythonhosted.org/panic/_modules/panic/ds/PyAlarm.html Methods to start and stop the background alarm update thread. ```python def start(self): if self.updateThread: if self.updateThread.isAlive(): self.warning( 'Start not allowed, thread still working') return else: del self.updateThread self.info( 'Thread Starting') self.kill.clear() self.pause.clear() self.updateThread = threading.Thread(None,self.updateAlarms,'PyAlarm') self.updateThread.setDaemon(True) self.updateThread.start() ``` ```python def stop(self): self.info( 'In PyAlarm.stop() ...') self.kill.set() self.pause.set() self.updateThread.join(self.PollingPeriod) if self.updateThread.isAlive(): self.warning( 'Thread '+self.updateThread.getName()+' doesn''t Stop!') else: self.warning( 'Thread '+self.updateThread.getName()+' Stop') if self.worker and self.worker.isAlive(): self.worker.stop() return ```