allpy
changeset 41:b71e170354f3
view and download links
author | boris <bnagaev@gmail.com> |
---|---|
date | Wed, 15 Sep 2010 21:25:03 +0400 |
parents | e1c94228fe10 |
children | 901ca2aa9375 |
files | blocks3d-wt-widget.C |
diffstat | 1 files changed, 215 insertions(+), 202 deletions(-) [+] |
line diff
1.1 --- a/blocks3d-wt-widget.C Wed Sep 15 19:36:36 2010 +0400 1.2 +++ b/blocks3d-wt-widget.C Wed Sep 15 21:25:03 2010 +0400 1.3 @@ -10,6 +10,8 @@ 1.4 #include <Wt/WDoubleValidator> 1.5 #include <Wt/WIntValidator> 1.6 #include <Wt/WMessageBox> 1.7 +#include <Wt/WAnchor> 1.8 +#include <Wt/WFileResource> 1.9 1.10 #include <fstream> 1.11 #include <iostream> 1.12 @@ -17,238 +19,249 @@ 1.13 #include <stdlib.h> 1.14 1.15 Blocks3DWidget::Blocks3DWidget(Wt::WContainerWidget *parent) : 1.16 - Wt::WContainerWidget(parent) 1.17 + Wt::WContainerWidget(parent) 1.18 { 1.19 - alignment_upload = new Wt::WFileUpload(); 1.20 - alignment_textarea = new Wt::WTextArea(); 1.21 - alignment_textarea->setColumns(40); 1.22 - conformity_upload = new Wt::WFileUpload(); 1.23 - conformity_textarea = new Wt::WTextArea(); 1.24 - conformity_textarea->setColumns(40); 1.25 - 1.26 - Wt::WLabel *alignment_label = new Wt::WLabel("Alignment:"); 1.27 - alignment_label->setBuddy(alignment_textarea); 1.28 - 1.29 - Wt::WLabel *conformity_label = new Wt::WLabel("Confiomity file:"); 1.30 - conformity_label->setBuddy(alignment_textarea); 1.31 - 1.32 - Wt::WTable *table = new Wt::WTable(this); 1.33 - 1.34 - table->elementAt(0, 0)->addWidget(alignment_label); 1.35 - table->elementAt(1, 0)->addWidget(alignment_textarea); 1.36 - table->elementAt(2, 0)->addWidget(alignment_upload); 1.37 - 1.38 - table->elementAt(0, 1)->addWidget(conformity_label); 1.39 - table->elementAt(1, 1)->addWidget(conformity_textarea); 1.40 - table->elementAt(2, 1)->addWidget(conformity_upload); 1.41 - 1.42 - new Wt::WBreak(this); 1.43 - delta_input = new Wt::WLineEdit(Malakite::defaults::delta, this); 1.44 - delta_validator = new Wt::WDoubleValidator(0.0, 10.0); // FIXME: not to allow empty 1.45 - delta_input->setValidator(delta_validator); 1.46 - Wt::WLabel *delta_label = new Wt::WLabel("Distance spreading", this); 1.47 - delta_label->setBuddy(delta_input); 1.48 - 1.49 - new Wt::WBreak(this); 1.50 - min_block_width_input = new Wt::WLineEdit(Malakite::defaults::min_block_width, this); 1.51 - min_block_width_validator = new Wt::WIntValidator(3, 9999); 1.52 - min_block_width_input->setValidator(min_block_width_validator); 1.53 - Wt::WLabel *min_block_width_label = new Wt::WLabel("Min block width", this); 1.54 - min_block_width_label->setBuddy(min_block_width_input); 1.55 - 1.56 - new Wt::WBreak(this); 1.57 - timeout_input = new Wt::WLineEdit(Malakite::defaults::timeout, this); 1.58 - timeout_validator = new Wt::WIntValidator(-1, 30*24*3600); 1.59 - timeout_input->setValidator(timeout_validator); 1.60 - Wt::WLabel *timeout_label = new Wt::WLabel( 1.61 - "Bron-Kerbosh (couple cores) timeout", this); 1.62 - timeout_label->setBuddy(timeout_input); 1.63 - 1.64 - new Wt::WBreak(this); 1.65 - timeout2_input = new Wt::WLineEdit(Malakite::defaults::timeout2, this); 1.66 - timeout2_validator = new Wt::WIntValidator(-1, 30*24*3600); 1.67 - timeout2_input->setValidator(timeout2_validator); 1.68 - Wt::WLabel *timeout2_label = new Wt::WLabel( 1.69 - "Bron-Kerbosh (blocks) timeout", this); 1.70 - timeout2_label->setBuddy(timeout2_input); 1.71 - 1.72 - 1.73 - new Wt::WBreak(this); 1.74 - Wt::WPushButton *go_button = new Wt::WPushButton("Run", this); 1.75 - 1.76 - new Wt::WBreak(this); 1.77 - results_panel = new Wt::WContainerWidget(this); 1.78 - 1.79 - go_button->clicked().connect(this, &Blocks3DWidget::go_button_click); 1.80 - alignment_upload->uploaded().connect(this, &Blocks3DWidget::alignment_uploaded); 1.81 - conformity_upload->uploaded().connect(this, &Blocks3DWidget::conformity_uploaded); 1.82 - alignment_upload->fileTooLarge().connect(this, &Blocks3DWidget::fileTooLarge); 1.83 - conformity_upload->fileTooLarge().connect(this, &Blocks3DWidget::fileTooLarge); 1.84 - 1.85 - alignment_upload->changed().connect(alignment_upload, &Wt::WFileUpload::upload); 1.86 - conformity_upload->changed().connect(conformity_upload, &Wt::WFileUpload::upload); 1.87 - 1.88 - timer = new Wt::WTimer(this); 1.89 - timer->timeout().connect(this, &Blocks3DWidget::timeout); 1.90 - timer->setInterval(Malakite::refresh_period); 1.91 + alignment_upload = new Wt::WFileUpload(); 1.92 + alignment_textarea = new Wt::WTextArea(); 1.93 + alignment_textarea->setColumns(40); 1.94 + conformity_upload = new Wt::WFileUpload(); 1.95 + conformity_textarea = new Wt::WTextArea(); 1.96 + conformity_textarea->setColumns(40); 1.97 + 1.98 + Wt::WLabel *alignment_label = new Wt::WLabel("Alignment:"); 1.99 + alignment_label->setBuddy(alignment_textarea); 1.100 + 1.101 + Wt::WLabel *conformity_label = new Wt::WLabel("Confiomity file:"); 1.102 + conformity_label->setBuddy(alignment_textarea); 1.103 + 1.104 + Wt::WTable *table = new Wt::WTable(this); 1.105 + 1.106 + table->elementAt(0, 0)->addWidget(alignment_label); 1.107 + table->elementAt(1, 0)->addWidget(alignment_textarea); 1.108 + table->elementAt(2, 0)->addWidget(alignment_upload); 1.109 + 1.110 + table->elementAt(0, 1)->addWidget(conformity_label); 1.111 + table->elementAt(1, 1)->addWidget(conformity_textarea); 1.112 + table->elementAt(2, 1)->addWidget(conformity_upload); 1.113 + 1.114 + new Wt::WBreak(this); 1.115 + delta_input = new Wt::WLineEdit(Malakite::defaults::delta, this); 1.116 + delta_validator = new Wt::WDoubleValidator(0.0, 10.0); // FIXME: not to allow empty 1.117 + delta_input->setValidator(delta_validator); 1.118 + Wt::WLabel *delta_label = new Wt::WLabel("Distance spreading", this); 1.119 + delta_label->setBuddy(delta_input); 1.120 + 1.121 + new Wt::WBreak(this); 1.122 + min_block_width_input = new Wt::WLineEdit(Malakite::defaults::min_block_width, this); 1.123 + min_block_width_validator = new Wt::WIntValidator(3, 9999); 1.124 + min_block_width_input->setValidator(min_block_width_validator); 1.125 + Wt::WLabel *min_block_width_label = new Wt::WLabel("Min block width", this); 1.126 + min_block_width_label->setBuddy(min_block_width_input); 1.127 + 1.128 + new Wt::WBreak(this); 1.129 + timeout_input = new Wt::WLineEdit(Malakite::defaults::timeout, this); 1.130 + timeout_validator = new Wt::WIntValidator(-1, 30*24*3600); 1.131 + timeout_input->setValidator(timeout_validator); 1.132 + Wt::WLabel *timeout_label = new Wt::WLabel( 1.133 + "Bron-Kerbosh (couple cores) timeout", this); 1.134 + timeout_label->setBuddy(timeout_input); 1.135 + 1.136 + new Wt::WBreak(this); 1.137 + timeout2_input = new Wt::WLineEdit(Malakite::defaults::timeout2, this); 1.138 + timeout2_validator = new Wt::WIntValidator(-1, 30*24*3600); 1.139 + timeout2_input->setValidator(timeout2_validator); 1.140 + Wt::WLabel *timeout2_label = new Wt::WLabel( 1.141 + "Bron-Kerbosh (blocks) timeout", this); 1.142 + timeout2_label->setBuddy(timeout2_input); 1.143 + 1.144 + 1.145 + new Wt::WBreak(this); 1.146 + Wt::WPushButton *go_button = new Wt::WPushButton("Run", this); 1.147 + 1.148 + new Wt::WBreak(this); 1.149 + results_panel = new Wt::WContainerWidget(this); 1.150 + 1.151 + go_button->clicked().connect(this, &Blocks3DWidget::go_button_click); 1.152 + alignment_upload->uploaded().connect(this, &Blocks3DWidget::alignment_uploaded); 1.153 + conformity_upload->uploaded().connect(this, &Blocks3DWidget::conformity_uploaded); 1.154 + alignment_upload->fileTooLarge().connect(this, &Blocks3DWidget::fileTooLarge); 1.155 + conformity_upload->fileTooLarge().connect(this, &Blocks3DWidget::fileTooLarge); 1.156 + 1.157 + alignment_upload->changed().connect(alignment_upload, &Wt::WFileUpload::upload); 1.158 + conformity_upload->changed().connect(conformity_upload, &Wt::WFileUpload::upload); 1.159 + 1.160 + timer = new Wt::WTimer(this); 1.161 + timer->timeout().connect(this, &Blocks3DWidget::timeout); 1.162 + timer->setInterval(Malakite::refresh_period); 1.163 } 1.164 1.165 void Blocks3DWidget::go_button_click() 1.166 { 1.167 - try_to_run(); 1.168 + try_to_run(); 1.169 } 1.170 1.171 void Blocks3DWidget::fileTooLarge() 1.172 { 1.173 - Wt::WMessageBox::show("Error", "File too large", Wt::Ok); 1.174 + Wt::WMessageBox::show("Error", "File too large", Wt::Ok); 1.175 } 1.176 1.177 void Blocks3DWidget::textarea_from_file(Wt::WTextArea* ta, const char* file) 1.178 { 1.179 - std::string temp(""); 1.180 - std::string total(""); 1.181 - std::ifstream uploaded_file; 1.182 + std::string temp(""); 1.183 + std::string total(""); 1.184 + std::ifstream uploaded_file; 1.185 1.186 - uploaded_file.open(file); 1.187 - if (!uploaded_file) 1.188 - { 1.189 - return; 1.190 - } 1.191 - while (uploaded_file >> temp) 1.192 - { 1.193 - total += temp + "\n"; 1.194 - } 1.195 - uploaded_file.close(); 1.196 - 1.197 - ta->setText(total); 1.198 + uploaded_file.open(file); 1.199 + if (!uploaded_file) 1.200 + { 1.201 + return; 1.202 + } 1.203 + while (uploaded_file >> temp) 1.204 + { 1.205 + total += temp + "\n"; 1.206 + } 1.207 + uploaded_file.close(); 1.208 + 1.209 + ta->setText(total); 1.210 } 1.211 1.212 void Blocks3DWidget::alignment_uploaded() 1.213 { 1.214 - textarea_from_file(alignment_textarea, alignment_upload->spoolFileName().c_str()); 1.215 + textarea_from_file(alignment_textarea, alignment_upload->spoolFileName().c_str()); 1.216 } 1.217 1.218 void Blocks3DWidget::conformity_uploaded() 1.219 { 1.220 - textarea_from_file(conformity_textarea, conformity_upload->spoolFileName().c_str()); 1.221 + textarea_from_file(conformity_textarea, conformity_upload->spoolFileName().c_str()); 1.222 } 1.223 1.224 void Blocks3DWidget::try_to_run() 1.225 { 1.226 - std::string alignment = alignment_textarea->text().toUTF8(); 1.227 - std::string conformity = conformity_textarea->text().toUTF8(); 1.228 - if (alignment.empty()) 1.229 - { 1.230 - return; 1.231 - } 1.232 - if (delta_input->validate() != Wt::WValidator::Valid) 1.233 - { 1.234 - return; 1.235 - } 1.236 - if (min_block_width_input->validate() != Wt::WValidator::Valid) 1.237 - { 1.238 - return; 1.239 - } 1.240 - if (timeout_input->validate() != Wt::WValidator::Valid) 1.241 - { 1.242 - return; 1.243 - } 1.244 - if (timeout2_input->validate() != Wt::WValidator::Valid) 1.245 - { 1.246 - return; 1.247 - } 1.248 - 1.249 - std::string r = generateSalt(); 1.250 - 1.251 - tempfile_alignment = 1.252 - str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_alignment); 1.253 - tempfile_conformity = 1.254 - str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_conformity); 1.255 - tempfile_html = 1.256 - str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_html); 1.257 - tempfile_check = 1.258 - str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_check); 1.259 - tempfile_sh = 1.260 - str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_sh); 1.261 - 1.262 - std::ofstream alignment_file; 1.263 - alignment_file.open(tempfile_alignment.c_str()); 1.264 - alignment_file << alignment; 1.265 - alignment_file.close(); 1.266 - 1.267 - if (!conformity.empty()) 1.268 - { 1.269 - std::ofstream conformity_file; 1.270 - conformity_file.open(tempfile_conformity.c_str()); 1.271 - conformity_file << conformity; 1.272 - conformity_file.close(); 1.273 - } 1.274 - 1.275 - std::string conformity_option = ""; 1.276 - if (!conformity.empty()) 1.277 - { 1.278 - conformity_option = str(boost::format("-c %s") % tempfile_conformity); 1.279 - } 1.280 - 1.281 - std::string cmd = str( 1.282 - boost::format("cd %s ; %s %s -i %s %s -H %s -d %s -m %s -t %s -T %s; echo 'f' > %s;") 1.283 - % Malakite::temp_path 1.284 - % Malakite::python_path % Malakite::blocks3d_path 1.285 - % tempfile_alignment 1.286 - % conformity_option 1.287 - % tempfile_html 1.288 - % delta_input->text().toUTF8() % min_block_width_input->text().toUTF8() 1.289 - % timeout_input->text().toUTF8() % timeout2_input->text().toUTF8() 1.290 - % tempfile_check 1.291 - ); 1.292 - 1.293 - std::cout << cmd << std::endl; 1.294 - 1.295 - std::ofstream tempfile_sh_file; 1.296 - tempfile_sh_file.open(tempfile_sh.c_str()); 1.297 - tempfile_sh_file << cmd; 1.298 - tempfile_sh_file.close(); 1.299 - 1.300 - // security??? 1.301 - system(str(boost::format("sh %s &") % tempfile_sh.c_str()).c_str()); 1.302 - new Wt::WBreak(this); 1.303 - new Wt::WText("Task start", results_panel); 1.304 - 1.305 - timer->start(); 1.306 - 1.307 + std::string alignment = alignment_textarea->text().toUTF8(); 1.308 + std::string conformity = conformity_textarea->text().toUTF8(); 1.309 + if (alignment.empty()) 1.310 + { 1.311 + new Wt::WBreak(results_panel); 1.312 + new Wt::WText("No alignment provided", results_panel); 1.313 + return; 1.314 + } 1.315 + if (delta_input->validate() != Wt::WValidator::Valid) 1.316 + { 1.317 + return; 1.318 + } 1.319 + if (min_block_width_input->validate() != Wt::WValidator::Valid) 1.320 + { 1.321 + return; 1.322 + } 1.323 + if (timeout_input->validate() != Wt::WValidator::Valid) 1.324 + { 1.325 + return; 1.326 + } 1.327 + if (timeout2_input->validate() != Wt::WValidator::Valid) 1.328 + { 1.329 + return; 1.330 + } 1.331 + 1.332 + std::string r = generateSalt(); 1.333 + 1.334 + tempfile_alignment = 1.335 + str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_alignment); 1.336 + tempfile_conformity = 1.337 + str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_conformity); 1.338 + tempfile_html = 1.339 + str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_html); 1.340 + tempfile_check = 1.341 + str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_check); 1.342 + tempfile_sh = 1.343 + str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_sh); 1.344 + 1.345 + std::ofstream alignment_file; 1.346 + alignment_file.open(tempfile_alignment.c_str()); 1.347 + alignment_file << alignment; 1.348 + alignment_file.close(); 1.349 + 1.350 + if (!conformity.empty()) 1.351 + { 1.352 + std::ofstream conformity_file; 1.353 + conformity_file.open(tempfile_conformity.c_str()); 1.354 + conformity_file << conformity; 1.355 + conformity_file.close(); 1.356 + } 1.357 + 1.358 + std::string conformity_option = ""; 1.359 + if (!conformity.empty()) 1.360 + { 1.361 + conformity_option = str(boost::format("-c %s") % tempfile_conformity); 1.362 + } 1.363 + 1.364 + std::string cmd = str( 1.365 + boost::format("cd %s ; %s %s -i %s %s -H %s -d %s -m %s -t %s -T %s; echo 'f' > %s;") 1.366 + % Malakite::temp_path 1.367 + % Malakite::python_path % Malakite::blocks3d_path 1.368 + % tempfile_alignment 1.369 + % conformity_option 1.370 + % tempfile_html 1.371 + % delta_input->text().toUTF8() % min_block_width_input->text().toUTF8() 1.372 + % timeout_input->text().toUTF8() % timeout2_input->text().toUTF8() 1.373 + % tempfile_check 1.374 + ); 1.375 + 1.376 + std::cout << cmd << std::endl; 1.377 + 1.378 + std::ofstream tempfile_sh_file; 1.379 + tempfile_sh_file.open(tempfile_sh.c_str()); 1.380 + tempfile_sh_file << cmd; 1.381 + tempfile_sh_file.close(); 1.382 + 1.383 + // security??? 1.384 + system(str(boost::format("sh %s &") % tempfile_sh.c_str()).c_str()); 1.385 + new Wt::WBreak(results_panel); 1.386 + new Wt::WText("Task start", results_panel); 1.387 + 1.388 + timer->start(); 1.389 + 1.390 } 1.391 1.392 void Blocks3DWidget::timeout() 1.393 { 1.394 - // FIXME: check status of task 1.395 - std::ifstream check_file; 1.396 - check_file.open(tempfile_check.c_str()); 1.397 - if (!check_file) 1.398 - { 1.399 - return; 1.400 - } 1.401 - check_file.close(); 1.402 - 1.403 - timer->stop(); 1.404 - 1.405 - std::ifstream tempfile_html_file; 1.406 - tempfile_html_file.open(tempfile_html.c_str()); 1.407 - if (!tempfile_html_file) 1.408 - { 1.409 - //~ Wt::WMessageBox::show("Ok", "Ok", Wt::Ok); 1.410 - new Wt::WBreak(this); 1.411 - new Wt::WText("Task failed. Please contact developer", results_panel); 1.412 - return; 1.413 - } 1.414 - tempfile_html_file.close(); 1.415 - 1.416 - new Wt::WBreak(this); 1.417 - new Wt::WText("Task finished", results_panel); 1.418 - 1.419 - 1.420 - 1.421 - // FIXME Anchor 1.422 - 1.423 + // FIXME: check status of task 1.424 + std::ifstream check_file; 1.425 + check_file.open(tempfile_check.c_str()); 1.426 + if (!check_file) 1.427 + { 1.428 + return; 1.429 + } 1.430 + check_file.close(); 1.431 + 1.432 + timer->stop(); 1.433 + 1.434 + std::ifstream tempfile_html_file; 1.435 + tempfile_html_file.open(tempfile_html.c_str()); 1.436 + if (!tempfile_html_file) 1.437 + { 1.438 + //~ Wt::WMessageBox::show("Ok", "Ok", Wt::Ok); 1.439 + new Wt::WBreak(results_panel); 1.440 + new Wt::WText("Task failed. Please contact developer", results_panel); 1.441 + return; 1.442 + } 1.443 + tempfile_html_file.close(); 1.444 + 1.445 + new Wt::WBreak(results_panel); 1.446 + new Wt::WText("Task finished", results_panel); 1.447 + 1.448 + Wt::WFileResource* html_view = 1.449 + new Wt::WFileResource("text/html", tempfile_html, this); 1.450 + new Wt::WBreak(results_panel); 1.451 + Wt::WAnchor* a_view = new Wt::WAnchor(html_view, "View", results_panel); 1.452 + a_view->setTarget(Wt::TargetNewWindow); 1.453 + 1.454 + Wt::WFileResource* html_download = 1.455 + new Wt::WFileResource("application/octet-stream", tempfile_html, this); 1.456 + new Wt::WBreak(results_panel); 1.457 + Wt::WAnchor* a_download = new Wt::WAnchor(html_download, "View", results_panel); 1.458 + 1.459 + // FIXME Anchor 1.460 + 1.461 } 1.462 1.463