Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def qt4_editor_factory(parent, editor, use_dir=False, *args):
from pyface.qt import QtCore, QtGui
from traitsui.qt4.helper import IconButton
editor.control = panel = QtGui.QWidget()
layout = QtGui.QHBoxLayout( panel )
layout.setContentsMargins(0,0,0,0)
editor.use_dir = use_dir
editor.text_control = text_control = QtGui.QLineEdit()
layout.addWidget(text_control)
signal = QtCore.SIGNAL('editingFinished()')
QtCore.QObject.connect(text_control, signal, lambda:update_file_obj(editor))
button = IconButton(QtGui.QStyle.SP_DirIcon, lambda:button_click(editor))
layout.addWidget(button)
return panel
def create_control(self, parent):
""" Create the toolkit-specific control that represents the part. """
from pyface.qt import QtGui
control = QtGui.QWidget(parent)
palette = control.palette()
palette.setColor(QtGui.QPalette.Window, QtGui.QColor("red"))
control.setPalette(palette)
control.setAutoFillBackground(True)
return control
vheader.setHighlightSections(False)
else:
vheader.hide()
if factory.show_row_titles and factory.auto_resize_rows:
vheader.setResizeMode(QtGui.QHeaderView.ResizeToContents)
else:
# Set a default height for rows. Although setting the resize mode to
# ResizeToContents would provide the best sizes, this is far too
# expensive when the TabularEditor has a large amount of data. Instead,
# we make a reasonable guess based on the minimum size hint and the font
# of the first row.
size = vheader.minimumSectionSize()
font = editor.adapter.get_font(editor.object, editor.name, 0)
if font is not None:
size = max(size, QtGui.QFontMetrics(QtGui.QFont(font)).height())
vheader.setDefaultSectionSize(size)
# Configure the column headings.
hheader = self.horizontalHeader()
hheader.setStretchLastSection(factory.stretch_last_section)
if factory.show_titles:
hheader.setHighlightSections(False)
else:
hheader.hide()
# Turn off the grid lines--we'll draw our own
self.setShowGrid(False)
self.setItemDelegate(_ItemDelegate(self))
# Configure the selection behaviour.
self.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
syntax_stack = ("root",)
def __init__(self, **kwds):
QtGui.QTextBlockUserData.__init__(self)
for key, value in kwds.items():
setattr(self, key, value)
def __repr__(self):
attrs = ["syntax_stack"]
kwds = ", ".join(
["%s=%r" % (attr, getattr(self, attr)) for attr in attrs]
)
return "BlockUserData(%s)" % kwds
class PygmentsHighlighter(QtGui.QSyntaxHighlighter):
""" Syntax highlighter that uses Pygments for parsing. """
def __init__(self, parent, lexer=None):
super(PygmentsHighlighter, self).__init__(parent)
try:
self._lexer = get_lexer_by_name(lexer)
except:
self._lexer = PythonLexer()
self._style = DefaultStyle
# Caches for formats and brushes.
self._brushes = {}
self._formats = {}
def highlightBlock(self, qstring):
def create_button(self, name):
""" Returns the QAbstractButton used for the radio button.
"""
label = self.string_value(name, capitalize)
return QtGui.QRadioButton(label)
# Create an empty top-level container
if is_image:
top_container = self._create_top_img_container()
else:
top_container = self._create_top_container()
# The PlotSession of which we are a part. We need to know this in order
# to notify it of our being closed, etc.
self.session = None
# Create the Enable Window object, and store a reference to it.
# (This will be handy later.) The Window requires a parent object
# as its first argument, so we just pass 'self'.
self.plot_window = Window(self, component=top_container)
layout = QtGui.QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.plot_window.control)
self.setLayout(layout)
size = kw.get("size", QtCore.QSize(600,600))
self.set_size(size.width(), size.height())
self.show()
def __init__(self, parent=None):
super(DosVisualization, self).__init__()
self.first_plot_bool = True
# a figure instance to plot on
self.figure = plt.figure(1)
plt.close(plt.figure(1))
self.ax = None
self.last_dos = None
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
color = self.palette().color(QtGui.QPalette.Base)
self.figure.patch.set_facecolor([color.red() / 255, color.green() / 255, color.blue() / 255])
if sum([color.red(), color.blue(), color.green()]) / 3 < 100:
self.dark_mode = True
self.bg_color = [color.red() / 255, color.green() / 255, color.blue() / 255]
else:
self.dark_mode = False
self.bg_color = None
layout = QtGui.QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
option_widget = QtGui.QWidget()
option_widget.setFixedHeight(60)
option_layout = QtGui.QHBoxLayout(option_widget)
return plot
def _on_window_close(self, event):
if self.session:
try:
ndx = self.session.windows.index(self)
self.session.del_window(ndx)
except ValueError:
pass
elif ETSConfig.toolkit == "qt4":
from pyface.qt import QtCore, QtGui
class PlotWindow(QtGui.QFrame):
""" A window for holding top-level plot containers.
Contains many utility methods for controlling the appearance of the
window, which mostly pass through to underlying Qt calls.
"""
def __init__(self, is_image=False, bgcolor="white",
image_default_origin="top left", *args, **kw):
size = kw.pop("size", None)
if isinstance(size, tuple):
size = QtCore.QSize(*size)
super(PlotWindow, self).__init__(None, *args, **kw )
if size is not None:
def object_load_button_changed(self, info):
"""Method used to load a measurement saved in a file.
"""
if info.initialized:
dlg = QtGui.QFileDialog(info.ui.control)
dlg.setNameFilter('*.ini')
dlg.setFileMode(QtGui.QFileDialog.ExistingFile)
if dlg.exec_() == QtGui.QDialog.Accepted:
path = dlg.selectedFiles()[0]
task_config = IniConfigTask(task_parent = None,
template_path = path,
task_class = RootTask,
task_name = 'Root')
task = task_config.build_task()
task.task_builder = TaskBuilder
info.object.root_task = task
#
# This software is provided without warranty under the terms of the BSD license.
# However, when used with the GPL version of PyQt the additional terms described in the PyQt GPL exception also apply
# ------------------------------------------------------------------------------
import sys
from pyface.qt import QtCore, QtGui, qt_api
from pyface.image_resource import ImageResource
class SplitTabWidget(QtGui.QSplitter):
""" The SplitTabWidget class is a hierarchy of QSplitters the leaves of
which are QTabWidgets. Any tab may be moved around with the hierarchy
automatically extended and reduced as required.
"""
# Signals for WorkbenchWindowLayout to handle
new_window_request = QtCore.Signal(QtCore.QPoint, QtGui.QWidget)
tab_close_request = QtCore.Signal(QtGui.QWidget)
tab_window_changed = QtCore.Signal(QtGui.QWidget)
editor_has_focus = QtCore.Signal(QtGui.QWidget)
focus_changed = QtCore.Signal(QtGui.QWidget, QtGui.QWidget)
# The different hotspots of a QTabWidget. An non-negative value is a tab
# index and the hotspot is to the left of it.
tabTextChanged = QtCore.Signal(QtGui.QWidget, str)