예제 #1
0
        filename, mode = args
        if not os.path.isabs(
                filename):  # path to logging file given in config_file?
            filename = os.path.join(fb.base_dir, filename)  # no, use basedir
        logging.FileHandler.__init__(self, filename, mode)


# "register" custom class DynFileHandler as an attribute for the logging module
# to use it inside the logging config file and pass file name / path and mode
# as parameters:
logging.DynFileHandler = DynFileHandler
logging.config.fileConfig(os.path.join(
    fb.base_dir, rc.log_config_file))  #, disable_existing_loggers=True)

if not os.path.exists(rc.save_dir):
    home_dir = pyfda_lib.get_home_dir()
    logger.warning(
        'save_dir "%s" specified in pyfda_rc.py doesn\'t exist, using "%s" instead.\n',
        rc.save_dir, home_dir)  #fb.base_dir
    rc.save_dir = home_dir  #fb.base_dir

#class Whitelist(logging.Filter):
#    def __init__(self, **whitelist):
#        self.whitelist = [logging.Filter(name) for name in whitelist]
#        print("filter intialized with", whitelist)
#
#    def filter(self, record):
#        """filter logging record"""
#        arg = any(f.filter(record) for f in self.whitelist)
#        # record.levelno == logging.ERROR
#        # arg = self.param not in record.msg
예제 #2
0
파일: pyfdax.py 프로젝트: cfelton/pyFDA
    def emit(self, record):
        msg = self.format(record)
        if msg: XStream.stdout().write('%s'%msg)

# "register" custom class DynFileHandler as an attribute for the logging module
# to use it inside the logging config file and pass file name / path and mode
# as parameters:
logging.DynFileHandler = DynFileHandler
logging.QEditHandler = QEditHandler
logging.config.fileConfig(os.path.join(base_dir, log_config_file))#, disable_existing_loggers=True)

from pyfda import pyfda_lib
from pyfda import pyfda_rc as rc
if not os.path.exists(rc.save_dir):
    home_dir = pyfda_lib.get_home_dir()
    logger.info('save_dir "%s" specified in pyfda_rc.py doesn\'t exist, using "%s" instead.\n',
        rc.save_dir, home_dir)
    rc.save_dir = home_dir


#==============================================================================
import pyfda.filterbroker as fb
# store as base_dir (= pyfdax.py directory) in filterbroker
fb.base_dir = base_dir

from .compat import (HAS_QT5, QT_VERSION_STR, QtCore, QMainWindow, QApplication, QFontMetrics,
                     QSplitter, QIcon, QMessageBox, QWidget, QHBoxLayout, QPlainTextEdit,
                     QGridLayout, QTextBrowser, QVBoxLayout, QLabel, QtGui)
