Skip to content

Commit

Permalink
set default path for 'Filename' parameter in Script Converter and 'Pl…
Browse files Browse the repository at this point in the history
…ugin Directory' in Script Converter and Prototype Converter (see #31 and #21)
  • Loading branch information
NiklasRosenstein committed Feb 24, 2018
1 parent e06196a commit d6fec89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions c4d_prototype_converter/c4dutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,21 @@ def __FileSelectorCallback(self, widget, event):
'save': c4d.FILESELECT_SAVE,
'directory': c4d.FILESELECT_DIRECTORY
}[widget['fileselecttype']]
path = c4d.storage.LoadDialog(flags=flags)
path = c4d.storage.LoadDialog(flags=flags, def_path=widget['def_path'])
if path:
self.SetString(widget['id.string'], path)
self.SendCommand(widget['id.string'])
return True

def AddFileSelector(self, param_id, flags, type='load'):
def AddFileSelector(self, param_id, flags, type='load', def_path=None):
if type not in ('load', 'save', 'directory'):
raise ValueError('invalid type: {!r}'.format(type))
widget = {
'type': 'fileselector',
'id.string': self.AllocId(),
'id.button': self.AllocId(),
'callback': self.__FileSelectorCallback,
'def_path': def_path,
'fileselecttype': type
}
self.__widgets[param_id] = widget
Expand Down
14 changes: 10 additions & 4 deletions c4d_prototype_converter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@ def do_create(self):
# c4d.gui.GeDialog

def CreateLayout(self):
plugins_dir = os.path.join(c4d.storage.GeGetC4DPath(c4d.C4D_PATH_LIBRARY_USER), 'plugins')
self.SetTitle('Prototype Converter')
self.GroupBorderSpace(6, 6, 6, 6)
self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_TOP, 0, 1) # MAIN {
Expand Down Expand Up @@ -1053,7 +1054,8 @@ def CreateLayout(self):
self.AddStaticText(0, c4d.BFH_LEFT, name='Icon')
self.AddFileSelector(self.ID_ICON_FILE, c4d.BFH_SCALEFIT, type='load')
self.AddStaticText(self.ID_DIRECTORY_TEXT, c4d.BFH_LEFT, name='Plugin Directory')
self.AddFileSelector(self.ID_DIRECTORY, c4d.BFH_SCALEFIT, type='directory')
self.AddFileSelector(self.ID_DIRECTORY, c4d.BFH_SCALEFIT, type='directory',
def_path=plugins_dir)
self.GroupEnd() # } MAIN/LEFT/PARAMS/EXPORTSETTINGS

self.GroupEnd() # } MAIN/LEFT/PARAMS
Expand Down Expand Up @@ -1309,8 +1311,10 @@ def do_create(self):
c4d.storage.ShowInFinder(cnv.files()['directory'])

def CreateLayout(self):
scripts_dir = os.path.join(c4d.storage.GeGetC4DPath(c4d.C4D_PATH_LIBRARY_USER), 'scripts')
plugins_dir = os.path.join(c4d.storage.GeGetC4DPath(c4d.C4D_PATH_LIBRARY_USER), 'plugins')
self.script_filenames = self.get_library_scripts()
self.SetTitle('Script to Command Plugin Converter')
self.SetTitle('Script Converter')
self.GroupBorderSpace(6, 6, 6, 6)
self.GroupBegin(self.ID_GROUP_MAIN, c4d.BFH_SCALEFIT, 1, 0) # MAIN {

Expand All @@ -1330,11 +1334,13 @@ def CreateLayout(self):
for i, (fn, name, _) in enumerate(self.script_filenames, 1):
self.AddChild(self.ID_SCRIPT_COMBOBOX, i, name)
self.AddStaticText(self.ID_SCRIPT_FILE_TEXT, c4d.BFH_LEFT, name='Filename *')
self.AddFileSelector(self.ID_SCRIPT_FILE, c4d.BFH_SCALEFIT, type='load')
self.AddFileSelector(self.ID_SCRIPT_FILE, c4d.BFH_SCALEFIT, type='load',
def_path=scripts_dir)
self.AddStaticText(0, c4d.BFH_LEFT, name='Icon')
self.AddFileSelector(self.ID_ICON_FILE, c4d.BFH_SCALEFIT, type='load')
self.AddStaticText(0, c4d.BFH_LEFT, name='Plugin Directory')
self.AddFileSelector(self.ID_DIRECTORY, c4d.BFH_SCALEFIT, type='directory')
self.AddFileSelector(self.ID_DIRECTORY, c4d.BFH_SCALEFIT, type='directory',
def_path=plugins_dir)
self.GroupEnd()
self.GroupEnd() # } MAIN/PARAMS

Expand Down

0 comments on commit d6fec89

Please sign in to comment.