コード例 #1
0
ファイル: snuffling.py プロジェクト: trokia/pyrocko
    def make_panel(self, parent):
        '''Create a widget for the snuffling's control panel.
        
        Normally called from the :py:meth:`setup_gui` method. Returns ``None`` if no panel
        is needed (e.g. if the snuffling has no adjustable parameters).'''
    
        params = self.get_parameters()
        self._param_controls = {}
        if params:
            sarea = MyScrollArea(parent.get_panel_parent_widget())
            sarea.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
            frame = QFrame(sarea)
            frame.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum))
            sarea.setWidget(frame)
            sarea.setWidgetResizable(True)
            layout = QGridLayout()
            layout.setContentsMargins(0,0,0,0)
            layout.setSpacing(0)
            frame.setLayout( layout )
            
            parlayout = QGridLayout()
            
            irow = 0
            ipar = 0
            have_switches = False
            have_params = False
            for iparam, param in enumerate(params):
                if isinstance(param, Param):
                    if param.minimum <= 0.0:
                        param_control = LinValControl(high_is_none=param.high_is_none, low_is_none=param.low_is_none)
                    else:
                        param_control = ValControl(high_is_none=param.high_is_none, low_is_none=param.low_is_none, low_is_zero=param.low_is_zero)
                    
                    param_control.setup(param.name, param.minimum, param.maximum, param.default, iparam)
                    self.get_viewer().connect( param_control, SIGNAL("valchange(PyQt_PyObject,int)"), self.modified_snuffling_panel )

                    self._param_controls[param.ident] = param_control
                    for iw, w in enumerate(param_control.widgets()):
                        parlayout.addWidget(w, ipar, iw)

                    ipar +=1
                    have_params = True

                elif isinstance(param, Choice):
                    param_widget = ChoiceControl(param.ident, param.default, param.choices, param.name)
                    self.get_viewer().connect( param_widget, SIGNAL('choosen(PyQt_PyObject,PyQt_PyObject)'), self.choose_on_snuffling_panel )
                    self._param_controls[param.ident] = param_widget
                    parlayout.addWidget(param_widget, ipar, 0, 1, 3)
                    ipar += 1
                    have_params = True

                elif isinstance(param, Switch):
                    have_switches = True

            if have_params: 
                parframe = QFrame(sarea)
                parframe.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum))
                parframe.setLayout(parlayout)
                layout.addWidget(parframe, irow, 0)
                irow += 1

            if have_switches:
                swlayout = QGridLayout()
                isw = 0
                for iparam, param in enumerate(params):
                    if isinstance(param, Switch):
                        param_widget = SwitchControl(param.ident, param.default, param.name)
                        self.get_viewer().connect( param_widget, SIGNAL('sw_toggled(PyQt_PyObject,bool)'), self.switch_on_snuffling_panel )
                        self._param_controls[param.ident] = param_widget
                        swlayout.addWidget( param_widget, isw/10, isw%10 )
                        isw += 1
                
                swframe = QFrame(sarea)
                swframe.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum))
                swframe.setLayout( swlayout )
                layout.addWidget( swframe, irow, 0 )
                irow += 1
            
            butframe = QFrame(sarea)
            butframe.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum))
            butlayout = QHBoxLayout()
            butframe.setLayout( butlayout )

            live_update_checkbox = QCheckBox('Auto-Run')
            if self._live_update:
                live_update_checkbox.setCheckState(Qt.Checked)

            butlayout.addWidget( live_update_checkbox )
            self.get_viewer().connect( live_update_checkbox, SIGNAL("toggled(bool)"), self.live_update_toggled )
        
            clear_button = QPushButton('Clear')
            butlayout.addWidget( clear_button )
            self.get_viewer().connect( clear_button, SIGNAL("clicked()"), self.clear_button_triggered )
        
            call_button = QPushButton('Run')
            butlayout.addWidget( call_button )
            self.get_viewer().connect( call_button, SIGNAL("clicked()"), self.call_button_triggered )

            for name, method in self._triggers:
                but = QPushButton(name)
                def call_and_update(method):
                    def f():
                        try:
                            method()
                        except SnufflingError, e:
                            if not isinstance(e, SnufflingCallFailed):  # those have logged within error()
                                logger.error('%s: %s' % (self._name, e))
                            logger.error('%s: Snuffling action failed' % self._name)

                        self.get_viewer().update()
                    return f

                self.get_viewer().connect( but, SIGNAL('clicked()'), call_and_update(method) )
                butlayout.addWidget( but )

            layout.addWidget(butframe, irow, 0)

            irow += 1
            spacer = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding)
            layout.addItem(spacer, irow, 0)

            return sarea 
