Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add text read (prompt/input) block #24

Closed
GoogleCodeExporter opened this issue Dec 14, 2015 · 3 comments
Closed

Add text read (prompt/input) block #24

GoogleCodeExporter opened this issue Dec 14, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

Need user input for interactive programing.

I implement javascript & python version of prompt(input) block.

demo: http://www.gasolin.idv.tw/public/blockly/demos/code/index.html

in language/en/text.js

Blockly.Language.text_prompt = {
  // Prompt statement.
  category: 'Text',
  helpUrl: 'http://www.liv.ac.uk/HPC/HTMLF90Course/HTMLF90CourseNotesnode92.html',
  init: function() {
    this.setColour(160);
    this.addTitle('prompt');
    this.appendInput('', Blockly.INPUT_VALUE, 'TEXT');
    this.setOutput(true);
    this.setTooltip('Prompt for user input with the specified text.');
  }
};

in generator/python/text.js

Blockly.Python.text_prompt = function() {
  // prompt a user input dialog.
  var argument0 = Blockly.JavaScript.valueToCode(this, 'TEXT', true) || '\'\'';
  return 'raw_input(' + argument0 + ');\n';
};

in generator/javascript/text.js

Blockly.JavaScript.text_prompt = function() {
  // prompt a user input dialog.
  var argument0 = Blockly.JavaScript.valueToCode(this, 'TEXT', true) || '\'\'';
  return 'prompt(' + argument0 + ');\n';
};

in dart..

no idea, may be 
http://stackoverflow.com/questions/10257744/is-it-possible-to-read-from-console-
in-dart

Original issue reported on code.google.com by gasolin on 10 Jun 2012 at 5:47

@GoogleCodeExporter
Copy link
Author

update with type conversion.

language:

Blockly.Language.text_prompt = {
  // Prompt statement.
  category: 'Text',
  helpUrl: 'http://www.liv.ac.uk/HPC/HTMLF90Course/HTMLF90CourseNotesnode92.html',
  init: function() {
    this.setColour(160);
    this.appendTitle('read');
    var menu = new Blockly.FieldDropdown(this.OPERATORS);
    this.appendTitle(menu, 'TYPE');
    this.appendInput('', Blockly.INPUT_VALUE, 'TEXT');
    this.setOutput(true);
    this.setTooltip('Prompt for user input with the specified text.');
  }
};

Blockly.Language.text_prompt.OPERATORS =
    [['string', 'STRING'], ['integer', 'INTEGER']];


python generator:

Blockly.Python.text_prompt = function() {
  // prompt a user input dialog.
  var mode = this.getTitleValue('TYPE');
  console.log(mode);
  var operator = Blockly.Python.text_prompt.OPERATORS[mode];
  var argument0 = Blockly.Python.valueToCode(this, 'TEXT', true) || '\'\'';
  return operator+'(raw_input(' + argument0 + '));\n';
};

Blockly.Python.text_prompt.OPERATORS = {
  STRING: 'str',
  INTEGER: 'int'
};

Original comment by gasolin on 16 Jun 2012 at 8:02

@GoogleCodeExporter
Copy link
Author

Issue 29 has been merged into this issue.

Original comment by gasolin on 16 Jun 2012 at 8:06

@GoogleCodeExporter
Copy link
Author

Done in r260 and r261.

Modal I/O is a terrible UI experience.  As such, Print and Prompt should be 
treated as emergency functions.  Any real environment would have much better 
I/O APIs.  But they are still very useful for debugging and "Hello World" 
applications.

Since this is an emergency debugging function, I've converted the prompt 
message input into an inline field.  This is simpler and sufficient most of the 
time.  If one really wants a dynamically customizable message field, then one 
should probably be using a better API.

Type conversion functions are also something we need, but I've folded them into 
this block, again for convenience.

The use of window.prompt in Dart is questionable.  It will only work in a 
browser, not in the command-line version.  Likewise there's a complicated 
asynchronous readLine version that only works in the command-line version and 
not the browser.

Original comment by neil.fra...@gmail.com on 19 Jun 2012 at 1:01

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant