Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion buttleofx/MainWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import QtQuick.LocalStorage 2.0
import "gui/graph/qml"
import "gui/viewer/qml"
import "gui/paramEditor/qml"
import "gui/browser_v2/qml"
import "gui/browser/qml"
import "gui/plugin/qml"
import "gui/shortcut/qml"
import "gui/dialogs"
Expand Down Expand Up @@ -880,6 +880,8 @@ ApplicationWindow {
onItemClicked: isSupported ? browser.fileWindow.onItemClickedSlot(pathImg) : 0
onItemDoubleClicked: isSupported ? browser.fileWindow.onItemDoubleClickedSlot(absolutePath) : 0
}

Component.onCompleted: browser.fileWindow.forceActiveFocus()
}

Item {
Expand Down
2 changes: 0 additions & 2 deletions buttleofx/gui/browser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# flake8: noqa
from .fileModelBrowser import FileModelBrowser
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def __init__(self, browserItem):
self._browserItem = browserItem

# required for abort processing
self._abortFlag = False # if action have been aborted
self._progress = 0.0 # progression of action between 0 and 1,will be used with Tuttle process in execute
self._abortFlag = False # if action has been aborted
self._progress = 0.0 # progression of action between 0 and 1 will be used with Tuttle process in execute
self._failed = False

def __del__(self):
logging.debug("Action destroyed")
pass

def begin(self):
if self._browserItem:
Expand All @@ -34,11 +34,12 @@ def abort(self):
"""
Process revert() if action processed
"""
if self._browserItem:
self._abortFlag = True
if self.isProcessed():
self.revert()
self._browserItem.notifyRemoveAction()
if not self._browserItem or self._failed:
return

self._abortFlag = True
if self.isProcessed():
self.revert()

def execute(self):
raise NotImplementedError("ActionInterface::execute() must be implemented")
Expand All @@ -49,10 +50,17 @@ def revert(self):
def process(self):
if self._abortFlag:
return

self.begin()
self.execute()

try:
self.execute()
except Exception as e:
print(str(e))
self._failed = True

self.end()
self._progress = 1
self._progress = 0 if self._failed else 1
self.progressChanged.emit()

def getBrowserItem(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from quickmamba.models import QObjectListModel

from buttleofx.gui.browser_v2.actions.actionWorker import ActionWorker
from buttleofx.gui.browser.actions.actionWorker import ActionWorker


class ActionManager(QtCore.QObject):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class ActionWrapper(QtCore.QObject):
"""
Expose useful data for qml such as nbActions and progression
"""
# signals for qml
nbProcessedChanged = QtCore.pyqtSignal()
abortNotified = QtCore.pyqtSignal()
progressChanged = QtCore.pyqtSignal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

from pySequenceParser import sequenceParser

from buttleofx.gui.browser_v2.actions.actionManager import globalActionManager
from buttleofx.gui.browser_v2.actions.actionWrapper import ActionWrapper
from buttleofx.gui.browser_v2.browserItem import BrowserItem
from buttleofx.gui.browser_v2.actions.concreteActions.copy import Copy
from buttleofx.gui.browser_v2.actions.concreteActions.move import Move
from buttleofx.gui.browser_v2.actions.concreteActions.create import Create
from buttleofx.gui.browser_v2.actions.concreteActions.delete import Delete
from buttleofx.gui.browser_v2.browserModel import globalBrowserDialog, globalBrowser
from buttleofx.gui.browser.actions.actionManager import globalActionManager
from buttleofx.gui.browser.actions.actionWrapper import ActionWrapper
from buttleofx.gui.browser.browserItem import BrowserItem
from buttleofx.gui.browser.actions.concreteActions.copy import Copy
from buttleofx.gui.browser.actions.concreteActions.move import Move
from buttleofx.gui.browser.actions.concreteActions.create import Create
from buttleofx.gui.browser.actions.concreteActions.delete import Delete


class BrowserAction(QtCore.QObject):
Expand Down Expand Up @@ -40,11 +39,14 @@ def getCache(self):

@QtCore.pyqtSlot(QtCore.QObject)
def pushToActionManager(self, actionWrapper=None):
"""
Will process the action automatically by pushing to actionManager
"""
if actionWrapper:
globalActionManager.push(actionWrapper)
else:
if self._cacheActions:
globalActionManager.push(self._cacheActions)
return
if self._cacheActions:
globalActionManager.push(self._cacheActions)

@QtCore.pyqtSlot()
def handleCopy(self):
Expand Down Expand Up @@ -75,6 +77,8 @@ def handlePaste(self, destination):
for action in self._cacheActions.getActions():
action.setDestinationPath(destination)
self.pushToActionManager()
self._cacheActions = None
self.cacheChanged.emit()

@QtCore.pyqtSlot()
def handleDelete(self):
Expand All @@ -96,8 +100,4 @@ def handleNew(self, typeItem):
self.pushToActionManager(ActionWrapper([Create(parent, new)]))

# cache empty ?
isCache = QtCore.pyqtProperty(bool, isEmptyCache, notify=cacheChanged)


globalBrowserAction = BrowserAction(globalBrowser)
globalBrowserActionDialog = BrowserAction(globalBrowserDialog)
isCache = QtCore.pyqtProperty(bool, isEmptyCache, notify=cacheChanged)
65 changes: 65 additions & 0 deletions buttleofx/gui/browser/actions/concreteActions/copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
import shutil
import os.path as op

from buttleofx.gui.browser.actions.actionInterface import ActionInterface


class Copy(ActionInterface):

def __init__(self, browserItem):
ActionInterface.__init__(self, browserItem)
self._srcPath = browserItem.getParentPath()
self._destPath = ''
self._framesPaths = [] # files sequences path copied
self._successCopy = True

def setDestinationPath(self, newPath):
if not op.isdir(newPath):
raise TypeError
self._destPath = newPath.strip()

def execute(self):
browserItem = self._browserItem
destPath = self._destPath

# avoid recurse copy
if not op.exists(destPath) or browserItem.getPath() in destPath:
self._failed = True
print('%s already in %s: fail to copy' % (destPath, browserItem.getPath()))
return

if browserItem.isFile():
shutil.copy2(browserItem.getPath(), destPath)

elif browserItem.isFolder():
shutil.copytree(browserItem.getPath(), op.join(destPath, browserItem.getName()))

elif browserItem.isSequence():
seqParsed = browserItem.getSequence().getSequenceParsed()
frames = seqParsed.getFramesIterable()

for f in frames:
filename = seqParsed.getFilenameAt(f)
filePath = op.join(browserItem.getParentPath(), filename)
try:
shutil.copy2(filePath, destPath)
self._framesPaths.append(op.join(destPath, filename))
except Exception as e:
print(str(e))
pass

def revert(self):
browserItem = self.getBrowserItem()
copiedPath = op.join(self._destPath, browserItem.getName())

if browserItem.isFile() and op.exists(copiedPath):
os.remove(copiedPath)

if browserItem.isFolder() and op.exists(copiedPath):
shutil.rmtree(copiedPath)

if browserItem.isSequence():
for f in self._framesPaths:
if op.exists(f):
os.remove(f)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shutil
import logging

from buttleofx.gui.browser_v2.actions.actionInterface import ActionInterface
from buttleofx.gui.browser.actions.actionInterface import ActionInterface


class Create(ActionInterface):
Expand All @@ -17,7 +17,7 @@ def __init__(self, parentBrowserItem, newBrowserItem):

def execute(self):
# TODO: Check parent's permission in try catch

# TODO: find elegant way to find next: sort, find next if match then extract version number
parent = self.getBrowserItem()
newBrowserItem = self._newBrowserItem
parentPath = parent.getPath()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shutil
import tempfile
from buttleofx.gui.browser_v2.actions.actionInterface import ActionInterface
from buttleofx.gui.browser.actions.actionInterface import ActionInterface


class Delete(ActionInterface):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
import os
import shutil
import os.path as op

from buttleofx.gui.browser_v2.actions.actionInterface import ActionInterface
from buttleofx.gui.browser.actions.actionInterface import ActionInterface


class Move(ActionInterface):

def __init__(self, browserItem):
# destination must be a directory
# if not destination.isFolder():
# raise TypeError
ActionInterface.__init__(self, browserItem)
self._srcPath = browserItem.getParentPath()
self._destPath = ""
self._destPath = ''

def setDestinationPath(self, newPath):
if not op.isdir(newPath):
raise TypeError
self._destPath = newPath.strip()

def execute(self):
browserItem = self._browserItem
destinationPath = self._destPath
copyPath = op.join(destinationPath, browserItem.getName())

if browserItem.getPath() in destinationPath or op.exists(copyPath):
self._failed = True
return

# Move file, folder, and sequence
# TODO: Check destination permission in try catch
if browserItem.isFile() or browserItem.isFolder():
if os.path.exists(destinationPath):
if op.exists(destinationPath):
shutil.move(browserItem.getPath(), destinationPath)

def revert(self):
browserItem = self._browserItem
srcPath = self._srcPath
destPath = self._destPath
destItemPath = os.path.join(destPath, browserItem.getName())
destItemPath = op.join(destPath, browserItem.getName())

if op.exists(op.join(srcPath, op.basename(destItemPath))):
self._failed = True
return

if browserItem.isFile() or browserItem.isFolder():
if os.path.exists(srcPath):
if op.exists(srcPath):
shutil.move(destItemPath, srcPath)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from buttleofx.gui.browser_v2.actions.actionInterface import ActionInterface
from buttleofx.gui.browser.actions.actionInterface import ActionInterface


class Rename(ActionInterface):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# How to run test

$PYTHONHOME/bin/python -m unittest discover -v $BUTTLE_TOP_DIR/ButtleOFX/buttleofx/gui/browser_v2/actions/testConcreteActions
$PYTHONHOME/bin/python -m unittest discover -v $BUTTLE_TOP_DIR/ButtleOFX/buttleofx/gui/browser/actions/testConcreteActions
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

# from OpenGL import GL

from buttleofx.gui.browser_v2.browserItem import BrowserItem
from buttleofx.gui.browser_v2.actions.concreteActions.copy import Copy
from buttleofx.gui.browser.browserItem import BrowserItem
from buttleofx.gui.browser.actions.concreteActions.copy import Copy
from pySequenceParser import sequenceParser
import buttleofx.gui.browser_v2.actions.testConcreteActions.helper as h
import buttleofx.gui.browser.actions.testConcreteActions.helper as h


class TestCopy(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import tempfile
import os

from buttleofx.gui.browser_v2.browserItem import BrowserItem
from buttleofx.gui.browser_v2.actions.concreteActions.create import Create
from buttleofx.gui.browser.browserItem import BrowserItem
from buttleofx.gui.browser.actions.concreteActions.create import Create
from pySequenceParser import sequenceParser


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

# from OpenGL import GL

from buttleofx.gui.browser_v2.browserItem import BrowserItem
from buttleofx.gui.browser_v2.actions.concreteActions.delete import Delete
from buttleofx.gui.browser.browserItem import BrowserItem
from buttleofx.gui.browser.actions.concreteActions.delete import Delete
from pySequenceParser import sequenceParser
import buttleofx.gui.browser_v2.actions.testConcreteActions.helper as h
import buttleofx.gui.browser.actions.testConcreteActions.helper as h


class TestDelete(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

# from OpenGL import GL

from buttleofx.gui.browser_v2.browserItem import BrowserItem
from buttleofx.gui.browser_v2.actions.concreteActions.move import Move
from buttleofx.gui.browser.browserItem import BrowserItem
from buttleofx.gui.browser.actions.concreteActions.move import Move
from pySequenceParser import sequenceParser


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

# from OpenGL import GL

from buttleofx.gui.browser_v2.browserItem import BrowserItem
from buttleofx.gui.browser_v2.actions.concreteActions.rename import Rename
from buttleofx.gui.browser.browserItem import BrowserItem
from buttleofx.gui.browser.actions.concreteActions.rename import Rename
from pySequenceParser import sequenceParser
import buttleofx.gui.browser_v2.actions.testConcreteActions.helper as h
import buttleofx.gui.browser.actions.testConcreteActions.helper as h

class TestRename(unittest.TestCase):

Expand Down
Loading