Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/1edfb7e96cb4
Дата изменения: Unknown
Дата индексирования: Mon Oct 1 23:57:56 2012
Кодировка:
allpy: 1edfb7e96cb4

allpy

changeset 18:1edfb7e96cb4

form file uploading contrl
author boris <bnagaev@gmail.com>
date Tue, 14 Sep 2010 23:57:33 +0400
parents 18abe8f33d37
children 9cbace0709fc
files blocks3d-wt-widget.C blocks3d-wt-widget.h blocks3d-wt.C blocks3d-wt.pro config.C config.h
diffstat 6 files changed, 196 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/blocks3d-wt-widget.C	Tue Sep 14 23:57:33 2010 +0400
     1.3 @@ -0,0 +1,121 @@
     1.4 +
     1.5 +#include "config.h"
     1.6 +#include "blocks3d-wt-widget.h"
     1.7 +
     1.8 +#include <Wt/WText>
     1.9 +#include <Wt/WBreak>
    1.10 +#include <Wt/WTable>
    1.11 +#include <Wt/WLabel>
    1.12 +#include <Wt/WDoubleValidator>
    1.13 +#include <Wt/WIntValidator>
    1.14 +#include <Wt/WMessageBox>
    1.15 +
    1.16 +#include <fstream>
    1.17 +
    1.18 +
    1.19 +Blocks3DWidget::Blocks3DWidget(WContainerWidget *parent) :
    1.20 +  WContainerWidget(parent)
    1.21 +{
    1.22 +  alignment_upload = new Wt::WFileUpload();
    1.23 +  alignment_textarea = new Wt::WTextArea();
    1.24 +  conformity_upload = new Wt::WFileUpload();
    1.25 +  conformity_textarea = new Wt::WTextArea();
    1.26 +  
    1.27 +  Wt::WLabel *alignment_label = new Wt::WLabel("Alignment:");
    1.28 +  alignment_label->setBuddy(alignment_textarea);
    1.29 +  
    1.30 +  Wt::WLabel *conformity_label = new Wt::WLabel("Confiomity file:");
    1.31 +  conformity_label->setBuddy(alignment_textarea);
    1.32 +   
    1.33 +  Wt::WTable *table = new Wt::WTable(this);
    1.34 +  table->elementAt(0, 0)->addWidget(alignment_label);
    1.35 +  table->elementAt(0, 1)->addWidget(conformity_label);
    1.36 +  table->elementAt(2, 0)->addWidget(alignment_upload);
    1.37 +  table->elementAt(1, 1)->addWidget(conformity_textarea);
    1.38 +  table->elementAt(2, 1)->addWidget(conformity_upload);
    1.39 +  
    1.40 +  new Wt::WBreak(this);
    1.41 +  delta_input = new Wt::WLineEdit(Malakite::default::delta, this);
    1.42 +  Wt::WDoubleValidator *delta_validator = new Wt::WDoubleValidator(0.0, 10.0);
    1.43 +  delta_input->setValidator(delta_validator);  
    1.44 +  Wt::WLabel *delta_label = new Wt::WLabel("Distance spreading", this);
    1.45 +  delta_label->setBuddy(delta_input);
    1.46 +  
    1.47 +  new Wt::WBreak(this);
    1.48 +  min_block_width_input = new Wt::WLineEdit(Malakite::default::min_block_width, this);
    1.49 +  Wt::WIntValidator *min_block_width_validator = new Wt::WIntValidator(3, 9999);
    1.50 +  min_block_width_input->setValidator(min_block_width_validator);  
    1.51 +  Wt::WLabel *min_block_width_label = new Wt::WLabel("Min block width", this);
    1.52 +  min_block_width_label->setBuddy(min_block_width_input);
    1.53 +  
    1.54 +  new Wt::WBreak(this);
    1.55 +  timeout_input = new Wt::WLineEdit(Malakite::default::timeout, this);
    1.56 +  Wt::WIntValidator *timeout_validator = new Wt::WIntValidator(-1, 30*24*3600);
    1.57 +  timeout_input->setValidator(timeout_validator);  
    1.58 +  Wt::WLabel *timeout_label = new Wt::WLabel(
    1.59 +    "Bron-Kerbosh (couple cores) timeout", this);
    1.60 +  timeout_label->setBuddy(timeout_input);
    1.61 +  
    1.62 +  new Wt::WBreak(this);
    1.63 +  timeout2_input = new Wt::WLineEdit(Malakite::default::timeout2, this);
    1.64 +  Wt::WIntValidator *timeout2_validator = new Wt::WIntValidator(-1, 30*24*3600);
    1.65 +  timeout2_input->setValidator(timeout2_validator);  
    1.66 +  Wt::WLabel *timeout2_label = new Wt::WLabel(
    1.67 +    "Bron-Kerbosh (blocks) timeout", this);
    1.68 +  timeout2_label->setBuddy(timeout2_input);
    1.69 +  
    1.70 +  
    1.71 +  new Wt::WBreak(this);
    1.72 +  Wt::WPushButton *go_button = new Wt::WPushButton("Run", this);  
    1.73 +  go_button->clicked().connect(go_button, &Blocks3DWidget::go_button_click);
    1.74 +  //~ go_button->clicked().connect(go_button, &Wt::WPushButton::disable);
    1.75 +  go_button->clicked().connect(alignment_upload, Wt::WFileUpload::upload);
    1.76 +  go_button->clicked().connect(conformity_upload, Wt::WFileUpload::upload);
    1.77 +  alignment_upload->uploaded().connect(this, &Blocks3DWidget::alignment_uploaded);
    1.78 +  conformity_upload->uploaded().connect(this, &Blocks3DWidget::conformity_uploaded);
    1.79 +  alignment_upload->fileTooLarge().connect(this, &Blocks3DWidget::fileTooLarge);
    1.80 +  conformity_upload->fileTooLarge().connect(this, &Blocks3DWidget::fileTooLarge);
    1.81 +  
    1.82 +  
    1.83 +}
    1.84 +
    1.85 +void Blocks3DWidget::fileTooLarge()
    1.86 +{
    1.87 +  Wt::WMessageBox::show("Error", "File too large", Wt::Ok);		
    1.88 +}
    1.89 +
    1.90 +void Blocks3DWidget::textarea_from_file(Wt::WTextArea* ta, char* file)
    1.91 +{
    1.92 +  std::string temp("");
    1.93 +  std::string total("");
    1.94 +  ifstream uploaded_file;
    1.95 +
    1.96 +  uploaded_file.open(file);
    1.97 +  if (!inFile) 
    1.98 +  {
    1.99 +    return;
   1.100 +  }
   1.101 +  while (uploaded_file >> temp) 
   1.102 +  {
   1.103 +    total += temp;
   1.104 +  }
   1.105 +  uploaded_file.close();
   1.106 +  
   1.107 +  ta->setText(total);
   1.108 +}
   1.109 +
   1.110 +void Blocks3DWidget::alignment_uploaded()
   1.111 +{
   1.112 +  textarea_from_file(alignment_textarea, alignment_upload->spoolFileName());
   1.113 +}
   1.114 +
   1.115 +void Blocks3DWidget::conformity_uploaded()
   1.116 +{
   1.117 +  textarea_from_file(conformity_textarea, conformity_upload->spoolFileName());
   1.118 +}
   1.119 +
   1.120 +void Blocks3DWidget::try_to_run()
   1.121 +{
   1.122 +  textarea_from_file(conformity_textarea, conformity_upload->spoolFileName());
   1.123 +}
   1.124 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/blocks3d-wt-widget.h	Tue Sep 14 23:57:33 2010 +0400
     2.3 @@ -0,0 +1,41 @@
     2.4 +
     2.5 +#include "config.h"
     2.6 +#include <stdlib.h>
     2.7 +
     2.8 +#include <Wt/WSelectionBox>
     2.9 +#include <Wt/WPanel>
    2.10 +#include <Wt/WString>
    2.11 +#include <Wt/WHBoxLayout>
    2.12 +#include <Wt/WVBoxLayout>
    2.13 +#include <Wt/WImage>
    2.14 +
    2.15 +#include <Wt/WContainerWidget>
    2.16 +#include <Wt/WFileUpload>
    2.17 +#include <Wt/WTextArea>
    2.18 +#include <Wt/WPushButton>
    2.19 +#include <Wt/WLineEdit>
    2.20 +
    2.21 +#include <stdlib.h>
    2.22 +
    2.23 +class Blocks3DWidget : public WContainerWidget
    2.24 +{
    2.25 +public:
    2.26 +  Blocks3DWidget(WContainerWidget *parent=0);
    2.27 +private:
    2.28 +  Wt::WFileUpload* alignment_upload;
    2.29 +  Wt::WTextArea* alignment_textarea;
    2.30 +  Wt::WFileUpload* conformity_upload;
    2.31 +  Wt::WTextArea* conformity_textarea;
    2.32 +  
    2.33 +  Wt::WLineEdit* delta_input;
    2.34 +  Wt::WLineEdit* min_block_width_input;
    2.35 +  Wt::WLineEdit* timeout_input;
    2.36 +  Wt::WLineEdit* timeout2_input;
    2.37 +  
    2.38 +  void textarea_from_file(Wt::WTextArea* ta, char* file);
    2.39 +  void go_button_click();
    2.40 +  void alignment_uploaded();
    2.41 +  void conformity_uploaded();
    2.42 +  void try_to_run();
    2.43 +  void fileTooLarge();
    2.44 +};
     3.1 --- a/blocks3d-wt.C	Tue Sep 14 22:32:55 2010 +0400
     3.2 +++ b/blocks3d-wt.C	Tue Sep 14 23:57:33 2010 +0400
     3.3 @@ -1,26 +1,28 @@
     3.4  
     3.5  #include "config.h"
     3.6 +#include "blocks3d-wt-widget.h"
     3.7  
     3.8  #include <Wt/WEnvironment>
     3.9  #include <Wt/WApplication>
    3.10 -#include <Wt/WContainerWidget>
    3.11  #include <Wt/WServer>
    3.12 -#include <Wt/WSelectionBox>
    3.13 -#include <Wt/WPanel>
    3.14 -#include <Wt/WText>
    3.15 -#include <Wt/WContainerWidget>
    3.16 -#include <Wt/WString>
    3.17 -#include <Wt/WHBoxLayout>
    3.18 -#include <Wt/WVBoxLayout>
    3.19 -#include <Wt/WImage>
    3.20 -#include <Wt/WPushButton>
    3.21 +
    3.22  
    3.23  class Blocks3DApplication : public WApplication
    3.24  {
    3.25  public:
    3.26    Blocks3DApplication(const WEnvironment& env);
    3.27 +private:
    3.28 +  Blocks3DWidget* blocks3d_widget;
    3.29  };
    3.30  
    3.31 +Blocks3DApplication::Blocks3DApplication(const WEnvironment& env) : 
    3.32 +  WApplication(env)
    3.33 +{
    3.34 +  blocks3d_widget = new Blocks3DWidget(this);
    3.35 +}
    3.36 +
    3.37 +
    3.38 +
    3.39  
    3.40  Blocks3DApplication* createApplication(const WEnvironment& env)
    3.41  {
     4.1 --- a/blocks3d-wt.pro	Tue Sep 14 22:32:55 2010 +0400
     4.2 +++ b/blocks3d-wt.pro	Tue Sep 14 23:57:33 2010 +0400
     4.3 @@ -2,6 +2,7 @@
     4.4  
     4.5  SOURCES += config.C
     4.6  SOURCES += blocks3d-wt.C
     4.7 +SOURCES += blocks3d-wt-widget.C
     4.8  
     4.9  CONFIG += debug
    4.10  CONFIG += precompile_header
     5.1 --- a/config.C	Tue Sep 14 22:32:55 2010 +0400
     5.2 +++ b/config.C	Tue Sep 14 23:57:33 2010 +0400
     5.3 @@ -11,5 +11,18 @@
     5.4  
     5.5  const char* main_url = "/";
     5.6  
     5.7 +
     5.8 +namespace default
     5.9 +{
    5.10 +
    5.11 +const char* delta = "2.0";
    5.12 +const char* min_block_width_input = "3";
    5.13 +const char* timeout = "10";
    5.14 +const char* timeout2 = "10";
    5.15 +
    5.16  }
    5.17  
    5.18 +
    5.19 +
    5.20 +}
    5.21 +
     6.1 --- a/config.h	Tue Sep 14 22:32:55 2010 +0400
     6.2 +++ b/config.h	Tue Sep 14 23:57:33 2010 +0400
     6.3 @@ -9,4 +9,12 @@
     6.4  
     6.5  extern const char* main_url;
     6.6  
     6.7 +namespace default
     6.8 +{
     6.9 +
    6.10 +extern const char* delta;
    6.11 +extern const char* min_block_width_input;
    6.12 +extern const char* timeout;
    6.13 +extern const char* timeout2;
    6.14 +
    6.15  }