ui.inputBox request

I’ve found for simple confirmation dialogs, a quick call to ui.messageBox makes injecting a check super easy. It would be nice if there were a similar simple built-in pop dialog that could return a string submission from a user.

I’m aware of the popDialog in TDResources/palette, and with enough fanagling with the callbacks I can kind of get what I want from it, but its nowhere near as simple as something like:

ui.inputBox(title, message, defaultText='', buttons=['Ok', 'Cancel'])→ str:

and I would argue that its the kind of thing that warrants a clean generic built-in method. Anybody else think something like that would be useful?

I can make popDialog easier if you have specific requests. I think this is not a high priority for the C++ team.

I’ve found popDialog to be easier to use if you use a wrapper like this:

def showPromptDialog(
		title=None,
		text=None,
		default='',
		textEntry=True,
		okText='OK',
		cancelText='Cancel',
		ok: Callable = None,
		cancel: Callable = None,
):
	def _callback(info: dict):
		if info['buttonNum'] == 1:
			if ok:
				if not textEntry:
					ok()
				else:
					ok(info.get('enteredText'))
		elif info['buttonNum'] == 2:
			if cancel:
				cancel()
	dialog = op.TDResources.op('popDialog')  # type: PopDialogExt
	dialog.Open(
		title=title,
		text=text,
		textEntry=False if not textEntry else (default or ''),
		buttons=[okText, cancelText],
		enterButton=1, escButton=2, escOnClickAway=True,
		callback=_callback)

Then you can use it like this:

def tryToDoTheThing():
	def _actuallyDoTheThing(text):
	   pass

	showPromptDialog(
				title='Title text',
				text='Description...',
				default='some default text',
				textEntry=True,
				ok=_actuallyDoTheThing,
			)

The challenge there is the async nature of it. The system doesn’t stall while waiting for input, so instead of returning a value, you pass in a callback that gets invoked once the input is ready.

the async thing has been my main issue. I’m imagining a scenario where this dialog is the exception in a for loop, and will wait on user input before continuing with the rest of the process. Maybe an async toggle that could interrupt the process would be feasible for the current popDialog.

I’m working with widget buttons not dissimilar to the ones in the palette, and would like to use a one liner onClick run script that functions how I’m already using ui.messageBox, bypassing the need for more extraneous operators and functions

The popDialog is also limited to four buttons, and while that should be sufficient for most needs, it doesn’t scale well if I would like more options. I suppose in that case what would actually be better is an optional drop down menu instead of buttons populated by kwargs for label : value. To this end, the popDialog tox could have width/height/auto scale arguments to accommodate dynamically populated menus.

Obviously these aren’t super high priority rfe’s, and it would be simple enough to fork and modify the existing popDialog if I really needed any of these features, but since the template already exists in ui.messageBox with the functionality I’m looking for, i figured a string input ui class dialog might be worth bringing up