def create_itemview_tabwidget(self): result = QTabWidget() init_widget(result, "bottomLeftTabWidget") result.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Ignored) tree_view = QTreeView() init_widget(tree_view, "treeView") filesystem_model = QFileSystemModel(tree_view) filesystem_model.setRootPath(QDir.rootPath()) tree_view.setModel(filesystem_model) table_widget = QTableWidget() init_widget(table_widget, "tableWidget") table_widget.setRowCount(10) table_widget.setColumnCount(10) list_model = QStandardItemModel(0, 1, result) list_model.appendRow(QStandardItem(QIcon(DIR_OPEN_ICON), "Directory")) list_model.appendRow(QStandardItem(QIcon(COMPUTER_ICON), "Computer")) list_view = QListView() init_widget(list_view, "listView") list_view.setModel(list_model) icon_mode_listview = QListView() init_widget(icon_mode_listview, "iconModeListView") icon_mode_listview.setViewMode(QListView.IconMode) icon_mode_listview.setModel(list_model) result.addTab(embed_into_hbox_layout(tree_view), "Tree View") result.addTab(embed_into_hbox_layout(table_widget), "Table") result.addTab(embed_into_hbox_layout(list_view), "List") result.addTab(embed_into_hbox_layout(icon_mode_listview), "Icon Mode List") return result
def __init__(self, args: List[str]): """ At the moment the very, very long initialization of the main window, setting up everything. :param default_path: Use a user defined path as entrypoint. If it's empty, the home directory of the current user will be used. :type default_path: str """ super(tfm, self).__init__() self.setupUi(self) self.setWindowIcon(QIcon.fromTheme('system-file-manager')) self.clipboard = QApplication.clipboard() self.marked_to_cut = [] self.back_stack = stack() self.forward_stack = stack() self.config_dir = os.path.join( QStandardPaths.writableLocation( QStandardPaths().ConfigLocation), type(self).__name__) self.current_path = utility.handle_args(args) self.default_path = self.current_path self.threadpool = QThreadPool() # MAIN VIEW # # set up QFileSystemModel self.filesystem = QFileSystemModel() self.filesystem.setRootPath(self.current_path) self.filesystem.setReadOnly(False) # connect QFileSystemModel to View self.table_view.setModel(self.filesystem) self.table_view.setRootIndex( self.filesystem.index(self.current_path)) # set up header self.horizontal_header = self.table_view.horizontalHeader() self.horizontal_header.setSectionsMovable(True) # name self.horizontal_header.resizeSection(0, 200) # size self.horizontal_header.resizeSection(1, 100) # type self.horizontal_header.resizeSection(2, 100) # FS TREE # # create seperate FileSystemModel for the fs tree self.fs_tree_model = QFileSystemModel() self.fs_tree_model.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot) self.fs_tree_model.setRootPath(QDir.rootPath()) # connect model to view self.fs_tree.setModel(self.fs_tree_model) # hide unneeded columns for column in range(1, self.fs_tree.header().count()): self.fs_tree.hideColumn(column) # expand root item self.fs_tree.expand(self.fs_tree_model.index(0, 0)) # BOOKMARKS # self.bookmarks = bm(path_to_bookmark_file=os.path.join(self.config_dir, 'bookmarks')) self.bookmark_view.setModel(self.bookmarks) # MOUNTS # self.udev_context = Context() self.mounts = mounts_model(context=self.udev_context) self.mounts_view.setModel(self.mounts) udev_monitor = Monitor.from_netlink(self.udev_context) udev_monitor.filter_by(subsystem='block', device_type='partition') udev_observer = MonitorObserver(udev_monitor, self.devices_changed) udev_observer.start() # STATUSBAR # # TODO: dir info self.item_info = QLabel() # self.dir_info = QLabel() self.part_info = QLabel() self.statusbar.addPermanentWidget(self.item_info) # self.statusbar.addPermanentWidget(self.dir_info) self.statusbar.addPermanentWidget(self.part_info) self.part_info.setText(utility.part_info(self.current_path)) # TOOLBAR # # initially disable back/forward navigation self.action_back.setEnabled(False) self.action_forward.setEnabled(False) # main menu self.main_menu = QMenu() self.main_menu.addAction(self.action_show_hidden) self.menu_button = QToolButton() self.menu_button.setMenu(self.main_menu) self.menu_button.setPopupMode(QToolButton().InstantPopup) self.menu_button.setDefaultAction(self.action_menu) self.toolbar.insertWidget(self.action_back, self.menu_button) # adress bar self.adressbar = QLineEdit() self.adressbar.setText(self.current_path) self.toolbar.insertWidget(self.action_go, self.adressbar) # menu for new file or directory self.new_menu = QMenu() self.new_menu.addAction(self.action_new_dir) self.new_menu.addAction(self.action_new_file) self.new_button = QToolButton() self.new_button.setMenu(self.new_menu) self.new_button.setPopupMode(QToolButton().MenuButtonPopup) self.new_button.setDefaultAction(self.action_new_dir) self.toolbar.insertWidget(self.action_back, self.new_button) self.connect_actions_to_events() self.set_shortcuts() self.set_icons() self.set_context_menus()