def on_click_del(self): indexes = self.tableFiles.selectedIndexes() if not indexes: g.info("No file is selected.") return rows = {} for index in indexes: r = index.row() t = self.modelFiles.item(r, 0) name = t.text() # remove leading and tailing spaces if name[0] == ' ': name = name[1:] if name[-1] == ' ': name = name[:-1] rows[r] = name if len(rows) == 1: ret = g.ask("Delete File", "Sure to delete '%s'?" % list(rows.values())[0]) else: ret = g.ask("Delete Files", "Sure to delete the selected %d files?" % len(rows)) if not ret: return row_list = list(rows) row_list.sort() for i in row_list[::-1]: self.modelFiles.removeRow(i) cfg.del_tab_vpath(rows[i]) self.tableFiles.resizeColumnToContents(0) cfg.save()
def enable_virtual_folder(self, on, index=None): if index is None or index == cfg.active_tab: self.comboPath.setVisible(not on) self.btnBrowser.setVisible(not on) self.tableFiles.setVisible(on) self.frameVirtualRight.setVisible(on) if on: # load paths self.modelFiles.setRowCount(0) vpaths = cfg.get_tab_vpaths() for v in vpaths: items = QStandardItem(" %s " % v), QStandardItem(" %s " % vpaths[v]) if not os.access(vpaths[v], os.F_OK): items[0].setForeground(QColor(0xff0000)) items[1].setForeground(QColor(0xff0000)) items[1].setToolTip(vpaths[v]) self.modelFiles.appendRow(items) self.tableFiles.resizeColumnToContents(0) else: # load path self.comboPath.setEditText(cfg.get_tab_path()) # load history self.comboPath.clear() self.comboPath.addItems(cfg.get_tab_paths()[::-1]) cfg.set_tab_virtualized(on, index=index) cfg.save()
def on_click_clear(self): if not cfg.get_tab_vpaths(): return if not g.ask("Warning", "Sure to delete all virtual files?"): return self.modelFiles.setRowCount(0) cfg.get_tab_vpaths().clear() cfg.save()
def on_click_browser(self): path = QFileDialog.getExistingDirectory(self, "Pick a path", cfg.get_tab_path()) if path: cfg.set_tab_path(path, record=True) self.comboPath.clear() self.comboPath.addItems(cfg.get_tab_paths()[::-1]) self.comboPath.setEditText(path) cfg.save()
def on_path_changed(self, path): if path: self.comboPath.currentTextChanged.disconnect( self.on_path_changed) # prevent recursion cfg.set_tab_path(path) self.comboPath.clear() self.comboPath.addItems(cfg.get_tab_paths()[::-1]) cfg.save() self.comboPath.currentTextChanged.connect( self.on_path_changed) # prevent recursion
def on_action_always_top(self, checked: bool): # flags = self.windowFlags() # if checked: # self.setWindowFlags(flags | Qt.WindowStaysOnTopHint) # else: # self.setWindowFlags(flags & ~Qt.WindowStaysOnTopHint) self.setWindowFlag(Qt.WindowStaysOnTopHint, checked) super(MainWindow, self).show() cfg.always_top = checked cfg.save()
def on_remove(self, checked: bool): ret = g.ask("Delete Tab", "Sure to delete '%s'?" % self.tabText(self.clicked_index)) if ret: count = self.count() log.debug("remove tab %d/%d" % (self.clicked_index, count)) self.removeTab(self.clicked_index) if self.clicked_index == count - 2: self.setCurrentIndex(self.clicked_index - 1) cfg.tabs.pop(self.clicked_index) cfg.save()
def closeEvent(self, event: QCloseEvent): log.warn("terminated for window closed") # save window geometry g = self.geometry() cfg.position = g.x(), g.y() cfg.size = g.width(), g.height() # save column widths for i in range(len(cfg.col_widths)): cfg.col_widths[i] = self.tableSessions.columnWidth(i) # save to file cfg.save() sys.exit(0)
def on_rename(self, checked: bool): dlg = QInputDialog(self) dlg.setInputMode(QInputDialog.TextInput) dlg.setWindowTitle("Rename %s to" % self.tabText(self.clicked_index)) dlg.setLabelText("New name:") dlg.resize(500, 80) dlg.setTextValue(self.tabText(self.clicked_index)) ok = dlg.exec_() text = dlg.textValue() if ok and text: self.setTabText(self.clicked_index, text) log.debug("rename tab", self.clicked_index, "to", text) cfg.tabs[self.clicked_index]["name"] = text cfg.save()
def on_activate_tab(self, index): if 0 <= index < len(cfg.tabs): # change index cfg.active_tab = index # change content ui self.enable_virtual_folder(cfg.get_tab_virtualized()) # save cfg.save() elif index == len(cfg.tabs): log.debug("add a tab") self.tabWidget.addTab(QWidget(), "+") cfg.tabs.append({}) self.tabWidget.setTabText(index, cfg.get_tab_name(index)) self.on_activate_tab(index)
def main(): log.trace("pid:", os.getpid()) g.app = QApplication(sys.argv) g.main = MainWindow() g.spawn(run_main_ui, g.app) g.server = TftpServer(cfg.port) g.server.set_callback(g.main.start_session, g.main.update_session, g.main.stop_session) g.spawn_later(0.5, g.server.start) g.spawn_later(1, run_ui_timer, g.main, g.server) g.goin() # sys.exit(G.app.exec_()) cfg.save()
def on_click_add(self): path, accepts = QFileDialog.getSaveFileName( self, "Add virtual file", options=QFileDialog.DontConfirmOverwrite) if not path: return name = os.path.basename(path) if not cfg.add_tab_vpath(name, path): g.info("'%s' is in the list already." % name) return items = [QStandardItem(" %s " % name), QStandardItem(" %s " % path)] if not os.access(path, os.F_OK): items[0].setForeground(QColor(0xff0000)) items[1].setForeground(QColor(0xff0000)) items[1].setToolTip(path) self.modelFiles.appendRow(items) self.tableFiles.resizeColumnToContents(0) self.tableFiles.scrollToBottom() cfg.save()
def on_action_min2tray(checked: bool): cfg.min2tray = checked cfg.save()