Skip to content

Commit 95f15c4

Browse files
SpudmnAaron Keith
andauthored
Added the ability to show an image with user.prompt. … (#905)
* Added the ability to show an image with user.prompt. … e.g. “user.prompt('Image example',text_input=False,image_url = "http://localhost:5555/lights.jpg") user.prompt now has the optional parameter image_url. At the moment the image must be served from a web server. I don’t know how to get Angular to display images from a file system. The workaround is to use python SimpleHTTPServer to serve a folder of images “e.g. python -m SimpleHTTPServer 5555” * Removed the show-image parameter Co-authored-by: Aaron Keith <[email protected]>
1 parent faac61a commit 95f15c4

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

openhtf/output/web_gui/src/app/plugs/user-input-plug.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
</div>
1111

1212
<div class="htf-layout-widget-body">
13+
14+
<img *ngIf="hasImage()" [src]="Image_URL" >
1315

1416
<div [innerHTML]="prompt"></div>
1517

openhtf/output/web_gui/src/app/plugs/user-input-plug.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export declare interface UserInputPlugState {
2222
id: string;
2323
message: string;
2424
'text-input': string;
25+
'image-url': string;
2526
}
2627

2728
@Component({
@@ -65,6 +66,14 @@ export class UserInputPlugComponent extends BasePlug {
6566
return this.getPlugState()['text-input'];
6667
}
6768

69+
hasImage() {
70+
return this.getPlugState()['image-url'];
71+
}
72+
73+
get Image_URL() {
74+
return this.getPlugState()['image-url'];
75+
}
76+
6877
sendResponse(input: HTMLInputElement) {
6978
const promptId = this.getPlugState().id;
7079
let response: string;

openhtf/plugs/user_input.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class PromptUnansweredError(Exception):
5656
"""Raised when a prompt times out or otherwise comes back unanswered."""
5757

5858

59-
Prompt = collections.namedtuple('Prompt', 'id message text_input')
59+
Prompt = collections.namedtuple('Prompt', 'id message text_input image_url')
6060

6161

6262
class ConsolePrompt(threading.Thread):
@@ -152,7 +152,8 @@ def _asdict(self):
152152
return
153153
return {'id': self._prompt.id,
154154
'message': self._prompt.message,
155-
'text-input': self._prompt.text_input}
155+
'text-input': self._prompt.text_input,
156+
'image-url': self._prompt.image_url}
156157

157158
def tearDown(self):
158159
self.remove_prompt()
@@ -166,7 +167,7 @@ def remove_prompt(self):
166167
self._console_prompt = None
167168
self.notify_update()
168169

169-
def prompt(self, message, text_input=False, timeout_s=None, cli_color=''):
170+
def prompt(self, message, text_input=False, timeout_s=None, cli_color='', image_url = None):
170171
"""Display a prompt and wait for a response.
171172
172173
Args:
@@ -182,10 +183,10 @@ def prompt(self, message, text_input=False, timeout_s=None, cli_color=''):
182183
MultiplePromptsError: There was already an existing prompt.
183184
PromptUnansweredError: Timed out waiting for the user to respond.
184185
"""
185-
self.start_prompt(message, text_input, cli_color)
186+
self.start_prompt(message, text_input, cli_color, image_url)
186187
return self.wait_for_prompt(timeout_s)
187188

188-
def start_prompt(self, message, text_input=False, cli_color=''):
189+
def start_prompt(self, message, text_input=False, cli_color='', image_url = None):
189190
"""Display a prompt.
190191
191192
Args:
@@ -208,7 +209,7 @@ def start_prompt(self, message, text_input=False, cli_color=''):
208209

209210
self._response = None
210211
self._prompt = Prompt(
211-
id=prompt_id, message=message, text_input=text_input)
212+
id=prompt_id, message=message, text_input=text_input, image_url=image_url)
212213
if sys.stdin.isatty():
213214
self._console_prompt = ConsolePrompt(
214215
message, functools.partial(self.respond, prompt_id), cli_color)

0 commit comments

Comments
 (0)