Ejemplo n.º 1
0
  AxisRow(Model *model, int axis) :
    m_inhibit_update(false), m_model(model), m_axis(axis)
  {
    add(*(new Gtk::Label(axis_names[axis])));
    Gtk::Button *home = new Gtk::Button("Home");
    home->signal_clicked().connect
      (sigc::mem_fun (*this, &AxisRow::home_clicked));
    add (*home);

    add_nudge_button (-10.0);
    add_nudge_button (-1.0);
    add_nudge_button (-0.1);
    m_target = new Gtk::SpinButton();
    m_target->set_digits (1);
    m_target->set_increments (0.1, 1);
    m_target->set_range(-200.0, +200.0);
    m_target->set_value(0.0);
    add (*m_target);
    m_target->signal_value_changed().connect
      (sigc::mem_fun(*this, &AxisRow::spin_value_changed));

    add_nudge_button (+0.1);
    add_nudge_button (+1.0);
    add_nudge_button (+10.0);
  }
Ejemplo n.º 2
0
  TempRow(Model *model, TempType type) :
    m_model(model), m_type(type)
  {
    static const char *names[] = { "Nozzle", "Bed" };

    add(*(new Gtk::Label(names[type])));
    Gtk::ToggleButton *pOn = new Gtk::ToggleButton("Heat On");
    pOn->signal_toggled().connect
      (sigc::bind (sigc::mem_fun (*this, &TempRow::heat_toggled), pOn));
    add(*pOn);
    m_temp = new Gtk::Label();
    add (*m_temp);
    add(*(new Gtk::Label("Target Temperature (°C)")));
    m_target = new Gtk::SpinButton();
    m_target->set_increments (1, 5);
    m_target->set_range(25.0, 256.0);
    switch (type) {
    case TEMP_NOZZLE:
    default:
      m_target->set_value(200.0);
      break;
    case TEMP_BED:
      m_target->set_value(100.0);
      break;
    }
    add (*m_target);
  }
Ejemplo n.º 3
0
  TempRow(Model *model, Printer *printer, TempType type) :
    m_model(model), printer(printer), m_type(type)
  {
    static const char *names[] = { N_("Nozzle"), N_("Bed") };

    add(*(new Gtk::Label(_(names[type]))));
    Gtk::ToggleButton *pOn = new Gtk::ToggleButton(_("Heat On"));
    pOn->signal_toggled().connect
      (sigc::bind (sigc::mem_fun (*this, &TempRow::heat_toggled), pOn));
    add(*pOn);
    add(*(new Gtk::Label(_("Temp. (°C)"))));
    m_temp = new Gtk::Label(_("<unknown>"));
    add (*m_temp);

    add(*(new Gtk::Label(_("Target:"))));
    m_target = new Gtk::SpinButton();
    m_target->set_increments (1, 5);
    m_target->set_range(25.0, 256.0);
    switch (type) {
    case TEMP_NOZZLE:
    default:
      m_target->set_value(225.0);
      break;
    case TEMP_BED:
      m_target->set_value(60.0);
      break;
    }
    add (*m_target);
  }
Ejemplo n.º 4
0
/*! Constructor
 * \param[in]	el	the configuration element to display
 * \param[in]	differ	shall the changes be applied later using apply_changes()?
 */
