예제 #1
0
void regression_serv::set_config(const string& config) {
  core::common::jsonconfig::config config_root(lexical_cast<json>(config));
  regression_serv_config conf =
    core::common::jsonconfig::config_cast_check<regression_serv_config>(
      config_root);

  config_ = config;

  core::common::jsonconfig::config param;
  if (conf.parameter) {
    param = *conf.parameter;
  }

  shared_ptr<core::storage::storage_base> model = make_model(argv());

  regression_.reset(
      new core::driver::regression(
          model,
          core::regression::regression_factory::create_regression(
              conf.method, param, model),
          core::fv_converter::make_fv_converter(conf.converter)));
  mixer_->set_mixable_holder(regression_->get_mixable_holder());

  // TODO(kuenishi): switch the function when set_config is done
  // because mixing method differs btwn PA, CW, etc...
  LOG(INFO) << "config loaded: " << config;
}
예제 #2
0
파일: arp.cpp 프로젝트: Droker/wirelessui
arp::arp(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::arp)
{
    ui->setupUi(this);
    make_model();
}
예제 #3
0
fakeap::fakeap(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::fakeap)
{
    ui->setupUi(this);
    connect(ui->fakelistButton, SIGNAL(clicked()),SLOT(require_fake_list()));
    make_model();
}
예제 #4
0
aplist::aplist(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::aplist)
{
    ui->setupUi(this);
  //  ui->aplistButton->setEnabled(false);
    connect(ui->aplistButton, SIGNAL(clicked()),SLOT(require_ap_list()));
    make_model();
    get_veriyed();
}
예제 #5
0
int recommender_serv::set_config(config_data config) {
  LOG(INFO) << __func__;
  shared_ptr<fv_converter::datum_to_fv_converter> converter
      = fv_converter::make_fv_converter(config.converter);
  config_ = config;
  converter_ = converter;
  rcmdr_.set_model(make_model());
  (*converter_).set_weight_manager(wm_.get_model());
  return 0;
}
예제 #6
0
int recommender_serv::set_config(config_data config)
{
  config_ = config;
  shared_ptr<fv_converter::datum_to_fv_converter> converter(new fv_converter::datum_to_fv_converter);
  fv_converter::converter_config c;
  convert<jubatus::converter_config, fv_converter::converter_config>(config.converter, c);
  fv_converter::initialize_converter(c, *converter);
  converter_ = converter;
  rcmdr_.set_model(make_model());
  return 0;
}
예제 #7
0
classifier_serv::classifier_serv(const framework::server_argv& a)
  :framework::jubatus_serv(a)
{
  clsfer_.set_model(make_model());
  register_mixable(framework::mixable_cast(&clsfer_));

  wm_.wm_ = common::cshared_ptr<fv_converter::weight_manager>(new weight_manager);
  wm_.set_model(wm_.wm_);

  register_mixable(framework::mixable_cast(&wm_));
}
예제 #8
0
regression_serv::regression_serv(const framework::server_argv& a,
                                 const cshared_ptr<lock_service>& zk)
    : server_base(a) {
  gresser_.set_model(make_model(a));
  wm_.set_model(mixable_weight_manager::model_ptr(new weight_manager));

  mixer_.reset(mixer::create_mixer(a, zk));
  mixable_holder_.reset(new mixable_holder());

  mixer_->set_mixable_holder(mixable_holder_);
  mixable_holder_->register_mixable(&gresser_);
  mixable_holder_->register_mixable(&wm_);
}
예제 #9
0
bool recommender_serv::set_config(std::string config) {
  jsonconfig::config conf_root(lexical_cast<json>(config));
  recommender_serv_config conf =
      jsonconfig::config_cast_check<recommender_serv_config>(conf_root);

  shared_ptr<fv_converter::datum_to_fv_converter> converter =
      fv_converter::make_fv_converter(conf.converter);
  config_ = config;
  converter_ = converter;
  rcmdr_.set_model(make_model(conf));
  (*converter_).set_weight_manager(wm_.get_model());

  LOG(INFO) << "config loaded: " << config;
  return true;
}
예제 #10
0
파일: pmp_bf.c 프로젝트: brsaran/FuzzyApp
/*************************************************************************
 * Entry point for pmp_bf
 *************************************************************************/
