Exemplo n.º 1
0
static GtkWidget*
grain_stats_add_aux_button(GtkWidget *hbox,
                           const gchar *stock_id,
                           const gchar *tooltip)
{
    GtkTooltips *tips;
    GtkWidget *button;

    tips = gwy_app_get_tooltips();
    button = gtk_button_new();
    gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
    gtk_tooltips_set_tip(tips, button, tooltip, NULL);
    gtk_container_add(GTK_CONTAINER(button),
                      gtk_image_new_from_stock(stock_id,
                                               GTK_ICON_SIZE_SMALL_TOOLBAR));
    gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);

    return button;
}
Exemplo n.º 2
0
/**
 * gwy_tool_add_hide_button:
 * @tool: A tool.
 * @set_default: Whether hide should become the default tool dialog response.
 *
 * Adds a Hide button to a tool dialog.
 *
 * All tools should have a Hide button added by this method.  The reason why
 * it is not added automatically is because the usual placement of the Hide
 * button is next to the execution button (Apply), which is not present
 * for informational-only tools.  In that case Hide should become the default
 * dialog button.
 **/
void
gwy_tool_add_hide_button(GwyTool *tool,
                         gboolean set_default)
{
    GtkAccelGroup *accelgroup;
    GtkTooltips *tips;
    GtkWidget *button;

    g_return_if_fail(GWY_IS_TOOL(tool));

    tips = gwy_app_get_tooltips();
    button = gtk_dialog_add_button(GTK_DIALOG(tool->dialog), _("Hide"),
                                   GTK_RESPONSE_DELETE_EVENT);
    gtk_tooltips_set_tip(tips, button, _("Hide tool dialog (Esc)"), NULL);
    if (set_default)
        gtk_dialog_set_default_response(GTK_DIALOG(tool->dialog),
                                        GTK_RESPONSE_DELETE_EVENT);

    accelgroup = gtk_accel_group_new();
    gtk_window_add_accel_group(GTK_WINDOW(tool->dialog), accelgroup);
    gtk_widget_add_accelerator(button, "activate", accelgroup,
                               GDK_Escape, 0, 0);
    g_object_unref(accelgroup);
}
Exemplo n.º 3
0
/**
 * gwy_app_recent_file_list_new:
 *
 * Creates document history browser.
 *
 * There should be at most one document history browser, so this function
 * fails if it already exists.
 *
 * Returns: The newly created document history browser window.
 **/
