def test_copy_directory(fake_filesystem): model = FileModel() dir_a_index = model.pathIndex(fake_filesystem.join("dir A")) # Copy directory model._copy_file(fake_filesystem.join("dir B"), dir_a_index) assert fake_filesystem.join("dir A", "dir B", "file d").exists() assert fake_filesystem.join("dir B", "file d").exists()
def test_copy_file(fake_filesystem): model = FileModel() dir_b_index = model.pathIndex(fake_filesystem.join("dir B")) # Copy file model._copy_file(fake_filesystem.join("dir A", "file a"), dir_b_index) assert fake_filesystem.join("dir A", "file a").exists() assert fake_filesystem.join("dir B", "file a").exists()
def __init__(self, path, parent=None): super().__init__(parent) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowTitle(_("Universal File Organiser")) self.setWindowIcon(QtGui.QIcon.fromTheme('system-file-manager')) self.model = FileModel() self.pane = FilePane(self.model, path, self) self._create_actions() self._create_menus() self.setCentralWidget(self.pane)
def test_create_new_directory(tmpdir): model = FileModel() for i, dirname in enumerate( ('New Folder', 'New Folder (1)', 'New Folder (2)')): index = model.create_new_directory(tmpdir) assert tmpdir.join(dirname).isdir( ) # The directory effectively was created on the filesystem assert index.isValid() # The returned index is a valid index assert index.data(QtCore.Qt.UserRole) == tmpdir.join( dirname) # The path returned by the index is ok assert model.rowCount( index.parent() ) == i + 1 # The number of directory in the parent directory is as expected assert index.row() == i # The row number is the ith element we created
def test_delete_files(fake_filesystem): model = FileModel() dir_a_index = model.pathIndex(fake_filesystem.join("dir A")) dir_b_index = model.pathIndex(fake_filesystem.join("dir B")) file_a = model.pathIndex(fake_filesystem.join("dir A", "file a")) file_b = model.pathIndex(fake_filesystem.join("dir A", "file b")) # Delete one file model.delete_files([file_a]) assert not fake_filesystem.join("dir A", "file a").exists() assert model.rowCount(dir_a_index) == 2 # Delete one dir and one file model.delete_files([dir_b_index, file_b]) assert not fake_filesystem.join("dir B").exists() assert model.rowCount(dir_a_index) == 1
def test_rename_file(fake_filesystem): model = FileModel() file_a_index = model.pathIndex(fake_filesystem.join("dir A", "file a")) model.setData(file_a_index, "file e") assert model.rowCount(file_a_index.parent()) == 3 assert not fake_filesystem.join("dir A", "file a").exists() assert fake_filesystem.join("dir A", "file e").exists() assert model.data(file_a_index, QtCore.Qt.UserRole) == fake_filesystem.join( "dir A", "file e")
def test_move_file(fake_filesystem): model = FileModel() dir_a_index = model.pathIndex(fake_filesystem.join("dir A")) dir_b_index = model.pathIndex(fake_filesystem.join("dir B")) model._move_file(fake_filesystem.join("dir A", "file a"), dir_b_index) # Ensure the file moved on the filesystem assert not fake_filesystem.join("dir A", "file a").exists() assert fake_filesystem.join("dir B", "file a").exists() # Ensure the model was updated accordingly assert model.rowCount(dir_a_index) == 2 assert model.rowCount(dir_b_index) == 2
def pane_fixture(qtbot, fake_filesystem): model = FileModel() pane = FilePane(model, str(fake_filesystem)) qtbot.addWidget(pane) return pane
class MainWindow(QtWidgets.QMainWindow): def __init__(self, path, parent=None): super().__init__(parent) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowTitle(_("Universal File Organiser")) self.setWindowIcon(QtGui.QIcon.fromTheme('system-file-manager')) self.model = FileModel() self.pane = FilePane(self.model, path, self) self._create_actions() self._create_menus() self.setCentralWidget(self.pane) def _create_actions(self): self.action_new = QtWidgets.QAction(_("New Window"), self) self.action_new.setShortcuts(shortcuts.new_window) self.action_new.triggered.connect(self.on_action_new) self.action_close = QtWidgets.QAction(_("Close Window"), self) self.action_close.setShortcuts(shortcuts.close_window) self.action_close.triggered.connect(self.close) self.action_new_folder = QtWidgets.QAction(_("New Folder"), self) self.action_new_folder.setShortcuts(shortcuts.new_folder) self.action_new_folder.triggered.connect(self.create_new_directory) def _create_menus(self): app_menu = self.menuBar().addMenu(_("Ufo")) app_menu.addAction(self.action_new) # new tab app_menu.addAction(self.action_close) file_menu = self.menuBar().addMenu(_("File")) file_menu.addAction(self.action_new_folder) # new file # new... # cut / copy / paste file_menu.addAction(self.pane.view.action_delete) # select all / none go_menu = self.menuBar().addMenu(_("Go")) # TODO: open go_menu.addAction(self.pane.path_view.back_action) go_menu.addAction(self.pane.path_view.forth_action) go_menu.addAction(self.pane.path_view.up_action) go_menu.addAction(self.pane.path_view.home_action) ## View view_menu = self.menuBar().addMenu(_("View")) view_menu.addAction(self.pane.view.action_hidden) # Directory tree # File preview # Split / unsplit ## Help # About # Help # Whats this def on_action_new(self): args = [sys.argv[0], self.pane.current_directory] subprocess.Popen(args) def create_new_directory(self): index = self.model.create_new_directory(self.pane.current_directory) self.pane.view.proxy.invalidate() pindex = self.pane.view.proxy.mapFromSource(index) self.pane.view.setCurrentIndex(pindex) # TODO: why doesn't it work?