def __init__(self, parent=None): super(LabelError, self).__init__(parent) # Setup the two layouts that will house the message and the # acknowledgement fields. self.window_layout = QtWidgets.QVBoxLayout() self.window_layout.setContentsMargins(QtCore.QMargins(2, 2, 2, 2)) self.button_layout = QtWidgets.QHBoxLayout() self.button_layout.addStretch() self.button_layout.setContentsMargins(QtCore.QMargins(4, 2, 4, 2)) self.setWindowTitle("Label Error") self.resize(400, 140) # Create and populate the message and the acknowledgement fields. self.message_field = QtWidgets.QLabel( "<font color=black size=24><center><b>No label found.</b>" + "</center></font>") self.message_field.resize(350, 100) self.confirm_button = QtWidgets.QPushButton("Ok") self.confirm_button.clicked.connect(self.confirm) # Add the fields to the their layouts and the layouts to the Qdialog self.window_layout.addWidget(self.message_field, stretch=0) self.button_layout.addWidget(self.confirm_button) self.layout = QtWidgets.QGridLayout() self.layout.addLayout(self.window_layout, 0, 0) self.layout.addLayout(self.button_layout, 1, 0) self.setLayout(self.layout)
def __init__(self, parent): super(LabelView, self).__init__(parent) # Initialize the subdialogs self._finder_window = None self.parent = parent self.is_open = True # Setting up the layout boxes. self.text_layout = QtWidgets.QVBoxLayout() self.text_layout.setContentsMargins(QtCore.QMargins(2, 2, 2, 2)) self.button_layout = QtWidgets.QHBoxLayout() self.button_layout.addStretch() self.button_layout.setContentsMargins(QtCore.QMargins(4, 2, 4, 2)) self.layout = QtWidgets.QGridLayout() # Setting up window details. self.setWindowTitle("Label") self.resize(640, 620) # Setting up the area where the label will be displayed. self.label_contents = QtWidgets.QTextEdit() self.label_contents.setReadOnly(True) self.font = QtGui.QFont("Courier") self.font.setPointSize(12) self.label_contents.setFont(self.font) # Setting up the label and adding it to the label field. self.label_contents.setText('\n'.join(self.parent.image_label)) # Creating and binding the buttons. self.find_button = QtWidgets.QPushButton("Find") self.find_button.clicked.connect(self.finder_window) self.cancel_button = QtWidgets.QPushButton("Cancel") self.cancel_button.clicked.connect(self.cancel) # Adding the text and button widgets to the layout boxes. self.text_layout.addWidget(self.label_contents, stretch=0) self.button_layout.addWidget(self.find_button) self.button_layout.addWidget(self.cancel_button) # Adding all of the layout boxes to the overall layout. self.layout.addLayout(self.text_layout, 0, 0) self.layout.addLayout(self.button_layout, 1, 0) # Adding the overall layout to the dialog box. self.setLayout(self.layout)
def _subtable(self, subdata): if subdata is not None: if self.subtable is None: self.subtable = RecursiveTable(parent=self, main_data=subdata) self.subtable.layout().setContentsMargins(QtCore.QMargins(0, 0, 0, 0)) self.dispatcher.add_child(self.subtable.dispatcher) self._splitter.addWidget(self.subtable) self.subtable.hide() # noinspection PyProtectedMember self.subtable.data_changed.connect(self._data_changed) self.subtable.set_main_data(subdata) return self.subtable
def create_traceback_box(self): """ Creates a special box for the exception dialog that contains the traceback information and returns it. """ # Create a traceback box traceback_box = QW.QWidget(self) traceback_box.setHidden(True) # Create layout layout = QW.QVBoxLayout() layout.setContentsMargins(QC.QMargins()) traceback_box.setLayout(layout) # Add a horizontal line to the layout frame = QW.QFrame(traceback_box) frame.setFrameShape(frame.HLine) frame.setFrameShadow(frame.Sunken) layout.addWidget(frame) # Format the traceback tb_str = self.format_traceback() # Add a textedit to the layout tb_text_box = QW.QTextEdit(traceback_box) tb_text_box.setMinimumHeight(100) tb_text_box.setFocusPolicy(QC.Qt.NoFocus) tb_text_box.setReadOnly(True) tb_text_box.setText(tb_str) layout.addWidget(tb_text_box) # Create a 'show traceback' button self.tb_labels = ['Hide Traceback...', 'Show Traceback...'] # Return traceback box return (traceback_box)
def __init__(self): Viewer.__init__(self) from ginga.qtw.ImageViewCanvasQt import ImageViewCanvas fi = ImageViewCanvas(render='widget') fi.enable_autocuts('on') fi.set_autocut_params('zscale') fi.enable_autozoom('on') fi.set_bg(0.2, 0.2, 0.2) fi.ui_setActive(True) fi.enable_draw(False) self.fitsimage = fi bd = fi.get_bindings() bd.enable_all(True) w = fi.get_widget() w.resize(512, 512) vbox = QtWidgets.QVBoxLayout() vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2)) vbox.setSpacing(1) vbox.addWidget(w, stretch=1) self.setLayout(vbox)
def _GetNumPyImage(self, clip_rect: QC.QRect, target_resolution: QC.QSize): if self._numpy_image is None: return numpy.zeros( (target_resolution.height(), target_resolution.width()), dtype='uint8') clip_size = clip_rect.size() clip_width = clip_size.width() clip_height = clip_size.height() (my_width, my_height) = self._resolution my_full_rect = QC.QRect(0, 0, my_width, my_height) ZERO_MARGIN = QC.QMargins(0, 0, 0, 0) clip_padding = ZERO_MARGIN target_padding = ZERO_MARGIN if clip_rect == my_full_rect: # full image source = self._numpy_image else: if target_resolution.width() > clip_width: # this is a tile that is being scaled up! # to reduce tiling artifacts (disagreement at otherwise good borders), we want to oversample the clip for our tile so lanczos and friends can get good neighbour data and then crop it # therefore, we'll figure out some padding for the clip, and then calculate what that means in the target end, and do a crop at the end # we want to pad. that means getting a larger resolution and keeping a record of the padding # can't pad if we are at 0 for x or y, or up against width/height max, but no problem in that case obviously # there is the float-int precision calculation problem again. we can't pick a padding of 3 in the clip if we are zooming by 150%--what do we clip off in the target: 4 or 5 pixels? whatever, we get warping # first let's figure a decent zoom estimate: zoom_estimate = target_resolution.width( ) / clip_width if target_resolution.width( ) > target_resolution.height( ) else target_resolution.height() / clip_height # now, if zoom is 150% (as a fraction, 3/2), we want a padding at the target of something that divides by 3 cleanly, or, since we are choosing at the clip in this case and will be multiplying, something that divides cleanly to 67% zoom_estimate_for_clip_padding_multiplier = 1 / zoom_estimate # and we want a nice padding size limit, big enough to make clean numbers but not so big that we are rendering the 8 tiles in a square around the one we want no_bigger_than = max(4, (clip_width + clip_height) // 4) nice_number = HydrusData.GetNicelyDivisibleNumberForZoom( zoom_estimate_for_clip_padding_multiplier, no_bigger_than) if nice_number != -1: # lanczos, I think, uses 4x4 neighbour grid to render. we'll say padding of 4 pixels to be safe for now, although 2 or 3 is probably correct??? # however it works, numbers these small are not a big deal while nice_number < 4: nice_number *= 2 PADDING_AMOUNT = nice_number # LIMITATION: There is still a problem here for the bottom and rightmost edges. These tiles are not squares, so the shorter/thinner dimension my be an unpleasant number and be warped _anyway_, regardless of nice padding # perhaps there is a way to boost left or top padding so we are rendering a full square tile but still cropping our target at the end, but with a little less warping # I played around with this idea but did not have much success LEFT_PADDING_AMOUNT = PADDING_AMOUNT TOP_PADDING_AMOUNT = PADDING_AMOUNT left_padding = min(LEFT_PADDING_AMOUNT, clip_rect.x()) top_padding = min(TOP_PADDING_AMOUNT, clip_rect.y()) right_padding = min(PADDING_AMOUNT, (my_width - 1) - clip_rect.bottomRight().x()) bottom_padding = min(PADDING_AMOUNT, (my_height - 1) - clip_rect.bottomRight().y()) clip_padding = QC.QMargins(left_padding, top_padding, right_padding, bottom_padding) target_padding = clip_padding * zoom_estimate clip_rect_with_padding = clip_rect + clip_padding (x, y, clip_width, clip_height) = (clip_rect_with_padding.x(), clip_rect_with_padding.y(), clip_rect_with_padding.width(), clip_rect_with_padding.height()) source = self._numpy_image[y:y + clip_height, x:x + clip_width] if target_resolution == clip_size: # 100% zoom result = source else: if clip_padding == ZERO_MARGIN: result = ClientImageHandling.ResizeNumPyImageForMediaViewer( self._mime, source, (target_resolution.width(), target_resolution.height())) else: target_width_with_padding = target_resolution.width( ) + target_padding.left() + target_padding.right() target_height_with_padding = target_resolution.height( ) + target_padding.top() + target_padding.bottom() result = ClientImageHandling.ResizeNumPyImageForMediaViewer( self._mime, source, (target_width_with_padding, target_height_with_padding)) y = target_padding.top() x = target_padding.left() result = result[y:y + target_resolution.height(), x:x + target_resolution.width()] if not result.data.c_contiguous: result = result.copy() return result
def _GetNumPyImage(self, clip_rect: QC.QRect, target_resolution: QC.QSize): clip_size = clip_rect.size() (my_width, my_height) = self._resolution my_full_rect = QC.QRect(0, 0, my_width, my_height) ZERO_MARGIN = QC.QMargins(0, 0, 0, 0) clip_padding = ZERO_MARGIN target_padding = ZERO_MARGIN if clip_rect == my_full_rect: # full image source = self._numpy_image else: if target_resolution.width() > clip_size.width(): # this is a tile that is being scaled! # to reduce tiling artifacts, we want to oversample the clip for our tile so lanczos and friends can get good neighbour data and then crop it # therefore, we'll figure out some padding for the clip, and then calculate what that means in the target end, and do a crop at the end # we want to pad. that means getting a larger resolution and keeping a record of the padding # can't pad if we are at 0 for x or y, or up against width/height max # but if we can pad, we will get a larger clip size and then _clip_ a better target endpoint. this is tricky. PADDING_AMOUNT = 4 left_padding = min(PADDING_AMOUNT, clip_rect.x()) top_padding = min(PADDING_AMOUNT, clip_rect.y()) right_padding = min(PADDING_AMOUNT, my_width - clip_rect.bottomRight().x()) bottom_padding = min(PADDING_AMOUNT, my_height - clip_rect.bottomRight().y()) clip_padding = QC.QMargins(left_padding, top_padding, right_padding, bottom_padding) # this is ugly and super inaccurate target_padding = clip_padding * (target_resolution.width() / clip_size.width()) clip_rect_with_padding = clip_rect + clip_padding (x, y, clip_width, clip_height) = (clip_rect_with_padding.x(), clip_rect_with_padding.y(), clip_rect_with_padding.width(), clip_rect_with_padding.height()) source = self._numpy_image[y:y + clip_height, x:x + clip_width] if target_resolution == clip_size: # 100% zoom result = source else: if clip_padding == ZERO_MARGIN: result = ClientImageHandling.ResizeNumPyImageForMediaViewer( self._mime, source, (target_resolution.width(), target_resolution.height())) else: target_width_with_padding = target_resolution.width( ) + target_padding.left() + target_padding.right() target_height_with_padding = target_resolution.height( ) + target_padding.top() + target_padding.bottom() result = ClientImageHandling.ResizeNumPyImageForMediaViewer( self._mime, source, (target_width_with_padding, target_height_with_padding)) y = target_padding.top() x = target_padding.left() result = result[y:y + target_resolution.height(), x:x + target_resolution.width()] if not result.data.c_contiguous: result = result.copy() return result