int main(int argc, char *argv[]) {

  char* bg_filename = NULL;
  char* motif_name = "motif"; // Use this motif name in the output.
  STRING_LIST_T* selected_motifs = NULL;
  double fg_rate = 1.0;
  double bg_rate = 1.0;
  double purine_pyrimidine = 1.0; // r
  double transition_transversion = 0.5; // R
  double pseudocount = 0.1;
  GAP_SUPPORT_T gap_support = SKIP_GAPS;
  MODEL_TYPE_T model_type = F81_MODEL;
  BOOLEAN_T use_halpern_bruno = FALSE;
  char* ustar_label = NULL;	// TLB; create uniform star tree
  int i;

  program_name = "pmp_bf";

  /**********************************************
   * COMMAND LINE PROCESSING
   **********************************************/

  // Define command line options. (FIXME: Repeated code)
  // FIXME: Note that if you add or remove options you
  // must change n_options.
  int n_options = 12;
  cmdoption const pmp_options[] = {
    {"hb", NO_VALUE},
    {"ustar", REQUIRED_VALUE},
    {"model", REQUIRED_VALUE},
    {"pur-pyr", REQUIRED_VALUE},
    {"transition-transversion", REQUIRED_VALUE},
    {"bg", REQUIRED_VALUE},
    {"fg", REQUIRED_VALUE},
    {"motif", REQUIRED_VALUE},
    {"motif-name", REQUIRED_VALUE},
    {"bgfile", REQUIRED_VALUE},
    {"pseudocount", REQUIRED_VALUE},
    {"verbosity", REQUIRED_VALUE}
  };

  int option_index = 0;

  // Define the usage message.
  char      usage[1000] = "";
  strcat(usage, "USAGE: pmp [options] <tree file> <MEME file>\n");
  strcat(usage, "\n");
  strcat(usage, "   Options:\n");

  // Evolutionary model parameters.
  strcat(usage, "     --hb\n");
  strcat(usage, "     --model single|average|jc|k2|f81|f84|hky|tn");
  strcat(usage, " (default=f81)\n");
  strcat(usage, "     --pur-pyr <float> (default=1.0)\n");
  strcat(usage, "     --transition-transversion <float> (default=0.5)\n");
  strcat(usage, "     --bg <float> (default=1.0)\n");
  strcat(usage, "     --fg <float> (default=1.0)\n");

  // Motif parameters.
  strcat(usage, "     --motif <id> (default=all)\n");
  strcat(usage, "     --motif-name <string> (default from motif file)\n");

  // Miscellaneous parameters
  strcat(usage, "     --bgfile <background> (default from motif file)\n");
  strcat(usage, "     --pseudocount <float> (default=0.1)\n");
  strcat(usage, "     --ustar <label>\n");	// TLB; create uniform star tree
  strcat(usage, "     --verbosity [1|2|3|4] (default 2)\n");
  strcat(usage, "\n    Prints the FP and FN rate at each of 10000 score values.\n");
  strcat(usage, "\n    Output format: [<motif_id> score <score> FPR <fpr> TPR <tpr>]+\n");

  // Parse the command line.
  if (simple_setopt(argc, argv, n_options, pmp_options) != NO_ERROR) {
    die("Error processing command line options: option name too long.\n");
  }

  while (TRUE) { 
    int c = 0;
    char* option_name = NULL;
    char* option_value = NULL;
    const char * message = NULL;

    // Read the next option, and break if we're done.
    c = simple_getopt(&option_name, &option_value, &option_index);
    if (c == 0) {
      break;
    } else if (c < 0) {
      (void) simple_getopterror(&message);
      die("Error processing command line options (%s)\n", message);
    }
    
    if (strcmp(option_name, "model") == 0) {
      if (strcmp(option_value, "jc") == 0) {
        model_type = JC_MODEL;
      } else if (strcmp(option_value, "k2") == 0) {
        model_type = K2_MODEL;
      } else if (strcmp(option_value, "f81") == 0) {
        model_type = F81_MODEL;
      } else if (strcmp(option_value, "f84") == 0) {
        model_type = F84_MODEL;
      } else if (strcmp(option_value, "hky") == 0) {
        model_type = HKY_MODEL;
      } else if (strcmp(option_value, "tn") == 0) {
        model_type = TAMURA_NEI_MODEL;
      } else if (strcmp(option_value, "single") == 0) {
        model_type = SINGLE_MODEL;
      } else if (strcmp(option_value, "average") == 0) {
        model_type = AVERAGE_MODEL;
      } else {
        die("Unknown model: %s\n", option_value);
      }
    } else if (strcmp(option_name, "hb") == 0){
        use_halpern_bruno = TRUE;
    } else if (strcmp(option_name, "ustar") == 0){	// TLB; create uniform star tree
        ustar_label = option_value;
    } else if (strcmp(option_name, "pur-pyr") == 0){
        purine_pyrimidine = atof(option_value);
    } else if (strcmp(option_name, "transition-transversion") == 0){
        transition_transversion = atof(option_value);
    } else if (strcmp(option_name, "bg") == 0){
      bg_rate = atof(option_value);
    } else if (strcmp(option_name, "fg") == 0){
      fg_rate = atof(option_value);
    } else if (strcmp(option_name, "motif") == 0){
        if (selected_motifs == NULL) {
          selected_motifs = new_string_list();
        }
       add_string(option_value, selected_motifs);
    } else if (strcmp(option_name, "motif-name") == 0){
        motif_name = option_value;
    } else if (strcmp(option_name, "bgfile") == 0){
      bg_filename = option_value;
    } else if (strcmp(option_name, "pseudocount") == 0){
        pseudocount = atof(option_value);
    } else if (strcmp(option_name, "verbosity") == 0){
        verbosity = atoi(option_value);
    }
  }

  // Must have tree and motif file names
  if (argc != option_index + 2) {
    fprintf(stderr, "%s", usage);
    exit(EXIT_FAILURE);
  } 

  /**********************************************
   * Read the phylogenetic tree.
   **********************************************/
  char* tree_filename = NULL;
  TREE_T* tree = NULL;
  tree_filename = argv[option_index];
  option_index++;
  tree = read_tree_from_file(tree_filename);

  // get the species names
  STRING_LIST_T* alignment_species = make_leaf_list(tree);
  char *root_label = get_label(tree);	// in case target in center
  if (strlen(root_label)>0) add_string(root_label, alignment_species);
  //write_string_list(" ", alignment_species, stderr);

  // TLB; Convert the tree to a uniform star tree with
  // the target sequence at its center.
  if (ustar_label != NULL) {
    tree = convert_to_uniform_star_tree(tree, ustar_label);
    if (tree == NULL) 
      die("Tree or alignment missing target %s\n", ustar_label);
    if (verbosity >= NORMAL_VERBOSE) {
      fprintf(stderr, 
	"Target %s placed at center of uniform (d=%.3f) star tree:\n", 
          ustar_label, get_total_length(tree) / get_num_children(tree) 
      );
      write_tree(tree, stderr);
    }
  }

  /**********************************************
   * Read the motifs.
   **********************************************/
  char* meme_filename = argv[option_index];
  option_index++;
  int num_motifs = 0; 

  MREAD_T *mread;
  ALPH_T alph;
  ARRAYLST_T *motifs;
  ARRAY_T *bg_freqs;

  mread = mread_create(meme_filename, OPEN_MFILE);
  mread_set_bg_source(mread, bg_filename);
  mread_set_pseudocount(mread, pseudocount);
  // read motifs
  motifs = mread_load(mread, NULL);
  alph = mread_get_alphabet(mread);
  bg_freqs = mread_get_background(mread);
  // check
  if (arraylst_size(motifs) == 0) die("No motifs in %s.", meme_filename);

  

  // TLB; need to resize bg_freqs array to ALPH_SIZE items
  // or copy array breaks in HB mode.  This throws away
  // the freqs for the ambiguous characters;
  int asize = alph_size(alph, ALPH_SIZE);
  resize_array(bg_freqs, asize);

  /**************************************************************
  * Compute probability distributions for each of the selected motifs.
  **************************************************************/
  int motif_index;
  for (motif_index = 0; motif_index < arraylst_size(motifs); motif_index++) {

    MOTIF_T* motif = (MOTIF_T*)arraylst_get(motif_index, motifs);
    char* motif_id = get_motif_id(motif);
    char* bare_motif_id = motif_id;

    // We may have specified on the command line that
    // only certain motifs were to be used.
    if (selected_motifs != NULL) {
      if (*bare_motif_id == '+' || *bare_motif_id == '-') {
        // The selected  motif id won't included a strand indicator.
        bare_motif_id++;
      }
      if (have_string(bare_motif_id, selected_motifs) == FALSE) {
        continue;
      }
    }

    if (verbosity >= NORMAL_VERBOSE) {
      fprintf(
        stderr, 
        "Using motif %s of width %d.\n",
        motif_id, get_motif_length(motif)
      );
    }

    // Build an array of evolutionary models for each position in the motif.
    EVOMODEL_T** models = make_motif_models(
      motif, 
      bg_freqs,
      model_type,
      fg_rate, 
      bg_rate, 
      purine_pyrimidine, 
      transition_transversion, 
      use_halpern_bruno
    );

    // Get the frequencies under the background model (row 0) 
    // and position-dependent scores (rows 1..w)
    // for each possible alignment column.
    MATRIX_T* pssm_matrix = build_alignment_pssm_matrix(
      alph,
      alignment_species,
      get_motif_length(motif) + 1, 
      models, 
      tree, 
      gap_support
    );
    ARRAY_T* alignment_col_freqs = allocate_array(get_num_cols(pssm_matrix)); 
    copy_array(get_matrix_row(0, pssm_matrix), alignment_col_freqs);
    remove_matrix_row(0, pssm_matrix);		// throw away first row
    //print_col_frequencies(alph, alignment_col_freqs);

    //
    // Get the position-dependent null model alignment column frequencies
    //
    int w = get_motif_length(motif);
    int ncols = get_num_cols(pssm_matrix); 
    MATRIX_T* pos_dep_bkg = allocate_matrix(w, ncols);
    for (i=0; i<w; i++) {
      // get the evo model corresponding to this column of the motif
      // and store it as the first evolutionary model.
      myfree(models[0]);
      // Use motif PSFM for equilibrium freqs. for model.
      ARRAY_T* site_specific_freqs = allocate_array(asize);
      int j = 0;
      for(j = 0; j < asize; j++) {
	double value = get_matrix_cell(i, j, get_motif_freqs(motif));
	set_array_item(j, value, site_specific_freqs);
      }
      if (use_halpern_bruno == FALSE) {
	models[0] = make_model(
	  model_type,
	  fg_rate,
	  transition_transversion,
	  purine_pyrimidine,
	  site_specific_freqs,
          NULL
	);
      } else {
        models[0] = make_model(
	  model_type,
	  fg_rate,
	  transition_transversion,
	  purine_pyrimidine,
	  bg_freqs,
	  site_specific_freqs
	);
      }
      // get the alignment column frequencies using this model
      MATRIX_T* tmp_pssm_matrix = build_alignment_pssm_matrix(
        alph,
	alignment_species,
	2,				// only interested in freqs under bkg
	models, 
	tree, 
	gap_support
      );
      // assemble the position-dependent background alignment column freqs.
      set_matrix_row(i, get_matrix_row(0, tmp_pssm_matrix), pos_dep_bkg);
      // chuck the pssm (not his real name)
      free_matrix(tmp_pssm_matrix);
    }

    //
    // Compute and print the score distribution under the background model
    // and under the (position-dependent) motif model.
    //
    int range = 10000;	// 10^4 gives same result as 10^5, but 10^3 differs

    // under background model
    PSSM_T* pssm = build_matrix_pssm(alph, pssm_matrix, alignment_col_freqs, range);

    // under position-dependent background (motif) model
    PSSM_T* pssm_pos_dep = build_matrix_pssm(alph, pssm_matrix, alignment_col_freqs, range);
    get_pv_lookup_pos_dep(
      pssm_pos_dep, 
      pos_dep_bkg, 
      NULL // no priors used
    );

    // print FP and FN distributions
    int num_items = get_pssm_pv_length(pssm_pos_dep);
    for (i=0; i<num_items; i++) {
      double pvf = get_pssm_pv(i, pssm);
      double pvt = get_pssm_pv(i, pssm_pos_dep);
      double fpr = pvf;
      double fnr = 1 - pvt;
      if (fpr >= 0.99999 || fnr == 0) continue;
      printf("%s score %d FPR %.3g FNR %.3g\n", motif_id, i, fpr, fnr);
    }

    // free stuff
    free_pssm(pssm);
    free_pssm(pssm_pos_dep);
    if (models != NULL) {
      int model_index;
      int num_models = get_motif_length(motif) + 1;
      for (model_index = 0; model_index < num_models; model_index++) {
        free_model(models[model_index]);
      }
      myfree(models);
    }

  } // motif

  arraylst_destroy(destroy_motif, motifs);

  /**********************************************
   * Clean up.
   **********************************************/
  // TLB may have encountered a memory corruption bug here
  // CEG has not been able to reproduce it. valgrind says all is well.
  free_array(bg_freqs);
  free_tree(TRUE, tree);
  free_string_list(selected_motifs);

  return(0);
} // main
예제 #11
0
//-----------------------------------------------------------------------------
int main()
{
  {
    // Generate some data
    plJointDistribution orig = make_model();
    generate_data(orig, "model_asia.csv", 10000);
    plCSVDataDescriptor dataset("model_asia.csv", orig.get_variables());
    plNodeScoreBIC node_score(dataset);
    std::cout << "Original model: " << orig << std::endl
              << "BIC score of the original model on the whole dataset: "
              << node_score(orig) << std::endl;
    save("model_asia", orig);
  }

  plSymbol A("A", PL_BINARY_TYPE); // visit to Asia?
  plSymbol S("S", PL_BINARY_TYPE); // Smoker?
  plSymbol T("T", PL_BINARY_TYPE); // has Tuberculosis
  plSymbol L("L", PL_BINARY_TYPE); // has Lung cancer
  plSymbol B("B", PL_BINARY_TYPE); // has Bronchitis
  plSymbol O("O", PL_BINARY_TYPE); // has tuberculosis Or cancer
  plSymbol X("X", PL_BINARY_TYPE); // positive X-Ray
  plSymbol D("D", PL_BINARY_TYPE); // Dyspnoea?

  plVariablesConjunction variables = A^S^T^L^B^O^X^D;
  plCSVDataDescriptor dataset("model_asia.csv", variables);
  plStructureLearner learner(variables);

  // Learn the dependancy structure between our variables from the
  // dataset, using the Directed Maximum Spanning Tree algorithm.
  unsigned int root_index = 0; // using 'A' as the root node.
  std::vector<plSymbol> order;
  plEdgeScoreBIC edge_score(dataset);
  bool result = learner.DMST(edge_score, order, variables[root_index]);
  plJointDistribution result_dmst = learner.get_joint_distribution(dataset);

  // Apply the GS algorithm with BIC score on the same dataset.
  // Use the output of the DMST algo as a starting point.
  plNodeScoreBIC node_score(dataset);
  learner.GS(node_score);
  plJointDistribution result_gs = learner.get_joint_distribution(dataset);

  std::cout << "DMST-BIC obtained the following model: " << result_dmst
            << std::endl
            << "BIC score of the learned model on the whole dataset: "
            << node_score(result_dmst) << std::endl;

  std::cout << "DMST + GS obtained the following model: " << result_gs
            << std::endl
            << "BIC score of the learned model on the whole dataset: "
            << node_score(result_gs) << std::endl;

  save("dmst_bic", result_dmst);
  save("dmst-gs_bic", result_gs);

  // On Windows (Visual C++, MinGW) only.
#if defined(WIN32) || defined(_WIN32)
  std::cout << "Press any key to terminate..." << std::endl;
  getchar();
#endif

  return 0;
}
예제 #12
0
regression_serv::regression_serv(const framework::server_argv & a)
  :jubatus_serv(a)
{
  gresser_.set_model(make_model());
  register_mixable(framework::mixable_cast(&gresser_));
}
예제 #13
0
파일: testtreefocus.c 프로젝트: 3v1n0/gtk
int
main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *vbox;
  GtkWidget *scrolled_window;
  GtkWidget *tree_view;
  GtkTreeModel *model;
  GtkCellRenderer *renderer;
  gint col_offset;
  GtkTreeViewColumn *column;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Card planning sheet");
  g_signal_connect (window, "destroy", gtk_main_quit, NULL);
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
  gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Jonathan's Holiday Card Planning Sheet"), FALSE, FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);

  model = make_model ();
  tree_view = gtk_tree_view_new_with_model (model);
  gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
			       GTK_SELECTION_MULTIPLE);
  renderer = gtk_cell_renderer_text_new ();
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
							    -1, "Holiday",
							    renderer,
							    "text", HOLIDAY_COLUMN, NULL);
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);

  /* Alex Column */
  renderer = gtk_cell_renderer_toggle_new ();
  g_signal_connect (renderer, "toggled", G_CALLBACK (alex_toggled), model);

  g_object_set (renderer, "xalign", 0.0, NULL);
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
							    -1, "Alex",
							    renderer,
							    "active", ALEX_COLUMN,
							    "visible", VISIBLE_COLUMN,
							    "activatable", WORLD_COLUMN,
							    NULL);
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);

  /* Havoc Column */
  renderer = gtk_cell_renderer_toggle_new ();
  g_signal_connect (renderer, "toggled", G_CALLBACK (havoc_toggled), model);

  g_object_set (renderer, "xalign", 0.0, NULL);
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
							    -1, "Havoc",
							    renderer,
							    "active", HAVOC_COLUMN,
							    "visible", VISIBLE_COLUMN,
							    NULL);
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);

  /* Tim Column */
  renderer = gtk_cell_renderer_toggle_new ();
  g_signal_connect (renderer, "toggled", G_CALLBACK (tim_toggled), model);

  g_object_set (renderer, "xalign", 0.0, NULL);
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Tim",
					       renderer,
					       "active", TIM_COLUMN,
					       "visible", VISIBLE_COLUMN,
					       "activatable", WORLD_COLUMN,
					       NULL);
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);

  /* Owen Column */
  renderer = gtk_cell_renderer_toggle_new ();
  g_signal_connect (renderer, "toggled", G_CALLBACK (owen_toggled), model);
  g_object_set (renderer, "xalign", 0.0, NULL);
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Owen",
					       renderer,
					       "active", OWEN_COLUMN,
					       "visible", VISIBLE_COLUMN,
					       NULL);
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);

  /* Owen Column */
  renderer = gtk_cell_renderer_toggle_new ();
  g_signal_connect (renderer, "toggled", G_CALLBACK (dave_toggled), model);
  g_object_set (renderer, "xalign", 0.0, NULL);
  col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Dave",
					       renderer,
					       "active", DAVE_COLUMN,
					       "visible", VISIBLE_COLUMN,
					       NULL);
  column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), col_offset - 1);
  gtk_tree_view_column_set_cell_data_func (column, renderer, set_indicator_size, NULL, NULL);
  gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED);
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 50);
  gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);

  gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);

  g_signal_connect (tree_view, "realize",
		    G_CALLBACK (gtk_tree_view_expand_all),
		    NULL);
  gtk_window_set_default_size (GTK_WINDOW (window),
			       650, 400);
  gtk_widget_show_all (window);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Model");
  g_signal_connect (window, "destroy", gtk_main_quit, NULL);
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
  gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("The model revealed"), FALSE, FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);


  tree_view = gtk_tree_view_new_with_model (model);
  g_object_unref (model);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Holiday Column",
					       gtk_cell_renderer_text_new (),
					       "text", 0, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Alex Column",
					       gtk_cell_renderer_text_new (),
					       "text", 1, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Havoc Column",
					       gtk_cell_renderer_text_new (),
					       "text", 2, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Tim Column",
					       gtk_cell_renderer_text_new (),
					       "text", 3, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Owen Column",
					       gtk_cell_renderer_text_new (),
					       "text", 4, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Dave Column",
					       gtk_cell_renderer_text_new (),
					       "text", 5, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "Visible Column",
					       gtk_cell_renderer_text_new (),
					       "text", 6, NULL);

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
					       -1, "World Holiday",
					       gtk_cell_renderer_text_new (),
					       "text", 7, NULL);

  g_signal_connect (tree_view, "realize",
		    G_CALLBACK (gtk_tree_view_expand_all),
		    NULL);
			   
  gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);


  gtk_window_set_default_size (GTK_WINDOW (window),
			       650, 400);

  gtk_widget_show_all (window);
  gtk_main ();

  return 0;
}
예제 #14
0
END_TEST