import matplotlib
# specify matplotlib backend for systems that have both PyQt4 and PyQt5 installed
예제 #3
0
    def _init_toolbar(self):
        #       Using the following path to the icons seems to fail in some cases, we
        #       rather rely on qrc files containing all icons
        #        iconDir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
        #           '..','images','icons', '')
        #        self.basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
        #           '..','images', 'icons', '')

        #---------------- Construct Toolbar using QRC icons ---------------------------

        # ENABLE:
        a = self.addAction(QtGui.QIcon(':/circle-check.svg'), 'Enable Plot',
                           self.enable_update)
        a.setToolTip('Enable plot update')
        a.setCheckable(True)
        a.setChecked(True)
        #        a.setEnabled(False)

        self.addSeparator()  #---------------------------------------------

        # HOME:
        self.a_ho = self.addAction(QtGui.QIcon(':/home.svg'), 'Home',
                                   self.home)
        self.a_ho.setToolTip('Reset original view')
        # BACK:
        self.a_ba = self.addAction(QtGui.QIcon(':/action-undo.svg'), 'Back',
                                   self.back)
        self.a_ba.setToolTip('Back to previous view')
        # FORWARD:
        self.a_fw = self.addAction(QtGui.QIcon(':/action-redo.svg'), 'Forward',
                                   self.forward)
        self.a_fw.setToolTip('Forward to next view')

        self.addSeparator()  #---------------------------------------------

        # PAN:
        self.a_pa = self.addAction(QtGui.QIcon(':/move.svg'), 'Pan', self.pan)
        self.a_pa.setToolTip(
            "Pan axes with left mouse button, zoom with right,\n"
            "pressing x / y / CTRL yields horizontal / vertical / diagonal constraints."
        )
        self._actions['pan'] = self.a_pa
        self.a_pa.setCheckable(True)

        # ZOOM RECTANGLE:
        self.a_zo = self.addAction(QtGui.QIcon(':/magnifying-glass.svg'),
                                   'Zoom', self.zoom)
        self.a_zo.setToolTip(
            "Zoom in / out to rectangle with left / right mouse button,\n"
            "pressing x / y / CTRL yields horizontal / vertical / diagonal constraints."
        )
        self._actions['zoom'] = self.a_zo
        self.a_zo.setCheckable(True)

        # FULL VIEW:
        self.a_fv = self.addAction(QtGui.QIcon(':/fullscreen-enter.svg'), \
            'Zoom full extent', self.parent.plt_full_view)
        self.a_fv.setToolTip('Zoom to full extent')

        # LOCK VIEW:
        self.a_lk = self.addAction(QtGui.QIcon(':/lock-locked.svg'), \
                                   'Lock zoom', self.toggle_lock_zoom)
        self.a_lk.setCheckable(True)
        self.a_lk.setChecked(False)
        self.a_lk.setToolTip('Lock current zoom setting')

        # --------------------------------------
        self.addSeparator()
        # --------------------------------------

        # GRID:
        self.a_gr = self.addAction(QtGui.QIcon(':/grid-four-up.svg'), 'Grid',
                                   self.toggle_grid)
        self.a_gr.setToolTip('Toggle Grid')
        self.a_gr.setCheckable(True)
        self.a_gr.setChecked(True)

        # REDRAW:
        self.a_rd = self.addAction(QtGui.QIcon(':/brush.svg'), 'Redraw',
                                   self.parent.redraw)
        self.a_rd.setToolTip('Redraw Plot')

        # SAVE:
        self.a_sv = self.addAction(QtGui.QIcon(':/file.svg'), 'Save',
                                   self.save_figure)
        self.a_sv.setToolTip('Save the figure')

        self.cb = None  #will be used for the clipboard
        self.temp_file = os.path.join(pyfda_lib.get_home_dir(), 'tempMPL.png')

        self.a_cb = self.addAction(QtGui.QIcon(':/camera-slr.svg'), 'Save',
                                   self.mpl2Clip)
        self.a_cb.setToolTip('Copy to clipboard')
        self.a_cb.setShortcut("Ctrl+C")

        # --------------------------------------
        self.addSeparator()
        # --------------------------------------

        if figureoptions is not None:
            self.a_op = self.addAction(QtGui.QIcon(':/cog.svg'), 'Customize',
                                       self.edit_parameters)
            self.a_op.setToolTip('Edit curves line and axes parameters')

        self.buttons = {}

        # Add the x,y location widget at the right side of the toolbar
        # The stretch factor is 1 which means any resizing of the toolbar
        # will resize this label instead of the buttons.
        if self.coordinates:
            self.locLabel = QLabel("", self)
            self.locLabel.setAlignment(QtCore.Qt.AlignRight
                                       | QtCore.Qt.AlignTop)
            self.locLabel.setSizePolicy(
                QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Ignored))
            labelAction = self.addWidget(self.locLabel)
            labelAction.setVisible(True)

        # reference holder for subplots_adjust window
        self.adj_window = None
예제 #4
0
파일: plot_utils.py 프로젝트: cfelton/pyFDA
    def _init_toolbar(self):
#       Using the following path to the icons seems to fail in some cases, we
#       rather rely on qrc files containing all icons
#        iconDir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
#           '..','images','icons', '')
#        self.basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
#           '..','images', 'icons', '')

#---------------- Construct Toolbar using QRC icons ---------------------------

        # ENABLE:
        self.a_en = self.addAction(QIcon(':/circle-x.svg'), 'Enable Update', self.enable_update)
        self.a_en.setToolTip('Enable / disable plot update')
        self.a_en.setCheckable(True)
        self.a_en.setChecked(True)
