def _arrange_items(self): """ This function is a mess and it is probably easier to achieve what I want, but I didn't find any way now. So keep it like this as long you dont find a better solution """ info_box_size = self.info_box.windowFrameRect().toRect().size() if self.model.monitor.primary: info_box_margin = self.info_box.getWindowFrameMargins() control_box_size = self.control_box.windowFrameRect().toRect( ).size() control_box_margin = self.control_box.getWindowFrameMargins() rect = QStyle.alignedRect( Qt.LeftToRight, Qt.AlignCenter, self._bounding_box(info_box_size, control_box_size), QRect(0, 0, self.model.monitor.screen_width, self.model.monitor.screen_height)) self.info_box.setPos(rect.left() + info_box_margin[0], rect.top() + info_box_margin[1]) self.control_box.setPos( rect.left() + info_box_size.width() + control_box_margin[0], rect.top() + (info_box_size.height() - control_box_size.height()) / 2 + control_box_margin[1]) else: self.info_box.setGeometry( QStyle.alignedRect( Qt.LeftToRight, Qt.AlignCenter, self.info_box.size().toSize(), QRect(0, 0, self.model.monitor.screen_width, self.model.monitor.screen_height)))
def pixel_pos_to_range_value(self, pos: QtCore.QPoint): opt = QtWidgets.QStyleOptionSlider() # Populate opt with the widget's style self.initStyleOption(opt) groove = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderGroove, self) if self.orientation() == QtCore.Qt.Horizontal: # sliderLength = handle.width() slider_min = groove.x() slider_max = groove.right() else: # sliderLength = handle.height() slider_min = groove.y() slider_max = groove.bottom() new_pos_scalar = pos.x() if self.orientation( ) == QtCore.Qt.Horizontal else pos.y() return QStyle.sliderValueFromPosition( self.minimum(), # min self.maximum(), # max new_pos_scalar, # pos (int) slider_max - slider_min, # span (int) opt.upsideDown # upside down (bool) )
def __init__(self): QMainWindow.__init__(self) self.setWindowTitle("PyPentest - Information Gathering") # Menu self.menu = self.menuBar() self.file_menu = self.menu.addMenu("File") self.about_menu = self.menu.addMenu("About") self.set_menu() self.set_icon() # Add Widget tab_widget = QTabWidget() tab_widget.addTab(NmapScanTab(), "Nmap") tab_widget.addTab(DirBusterTab(), "Dir Buster") tab_widget.addTab(ReverseShellTab(), "Reverse Shell") self.setCentralWidget(tab_widget) # Window dimensions & center geometry = qApp.desktop().availableGeometry(self) self.width_size = geometry.width() * 0.45 self.height_size = geometry.height() * 0.55 self.setGeometry( QStyle.alignedRect( Qt.LeftToRight, Qt.AlignCenter, QSize(self.width_size, self.height_size), geometry, ))
def resizeEvent(self, event): self.setGeometry( QStyle.alignedRect( Qt.LeftToRight, Qt.AlignCenter, self.map_view.size(), self.scr_2, ))
def centralisedRect(geometry, x_scale: float = 0.65, y_scale: float = 0.65): size = geometry.size() return QStyle.alignedRect( Qt.LeftToRight, Qt.AlignCenter, QSize( size.width() * x_scale, size.height() * y_scale, ), geometry)
def window_setup(self): self.adjustSize() self.setGeometry( QStyle.alignedRect( Qt.LeftToRight, Qt.AlignCenter, self.size(), QGuiApplication.primaryScreen().availableGeometry(), )) self.setWindowTitle("Saharah Paper") self.setWindowIcon(QIcon(f"{sys.argv[0]}/assets/app_icon.png"))
def __init__(self, app, path): super().__init__() self.ui = Ui_ImagePicker() self.title = "ImagePicker" self.ui.setupUi(self) # Ubuntu 16.04 LTS is too stupid to display the Menubar... self.ui.menubar.setNativeMenuBar(False) self.setGeometry( QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, self.size(), app.desktop().availableGeometry())) self.ui.actionOpenFolder.triggered.connect(lambda: self.open_folder()) self.ui.forward_small.clicked.connect( lambda: self.show_image(self.current_index + 1)) self.ui.backward_small.clicked.connect( lambda: self.show_image(self.current_index - 1)) self.ui.forward_big.clicked.connect(lambda: self.show_image( self.current_index + self.ui.step_spin.value())) self.ui.backward_big.clicked.connect(lambda: self.show_image( self.current_index - self.ui.step_spin.value())) self.ui.select.clicked.connect(self.select_image) self.ui.step_spin.valueChanged.connect(self.change_scroll_count) self.ui.actionCopy_Selected.triggered.connect( lambda: self.modify_items(SelectionStatus.SELECTED, ModificationType.COPY)) self.ui.actionCopy_Unselected.triggered.connect( lambda: self.modify_items(SelectionStatus.UNSELECTED, ModificationType.COPY)) self.ui.actionMove_Unselected.triggered.connect( lambda: self.modify_items(SelectionStatus.UNSELECTED, ModificationType.MOVE)) self.ui.actionRemove_Selected.triggered.connect( lambda: self.modify_items(SelectionStatus.SELECTED, ModificationType.REMOVE)) self.ui.actionMove_Selected.triggered.connect( lambda: self.modify_items(SelectionStatus.SELECTED, ModificationType.MOVE)) self.ui.actionRemove_Unselected.triggered.connect( lambda: self.modify_items(SelectionStatus.UNSELECTED, ModificationType.REMOVE)) self.file_list = {} # type: Dict[str, bool] self.selected_images = [] self.current_index = 0 # type: int self.path = "" # type: str if path: self.open_folder(path)
def _init_window_content_and_aspect(self) -> None: window_layout = QVBoxLayout() window_layout.addWidget(self._device_table) window_layout.addWidget(self._controls_section) self.setLayout(window_layout) screen_geom = self._app.desktop().availableGeometry(self) window_size = QSize(screen_geom.width(), screen_geom.height()) * 0.8 self.setGeometry( QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, window_size, screen_geom)) self.setWindowTitle(APP_NAME)
def mousePressEvent(self, event): """ Update the slider value with a single jump when clicking on the groove. @param event: @type event: """ pressVal = QStyle.sliderValueFromPosition( self.minimum(), self.maximum(), event.x(), self.width(), 0) # 0 is for horizontal slider only if abs(pressVal - self.value()) > (self.maximum() - self.minimum( )) * 20 / self.width(): # handle width should be near 20 self.setValue(pressVal) else: super().mousePressEvent(event)
def mousePressEvent(self, event): """ Update the slider value with a single jump when clicking on the groove. # min is at left or top. Change upsideDown to True to reverse this behavior. @param event: @type event: """ pressVal = QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width(), upsideDown=False) if abs(pressVal - self.value()) > (self.maximum() - self.minimum( )) * 20 / self.width(): # handle width should be near 20 self.setValue(pressVal) else: super().mousePressEvent(event)
def __init__(self, application, parent=None): super().__init__(parent) self.setWindowTitle("Eddy") self.setMinimumSize(600, 400) self.setGeometry( QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, QSize(*WINDOW_SIZE), self.screen().availableGeometry())) main_widget = TabSystem() # main_widget.LastTabClosed.connect(application.quit) main_widget.LastTabClosed.connect(main_widget.AddTab) self.setCentralWidget(main_widget) menubar = self.menuBar() file_menu = menubar.addMenu("&File") new_tab_action = QAction(QIcon(icons.TAB_NEW), "New &Tab", self) new_tab_action.setShortcut("Ctrl+T") new_tab_action.triggered.connect(main_widget.AddTab) file_menu.addAction(new_tab_action) self.addAction(new_tab_action) close_tab_action = QAction(QIcon(icons.TAB_CLOSE), "Close Tab", self) close_tab_action.setShortcut("Ctrl+W") close_tab_action.triggered.connect(main_widget.CloseCurrentTab) file_menu.addAction(close_tab_action) self.addAction(close_tab_action) exit_action = QAction(QIcon(icons.QUIT), "&Quit", self) exit_action.setShortcut("Ctrl+Q") exit_action.triggered.connect(application.quit) file_menu.addAction(exit_action) self.addAction(exit_action) toggle_menubar_action = QAction(self) toggle_menubar_action.setShortcut("Ctrl+M") toggle_menubar_action.triggered.connect( lambda: menubar.setVisible(not menubar.isVisible())) self.addAction(toggle_menubar_action) menubar.setVisible(False) main_widget.AddTab()
def __init__(self, w, parent=None): __initBac(self, w, parent=None) # windows appear in center of screen # now I know that __init__ sets geometry already # but it's always in the top left corner rect = QStyle.alignedRect( Qt.LeftToRight, Qt.AlignCenter, w.size(), QApplication.instance().desktop().availableGeometry() ) self.setGeometry(rect) self.btnRestore.setEnabled(False) self.btnMaximize.setEnabled(False) flags = self.windowFlags() | Qt.MSWindowsFixedSizeDialogHint self.setWindowFlags(flags) self.setAttribute(Qt.WA_DeleteOnClose, True)
def _restore_preview_ui(self): """Restore UI state from previous session.""" if not self._preview_window_state: self._settings.beginGroup(self._SETTINGS_GROUP_NAME) window_size = self._settings.value("windowSize") window_pos = self._settings.value("windowPosition") n_screens = self._settings.value("n_screens", defaultValue=1) window_maximized = self._settings.value("windowMaximized", defaultValue='false') splitter_state = {} for splitter in self._import_preview.findChildren(QSplitter): splitter_state[splitter] = self._settings.value( splitter.objectName() + "_splitterState") self._settings.endGroup() original_size = self.size() if window_size: self.resize(window_size) else: self.setGeometry( QStyle.alignedRect( Qt.LeftToRight, Qt.AlignCenter, QSize(1000, 700), QApplication.desktop().availableGeometry(self))) if window_pos: self.move(window_pos) if len(QGuiApplication.screens()) < int(n_screens): # There are less screens available now than on previous application startup self.move( 0, 0) # Move this widget to primary screen position (0,0) ensure_window_is_on_screen(self, original_size) if window_maximized == 'true': self.setWindowState(Qt.WindowMaximized) for splitter, state in splitter_state.items(): if state: splitter.restoreState(state) else: self.resize(self._preview_window_state["size"]) self.move(self._preview_window_state["position"]) self.setWindowState(self._preview_window_state["maximized"]) for splitter in self._import_preview.findChildren(QSplitter): name = splitter.objectName() splitter.restoreState( self._preview_window_state["splitters"][name])
def __init__(self, popup_type, text, focus): super(PopupWindow, self).__init__() msgbox = self # Set window center of screen msgbox.setGeometry( QStyle.alignedRect( Qt.LeftToRight, Qt.AlignCenter, self.size(), QGuiApplication.primaryScreen().availableGeometry(), ), ) msgbox.setWindowIcon(QIcon("static/images/main_icon.png")) title = "Network Assistant" if popup_type == "warning": msgbox.warning(self, title, text) focus.setFocus()
def ensure_window_is_on_screen(window, size): """ Checks if window is on screen and if not, moves and resizes it to make it visible on the primary screen. Args: window (QWidget): a window to check size (QSize): desired window size if the window is moved """ window_geometry = window.frameGeometry() widget_center = window_geometry.center() screens = QApplication.screens() widget_inside_screen = False for screen in screens: screen_geometry = screen.geometry() if screen_geometry.contains(widget_center): widget_inside_screen = True break if not widget_inside_screen: primary_screen = QApplication.primaryScreen() screen_geometry = primary_screen.availableGeometry() window.setGeometry(QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, size, screen_geometry))
def center(self): self.setGeometry( QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, self.size(), QDesktopWidget().availableGeometry()))
""" Contains the main entry point to the application. """ import sys from PySide2.QtCore import Qt from PySide2.QtWidgets import QApplication, QStyle from gui import DataGingerWindow if __name__ == "__main__": APP = QApplication(sys.argv) GEOMETRY = APP.desktop().availableGeometry() MAIN_WINDOW = DataGingerWindow() MAIN_WINDOW.show() MAIN_WINDOW.setGeometry( QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, GEOMETRY.size() * 0.75, GEOMETRY)) sys.exit(APP.exec_())