void model_setup(void)
{
    reset_errno();
    model = make_model();
    assert_not_null(model);
    assert_noerr();

    reset_errno();
    Mapping *root = make_mapping_node();
    assert_noerr();
    assert_not_null(root);

    reset_errno();
    Scalar *foo1 = make_scalar_node((uint8_t *)"foo1", 4, SCALAR_STRING);
    assert_noerr();
    assert_not_null(foo1);
    reset_errno();
    Scalar *one_point_five = make_scalar_node((uint8_t *)"1.5", 4, SCALAR_REAL);
    assert_noerr();
    assert_not_null(one_point_five);
    reset_errno();
    Sequence *one_value = make_sequence_node();
    assert_noerr();
    assert_not_null(one_value);
    reset_errno();
    sequence_add(one_value, node(foo1));
    assert_noerr();
    reset_errno();
    sequence_add(one_value, node(one_point_five));
    assert_noerr();
    reset_errno();
    mapping_put(root, (uint8_t *)"one", 3, node(one_value));
    assert_noerr();
    
    reset_errno();
    Scalar *two_value = make_scalar_node((uint8_t *)"foo2", 4, SCALAR_STRING);
    assert_noerr();
    assert_not_null(two_value);
    reset_errno();
    mapping_put(root, (uint8_t *)"two", 3, node(two_value));
    assert_noerr();
    
    reset_errno();
    Scalar *three_value = make_scalar_node((uint8_t *)"false", 5, SCALAR_BOOLEAN);
    assert_noerr();
    assert_not_null(three_value);
    reset_errno();
    mapping_put(root, (uint8_t *)"three", 5, node(three_value));
    assert_noerr();

    reset_errno();
    Scalar *four_value = make_scalar_node((uint8_t *)"true", 4, SCALAR_BOOLEAN);
    assert_noerr();
    assert_not_null(four_value);
    reset_errno();
    mapping_put(root, (uint8_t *)"four", 4, node(four_value));
    assert_noerr();

    reset_errno();
    Document *doc = make_document_node();
    document_set_root(doc, node(root));
    assert_noerr();
    assert_not_null(doc);
    reset_errno();
    model_add(model, doc);
    assert_noerr();
}