* Request for help Qt, C++ and guile REPL.
@ 2013-06-20 16:04 Eduardo Acuña
2013-06-20 17:46 ` Panicz Maciej Godek
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eduardo Acuña @ 2013-06-20 16:04 UTC (permalink / raw)
To: guile-user
[-- Attachment #1: Type: text/plain, Size: 2522 bytes --]
Hello!
I have found the archives of this mailing list very helpful in the
development of a piece of software i'm writing. And i have a few questions
about the integration between guile, c++ and the library Qt.
The program in question is a little gui repl, where the user can type guile
code in a 'QLineEdit' widget and the evaluation gets printed in a
'QTextBrowser' widget.
I have done this in a very basic way. But the problem is that if the user
types:
(begin (display "hello")(sleep 2))
the result gets printed after the 2 seconds. What can i do to get the gui
repl more like que standard guile repl?
Thank you in advance.
Eduardo Acuña Yeomans.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
the class declaration is this:
class GUIrepl : public QDialog
{
Q_OBJECT
QTextBrowser *output_text_browser;
QLineEdit *input_line_edit;
QPushButton *evaluate_btn;
SCM my_output_port;
public:
explicit GUIrepl(QWidget *parent = 0);
~GUIrepl();
private slots:
void evaluate_expression();
};
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
the function that handles the evaluation is this:
void GUIrepl::evaluate_expression()
{
QString input;
SCM result_obj;
SCM result_str;
QString to_print;
input = this->input_line_edit->text();
result_obj = scm_c_eval_string(input.toStdString().data());
result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
to_print = scm_to_locale_string(result_str);
SCM out = scm_get_output_string(this->my_output_port);
QString out_str = scm_to_locale_string(out);
input = "> "+input;
this->output_text_browser->append(input);
if(out_str != "")
this->pantalla->append(out_str);
if(to_print != "#<unspecified>")
this->output_text_browser->append(to_print);
this->input_line_edit->setText("");
scm_truncate_file(this->my_output_port, scm_from_uint16(0));
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
and in the GUIrepl class constructor i have this:
my_output_port = scm_open_output_string();
scm_set_current_output_port(my_output_port);
The entire proyect is in here:https://github.com/eduardoacye/Automaton
Its very basic and most of it is in spanish. Its going to be a program
where you can write algorithms in scheme for finite state machines, graph
theory, grammars and cellular automata and the graphic representation is in
c++.
[-- Attachment #2: Type: text/html, Size: 3826 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Request for help Qt, C++ and guile REPL.
2013-06-20 16:04 Request for help Qt, C++ and guile REPL Eduardo Acuña
@ 2013-06-20 17:46 ` Panicz Maciej Godek
2013-06-20 17:52 ` Noah Lavine
2013-06-20 18:49 ` Thien-Thi Nguyen
2 siblings, 0 replies; 4+ messages in thread
From: Panicz Maciej Godek @ 2013-06-20 17:46 UTC (permalink / raw)
To: Eduardo Acuña; +Cc: guile-user@gnu.org
[-- Attachment #1: Type: text/plain, Size: 839 bytes --]
Hi,
one way would be to run the code in a separate thread.
Perhaps it wouldn't be particularly elegant, but you could simply
append "(call-with-new-thread (lambda()" <code-from-your-text-field> "))"
before calling eval.
You'd need to reorganize your app, however, if you'd wish to display the
expression's resulting object, because if you did it that way, you'd only
get a thread object.
A possible solution would be to do something like this:
(define thread-results (make-hash-table))
(let ((thread (call-with-new-thread
(lambda()(let ((result <code-from-your-text-field>))
(hash-set! thread-results (current-thread)
result))))))
(set-thread-cleanup! (lambda() <display data from thread results to the
text field>)))
I probably wouldn't know however how to implement that at the C level.
Best regards
[-- Attachment #2: Type: text/html, Size: 1206 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Request for help Qt, C++ and guile REPL.
2013-06-20 16:04 Request for help Qt, C++ and guile REPL Eduardo Acuña
2013-06-20 17:46 ` Panicz Maciej Godek
@ 2013-06-20 17:52 ` Noah Lavine
2013-06-20 18:49 ` Thien-Thi Nguyen
2 siblings, 0 replies; 4+ messages in thread
From: Noah Lavine @ 2013-06-20 17:52 UTC (permalink / raw)
To: Eduardo Acuña; +Cc: Guile Mailing List
[-- Attachment #1: Type: text/plain, Size: 3298 bytes --]
It seems to me that the right way to handle this is to evaluate the Scheme
code in a different thread than the user interface, then have the interface
continually pull from Scheme's output port.
The other way to do it would be to notice if the Scheme code is a `begin'
or similar form and execute the forms (and print the result) one at a time.
That's doable (I would compile to Tree-IL first), but it'll still make your
entire program sleep for 2 seconds if the user types (sleep 2). But maybe
that's all right.
Best,
Noah
On Thu, Jun 20, 2013 at 9:04 AM, Eduardo Acuña <eduardo.acye@gmail.com>wrote:
> Hello!
>
> I have found the archives of this mailing list very helpful in the
> development of a piece of software i'm writing. And i have a few questions
> about the integration between guile, c++ and the library Qt.
>
> The program in question is a little gui repl, where the user can type
> guile code in a 'QLineEdit' widget and the evaluation gets printed in a
> 'QTextBrowser' widget.
>
> I have done this in a very basic way. But the problem is that if the user
> types:
>
> (begin (display "hello")(sleep 2))
>
> the result gets printed after the 2 seconds. What can i do to get the gui
> repl more like que standard guile repl?
>
> Thank you in advance.
>
> Eduardo Acuña Yeomans.
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> the class declaration is this:
>
> class GUIrepl : public QDialog
> {
> Q_OBJECT
>
> QTextBrowser *output_text_browser;
> QLineEdit *input_line_edit;
> QPushButton *evaluate_btn;
>
> SCM my_output_port;
> public:
> explicit GUIrepl(QWidget *parent = 0);
> ~GUIrepl();
> private slots:
> void evaluate_expression();
> };
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> the function that handles the evaluation is this:
>
> void GUIrepl::evaluate_expression()
> {
> QString input;
> SCM result_obj;
> SCM result_str;
> QString to_print;
>
> input = this->input_line_edit->text();
>
> result_obj = scm_c_eval_string(input.toStdString().data());
> result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
> to_print = scm_to_locale_string(result_str);
>
> SCM out = scm_get_output_string(this->my_output_port);
> QString out_str = scm_to_locale_string(out);
>
> input = "> "+input;
> this->output_text_browser->append(input);
> if(out_str != "")
> this->pantalla->append(out_str);
> if(to_print != "#<unspecified>")
> this->output_text_browser->append(to_print);
>
> this->input_line_edit->setText("");
> scm_truncate_file(this->my_output_port, scm_from_uint16(0));
> }
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> and in the GUIrepl class constructor i have this:
>
> my_output_port = scm_open_output_string();
> scm_set_current_output_port(my_output_port);
>
>
> The entire proyect is in here:https://github.com/eduardoacye/Automaton
> Its very basic and most of it is in spanish. Its going to be a program
> where you can write algorithms in scheme for finite state machines, graph
> theory, grammars and cellular automata and the graphic representation is in
> c++.
>
>
>
[-- Attachment #2: Type: text/html, Size: 4908 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Request for help Qt, C++ and guile REPL.
2013-06-20 16:04 Request for help Qt, C++ and guile REPL Eduardo Acuña
2013-06-20 17:46 ` Panicz Maciej Godek
2013-06-20 17:52 ` Noah Lavine
@ 2013-06-20 18:49 ` Thien-Thi Nguyen
2 siblings, 0 replies; 4+ messages in thread
From: Thien-Thi Nguyen @ 2013-06-20 18:49 UTC (permalink / raw)
To: Eduardo Acuña; +Cc: guile-user
[-- Attachment #1: Type: text/plain, Size: 363 bytes --]
() Eduardo Acuña <eduardo.acye@gmail.com>
() Thu, 20 Jun 2013 09:04:59 -0700
if the user types:
(begin (display "hello")(sleep 2))
the result gets printed after the 2 seconds.
What can i do to get the gui repl more like que standard guile repl?
Did you try to set stdout to be unbuffered?
--
Thien-Thi Nguyen
GPG key: 4C807502
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-06-20 18:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-20 16:04 Request for help Qt, C++ and guile REPL Eduardo Acuña
2013-06-20 17:46 ` Panicz Maciej Godek
2013-06-20 17:52 ` Noah Lavine
2013-06-20 18:49 ` Thien-Thi Nguyen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).