コード例 #2
0
ファイル: snuffling.py プロジェクト: iggcas-duyanan/pyrocko
    def make_panel(self, parent):
        '''Create a widget for the snuffling's control panel.
        
        Normally called from the :py:meth:`setup_gui` method. Returns ``None`` if no panel
        is needed (e.g. if the snuffling has no adjustable parameters).'''

        params = self.get_parameters()
        self._param_controls = {}
        if params:
            sarea = MyScrollArea(parent.get_panel_parent_widget())
            frame = QFrame(sarea)
            sarea.setWidget(frame)
            sarea.setWidgetResizable(True)
            layout = QGridLayout()
            layout.setContentsMargins(0, 0, 0, 0)
            layout.setSpacing(0)
            frame.setLayout(layout)

            parlayout = QVBoxLayout()

            irow = 0
            have_switches = False
            have_params = False
            for iparam, param in enumerate(params):
                if isinstance(param, Param):
                    if param.minimum <= 0.0:
                        param_widget = LinValControl(
                            high_is_none=param.high_is_none,
                            low_is_none=param.low_is_none)
                    else:
                        param_widget = ValControl(
                            high_is_none=param.high_is_none,
                            low_is_none=param.low_is_none)

                    param_widget.setup(param.name, param.minimum,
                                       param.maximum, param.default, iparam)
                    self.get_viewer().connect(
                        param_widget, SIGNAL("valchange(PyQt_PyObject,int)"),
                        self.modified_snuffling_panel)

                    self._param_controls[param.ident] = param_widget
                    parlayout.addWidget(param_widget)
                    have_params = True
                elif isinstance(param, Choice):
                    param_widget = ChoiceControl(param.ident, param.default,
                                                 param.choices, param.name)
                    self.get_viewer().connect(
                        param_widget,
                        SIGNAL('choosen(PyQt_PyObject,PyQt_PyObject)'),
                        self.choose_on_snuffling_panel)
                    self._param_controls[param.ident] = param_widget
                    parlayout.addWidget(param_widget)
                    have_params = True
                elif isinstance(param, Switch):
                    have_switches = True

            if have_params:
                parframe = QFrame(sarea)
                parframe.setLayout(parlayout)
                layout.addWidget(parframe, irow, 0)
                irow += 1

            if have_switches:
                swlayout = QGridLayout()
                isw = 0
                for iparam, param in enumerate(params):
                    if isinstance(param, Switch):
                        param_widget = SwitchControl(param.ident,
                                                     param.default, param.name)
                        self.get_viewer().connect(
                            param_widget,
                            SIGNAL('sw_toggled(PyQt_PyObject,bool)'),
                            self.switch_on_snuffling_panel)
                        self._param_controls[param.ident] = param_widget
                        swlayout.addWidget(param_widget, isw / 10, isw % 10)
                        isw += 1

                swframe = QFrame(sarea)
                swframe.setLayout(swlayout)
                layout.addWidget(swframe, irow, 0)
                irow += 1

            butframe = QFrame(sarea)
            butlayout = QHBoxLayout()
            butframe.setLayout(butlayout)

            live_update_checkbox = QCheckBox('Auto-Run')
            if self._live_update:
                live_update_checkbox.setCheckState(Qt.Checked)

            butlayout.addWidget(live_update_checkbox)
            self.get_viewer().connect(live_update_checkbox,
                                      SIGNAL("toggled(bool)"),
                                      self.live_update_toggled)

            clear_button = QPushButton('Clear')
            butlayout.addWidget(clear_button)
            self.get_viewer().connect(clear_button, SIGNAL("clicked()"),
                                      self.clear_button_triggered)

            call_button = QPushButton('Run')
            butlayout.addWidget(call_button)
            self.get_viewer().connect(call_button, SIGNAL("clicked()"),
                                      self.call_button_triggered)

            for name, method in self._triggers:
                but = QPushButton(name)

                def call_and_update(method):
                    def f():
                        try:
                            method()
                        except SnufflingError, e:
                            if not isinstance(
                                    e, SnufflingCallFailed
                            ):  # those have logged within error()
                                logger.error('%s: %s' % (self._name, e))
                            logger.error('%s: Snuffling action failed' %
                                         self._name)

                        self.get_viewer().update()

                    return f

                self.get_viewer().connect(but, SIGNAL('clicked()'),
                                          call_and_update(method))
                butlayout.addWidget(but)

            layout.addWidget(butframe, irow, 0)
            irow += 1

            return sarea
