def update_folder_icon(self, folder_name, folder_path, overlay_file=None): items = self.findItems(folder_name) if items: folder_icon = QFileIconProvider().icon(QFileInfo(folder_path)) folder_pixmap = folder_icon.pixmap(256, 256) if overlay_file: pixmap = CompositePixmap(folder_pixmap, resource(overlay_file)) else: pixmap = CompositePixmap(folder_pixmap) items[0].setIcon(QIcon(pixmap))
def add_folder(self, path, status_data=0): basename = os.path.basename(os.path.normpath(path)) if self.findItems(basename): logging.warning("Tried to add a folder (%s) that already exists", basename) return composite_pixmap = CompositePixmap(self.icon_folder.pixmap(256, 256)) name = QStandardItem(QIcon(composite_pixmap), basename) name.setToolTip(path) status = QStandardItem() mtime = QStandardItem() size = QStandardItem() action = QStandardItem() self.appendRow([name, status, mtime, size, action]) action_bar = QToolBar() action_bar.setIconSize(QSize(16, 16)) if sys.platform == 'darwin': # See: https://bugreports.qt.io/browse/QTBUG-12717 action_bar.setStyleSheet( 'background-color: white; border: 0px white') action_bar_action = QAction(self.icon_action, "Action...", self) action_bar_action.setStatusTip("Action...") action_bar_action.triggered.connect(self.view.on_right_click) action_bar.addAction(action_bar_action) self.view.setIndexWidget(action.index(), action_bar) self.view.hide_drop_label() self.set_status(basename, status_data)
def fade_row(self, folder_name, overlay_file=None): folder_item = self.findItems(folder_name)[0] if overlay_file: folder_pixmap = self.icon_folder_gray.pixmap(256, 256) pixmap = CompositePixmap(folder_pixmap, resource(overlay_file)) folder_item.setIcon(QIcon(pixmap)) else: folder_item.setIcon(self.icon_folder_gray) row = folder_item.row() for i in range(4): item = self.item(row, i) font = item.font() font.setItalic(True) item.setFont(font) item.setForeground(QColor('gray'))
def add_folder(self, path, status_data=0): basename = os.path.basename(os.path.normpath(path)) if self.findItems(basename): logging.warning("Tried to add a folder (%s) that already exists", basename) return composite_pixmap = CompositePixmap(self.icon_folder.pixmap(256, 256)) name = QStandardItem(QIcon(composite_pixmap), basename) name.setToolTip(path) status = QStandardItem() mtime = QStandardItem() size = QStandardItem() self.appendRow([name, status, mtime, size]) self.view.hide_drop_label() self.set_status(basename, status_data)
def __init__(self, view): super(Model, self).__init__(0, 5) self.view = view self.gui = self.view.gui self.gateway = self.view.gateway self.monitor = self.gateway.monitor self.status_dict = {} self.members_dict = {} self.grid_status = '' self.available_space = 0 self.setHeaderData(0, Qt.Horizontal, "Name") self.setHeaderData(1, Qt.Horizontal, "Status") self.setHeaderData(2, Qt.Horizontal, "Last modified") self.setHeaderData(3, Qt.Horizontal, "Size") self.setHeaderData(4, Qt.Horizontal, "") self.icon_blank = QIcon() self.icon_up_to_date = QIcon(resource('checkmark.png')) self.icon_user = QIcon(resource('user.png')) self.icon_folder = QFileIconProvider().icon(QFileInfo(config_dir)) composite_pixmap = CompositePixmap(self.icon_folder.pixmap(256, 256), overlay=None, grayout=True) self.icon_folder_gray = QIcon(composite_pixmap) self.icon_cloud = QIcon(resource('cloud-icon.png')) self.icon_action = QIcon(resource('dots-horizontal-triple.png')) self.monitor.connected.connect(self.on_connected) self.monitor.disconnected.connect(self.on_disconnected) self.monitor.nodes_updated.connect(self.on_nodes_updated) self.monitor.space_updated.connect(self.on_space_updated) self.monitor.status_updated.connect(self.set_status) self.monitor.mtime_updated.connect(self.set_mtime) self.monitor.size_updated.connect(self.set_size) self.monitor.members_updated.connect(self.on_members_updated) self.monitor.sync_started.connect(self.on_sync_started) self.monitor.sync_finished.connect(self.on_sync_finished) self.monitor.files_updated.connect(self.on_updated_files) self.monitor.check_finished.connect(self.update_natural_times) self.monitor.remote_folder_added.connect(self.add_remote_folder) self.monitor.transfer_progress_updated.connect( self.set_transfer_progress)
def __init__(self, gui): super(MainWindow, self).__init__() self.gui = gui self.gateways = [] self.crypter = None self.crypter_thread = None self.export_data = None self.export_dest = None self.setWindowTitle(APP_NAME) self.setMinimumSize(QSize(500, 300)) self.shortcut_new = QShortcut(QKeySequence.New, self) self.shortcut_new.activated.connect(self.gui.show_setup_form) self.shortcut_open = QShortcut(QKeySequence.Open, self) self.shortcut_open.activated.connect(self.select_folder) self.shortcut_close = QShortcut(QKeySequence.Close, self) self.shortcut_close.activated.connect(self.close) self.shortcut_quit = QShortcut(QKeySequence.Quit, self) self.shortcut_quit.activated.connect(self.confirm_quit) self.combo_box = ComboBox() self.combo_box.activated[int].connect(self.on_grid_selected) self.central_widget = CentralWidget(self.gui) self.setCentralWidget(self.central_widget) invite_action = QAction(QIcon(resource('invite.png')), 'Enter an Invite Code...', self) invite_action.setStatusTip('Enter an Invite Code...') invite_action.triggered.connect(self.open_invite_receiver) folder_icon_default = QFileIconProvider().icon(QFileInfo(config_dir)) folder_icon_composite = CompositePixmap( folder_icon_default.pixmap(256, 256), resource('green-plus.png')) folder_icon = QIcon(folder_icon_composite) folder_action = QAction(folder_icon, "Add folder...", self) folder_action.setStatusTip("Add folder...") folder_from_local_action = QAction(QIcon(resource('laptop.png')), "From local computer...", self) folder_from_local_action.setStatusTip("Add folder from local computer") folder_from_local_action.setToolTip("Add folder from local computer") #self.from_local_action.setShortcut(QKeySequence.Open) folder_from_local_action.triggered.connect(self.select_folder) folder_from_invite_action = QAction(QIcon(resource('invite.png')), "From Invite Code...", self) folder_from_invite_action.setStatusTip("Add folder from Invite Code") folder_from_invite_action.setToolTip("Add folder from Invite Code") folder_from_invite_action.triggered.connect(self.open_invite_receiver) folder_menu = QMenu(self) folder_menu.addAction(folder_from_local_action) folder_menu.addAction(folder_from_invite_action) folder_button = QToolButton(self) folder_button.setDefaultAction(folder_action) folder_button.setMenu(folder_menu) folder_button.setPopupMode(2) folder_button.setStyleSheet( 'QToolButton::menu-indicator { image: none }') pair_action = QAction(QIcon(resource('laptop.png')), 'Connect another device...', self) pair_action.setStatusTip('Connect another device...') pair_action.triggered.connect(self.open_pair_widget) export_action = QAction(QIcon(resource('export.png')), 'Export Recovery Key', self) export_action.setStatusTip('Export Recovery Key...') export_action.setShortcut(QKeySequence.Save) export_action.triggered.connect(self.export_recovery_key) preferences_action = QAction(QIcon(resource('preferences.png')), 'Preferences', self) preferences_action.setStatusTip('Preferences') preferences_action.setShortcut(QKeySequence.Preferences) preferences_action.triggered.connect(self.toggle_preferences_widget) spacer_left = QWidget() spacer_left.setSizePolicy(QSizePolicy.Expanding, 0) spacer_right = QWidget() spacer_right.setSizePolicy(QSizePolicy.Expanding, 0) self.toolbar = self.addToolBar('') #self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) #self.toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.toolbar.setIconSize(QSize(24, 24)) self.toolbar.setMovable(False) self.toolbar.addWidget(folder_button) #self.toolbar.addAction(invite_action) self.toolbar.addAction(pair_action) self.toolbar.addWidget(spacer_left) self.toolbar.addWidget(self.combo_box) self.toolbar.addWidget(spacer_right) self.toolbar.addAction(export_action) self.toolbar.addAction(preferences_action) self.status_bar = self.statusBar() self.status_bar_label = QLabel('Initializing...') self.status_bar.addPermanentWidget(self.status_bar_label) self.preferences_widget = PreferencesWidget() self.preferences_widget.accepted.connect(self.show_selected_grid_view) self.active_pair_widgets = [] self.active_invite_receivers = []
def __init__(self, gui): super(MainWindow, self).__init__() self.gui = gui self.gateways = [] self.welcome_dialog = None self.recovery_key_exporter = None self.setWindowTitle(APP_NAME) self.setMinimumSize(QSize(600, 400)) self.setUnifiedTitleAndToolBarOnMac(True) self.shortcut_new = QShortcut(QKeySequence.New, self) self.shortcut_new.activated.connect(self.show_welcome_dialog) self.shortcut_open = QShortcut(QKeySequence.Open, self) self.shortcut_open.activated.connect(self.select_folder) self.shortcut_close = QShortcut(QKeySequence.Close, self) self.shortcut_close.activated.connect(self.close) self.shortcut_quit = QShortcut(QKeySequence.Quit, self) self.shortcut_quit.activated.connect(self.confirm_quit) self.central_widget = CentralWidget(self.gui) self.setCentralWidget(self.central_widget) font = QFont() if sys.platform == 'darwin': font.setPointSize(11) else: font.setPointSize(8) folder_icon_default = QFileIconProvider().icon(QFileInfo(config_dir)) folder_icon_composite = CompositePixmap( folder_icon_default.pixmap(256, 256), resource('green-plus.png')) folder_icon = QIcon(folder_icon_composite) folder_action = QAction(folder_icon, "Add folder", self) folder_action.setToolTip("Add a folder...") folder_action.setFont(font) folder_action.triggered.connect(self.select_folder) invite_action = QAction( QIcon(resource('invite.png')), "Enter Code", self) invite_action.setToolTip("Enter an Invite Code...") invite_action.setFont(font) invite_action.triggered.connect(self.open_invite_receiver) history_action = QAction( QIcon(resource('time.png')), 'History', self) history_action.setToolTip("View history") history_action.setFont(font) history_action.triggered.connect(self.on_history_button_clicked) self.history_button = QToolButton(self) self.history_button.setDefaultAction(history_action) self.history_button.setCheckable(True) self.history_button.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) spacer_left = QWidget() spacer_left.setSizePolicy(QSizePolicy.Expanding, 0) self.combo_box = ComboBox() self.combo_box.currentIndexChanged.connect(self.on_grid_selected) spacer_right = QWidget() spacer_right.setSizePolicy(QSizePolicy.Expanding, 0) share_action = QAction(QIcon(resource('share.png')), "Share", self) share_action.setToolTip("Share...") share_action.setFont(font) share_action.triggered.connect(self.open_invite_sender_dialog) recovery_action = QAction( QIcon(resource('key.png')), "Recovery", self) recovery_action.setToolTip("Import/Export Recovery Key...") recovery_action.setFont(font) import_action = QAction(QIcon(), "Import Recovery Key...", self) import_action.setToolTip("Import Recovery Key...") import_action.triggered.connect(self.import_recovery_key) export_action = QAction(QIcon(), "Export Recovery Key...", self) export_action.setToolTip("Export Recovery Key...") export_action.setShortcut(QKeySequence.Save) export_action.triggered.connect(self.export_recovery_key) recovery_menu = QMenu(self) recovery_menu.addAction(import_action) recovery_menu.addAction(export_action) recovery_button = QToolButton(self) recovery_button.setDefaultAction(recovery_action) recovery_button.setMenu(recovery_menu) recovery_button.setPopupMode(2) recovery_button.setStyleSheet( 'QToolButton::menu-indicator { image: none }') recovery_button.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) preferences_action = QAction( QIcon(resource('preferences.png')), "Preferences", self) preferences_action.setStatusTip("Preferences") preferences_action.setToolTip("Preferences") preferences_action.setFont(font) preferences_action.setShortcut(QKeySequence.Preferences) preferences_action.triggered.connect(self.gui.show_preferences_window) self.toolbar = self.addToolBar('') if sys.platform != 'darwin': self.toolbar.setStyleSheet(""" QToolBar { border: 0px } QToolButton { color: rgb(50, 50, 50) } """) else: self.toolbar.setStyleSheet( "QToolButton { color: rgb(50, 50, 50) }") self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) self.toolbar.setIconSize(QSize(24, 24)) self.toolbar.setMovable(False) self.toolbar.addAction(folder_action) self.toolbar.addAction(invite_action) self.toolbar.addWidget(self.history_button) self.toolbar.addWidget(spacer_left) self.toolbar.addWidget(self.combo_box) self.toolbar.addWidget(spacer_right) self.toolbar.addAction(share_action) self.toolbar.addWidget(recovery_button) self.toolbar.addAction(preferences_action) if sys.platform != 'win32': # Text is getting clipped on Windows 10 for action in self.toolbar.actions(): widget = self.toolbar.widgetForAction(action) if isinstance(widget, QToolButton): widget.setMaximumWidth(68) self.active_invite_sender_dialogs = [] self.active_invite_receiver_dialogs = []