#        a.setEnabled(False)

        self.addSeparator() #---------------------------------------------

        # HOME:
        self.a_ho = self.addAction(QIcon(':/home.svg'), 'Home', self.home)
        self.a_ho.setToolTip('Reset original zoom')
        # BACK:
        self.a_ba = self.addAction(QIcon(':/action-undo.svg'), 'Back', self.back)
        self.a_ba.setToolTip('Back to previous zoom')
        # FORWARD:
        self.a_fw = self.addAction(QIcon(':/action-redo.svg'), 'Forward', self.forward)
        self.a_fw.setToolTip('Forward to next zoom')

        self.addSeparator() #---------------------------------------------

        # PAN:
        self.a_pa = self.addAction(QIcon(':/move.svg'), 'Pan', self.pan)
        self.a_pa.setToolTip("Pan axes with left mouse button, zoom with right,\n"
        "pressing x / y / CTRL yields horizontal / vertical / diagonal constraints.")
        self._actions['pan'] = self.a_pa
        self.a_pa.setCheckable(True)

        # ZOOM RECTANGLE:
        self.a_zo = self.addAction(QIcon(':/magnifying-glass.svg'), 'Zoom', self.zoom)
        self.a_zo.setToolTip("Zoom in / out to rectangle with left / right mouse button,\n"
        "pressing x / y / CTRL yields horizontal / vertical / diagonal constraints.")
        self._actions['zoom'] = self.a_zo
        self.a_zo.setCheckable(True)

        # FULL VIEW:
        self.a_fv = self.addAction(QIcon(':/fullscreen-enter.svg'), \
            'Zoom full extent', self.parent.plt_full_view)
        self.a_fv.setToolTip('Zoom to full extent')

        # LOCK ZOOM:
        self.a_lk = self.addAction(QIcon(':/lock-unlocked.svg'), \
                                   'Lock zoom', self.toggle_lock_zoom)
        self.a_lk.setCheckable(True)
        self.a_lk.setChecked(False)
        self.a_lk.setToolTip('Lock / unlock current zoom setting')

        # --------------------------------------
        self.addSeparator()
        # --------------------------------------

        # GRID:
        self.a_gr = self.addAction(QIcon(':/grid.svg'), 'Grid', self.toggle_grid)
        self.a_gr.setToolTip('Toggle Grid')
        self.a_gr.setCheckable(True)
        self.a_gr.setChecked(True)

        # REDRAW:
        self.a_rd = self.addAction(QIcon(':/brush.svg'), 'Redraw', self.parent.redraw)
        self.a_rd.setToolTip('Redraw Plot')

        # SAVE:
        self.a_sv = self.addAction(QIcon(':/file.svg'), 'Save', self.save_figure)
        self.a_sv.setToolTip('Save the figure')

        self.cb = None #will be used for the clipboard
        self.temp_file = os.path.join(pyfda_lib.get_home_dir(), 'tempMPL.png')

        self.a_cb = self.addAction(QIcon(':/clipboard.svg'), 'Save', self.mpl2Clip)
        self.a_cb.setToolTip('Copy to clipboard in png format.')
        self.a_cb.setShortcut("Ctrl+C")

        # --------------------------------------
        self.addSeparator()
        # --------------------------------------

        if figureoptions is not None:
            self.a_op = self.addAction(QIcon(':/settings.svg'), 'Customize', self.edit_parameters)
            self.a_op.setToolTip('Edit curves line and axes parameters')

#        self.buttons = {}

        # Add the x,y location widget at the right side of the toolbar
        # The stretch factor is 1 which means any resizing of the toolbar
        # will resize this label instead of the buttons.
        if self.coordinates:
            self.locLabel = QLabel("", self)
            self.locLabel.setAlignment(
                    QtCore.Qt.AlignRight | QtCore.Qt.AlignTop)
            self.locLabel.setSizePolicy(
                QSizePolicy(QSizePolicy.Expanding,
                                  QSizePolicy.Ignored))
            labelAction = self.addWidget(self.locLabel)
            labelAction.setVisible(True)

        # reference holder for subplots_adjust window
        self.adj_window = None