コード例 #3
0
ファイル: snuffling.py プロジェクト: carinaj/pyrocko
    def make_panel(self, parent):
        '''Create a widget for the snuffling's control panel.
        
        Normally called from the :py:meth:`setup_gui` method. Returns ``None`` if no panel
        is needed (e.g. if the snuffling has no adjustable parameters).'''
    
        params = self.get_parameters()
        self._param_controls = {}
        if params:
            sarea = MyScrollArea(parent.get_panel_parent_widget())
            frame = QFrame(sarea)
            sarea.setWidget(frame)
            sarea.setWidgetResizable(True)
            layout = QGridLayout()
            frame.setLayout( layout )
            
            irow = 0
            have_switches = False
            for iparam, param in enumerate(params):
                if isinstance(param, Param):
                    if param.minimum <= 0.0:
                        param_widget = LinValControl(high_is_none=param.high_is_none, low_is_none=param.low_is_none)
                    else:
                        param_widget = ValControl(high_is_none=param.high_is_none, low_is_none=param.low_is_none)
                    param_widget.setup(param.name, param.minimum, param.maximum, param.default, iparam)
                    self.get_viewer().connect( param_widget, SIGNAL("valchange(PyQt_PyObject,int)"), self.modified_snuffling_panel )

                    self._param_controls[param.ident] = param_widget
                    layout.addWidget( param_widget, irow, 0, 1, 3 )
                    irow += 1
                elif isinstance(param, Choice):
                    param_widget = ChoiceControl(param.ident, param.default, param.choices, param.name)
                    self.get_viewer().connect( param_widget, SIGNAL('choosen(PyQt_PyObject,PyQt_PyObject)'), self.choose_on_snuffling_panel )
                    self._param_controls[param.ident] = param_widget
                    layout.addWidget( param_widget, irow, 0, 1, 3 )
                    irow += 1
                elif isinstance(param, Switch):
                    have_switches = True

            if have_switches:

                swframe = QFrame(sarea)
                swlayout = QGridLayout()
                swframe.setLayout( swlayout )
                isw = 0
                for iparam, param in enumerate(params):
                    if isinstance(param, Switch):
                        param_widget = SwitchControl(param.ident, param.default, param.name)
                        self.get_viewer().connect( param_widget, SIGNAL('sw_toggled(PyQt_PyObject,bool)'), self.switch_on_snuffling_panel )
                        self._param_controls[param.ident] = param_widget
                        swlayout.addWidget( param_widget, isw/10, isw%10 )
                        isw += 1
                
                layout.addWidget( swframe, irow, 0, 1, 3 )
                irow += 1

            live_update_checkbox = QCheckBox('Auto-Run')
            if self._live_update:
                live_update_checkbox.setCheckState(Qt.Checked)
            layout.addWidget( live_update_checkbox, irow, 0 )
            self.get_viewer().connect( live_update_checkbox, SIGNAL("toggled(bool)"), self.live_update_toggled )
        
            clear_button = QPushButton('Clear')
            layout.addWidget( clear_button, irow, 1 )
            self.get_viewer().connect( clear_button, SIGNAL("clicked()"), self.clear_button_triggered )
        
            call_button = QPushButton('Run')
            layout.addWidget( call_button, irow, 2 )
            self.get_viewer().connect( call_button, SIGNAL("clicked()"), self.call_button_triggered )

            return sarea 
            
        else:
            return None
