def add_text_to_canvas(x, y, text, anchor=None, font_color="black", font_size=6, html_font_size=10): _text = str(text) text_item = self.canvas_plot_scene.addText(_text) w = text_item.boundingRect().width() h = text_item.boundingRect().height() text_item.setPos(int(x - w / 2.5), int(y - h / 2.5)) text_item.setFont(QtGui.QFont(text_item.font().family(), font_size))
def __init__(self, data, parent, sortable=False, column_labels=None, row_labels=None, row_labels_height=25, *args): self.data = data self.column_labels = column_labels self.row_labels = row_labels self.row_labels_height = row_labels_height # Get a set with the length of each column. rows_number = len(self.data) columns_number = len(self.data[0]) QtWidgets.QTableWidget.__init__(self, parent=parent, columnCount=columns_number, rowCount=rows_number, sortingEnabled=sortable, *args) self.set_data() self.resizeColumnsToContents() # self.resizeRowsToContents() self.setStyleSheet( "QTableView::item {border: 0px; padding: 0px; margin: 0px;}") # self.itemDoubleClicked.connect(self.on_click) default_font = QtGui.QFont() default_font.setPointSize(default_font.pointSize() - 1) self.setFont(default_font)
def build_plotting_area(self, use_controls=True, use_all_controls_buttons=True, messagebar_initial_text=None, update_messagebar=False, messagebar_text_on_update="", messagebar_vars_on_update=(), on_click_action=None, x_label_text="x", y_label_text="y", label_size=None, use_save_to_csv=True, hide_x_ticks=False, hide_y_ticks=False, # hide_x_label=False, # hide_y_label=False, highlight_points=True, ): """ Configures the plotting area of the window. # Arguments use_controls: adds to the plotting window a right column with checkbuttons to show/hide the lines plots in the drawing area. use_all_controls_buttons: adds to the plotting control column 'Show All' and 'Hide All' buttons. messagebar_initial_text: initial text to be displayed in the messagebar of the plotting window. update_messagebar: if 'True', the messagebar will be updated when clicking some point of the scatterplots. messagebar_text_on_update: text to be shown when the messagebar is update. If it contains the "__plot_name__", "__x__", "__y__" string, they will be substituted with the name of the plot, the x value and y value of the point respectively. If some 'additional_data' is provided for a plot, its data will also be used to update the messagebar. Each element of an 'additional_data' list has to correspond to a data point of a plot and must be a dictionary in which the keys are strings representing the names of the additional data series. If, for example, these dictionaries have a key named 'info' and if the 'messagebar_text_on_update' contains the string "__info__", it will be substituted with the value associated to the 'info' key of that 'additional_data' point. on_click_action: function to be called when a point of a scatterplot is clicked. This function must have the following argument: point_data: a dictionary with additional data for the point or a 'None' value. x_label_text: text for the x-axis label. y_label_text: text for the y-axis label. label_size: font size for the axis labels. use_save_to_csv: if 'True' add to the plotting window menu a command to save data in the csv format. hide_x_ticks: if 'True', hide the ticks and numbers of the x-axis. hide_y_ticks: if 'True', hide the ticks and numbers of the y-axis. highlight_points: if 'True', the scatterplot points will be highlighted when they are clicked with the mouse. """ # Stores the arguments. self.use_controls = use_controls if self.use_controls: self.upper_frame_layout.addWidget(self.info_frame, 0, 0) self.middle_splitter.addWidget(self.plot_frame) self.middle_splitter.addWidget(self.controls_scrollarea) self.upper_frame_layout.addWidget(self.middle_splitter, 1, 0) self.controls_scrollarea.resize(230, self.controls_scrollarea.sizeHint().height()) self.controls_frame_layout.addWidget(self.labels_title, 0, 0, 1, 2) self.lower_frame_layout.addWidget(self.on_click_label, 0, 2) self.lower_frame_layout.addWidget(self.interact_button, 0, 3) self.lower_frame_layout.addWidget(self.no_interaction_button, 0, 4) else: self.upper_frame_layout.addWidget(self.plot_frame, 0, 0) self.use_all_controls_buttons = use_all_controls_buttons if self.use_controls and self.use_all_controls_buttons: self.lower_frame_layout.addWidget(self.show_label, 0, 5) self.lower_frame_layout.addWidget(self.show_all_button, 0, 6) self.lower_frame_layout.addWidget(self.hide_all_button, 0, 7) self.messagebar_initial_text = messagebar_initial_text if self.messagebar_initial_text is not None: self.info_label.setText(self.messagebar_initial_text) self.update_messagebar = update_messagebar self.on_click_action = on_click_action if self.on_click_action is not None: if not hasattr(self.on_click_action, "__call__"): raise TypeError("'on_click_action' must be a function.") self.messagebar_text_on_update = messagebar_text_on_update self.messagebar_vars_on_update = messagebar_vars_on_update self.use_save_to_csv = use_save_to_csv if self.use_save_to_csv: self.file_menu.addAction(self.save_to_csv_action) self.file_menu.addAction(self.save_to_png_action) self.highlight_points = highlight_points # Configure the PlotWidget. self.graphWidget.setMenuEnabled(False) if label_size is not None: kwargs = {"font-size": "%spx" % label_size} font = QtGui.QFont() font.setPixelSize(label_size) # curve_pen = pyqtgraph.mkPen(width=2, color="r") # Color and width of the curve. else: kwargs = {} self.graphWidget.setLabel("left", y_label_text, **kwargs) self.graphWidget.setLabel("bottom", x_label_text, **kwargs) if label_size is not None: self.graphWidget.getAxis("left").tickFont = font self.graphWidget.getAxis("bottom").tickFont = font # self.graphWidget.getAxis("left").setPen(curve_pen) if hide_x_ticks: self.graphWidget.getAxis("bottom").setStyle(showValues=False, tickLength=0) if hide_y_ticks: self.graphWidget.getAxis("left").setStyle(showValues=False, tickLength=0) if self.on_click_action is not None: self.graphWidget.getViewBox().scene().sigMouseClicked.connect(self.on_scene_click)
''' Simple Text Editor ''' import os import sys import importlib try: from pymol.Qt import QtCore, QtWidgets, QtGui from pymol.Qt.utils import connectFontContextMenu, getMonospaceFont except ImportError: from PyQt5 import QtCore, QtWidgets, QtGui connectFontContextMenu = lambda *a: None getMonospaceFont = lambda: QtGui.QFont() class TextEditor(QtWidgets.QMainWindow): def sizeHint(self): return QtCore.QSize(600, 400) def _write(self, handle): content = self._get() handle.write(content) self._savedcontent = content def _open(self, filename): self.filename = filename or '' if filename and os.path.exists(filename): with open(filename, 'r') as handle: content = handle.read()
def set_input_widget_width(self, width): pass def set_auto_input_widget_width(self, width): pass def get_width_hint(self): return self.slider.sizeHint().width() + self.slider_label.sizeHint( ).width() ############################################################################### # CSS Styles used in PyMod. # ############################################################################### default_pt_size = QtGui.QFont().pointSize() active_entry_style = "background-color: white; color: #333333" inactive_entry_style = "background-color: #ccc; color: #7c7c7c" inactive_bg_color = "#e3e3e3" success_bg_color = "#98fb98" failure_bg_color = "#f08080" highlight_color = "#5ac8ff" options_title_style = "font-size: %spt; color: %s" % (default_pt_size + 1, highlight_color) small_font_style = "font-size: %spt" % (default_pt_size - 1) large_font_style = "font-size: %spt" % (default_pt_size + 1)
def __init__(self, parent, protocol): super(Hmmscan_results_window_qt, self).__init__(parent) self.protocol = protocol self.query_len = len( self.protocol.query_element.my_sequence.replace('-', '')) ######################### # Configure the window. # ######################### self.setWindowTitle("HMMSCAN Results") # Sets the central widget. self.central_widget = QtWidgets.QWidget() self.setCentralWidget(self.central_widget) # The window has a main vbox layout. self.main_vbox = QtWidgets.QVBoxLayout() # Parameters used to draw the 'QGraphicsView' widgets for showing domains. self.preferred_size_policy = QtWidgets.QSizePolicy( QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) self.view_bg_color = "transparent" self.full_seq_pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 0), 2) self.full_seq_color = "#7f7f7f" qcolor = QtGui.QColor(0, 0, 0) qcolor.setNamedColor(self.full_seq_color) self.full_seq_brush = QtGui.QBrush(qcolor) self.font_qcolor = QtGui.QColor(220, 220, 220, 255) self.font_size = 7 ################ # Upper frame. # ################ self.upper_frame = QtWidgets.QFrame() self.upper_frame_layout = QtWidgets.QGridLayout() self.upper_frame.setLayout(self.upper_frame_layout) self.main_vbox.addWidget(self.upper_frame) if 'query_descr' in self.protocol.parsed_res[ 0] and self.protocol.parsed_res[0]['query_descr']: labelseq = self.protocol.query_element.my_header # + '\n' + querydescr else: try: if len(self.protocol.query_element.description) > 79: labelseq = self.protocol.query_element.description[:78] + '...' else: labelseq = self.protocol.query_element.description except TypeError: labelseq = self.protocol.query_element.my_header self.upper_frame_title = QtWidgets.QLabel( "HMMSCAN search results for " + labelseq) self.upper_frame_layout.addWidget(self.upper_frame_title) #------------------------- # Domain graphics frame. - #------------------------- # Builds the scene where to draw the domain representations. self.canvas_plot_scene = QtWidgets.QGraphicsScene() self.canvas_plot_view = QtWidgets.QGraphicsView(self.canvas_plot_scene) self.canvas_plot_view.setFixedHeight(120) self.canvas_plot_view.setSizePolicy(self.preferred_size_policy) self.canvas_plot_view.setStyleSheet("background: %s" % self.view_bg_color) self.upper_frame_layout.addWidget(self.canvas_plot_view) # Draw a rectangle with the full sequence. self.x_init = 10 y_init = 95 # 95 self.domain_y_init = y_init - 7 self.full_seq_rect_w = 800 full_seq_rect_h = 10 self.canvas_plot_scene.addRect(self.x_init, y_init, self.full_seq_rect_w, full_seq_rect_h, self.full_seq_pen, self.full_seq_brush) # Draw the labels for the N- and C-terminal residues. text_offset_y = 15 text_offset_x = 10 text_n = self.canvas_plot_scene.addText("1") text_n.setPos(self.x_init - text_offset_x, y_init + text_offset_y) text_n.setDefaultTextColor(self.font_qcolor) text_n.setFont(QtGui.QFont(text_n.font().family(), self.font_size)) c_label = str(self.query_len) text_c = self.canvas_plot_scene.addText(c_label) text_offset_x_add = 5 if len(c_label) > 2: text_offset_x_add = 10 text_c.setPos( self.x_init + self.full_seq_rect_w - text_offset_x - text_offset_x_add, y_init + text_offset_y) text_c.setDefaultTextColor(self.font_qcolor) text_c.setFont(QtGui.QFont(text_c.font().family(), self.font_size)) ################# # Middle frame. # ################# # Scroll area which contains the widgets, set as the centralWidget. self.middle_scroll = QtWidgets.QScrollArea() self.main_vbox.addWidget(self.middle_scroll) # Widget that contains the collection of Vertical Box. self.middle_widget = QtWidgets.QWidget() # Scroll area properties. self.middle_scroll.setWidgetResizable(True) self.middle_scroll.setWidget(self.middle_widget) # QFormLayout in the middle frame. self.middle_formlayout = QtWidgets.QFormLayout() self.middle_widget.setLayout(self.middle_formlayout) #----------------- # Results frame. - #----------------- # Set the frame and its layout. self.results_frame = QtWidgets.QFrame() self.middle_formlayout.addRow(self.results_frame) self.results_grid = QtWidgets.QGridLayout() self.results_frame.setLayout(self.results_grid) # Calls a method which actually displays the similarity searches results. self.display_hmmscan_hits() # Align the gridded widgets to the left. self.results_grid.setAlignment(QtCore.Qt.AlignLeft) self.results_grid.setHorizontalSpacing(30) ################# # Bottom frame. # ################# self.main_button = QtWidgets.QPushButton("Submit") self.main_button.clicked.connect( lambda a=None: self.protocol.hmmer_results_state()) self.main_vbox.addWidget(self.main_button) self.main_button.setFixedWidth(self.main_button.sizeHint().width()) # Sets the main vertical layout. self.central_widget.setLayout(self.main_vbox) self.main_vbox.setAlignment(self.main_button, QtCore.Qt.AlignCenter)
def setupUi(self, UpdateDialog): UpdateDialog.setObjectName("UpdateDialog") UpdateDialog.resize(950, 470) self.verticalLayout = QtWidgets.QVBoxLayout(UpdateDialog) self.verticalLayout.setObjectName("verticalLayout") self.select_comp_label = QtWidgets.QLabel(UpdateDialog) self.select_comp_label.setObjectName("select_comp_label") self.verticalLayout.addWidget(self.select_comp_label) self.components_tableWidget = QtWidgets.QTableWidget(UpdateDialog) default_font = QtGui.QFont() default_font.setPointSize(default_font.pointSize()-1) self.components_tableWidget.setFont(default_font) self.components_tableWidget.setProperty("showDropIndicator", False) self.components_tableWidget.setDragDropOverwriteMode(False) self.components_tableWidget.setAlternatingRowColors(True) self.components_tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.components_tableWidget.setGridStyle(QtCore.Qt.NoPen) self.components_tableWidget.setColumnCount(self.n_cols) self.components_tableWidget.setObjectName("components_tableWidget") self.components_tableWidget.setRowCount(1) vertical_header_item = QtWidgets.QTableWidgetItem() self.components_tableWidget.setVerticalHeaderItem(0, vertical_header_item) for i in range(self.n_cols): item = QtWidgets.QTableWidgetItem() self.components_tableWidget.setHorizontalHeaderItem(i, item) item = QtWidgets.QTableWidgetItem() self.components_tableWidget.setItem(0, self.component_col_idx, item) item = QtWidgets.QTableWidgetItem() self.components_tableWidget.setItem(0, self.databases_col_idx, item) self.components_tableWidget.horizontalHeader().setVisible(True) self.components_tableWidget.horizontalHeader().setCascadingSectionResizes(False) self.components_tableWidget.setColumnWidth(self.component_col_idx, 210) self.components_tableWidget.setColumnWidth(self.databases_col_idx, 180) self.components_tableWidget.setColumnWidth(self.status_col_idx, 190) # self.components_tableWidget.setColumnWidth(self.source_col_idx, 390) # self.components_tableWidget.setColumnWidth(self.last_download_col_idx, 250) self.components_tableWidget.horizontalHeader().setStretchLastSection(True) self.components_tableWidget.verticalHeader().setVisible(False) self.components_tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) self.verticalLayout.addWidget(self.components_tableWidget) self.statusLabel = QtWidgets.QLabel(UpdateDialog) self.statusLabel.setObjectName("statusLabel") self.verticalLayout.addWidget(self.statusLabel) self.installation_progressBar = QtWidgets.QProgressBar(UpdateDialog) self.installation_progressBar.setEnabled(True) self.installation_progressBar.setProperty("value", 10) self.installation_progressBar.setObjectName("installation_progressBar") self.verticalLayout.addWidget(self.installation_progressBar) self.buttonsHorizontalLayout = QtWidgets.QHBoxLayout() self.buttonsHorizontalLayout.setObjectName("buttonsHorizontalLayout") self.installSel_button = QtWidgets.QPushButton(UpdateDialog) self.installSel_button.setObjectName("installSel_button") self.buttonsHorizontalLayout.addWidget(self.installSel_button) spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.buttonsHorizontalLayout.addItem(spacerItem) self.cancel_button = QtWidgets.QPushButton(UpdateDialog) self.cancel_button.setObjectName("cancel_button") self.buttonsHorizontalLayout.addWidget(self.cancel_button) self.verticalLayout.addLayout(self.buttonsHorizontalLayout) UpdateDialog.setWindowTitle("Install and update databases") self.select_comp_label.setText("Select components to install or update") self.components_tableWidget.setSortingEnabled(True) self.components_tableWidget.horizontalHeaderItem(self.component_col_idx).setText("Component") self.components_tableWidget.horizontalHeaderItem(self.databases_col_idx).setText("Databases Names") self.components_tableWidget.horizontalHeaderItem(self.status_col_idx).setText("Status") self.components_tableWidget.horizontalHeaderItem(self.source_col_idx).setText("Source") self.components_tableWidget.horizontalHeaderItem(self.last_download_col_idx).setText("Last Downloaded") __sortingEnabled = self.components_tableWidget.isSortingEnabled() self.components_tableWidget.setSortingEnabled(False) self.components_tableWidget.setSortingEnabled(__sortingEnabled) self.statusLabel.setText("") self.cancel_button.setText("Cancel") self.installSel_button.setText("Install Selected") QtCore.QMetaObject.connectSlotsByName(UpdateDialog)
def update_qt_font(self): """ Updates the font of the PyMod Qt main window. """ self.qfont = QtGui.QFont(self.font, self.font_size) self.fm = QtGui.QFontMetrics(self.qfont)