Skip to content

Commit

Permalink
set destination to package path
Browse files Browse the repository at this point in the history
  • Loading branch information
OlafHaag committed Oct 22, 2019
1 parent 6cfe688 commit bd4edd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions custommipmapsexport/graphutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
from sd.api.sdvaluetexture import SDValueTexture


def find_package_of_graph(graph):
# Thanks to NevTD from substance3d forum.
pkg_manager = sd.getContext().getSDApplication().getPackageMgr()
for pkg in pkg_manager.getUserPackages():
if pkg.findResourceFromUrl(graph.getUrl()):
return pkg


def save_test():
""" This is a temporary function that's just a reminder. """
sdContext = sd.getContext()
Expand Down
16 changes: 12 additions & 4 deletions custommipmapsexport/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import sd

from .graphutils import find_package_of_graph

DEFAULT_ICON_SIZE = 24


Expand All @@ -18,17 +20,18 @@ def get_ui_manager():

class ExportDialog(QtCore.QObject):
""" Handles all the events in the ui. """
def __init__(self, ui_file, parent=None):
def __init__(self, ui_file, graphview_id, parent=None):
super(ExportDialog, self).__init__(parent)
ui_file = QtCore.QFile(ui_file)
ui_file.open(QtCore.QFile.ReadOnly)

loader = QtUiTools.QUiLoader()
self.window = loader.load(ui_file)
ui_file.close()

self.__graph = get_ui_manager().getGraphFromGraphViewID(graphview_id)

# State variables' defaults.
self.destination_path = str(Path.cwd()) # ToDo: Get package path from some graphutils func.
self.destination_path = str(Path(self.get_pkg_path()).parent)

# Get references to widgets.
self.dest_edit_tab1 = self.window.findChild(QtWidgets.QLineEdit, 'edit_dest_t1')
Expand Down Expand Up @@ -57,6 +60,11 @@ def __init__(self, ui_file, parent=None):
def show(self):
# Todo: populate tree view.
self.window.show()

def get_pkg_path(self):
pkg = find_package_of_graph(self.__graph)
path = pkg.getFilePath()
return path

def populate_combobox(self, box):
pass
Expand Down Expand Up @@ -140,7 +148,7 @@ def tooltip(self):

def load_ui(self, filename, parent=None):
""" Returns an instance of the exporter dialog. """
ui = ExportDialog(filename, parent)
ui = ExportDialog(filename, self.__graphViewID, parent)
return ui

@classmethod
Expand Down

0 comments on commit bd4edd9

Please sign in to comment.