GtkWidget*
gwy_app_recent_file_list_new(void)
{
    GtkWidget *vbox, *filterbox, *buttonbox, *list, *scroll, *button;
    GtkTreeModelFilter *filter;
    GtkTreeSelection *selection;

    g_return_val_if_fail(gcontrols.store, gcontrols.window);
    g_return_val_if_fail(gcontrols.window == NULL, gcontrols.window);

    gcontrols.filter
        = gtk_tree_model_filter_new(GTK_TREE_MODEL(gcontrols.store),
                                    NULL);
    filter = GTK_TREE_MODEL_FILTER(gcontrols.filter);
    gtk_tree_model_filter_set_visible_func(filter,
                                           gwy_app_recent_file_list_filter,
                                           &gcontrols, NULL);

    gcontrols.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(gcontrols.window), _("Document History"));
    gtk_window_set_default_size(GTK_WINDOW(gcontrols.window), 400,
                                3*gdk_screen_height()/4);
    gwy_app_restore_window_position(GTK_WINDOW(gcontrols.window),
                                    "/app/document-history", FALSE);
    gwy_help_add_to_window(GTK_WINDOW(gcontrols.window),
                           "managing-files", "document-history",
                           GWY_HELP_DEFAULT);
    g_signal_connect(gcontrols.window, "unmap",
                     G_CALLBACK(gwy_app_recent_file_list_unmapped), NULL);

    vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(gcontrols.window), vbox);

    scroll = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
    gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);

    list = gwy_app_recent_file_list_construct(&gcontrols);
    gtk_container_add(GTK_CONTAINER(scroll), list);
    g_object_unref(gcontrols.filter);

    filterbox = gwy_app_recent_file_list_filter_construct(&gcontrols);
    gtk_box_pack_start(GTK_BOX(vbox), filterbox, FALSE, FALSE, 0);

    buttonbox = gtk_hbox_new(TRUE, 0);
    gtk_container_set_border_width(GTK_CONTAINER(buttonbox), 2);
    gtk_box_pack_start(GTK_BOX(vbox), buttonbox, FALSE, FALSE, 0);

    gcontrols.prune = gwy_stock_like_button_new(_("_Prune"),
                                                GTK_STOCK_FIND);
    gtk_box_pack_start(GTK_BOX(buttonbox), gcontrols.prune, TRUE, TRUE, 0);
    gtk_tooltips_set_tip(gwy_app_get_tooltips(), gcontrols.prune,
                         _("Remove entries of files that no longer exist"),
                         NULL);
    g_signal_connect_swapped(gcontrols.prune, "clicked",
                             G_CALLBACK(gwy_app_recent_file_list_prune),
                             &gcontrols);

    button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
    gtk_box_pack_start(GTK_BOX(buttonbox), button, TRUE, TRUE, 0);
    gtk_tooltips_set_tip(gwy_app_get_tooltips(), button,
                         _("Close file list"), NULL);
    g_signal_connect_swapped(button, "clicked",
                             G_CALLBACK(gtk_widget_destroy), gcontrols.window);

    gcontrols.open = gtk_button_new_from_stock(GTK_STOCK_OPEN);
    gtk_box_pack_start(GTK_BOX(buttonbox), gcontrols.open, TRUE, TRUE, 0);
    gtk_tooltips_set_tip(gwy_app_get_tooltips(), gcontrols.open,
                         _("Open selected file"), NULL);
    g_signal_connect_swapped(gcontrols.open, "clicked",
                             G_CALLBACK(gwy_app_recent_file_list_open), list);
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
    gtk_widget_set_sensitive(gcontrols.open,
                             gtk_tree_selection_get_selected(selection,
                                                             NULL, NULL));

    g_signal_connect_swapped(gcontrols.window, "destroy",
                             G_CALLBACK(gwy_app_recent_file_list_destroyed),
                             &gcontrols);

    gwy_app_recent_file_list_filter_apply(GTK_ENTRY(gcontrols.filter_glob),
                                          &gcontrols);
    gtk_widget_show_all(vbox);

    return gcontrols.window;
}
Exemplo n.º 4
0
static gboolean
immerse_dialog(ImmerseArgs *args)
{
    ImmerseControls controls;
    GwyContainer *data;
    GtkDialog *dialog;
    GtkWidget *table, *chooser, *hbox, *alignment, *label, *button, *vbox;
    GtkTooltips *tooltips;
    GdkDisplay *display;
    GwyDataField *dfield;
    gint response, row, id;
    gboolean ok;

    memset(&controls, 0, sizeof(ImmerseControls));
    controls.args = args;

    tooltips = gwy_app_get_tooltips();

    controls.dialog = gtk_dialog_new_with_buttons(_("Immerse Detail"),
                                                  NULL, 0, NULL);
    dialog = GTK_DIALOG(controls.dialog);
    button = gtk_dialog_add_button(dialog, _("_Locate"), RESPONSE_ESTIMATE);
    gtk_tooltips_set_tip(tooltips, button,
                         _("Locate detail by full image correlation search"),
                         NULL);
    button = gtk_dialog_add_button(dialog, _("_Improve"), RESPONSE_REFINE);
    gtk_tooltips_set_tip(tooltips, button,
                         _("Improve detail position by "
                           "correlation search in neighborhood"), NULL);
    gtk_dialog_add_button(dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
    gtk_dialog_add_button(dialog, GTK_STOCK_OK, GTK_RESPONSE_OK);
    gtk_dialog_set_default_response(dialog, GTK_RESPONSE_OK);
    gwy_help_add_to_proc_dialog(GTK_DIALOG(dialog), GWY_HELP_DEFAULT);

    hbox = gtk_hbox_new(FALSE, 2);
    gtk_box_pack_start(GTK_BOX(dialog->vbox), hbox, FALSE, FALSE, 4);

    /* Preview */
    data = gwy_app_data_browser_get(args->image.datano);
    id = args->image.id;
    dfield = gwy_container_get_object(data, gwy_app_get_data_key_for_id(id));
    controls.vf
        = gwy_data_field_get_value_format_xy(dfield,
                                             GWY_SI_UNIT_FORMAT_VFMARKUP, NULL);

    controls.mydata = gwy_container_new();
    gwy_container_set_object_by_name(controls.mydata, "/0/data", dfield);
    gwy_app_sync_data_items(data, controls.mydata, id, 0, FALSE,
                            GWY_DATA_ITEM_PALETTE,
                            GWY_DATA_ITEM_MASK_COLOR,
                            GWY_DATA_ITEM_RANGE,
                            0);
    gwy_container_set_boolean_by_name(controls.mydata, "/0/data/realsquare",
                                      TRUE);
    controls.view = create_preview(controls.mydata, 0, PREVIEW_SIZE, FALSE);
    alignment = GTK_WIDGET(gtk_alignment_new(0.5, 0, 0, 0));
    gtk_container_add(GTK_CONTAINER(alignment), controls.view);
    gtk_box_pack_start(GTK_BOX(hbox), alignment, FALSE, FALSE, 4);

    g_signal_connect_after(controls.view, "expose-event",
                           G_CALLBACK(immerse_view_expose), &controls);
    g_signal_connect(controls.view, "button-press-event",
                     G_CALLBACK(immerse_view_button_press), &controls);
    g_signal_connect(controls.view, "button-release-event",
                     G_CALLBACK(immerse_view_button_release), &controls);
    g_signal_connect(controls.view, "motion-notify-event",
                     G_CALLBACK(immerse_view_motion_notify), &controls);

    vbox = gtk_vbox_new(FALSE, 8);
    gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 4);

    /* Parameters table */
    table = gtk_table_new(8, 4, FALSE);
    gtk_table_set_row_spacings(GTK_TABLE(table), 2);
    gtk_table_set_col_spacings(GTK_TABLE(table), 6);
    gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 4);
    row = 0;

    /* Detail to immerse */
    chooser = gwy_data_chooser_new_channels();
    gwy_data_chooser_set_active_id(GWY_DATA_CHOOSER(chooser), &args->detail);
    gwy_data_chooser_set_filter(GWY_DATA_CHOOSER(chooser),
                                immerse_data_filter, &args->image, NULL);
    gwy_data_chooser_get_active_id(GWY_DATA_CHOOSER(chooser), &args->detail);
    g_signal_connect(chooser, "changed",
                     G_CALLBACK(immerse_detail_cb), &controls);
    gwy_table_attach_hscale(table, row, _("_Detail image:"), NULL,
                            GTK_OBJECT(chooser), GWY_HSCALE_WIDGET_NO_EXPAND);
    row++;

    /* Detail position */
    label = gtk_label_new(_("Position:"));
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), label,
                     0, 1, row, row+1, GTK_FILL, 0, 0, 0);

    controls.pos = gtk_label_new(NULL);
    gtk_misc_set_alignment(GTK_MISC(controls.pos), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), controls.pos,
                     1, 3, row, row+1, GTK_FILL, 0, 0, 0);
    gtk_table_set_row_spacing(GTK_TABLE(table), row, 8);
    row++;

    /* Sampling */
    label = gtk_label_new(_("Result Sampling"));
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), label,
                     0, 3, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
    row++;

    controls.sampling
        = gwy_radio_buttons_createl(G_CALLBACK(immerse_sampling_changed),
                                    &controls,
                                    args->sampling,
                                    _("_Upsample large image"),
                                    GWY_IMMERSE_SAMPLING_UP,
                                    _("_Downsample detail"),
                                    GWY_IMMERSE_SAMPLING_DOWN,
                                    NULL);

    row = gwy_radio_buttons_attach_to_table(controls.sampling, GTK_TABLE(table),
                                            4, row);
    gtk_table_set_row_spacing(GTK_TABLE(table), row-1, 8);

    /* Leveling */
    label = gtk_label_new(_("Detail Leveling"));
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), label,
                     0, 3, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
    row++;

    controls.leveling
        = gwy_radio_buttons_createl(G_CALLBACK(immerse_leveling_changed),
                                    &controls,
                                    args->leveling,
                                    gwy_sgettext("levelling|_None"),
                                    GWY_IMMERSE_LEVEL_NONE,
                                    _("_Mean value"), GWY_IMMERSE_LEVEL_MEAN,
                                    NULL);

    row = gwy_radio_buttons_attach_to_table(controls.leveling, GTK_TABLE(table),
                                            4, row);
    gtk_table_set_row_spacing(GTK_TABLE(table), row-1, 8);

    /* Draw frame */
    controls.draw_frame = gtk_check_button_new_with_mnemonic(_("Show _frame"));
    gtk_table_attach(GTK_TABLE(table), controls.draw_frame,
                     0, 3, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(controls.draw_frame),
                                 args->draw_frame);
    g_signal_connect(controls.draw_frame, "toggled",
                     G_CALLBACK(immerse_frame_toggled), &controls);

    gtk_widget_show_all(controls.dialog);
    display = gtk_widget_get_display(controls.dialog);
    controls.near_cursor = gdk_cursor_new_for_display(display, GDK_FLEUR);
    controls.move_cursor = gdk_cursor_new_for_display(display, GDK_CROSS);
    immerse_detail_cb(GWY_DATA_CHOOSER(chooser), &controls);

    ok = FALSE;
    do {
        response = gtk_dialog_run(dialog);
        switch (response) {
            case GTK_RESPONSE_CANCEL:
            case GTK_RESPONSE_DELETE_EVENT:
            case GTK_RESPONSE_NONE:
            immerse_controls_destroy(&controls);
            immerse_save_args(gwy_app_settings_get(), args);
            return FALSE;
            break;

            case RESPONSE_ESTIMATE:
            case RESPONSE_REFINE:
            immerse_search(&controls, response);
            break;

            case GTK_RESPONSE_OK:
            ok = TRUE;
            break;

            default:
            g_assert_not_reached();
            break;
        }
    } while (!ok);

    immerse_controls_destroy(&controls);
    immerse_save_args(gwy_app_settings_get(), args);

    return TRUE;
}
Exemplo n.º 5
0
static void
gwy_app_file_chooser_add_preview(GwyAppFileChooser *chooser)
{
    GwyContainer *settings;
    GtkListStore *store;
    GtkIconView *preview;
    GtkCellLayout *layout;
    GtkCellRenderer *renderer;
    GtkTooltips *tips;
    GtkWidget *scwin, *vbox, *button, *toolbar;
    gboolean setting;
    gint w;

    scwin = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scwin),
                                   GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
    store = gtk_list_store_new(2, G_TYPE_STRING, GDK_TYPE_PIXBUF);
    chooser->preview = gtk_icon_view_new_with_model(GTK_TREE_MODEL(store));
    g_object_unref(store);
    preview = GTK_ICON_VIEW(chooser->preview);
    layout = GTK_CELL_LAYOUT(preview);
    gtk_icon_view_set_columns(preview, 1);

    renderer = gtk_cell_renderer_pixbuf_new();
    gtk_cell_layout_pack_start(layout, renderer, FALSE);
    gtk_cell_layout_add_attribute(layout, renderer, "pixbuf", COLUMN_PIXBUF);

    renderer = gtk_cell_renderer_text_new();
    g_object_set(renderer,
                 "wrap-mode", PANGO_WRAP_WORD_CHAR,
                 "ellipsize", PANGO_ELLIPSIZE_END,
                 "ellipsize-set", TRUE,
                 NULL);
    gtk_cell_layout_pack_start(layout, renderer, FALSE);
    gtk_cell_layout_add_attribute(layout, renderer, "markup", COLUMN_FILEINFO);
    chooser->renderer_fileinfo = G_OBJECT(renderer);

    gtk_icon_view_set_selection_mode(preview, GTK_SELECTION_NONE);
    /* In Gtk+ 2.14 and older, things work.  2.16 adds some padding that
     * breaks everything.  And this padding together with the usual margin
     * meaks too much white space so we have to get rid of the margin in 2.16+.
     */
    if (gtk_major_version == 2 && gtk_minor_version <= 14) {
        gtk_icon_view_set_item_width(preview, TMS_NORMAL_THUMB_SIZE);
        w = TMS_NORMAL_THUMB_SIZE + 2*gtk_icon_view_get_margin(preview);
    }
    else {
        gtk_icon_view_set_margin(preview, 0);
        gtk_icon_view_set_item_width(preview, PADDED_THUMBNAIL_SIZE);
        w = PADDED_THUMBNAIL_SIZE;
    }
    gtk_widget_set_size_request(chooser->preview, w, -1);
    gtk_container_add(GTK_CONTAINER(scwin), chooser->preview);

    vbox = gtk_vbox_new(FALSE, 2);

    chooser->preview_filename = gtk_label_new(NULL);
    gtk_misc_set_alignment(GTK_MISC(chooser->preview_filename), 0.0, 0.5);
    gtk_label_set_single_line_mode(GTK_LABEL(chooser->preview_filename), TRUE);
    gtk_label_set_ellipsize(GTK_LABEL(chooser->preview_filename),
                            PANGO_ELLIPSIZE_END);
    gtk_box_pack_start(GTK_BOX(vbox), chooser->preview_filename,
                       FALSE, FALSE, 0);

    chooser->preview_type = gtk_label_new(NULL);
    gtk_misc_set_alignment(GTK_MISC(chooser->preview_type), 0.0, 0.5);
    gtk_label_set_single_line_mode(GTK_LABEL(chooser->preview_type), TRUE);
    gtk_label_set_ellipsize(GTK_LABEL(chooser->preview_type),
                            PANGO_ELLIPSIZE_END);
    gtk_box_pack_start(GTK_BOX(vbox), chooser->preview_type,
                       FALSE, FALSE, 0);

    gtk_box_pack_start(GTK_BOX(vbox), scwin, TRUE, TRUE, 0);

    toolbar = gtk_hbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);

    settings = gwy_app_settings_get();
    tips = gwy_app_get_tooltips();

    setting = FALSE;
    gwy_container_gis_boolean_by_name(settings, "/app/file/preview/plane-level",
                                      &setting);
    button = gtk_toggle_button_new();
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), setting);
    GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
    gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
    gtk_tooltips_set_tip(tips, button,
                         _("Plane-level previewed data"), NULL);
    gtk_container_add(GTK_CONTAINER(button),
                      gtk_image_new_from_stock(GWY_STOCK_LEVEL,
                              GTK_ICON_SIZE_SMALL_TOOLBAR));
    gtk_box_pack_start(GTK_BOX(toolbar), button, FALSE, FALSE, 0);
    g_signal_connect_swapped(button, "toggled",
                             G_CALLBACK(plane_level_changed), chooser);

    setting = FALSE;
    gwy_container_gis_boolean_by_name(settings, "/app/file/preview/row-level",
                                      &setting);
    button = gtk_toggle_button_new();
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), setting);
    GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);
    gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
    gtk_tooltips_set_tip(tips, button,
                         _("Row-level previewed data"), NULL);
    gtk_container_add(GTK_CONTAINER(button),
                      gtk_image_new_from_stock(GWY_STOCK_LINE_LEVEL,
                              GTK_ICON_SIZE_SMALL_TOOLBAR));
    gtk_box_pack_start(GTK_BOX(toolbar), button, FALSE, FALSE, 0);
    g_signal_connect_swapped(button, "toggled",
                             G_CALLBACK(row_level_changed), chooser);

    gtk_widget_show_all(vbox);

    gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(chooser), vbox);
    gtk_file_chooser_set_use_preview_label(GTK_FILE_CHOOSER(chooser), FALSE);
    g_signal_connect(chooser, "update-preview",
                     G_CALLBACK(gwy_app_file_chooser_update_preview), NULL);

    toolbar = gtk_hbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
}