def __init__(self, parent=None): super(CLEEDConsoleWidget, self).__init__(parent) layout = QtGui.QVBoxLayout(self) edit_layout = QtGui.QVBoxLayout() button_layout = QtGui.QHBoxLayout() self.ipyConsole = QIPythonWidget(customBanner= "*** Welcome to the CLEED embedded IPython console ***\n\n") self.tabWidget = QtGui.QTabWidget() layout.addWidget(self.tabWidget) from highlighter import PythonHighlighter self.save_button = QtGui.QPushButton('Save') self.load_button = QtGui.QPushButton('Load') self.run_button = QtGui.QPushButton('Run...') button_layout.addWidget(self.load_button) button_layout.addWidget(self.save_button) button_layout.addWidget(self.run_button) self.scriptEdit = QtGui.QPlainTextEdit() self.highlighter = PythonHighlighter(self.scriptEdit.document()) edit_layout.addWidget(self.scriptEdit) edit_layout.addLayout(button_layout) edit_widget = QtGui.QWidget() edit_widget.setLayout(edit_layout) self.tabWidget.addTab(self.ipyConsole, 'Console') self.tabWidget.addTab(edit_widget, 'Editor') self.ipyConsole.pushVariables( {"app": self.parent(), "console": self.ipyConsole }) self.ipyConsole.printText("The application handle variable 'app' " "is available. " "Use the 'whos' command for information on " "available variables.") self.setToolTip("CLEED scripting console. \n\n" "Note: type 'whos' for list of variables " "or help($var) for help")
def __init__(self, parent=None, text=None): super(MplLabelDialog, self).__init__(parent) self.setWindowTitle('Edit text') self.setWindowIcon(QtGui.QIcon(':/font_32x32.png')) layout = QtGui.QVBoxLayout(self) #self.tab_widget = QtGui.QTabWidget() #self.tab_widget.addTab(self, 'test') # self.font_label = QtGui.QLabel('Font Family:') self.size_label = QtGui.QLabel('Size:') self.text_label = QtGui.QLabel('Label:') self.color_label = QtGui.QLabel('Color:') self.alpha_label = QtGui.QLabel('Alpha:') self.fill_color_label = QtGui.QLabel("Background color:") self.fill_alpha_label = QtGui.QLabel("Background alpha:") self.font_combo = QtGui.QComboBox() self.color_combo = QtGui.QComboBox() self.text_edit = QtGui.QLineEdit() self.size_spin_box = QtGui.QSpinBox() self.alpha_spin_box = QtGui.QDoubleSpinBox() self.fill_alpha_spin_box = QtGui.QDoubleSpinBox() try: from matplotlib.backends.qt4_editor.formlayout import ColorButton self.color_button = ColorButton() self.color_button.colorChanged.connect(lambda x: self.callback(self.text.set_color(self.color_button.color))) except: pass self.bold_check = QtGui.QPushButton('B') self.italics_check = QtGui.QPushButton('I') self.underline_check = QtGui.QPushButton('U') self.underline_check.setVisible(False) # not yet implemented font = QtGui.QFont() font.setWeight(600) self.bold_check.setFont(font) self.bold_check.setCheckable(True) self.bold_check.setMinimumWidth(25) self.bold_check.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred) font = QtGui.QFont() font.setItalic(True) self.italics_check.setFont(font) self.italics_check.setCheckable(True) self.italics_check.setMinimumWidth(25) self.italics_check.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred) font = QtGui.QFont() font.setUnderline(True) self.underline_check.setFont(font) self.underline_check.setCheckable(True) self.underline_check.setMinimumWidth(25) self.underline_check.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred) self.alpha_spin_box.setMinimum(0.) self.alpha_spin_box.setMaximum(1.) self.alpha_spin_box.setSingleStep(0.1) self.fill_alpha_spin_box.setMinimum(0.) self.fill_alpha_spin_box.setMaximum(1.) self.fill_alpha_spin_box.setSingleStep(0.1) self.size_spin_box.setMinimum(1) self.size_spin_box.setMaximum(200) self.size_spin_box.setSingleStep(1) self._populate_fonts() self._populate_colors() spacer = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) layout.addWidget(self.font_label) font_layout = QtGui.QHBoxLayout() font_layout.addWidget(self.font_combo) font_layout.addWidget(self.bold_check) font_layout.addWidget(self.italics_check) font_layout.addWidget(self.underline_check) font_layout.addItem(spacer) layout.addLayout(font_layout) layout.addWidget(self.size_label) layout.addWidget(self.size_spin_box) layout.addWidget(self.color_label) color_layout = QtGui.QHBoxLayout() color_layout.addWidget(self.color_combo) if hasattr(self, 'color_button'): color_layout.addWidget(self.color_button) layout.addLayout(color_layout) layout.addWidget(self.alpha_label) layout.addWidget(self.alpha_spin_box) #layout.addWidget(self.fill_alpha_label) #layout.addWidget(self.fill_alpha_spin_box) layout.addWidget(self.text_label) layout.addWidget(self.text_edit) #self.addLayout(layout) self.text = text try: import matplotlib as mpl self.size_spin_box.setValue(text.get_size() or 12) self.text_edit.setText(text.get_text() if text.get_text() != '____' else '') self.font_combo.setCurrentIndex(self.families.index(text.get_family()[0])) self.font_combo.update() color = text.get_color() try: self.font_combo.setCurrentIndex(self.colors[color]) except KeyError: from matplotlib.colors import ColorConverter, rgb2hex, cnames code = rgb2hex(ColorConverter.colors[color]) for name in cnames: if cnames[name] == code: color = name try: self.font_combo.setCurrentIndex(self.colors[color]) except KeyError: self.font_combo.setCurrentIndex(self.colors['black']) finally: pass try: self.bold_check.setChecked((text.get_weight() >= 600)) except: pass try: self.italics_check.setChecked(text.get_style() == 'italic') except: pass except ImportWarning: pass self.text_edit.textChanged.connect(lambda x: self.callback(self._set_text(x))) self.color_combo.currentIndexChanged.connect(lambda x: self.callback(self.text.set_color(str(self.color_combo.itemText(x))))) self.font_combo.currentIndexChanged.connect(lambda x: self.callback(self.text.set_family(str(self.font_combo.itemText(x))))) self.size_spin_box.valueChanged.connect(lambda x: self.callback(self.text.set_size(x))) self.alpha_spin_box.valueChanged.connect(lambda x: self.callback(self.text.set_alpha(x))) self.bold_check.toggled.connect(lambda x: self.callback(self.text.set_weight('bold' if x else 'normal'))) self.italics_check.toggled.connect(lambda x: self.callback(self.text.set_style('italic' if x else 'normal'))) self.underline_check.toggled.connect(lambda x: self.callback(self.text.set_text('\\underline{%s}' % self.text.get_text() if x else self.text.get_text())))
def __init__(self, parent=None): super(MplBaseDialog, self).__init__(parent) layout = QtGui.QVBoxLayout(self) #self.tab_widget = QtGui.QTabWidget() #self.tab_widget.addTab(self, 'test') # self.font_label = QtGui.QLabel('Font Family:') self.size_label = QtGui.QLabel('Size:') self.text_label = QtGui.QLabel('Label:') self.color_label = QtGui.QLabel('Color:') self.alpha_label = QtGui.QLabel('Alpha:') self.fill_color_label = QtGui.QLabel("Fill color:") self.fill_alpha_label = QtGui.QLabel("Fill alpha:") self.font_combo = QtGui.QComboBox() self.color_combo = QtGui.QComboBox() self.text_edit = QtGui.QLineEdit() self.size_spin_box = QtGui.QSpinBox() self.alpha_spin_box = QtGui.QDoubleSpinBox() self.fill_alpha_spin_box = QtGui.QDoubleSpinBox() try: from matplotlib.backends.qt4_editor.formlayout import ColorButton self.color_button = ColorButton() self.fill_color_button = ColorButton() except: self.color_button = QtGui.QPushButton('') self.color_button.setVisible(False) self.fill_color_button = QtGui.QPushButton('') self.fill_color_button.setVisible(False) self.bold_check = QtGui.QPushButton('B') self.italics_check = QtGui.QPushButton('I') self.underline_check = QtGui.QPushButton('U') self.underline_check.setVisible(False) # not yet implemented font = QtGui.QFont() font.setWeight(600) self.bold_check.setFont(font) self.bold_check.setCheckable(True) self.bold_check.setMinimumWidth(25) self.bold_check.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred) font = QtGui.QFont() font.setItalic(True) self.italics_check.setFont(font) self.italics_check.setCheckable(True) self.italics_check.setMinimumWidth(25) self.italics_check.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred) font = QtGui.QFont() font.setUnderline(True) self.underline_check.setFont(font) self.underline_check.setCheckable(True) self.underline_check.setMinimumWidth(25) self.underline_check.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred) self.alpha_spin_box.setMinimum(0.) self.alpha_spin_box.setMaximum(1.) self.alpha_spin_box.setSingleStep(0.1) self.fill_alpha_spin_box.setMinimum(0.) self.fill_alpha_spin_box.setMaximum(1.) self.fill_alpha_spin_box.setSingleStep(0.1) self.size_spin_box.setMinimum(1) self.size_spin_box.setMaximum(200) self.size_spin_box.setSingleStep(1) self._populate_colors() for family in self.families: self.font_combo.addItem(family) spacer = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) layout.addWidget(self.font_label) font_layout = QtGui.QHBoxLayout() font_layout.addWidget(self.font_combo) font_layout.addWidget(self.bold_check) font_layout.addWidget(self.italics_check) font_layout.addWidget(self.underline_check) font_layout.addItem(spacer) layout.addLayout(font_layout) layout.addWidget(self.size_label) layout.addWidget(self.size_spin_box) layout.addWidget(self.color_label) color_layout = QtGui.QHBoxLayout() color_layout.addWidget(self.color_combo) color_layout.addWidget(self.color_button) layout.addLayout(color_layout) layout.addWidget(self.alpha_label) layout.addWidget(self.alpha_spin_box) #layout.addWidget(self.fill_alpha_label) #layout.addWidget(self.fill_alpha_spin_box) layout.addWidget(self.text_label) layout.addWidget(self.text_edit)