コード例 #4
0
ファイル: snuffling.py プロジェクト: carinaj/pyrocko
    def make_panel(self, parent):
        '''Create a widget for the snuffling's control panel.
        
        Normally called from the :py:meth:`setup_gui` method. Returns ``None`` if no panel
        is needed (e.g. if the snuffling has no adjustable parameters).'''

        params = self.get_parameters()
        self._param_controls = {}
        if params:
            sarea = MyScrollArea(parent.get_panel_parent_widget())
            frame = QFrame(sarea)
            sarea.setWidget(frame)
            sarea.setWidgetResizable(True)
            layout = QGridLayout()
            frame.setLayout(layout)

            irow = 0
            have_switches = False
            for iparam, param in enumerate(params):
                if isinstance(param, Param):
                    if param.minimum <= 0.0:
                        param_widget = LinValControl(
                            high_is_none=param.high_is_none,
                            low_is_none=param.low_is_none)
                    else:
                        param_widget = ValControl(
                            high_is_none=param.high_is_none,
                            low_is_none=param.low_is_none)
                    param_widget.setup(param.name, param.minimum,
                                       param.maximum, param.default, iparam)
                    self.get_viewer().connect(
                        param_widget, SIGNAL("valchange(PyQt_PyObject,int)"),
                        self.modified_snuffling_panel)

                    self._param_controls[param.ident] = param_widget
                    layout.addWidget(param_widget, irow, 0, 1, 3)
                    irow += 1
                elif isinstance(param, Choice):
                    param_widget = ChoiceControl(param.ident, param.default,
                                                 param.choices, param.name)
                    self.get_viewer().connect(
                        param_widget,
                        SIGNAL('choosen(PyQt_PyObject,PyQt_PyObject)'),
                        self.choose_on_snuffling_panel)
                    self._param_controls[param.ident] = param_widget
                    layout.addWidget(param_widget, irow, 0, 1, 3)
                    irow += 1
                elif isinstance(param, Switch):
                    have_switches = True

            if have_switches:

                swframe = QFrame(sarea)
                swlayout = QGridLayout()
                swframe.setLayout(swlayout)
                isw = 0
                for iparam, param in enumerate(params):
                    if isinstance(param, Switch):
                        param_widget = SwitchControl(param.ident,
                                                     param.default, param.name)
                        self.get_viewer().connect(
                            param_widget,
                            SIGNAL('sw_toggled(PyQt_PyObject,bool)'),
                            self.switch_on_snuffling_panel)
                        self._param_controls[param.ident] = param_widget
                        swlayout.addWidget(param_widget, isw / 10, isw % 10)
                        isw += 1

                layout.addWidget(swframe, irow, 0, 1, 3)
                irow += 1

            live_update_checkbox = QCheckBox('Auto-Run')
            if self._live_update:
                live_update_checkbox.setCheckState(Qt.Checked)
            layout.addWidget(live_update_checkbox, irow, 0)
            self.get_viewer().connect(live_update_checkbox,
                                      SIGNAL("toggled(bool)"),
                                      self.live_update_toggled)

            clear_button = QPushButton('Clear')
            layout.addWidget(clear_button, irow, 1)
            self.get_viewer().connect(clear_button, SIGNAL("clicked()"),
                                      self.clear_button_triggered)

            call_button = QPushButton('Run')
            layout.addWidget(call_button, irow, 2)
            self.get_viewer().connect(call_button, SIGNAL("clicked()"),
                                      self.call_button_triggered)

            return sarea

        else:
            return None