Skip to content

Commit

Permalink
Merge pull request getavalon#2 from aardschok/PLN-0017
Browse files Browse the repository at this point in the history
Implemented `open explorer here`
  • Loading branch information
aardschok authored Nov 10, 2017
2 parents bedddea + a9a05aa commit d3f8761
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
40 changes: 29 additions & 11 deletions launcher/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,6 @@ def launch(self, name):
# TODO(marcus): These shouldn't be necessary
# once the templates are used.
# ----------------------------------------------------------------------
template_rootpath = template_private.split("{silo}")[0]
template_assetpath = template_private.split("{asset}")[0] + "{asset}"
template_taskpath = template_private.split("{task}")[0] + "{task}"

silospath = template_rootpath.format(**frame["environment"])
assetpath = template_assetpath.format(**frame["environment"])
taskpath = template_taskpath.format(**frame["environment"])

frame["environment"]["silospath"] = silospath
frame["environment"]["assetpath"] = assetpath
frame["environment"]["taskpath"] = taskpath
frame["environment"]["workdir"] = workdir
# ----------------------------------------------------------------------

Expand Down Expand Up @@ -314,6 +303,35 @@ def run(self):

return process

@Slot()
def launch_explorer(self):
"""Initial draft of this method is subject to change and might
migrate to another module"""
# Todo: find a cleaner way, with .toml file for example

print("Openiing Explorer")

# Get the current environment
frame = self.current_frame()
frame["environment"]["root"] = self._root

# When we are outside of any project, do nothing
config = frame.get("config", None)
if config is None:
print("No project found in configuration")
return

template = config['template']['work']
path = lib.partial_format(template, frame["environment"])

# Keep only the part of the path that was formatted
path = os.path.normpath(path.split("{", 1)[0])

print(path)
if os.path.exists(path):
import subprocess
subprocess.Popen(r'explorer "{}"'.format(path))

def current_frame(self):
"""Shorthand for the current frame"""
try:
Expand Down
14 changes: 14 additions & 0 deletions launcher/lib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import subprocess
import string

from avalon.vendor import six
from PyQt5 import QtCore
Expand All @@ -10,6 +11,11 @@
self._current_task = None


class FormatDict(dict):
def __missing__(self, key):
return "{" + key + "}"


def resource(*path):
path = os.path.join(self._path, "res", *path)
return path.replace("\\", "/")
Expand Down Expand Up @@ -186,3 +192,11 @@ def launch(executable, args=None, environment=None, cwd=None):
def stream(stream):
for line in iter(stream.readline, ""):
yield line


def partial_format(s, mapping):

formatter = string.Formatter()
mapping = FormatDict(**mapping)

return formatter.vformat(s, (), mapping)
2 changes: 1 addition & 1 deletion launcher/res/qml/Breadcrumbs.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Item {
ToolButton {
contentItem: AwesomeIcon {
name: "home"
size: 12
size: 18
}

height: parent.height
Expand Down
15 changes: 15 additions & 0 deletions launcher/res/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ ApplicationWindow {
model: controller.breadcrumbs
}

/** Open explorer in set context based on template
*/
MyButton {

id: launchExplorerButton
implicitWidth: parent.height
implicitHeight: parent.height
icon: "folder-open"
Layout.alignment: Qt.AlignLeft

onClicked: controller.launch_explorer()

opacity: 0.4
}

/** Toggle Terminal on/off
*/
MyButton {
Expand Down

0 comments on commit d3f8761

Please sign in to comment.