Detecting cancellation of xbmcgui.Dialog().browse() ?
#1
Hey,

Im currently writing a file editor / text editor script and for each option in a select box of options, a choice of what action to perform. Thats fine.
Each option opens a browse dialog where the user can then select either a file or directory, depending on the action chosen.

The browse dialog is preselected to 
python:
xbmc.translatePath('special://home')
.
I want to allow creation, editing etc...  of files and directories in this immediate directory. But, if cancel is chosen, the pre-selected option is returned (the home path), that  tells me not to continue as a cancellation occurred.

So for the time, I cant allow this exact directory to be selected.

Is there a workaround that anyone knows of?
Thanks in advance.

In case you need to see my code: 
repo: https://github.com/nazarja/script.file.editor
An example is line number 52  in default.py:
Reply
#2
Try this.

python:
try:
     self.dir_path = dialog.browse(0, 'Select Location', 'files', '', False, False, home_path)
     if self.dir_path == "" or None:
          None
finally:
     if self.dir_path != home_path:
          kb = xbmc.Keyboard('', 'Enter New File Name And Extension')
Reply
#3
(2020-03-18, 12:22)M89SE Wrote: Try this.

python:
try:
     self.dir_path = dialog.browse(0, 'Select Location', 'files', '', False, False, home_path)
     if self.dir_path == "" or None:
          None
finally:
     if self.dir_path != home_path:
          kb = xbmc.Keyboard('', 'Enter New File Name And Extension')
Unfortunately, no luck there, the preselected path is always returned, regardless of whether ok or cancel is selected. Thanks though.
Reply
#4
(2020-03-18, 16:40)nazarja Wrote: Unfortunately, no luck there, the preselected path is always returned, regardless of whether ok or cancel is selected. Thanks though.

That is what the dialog is written to do, if cancel is selected.  From the documentation
Quote: If enableMultiple is False (default): returns filename and/or path as a string to the location of the highlighted item, if user pressed 'Ok' or a masked item was selected. Returns the default value if dialog was canceled.

See https://codedocs.xyz/xbmc/xbmc/group__py...d7620a6174
Learning Linux the hard way !!
Reply
#5
I'm not sure.

python:
def createNewFile(self):
     self.dir_path = dialog.browse(0, 'Select Location', 'files', '', False, False, home_path)
     home_path = ""
     if self.dir_path == "":
          kb = xbmc.Keyboard('', 'Enter New File Name And Extension')
Reply
#6
Thanks, but I dont think theres a way around this, The only solution I can think of is that if the root directory is detected as the choosen directory, to then show a select dialog with two choices.
I only need this for 2, maybe 3 different operations, all based around creating files, rather than deleting. When editing a file the root dir isnt chosen, so again, only needed for creating. 
Thanks for you response and help. Smile

Just in case, anyone else stumbles upon this, the only thing I could think was this, itll do for now.

python:

def createInRootOrCancel(self, action):
    option = dialog.select('Choose Option', ['Create {} In Root Directory'.format(action), 'Cancel Operation'])
    return True if option is 0 else False

#=====================#

def createNewFile(self):
    self.dir_path = dialog.browse(0, 'Select Location', '', 'files', False, False, home_path)
   
    if self.dir_path == home_path:
        if not self.createInRootOrCancel('File'): return

    kb = xbmc.Keyboard('', 'Enter New File Name And Extension')
    kb.doModal()
Reply

Logout Mark Read Team Forum Stats Members Help
Detecting cancellation of xbmcgui.Dialog().browse() ?0