ConfigElement::ConfigElement(crn::ConfigElement &el, bool differ):
	value(el.GetValue()),
	tmpvalue(el.GetValue())
{
	if (!value)
		throw crn::ExceptionUninitialized(_("The element was not initialized."));
	if (differ)
		tmpvalue = crn::Clone(*value);

	if (std::dynamic_pointer_cast<crn::Int>(tmpvalue))
		typ = U"Int";
	else if (std::dynamic_pointer_cast<crn::Real>(tmpvalue))
		typ = U"Real";
	else if (std::dynamic_pointer_cast<crn::Prop3>(tmpvalue))
		typ = U"Prop3";
	else if (std::dynamic_pointer_cast<crn::String>(tmpvalue))
		typ = U"String";
	else if (std::dynamic_pointer_cast<crn::StringUTF8>(tmpvalue))
		typ = U"StringUTF8";
	else if (std::dynamic_pointer_cast<crn::Path>(tmpvalue))
		typ = U"Path";

	Gtk::Label *lab = Gtk::manage(new Gtk::Label(el.GetName().CStr()));
	lab->show();
	pack_start(*lab, false, true, 2);

	if (typ == U"Prop3")
	{
		Prop3 *p = Gtk::manage(new Prop3(Gtk::ICON_SIZE_BUTTON, el.GetValue<crn::Prop3>()));
		p->signal_value_changed().connect(sigc::mem_fun(this, &ConfigElement::on_p3_changed));
		p->show();
		pack_start(*p, true, true, 2);
	}
	else if (!el.GetAllowedValues().IsEmpty())
	{ // any Int, Real, String, StringUTF8 or Path
		Gtk::ComboBoxText *cb = Gtk::manage(new Gtk::ComboBoxText);
		const std::vector<crn::StringUTF8> values(el.GetAllowedValues<crn::StringUTF8>());
		for (const crn::StringUTF8 &val : values)
#ifdef CRN_USING_GTKMM3
			cb->append(val.CStr());
#else /* CRN_USING_GTKMM3 */
			cb->append_text(val.CStr());
#endif /* CRN_USING_GTKMM3 */
		cb->set_active_text(el.GetValue<crn::StringUTF8>().CStr());
		cb->signal_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_combo_changed), cb));
		cb->show();
		pack_start(*cb, true, true, 2);
	}
	else if (typ == U"Int")
	{
		if (el.HasMinValue() && el.HasMaxValue())
		{ // has finite range, use a slider
#ifdef CRN_USING_GTKMM3
			auto *s = Gtk::manage(new Gtk::Scale(Gtk::ORIENTATION_HORIZONTAL));
			s->set_range(el.GetMinValue<int>(), el.GetMaxValue<int>() + 1);
			s->set_increments(1, 1);
#else
			Gtk::HScale *s = Gtk::manage(new Gtk::HScale(el.GetMinValue<int>(), el.GetMaxValue<int>() + 1, 1));
#endif
			s->set_value(el.GetValue<int>());
			s->signal_value_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_range_changed), s));
			s->show();
			pack_start(*s, true, true, 2);
		}
		else
		{ // has at least one infinite (maxed) bound, use a spin button
			Gtk::SpinButton *s = Gtk::manage(new Gtk::SpinButton);
			int m = std::numeric_limits<int>::min(), M = std::numeric_limits<int>::max();
			if (el.HasMinValue())
				m = el.GetMinValue<int>();
			if (el.HasMaxValue())
				M = el.GetMaxValue<int>();
			s->set_range(m, M);
			s->set_increments(1, 10);
			s->set_value(el.GetValue<int>());
			s->signal_value_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_spin_changed), s));
			s->show();
			pack_start(*s, true, true, 2);
		}
	}
	else if (typ == U"Real")
	{
		if (el.HasMinValue() && el.HasMaxValue())
		{ // has finite range, use a slider
#ifdef CRN_USING_GTKMM3
			auto *s = Gtk::manage(new Gtk::Scale(Gtk::ORIENTATION_HORIZONTAL));
			s->set_range(el.GetMinValue<double>(), el.GetMaxValue<double>() + 0.01);
			s->set_increments(0.01, 0.01);
#else
			Gtk::HScale *s = Gtk::manage(new Gtk::HScale(el.GetMinValue<double>(), el.GetMaxValue<double>() + 0.01, 0.01));
#endif
			s->set_digits(2);
			s->set_value(el.GetValue<double>());
			s->signal_value_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_range_changed), s));
			s->show();
			pack_start(*s, true, true, 2);
		}
		else
		{ // has at least one infinite (maxed) bound, use a spin button
			Gtk::SpinButton *s = Gtk::manage(new Gtk::SpinButton(0, 2));
			double m = -std::numeric_limits<double>::max(), M = std::numeric_limits<double>::max();
			if (el.HasMinValue())
				m = el.GetMinValue<double>();
			if (el.HasMaxValue())
				M = el.GetMaxValue<double>();
			s->set_range(m, M);
			s->set_increments(0.01, 1);
			s->set_value(el.GetValue<double>());
			s->signal_value_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_spin_changed), s));
			s->show();
			pack_start(*s, true, true, 2);
		}
	}
	else // string types
	{
		Gtk::Entry *e = Gtk::manage(new Gtk::Entry);
		e->set_text(el.GetValue<crn::StringUTF8>().CStr());
		e->signal_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_entry_changed), e));
		e->show();
		pack_start(*e, true, true, 2);
	}
	lab = Gtk::manage(new Gtk::Label("?"));
	lab->show();
	lab->set_tooltip_text(el.GetDescription().CStr());
	pack_start(*lab, false, true, 2);
}
Ejemplo n.º 5
0
void DimensionManager::addDimension() {
    Gtk::Dialog dialog(_("New Dimension"), true /*modal*/);
    // add dimension type combo box to the dialog
    Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel);
    for (int i = 0x01; i < 0xff; i++) {
        Glib::ustring sType =
            dimTypeAsString(static_cast<gig::dimension_t>(i));
        if (sType.find("Unknown") != 0) {
            Gtk::TreeModel::Row row = *(refComboModel->append());
            row[comboModel.m_type_id]   = i;
            row[comboModel.m_type_name] = sType;
        }
    }
    Gtk::Table table(2, 2);
    Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START);
    Gtk::ComboBox comboDimType;
    comboDimType.set_model(refComboModel);
    comboDimType.pack_start(comboModel.m_type_id);
    comboDimType.pack_start(comboModel.m_type_name);
    Gtk::Label labelZones(_("Zones:"), Gtk::ALIGN_START);
    table.attach(labelDimType, 0, 1, 0, 1);
    table.attach(comboDimType, 1, 2, 0, 1);
    table.attach(labelZones, 0, 1, 1, 2);
    dialog.get_vbox()->pack_start(table);

    // number of zones: use a combo box with fix values for gig
    // v2 and a spin button for v3
    Gtk::ComboBoxText comboZones;
    Gtk::SpinButton spinZones;
    bool version2 = false;
    if (region) {
        gig::File* file = (gig::File*)region->GetParent()->GetParent();
        version2 = file->pVersion && file->pVersion->major == 2;
    }
    if (version2) {
        for (int i = 1; i <= 5; i++) {
            char buf[3];
            sprintf(buf, "%d", 1 << i);
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 24) || GTKMM_MAJOR_VERSION < 2
            comboZones.append_text(buf);
#else
            comboZones.append(buf);
#endif
        }
        table.attach(comboZones, 1, 2, 1, 2);
    } else {
        spinZones.set_increments(1, 8);
        spinZones.set_numeric(true);
        spinZones.set_range(2, 128);
        spinZones.set_value(2);
        table.attach(spinZones, 1, 2, 1, 2);
    }

    dialog.add_button(_("_OK"), 0);
    dialog.add_button(_("_Cancel"), 1);
    dialog.show_all_children();

    if (!dialog.run()) { // OK selected ...
        Gtk::TreeModel::iterator iterType = comboDimType.get_active();
        if (!iterType) return;
        Gtk::TreeModel::Row rowType = *iterType;
        if (!rowType) return;
        int iTypeID = rowType[comboModel.m_type_id];
        gig::dimension_t type = static_cast<gig::dimension_t>(iTypeID);
        gig::dimension_def_t dim;
        dim.dimension = type;

        if (version2) {
            if (comboZones.get_active_row_number() < 0) return;
            dim.bits = comboZones.get_active_row_number() + 1;
            dim.zones = 1 << dim.bits;
        } else {
            dim.zones = spinZones.get_value_as_int();
            dim.bits = zoneCountToBits(dim.zones);
        }

        // assemble the list of regions where the selected dimension shall be
        // added to
        std::vector<gig::Region*> vRegions;
        if (allRegions()) {
            gig::Instrument* instr = (gig::Instrument*)region->GetParent();
            for (gig::Region* rgn = instr->GetFirstRegion(); rgn; rgn = instr->GetNextRegion()) {
                if (!rgn->GetDimensionDefinition(type)) vRegions.push_back(rgn);
            }
        } else vRegions.push_back(region);
            
        std::set<Glib::ustring> errors;

        for (uint iRgn = 0; iRgn < vRegions.size(); ++iRgn) {
            gig::Region* region = vRegions[iRgn];
            try {
                printf(
                    "Adding dimension (type=0x%x, bits=%d, zones=%d)\n",
                    dim.dimension, dim.bits, dim.zones
                );
                // notify everybody that we're going to update the region
                region_to_be_changed_signal.emit(region);
                // add the new dimension to the region
                // (implicitly creates new dimension regions)
                region->AddDimension(&dim);
                // let everybody know there was a change
                region_changed_signal.emit(region);
            } catch (RIFF::Exception e) {
                // notify that the changes are over (i.e. to avoid dead locks)
                region_changed_signal.emit(region);
                Glib::ustring txt = _("Could not add dimension: ") + e.Message;
                if (vRegions.size() == 1) {
                    // show error message directly
                    Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
                    msg.run();
                } else {
                    // remember error, they are shown after all regions have been processed
                    errors.insert(txt);
                }
            }
        }
        // update all GUI elements
        refreshManager();

        if (!errors.empty()) {
            Glib::ustring txt = _(
                "The following errors occurred while trying to create the dimension on all regions:"
            );
            txt += "\n\n";
            for (std::set<Glib::ustring>::const_iterator it = errors.begin();
                 it != errors.end(); ++it)
            {
                txt += "-> " + *it + "\n";
            }
            txt += "\n";
            txt += _(
                "You might also want to check the console for further warnings and "
                "error messages."
            );
            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
            msg.run();
        }
    }
}
Ejemplo n.º 6
0
void Settings::connect_to_ui (Builder &builder)
{
  // connect gcode configurable text sections
  GCode.m_impl->connectToUI (builder);

  // first setup ranges on spinbuttons ...
  for (uint i = 0; i < G_N_ELEMENTS (spin_ranges); i++) {
    Gtk::SpinButton *spin = NULL;
    builder->get_widget (spin_ranges[i].widget, spin);
    if (!spin)
      std::cerr << "missing spin button of name '" << spin_ranges[i].widget << "'\n";
    else {
      spin->set_range (spin_ranges[i].min, spin_ranges[i].max);
      spin->set_increments (spin_ranges[i].inc, spin_ranges[i].inc_page);
    }
  }
  // Ranges on [HV]Range widgets
  for (uint i = 0; i < G_N_ELEMENTS (ranges); i++) {
    Gtk::Range *range = NULL;
    builder->get_widget (ranges[i].widget, range);
    if (!range)
      std::cerr << "missing range slider of name '" << ranges[i].widget << "'\n";
    else {
      range->set_range (ranges[i].min, ranges[i].max);
      range->set_increments (ranges[i].inc, ranges[i].inc_page);
    }
  }

  // connect widget / values from our table
  for (uint i = 0; i < G_N_ELEMENTS (settings); i++) {
    const char *glade_name = settings[i].glade_name;

    if (!glade_name)
      continue;

    switch (settings[i].type) {
    case T_BOOL: {
      Gtk::CheckButton *check = NULL;
      builder->get_widget (glade_name, check);
      if (check)
	check->signal_toggled().connect
          (sigc::bind(sigc::bind(sigc::mem_fun(*this, &Settings::get_from_gui), i), builder));
      break;
    }
    case T_INT:
    case T_FLOAT: {
      Gtk::Widget *w = NULL;
      builder->get_widget (glade_name, w);
      if (!w) {
        std::cerr << "Missing user interface item " << glade_name << "\n";
        break;
      }
      Gtk::SpinButton *spin = dynamic_cast<Gtk::SpinButton *>(w);
      if (spin) {
        spin->signal_value_changed().connect
          (sigc::bind(sigc::bind(sigc::mem_fun(*this, &Settings::get_from_gui), i), builder));
        break;
      }
      Gtk::Range *range = dynamic_cast<Gtk::Range *>(w);
      if (range) {
        range->signal_value_changed().connect
          (sigc::bind(sigc::bind(sigc::mem_fun(*this, &Settings::get_from_gui), i), builder));
        break;
      }
      break;
    }
    case T_STRING: // unimplemented
      break;
    default:
      break;
    }
  }

  // Slicing.ShrinkQuality
  Gtk::ComboBox *combo = NULL;
  builder->get_widget ("Slicing.ShrinkQuality", combo);
  if (combo) {
    Glib::RefPtr<Gtk::ListStore> model;
    Gtk::TreeModelColumnRecord record;
    Gtk::TreeModelColumn<Glib::ustring> column;
    record.add (column);
    model = Gtk::ListStore::create(record);
    model->append()->set_value (0, Glib::ustring("Fast"));
    model->append()->set_value (0, Glib::ustring("Logick"));
    combo->set_model (model);
    combo->pack_start (column);

    combo->signal_changed().connect
      (sigc::bind(sigc::mem_fun(*this, &Settings::get_shrink_from_gui), builder));
  }

  // Colour selectors
  for (uint i = 0; i < G_N_ELEMENTS (colour_selectors); i++) {
    const char *glade_name = colour_selectors[i].glade_name;
    Gdk::Color c;
    Gtk::ColorButton *w = NULL;

    if (!glade_name)
      continue;

    builder->get_widget (glade_name, w);
    if (!w) continue;

    w->signal_color_set().connect
          (sigc::bind(sigc::bind(sigc::mem_fun(*this,
            &Settings::get_colour_from_gui), i), builder));
  }

  // Serial port speed
  Gtk::ComboBoxEntry *portspeed = NULL;
  builder->get_widget ("Hardware.SerialSpeed", portspeed);
  if (portspeed) {
    const guint32 speeds[] = {
        9600, 19200, 38400, 57600, 115200, 230400, 576000
    };

    Glib::RefPtr<Gtk::ListStore> model;
    Gtk::TreeModelColumnRecord record;
    Gtk::TreeModelColumn<Glib::ustring> column;
    record.add (column);
    model = Gtk::ListStore::create(record);
    for (guint i = 0; i < G_N_ELEMENTS(speeds); i++) {
      std::ostringstream val;
      val << speeds[i];
      model->append()->set_value (0, Glib::ustring(val.str()));
    }
    portspeed->set_model (model);
    portspeed->set_text_column (0);

    portspeed->signal_changed().connect
      (sigc::bind(sigc::mem_fun(*this, &Settings::get_port_speed_from_gui), builder));
  }

  /* Update UI with defaults */
  m_signal_update_settings_gui.emit();
}
Ejemplo n.º 7
0
    Argument::Argument (const MR::Argument& argument) :
      arg (argument),
      description_label (arg.lname)
    {
      set_border_width (GUI_SPACING);
      set_spacing (GUI_SPACING);
      pack_start (description_label, Gtk::PACK_SHRINK);

      switch (arg.type) {
        case Integer: 
          {
            Gtk::SpinButton* sb = manage (new Gtk::SpinButton);
            sb->set_value (arg.extra_info.i.def);
            sb->set_range (arg.extra_info.i.min, arg.extra_info.i.max);
            sb->set_increments (1, 10);
            pack_start (*sb);
            widget = (void*) sb;
          }
          break;
        case Float:
          {
            Gtk::SpinButton* sb = manage (new Gtk::SpinButton);
            sb->set_range (arg.extra_info.f.min, arg.extra_info.f.max);
            sb->set_increments (
                1e-4 *(arg.extra_info.f.max-arg.extra_info.f.min), 
                1e-2 *(arg.extra_info.f.max-arg.extra_info.f.min));
            sb->set_digits (4);
            sb->set_value (arg.extra_info.f.def);
            pack_start (*sb);
            widget = (void*) sb;
          }
          break;
        case Text:
        case IntSeq:
        case FloatSeq: 
          { 
            Gtk::Entry* entry = manage (new Gtk::Entry);
            pack_start (*entry);
            widget = (void*) entry;
          }
          break;
        case ArgFile:
        case ImageIn:
        case ImageOut:
          { 
            Gtk::Entry* entry = manage (new Gtk::Entry);
            Gtk::Button* browse = manage (new Gtk::Button (Gtk::Stock::OPEN));
            browse->signal_clicked().connect (sigc::mem_fun (*this, &Argument::on_browse));
            pack_start (*entry);
            pack_start (*browse, Gtk::PACK_SHRINK);
            widget = (void*) entry;
          }
          break;
        case Choice:
          {
            Gtk::ComboBoxText* choice = manage (new Gtk::ComboBoxText);
            for (const gchar** p = arg.extra_info.choice; *p; p++) choice->append_text (*p);
            choice->set_active (0);
            pack_start (*choice);
            widget = (void*) choice;
          }
          break;
        default: break;
      }

      set_tooltip_text (arg.desc);
    }