Skip to content

Commit

Permalink
prevent updating progress bar before the first image was open
Browse files Browse the repository at this point in the history
  • Loading branch information
aharotias2 committed Apr 6, 2023
1 parent 81e446b commit b4faf34
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/Utils/PixbufUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace ParaPara {
*/
public Pixbuf scale_fit_in_width(Pixbuf src_pixbuf, int max_width) {
int height = (int) (src_pixbuf.height * ((double) max_width / (double) src_pixbuf.width));
debug("PixbufUtils.scale_by_max_width (max_width = %d, height = %d)", max_width, height);
//debug("PixbufUtils.scale_by_max_width (max_width = %d, height = %d)", max_width, height);
return src_pixbuf.scale_simple(max_width, height, InterpType.BILINEAR);
}

Expand All @@ -55,7 +55,7 @@ namespace ParaPara {
*/
public Pixbuf scale_fit_in_height(Pixbuf src_pixbuf, int max_height) {
int width = (int) (src_pixbuf.width * ((double) max_height / (double) src_pixbuf.height));
debug("PixbufUtils.scale_by_max_height (max_height = %d, width = %d)", max_height, width);
//debug("PixbufUtils.scale_by_max_height (max_height = %d, width = %d)", max_height, width);
return src_pixbuf.scale_simple(width, max_height, InterpType.BILINEAR);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Widgets/SingleImageView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace ParaPara {
scrolled.add(image);
scrolled.size_allocate.connect((allocation) => {
if (image.fit) {
debug("size_allocated");
//debug("size_allocated");
image.fit_size_in_window();
update_title();
}
Expand Down Expand Up @@ -443,6 +443,7 @@ namespace ParaPara {
}

public async void open_async(File file) throws Error {
debug("SingleImageView.open_async " + file.get_path());
var saved_cursor = get_window().cursor;
change_cursor(WATCH);
try {
Expand Down
37 changes: 21 additions & 16 deletions src/Widgets/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ namespace ParaPara {
private SimpleAction action_save;
private bool is_open_when_value_changed = true;
private bool is_set_location = true;
private bool is_update_blocked = false;

public Window(Gtk.Application app) {
application = app;
Expand Down Expand Up @@ -166,7 +167,7 @@ namespace ParaPara {

open_button.add(open_button_inner_box);
open_button.clicked.connect(() => {
on_open_button_clicked();
on_open_button_clicked.begin();
});
}

Expand Down Expand Up @@ -242,7 +243,7 @@ namespace ParaPara {
welcome.append("document-open", _("Open Image"), _("Show and edit your image."));
welcome.activated.connect((i) => {
if (i == 0) {
on_open_button_clicked();
on_open_button_clicked.begin();
}
});
}
Expand Down Expand Up @@ -451,7 +452,7 @@ namespace ParaPara {

var action_open = new SimpleAction("open", null);
action_open.activate.connect(() => {
on_open_button_clicked();
on_open_button_clicked.begin();
});
add_action(action_open);

Expand Down Expand Up @@ -634,7 +635,7 @@ namespace ParaPara {
require_new_window();
break;
case Gdk.Key.o:
on_open_button_clicked();
on_open_button_clicked.begin();
break;
case Gdk.Key.w:
close();
Expand Down Expand Up @@ -679,7 +680,7 @@ namespace ParaPara {
css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}

public void on_open_button_clicked() {
public async void on_open_button_clicked() {
var dialog = new Gtk.FileChooserDialog(_("Choose file to open"), this, Gtk.FileChooserAction.OPEN,
_("Cancel"), Gtk.ResponseType.CANCEL, _("Open"), Gtk.ResponseType.ACCEPT);
if (file_list != null) {
Expand All @@ -689,13 +690,11 @@ namespace ParaPara {
if (res == Gtk.ResponseType.ACCEPT) {
var file_path = dialog.get_filename();
File file = File.new_for_path(file_path);
open_file_async.begin(file, (obj, res) => {
try {
open_file_async.end(res);
} catch (Error e) {
//show_error_dialog(e.message);
}
});
try {
yield open_file_async(file);
} catch (Error e) {
//show_error_dialog(e.message);
}
}
dialog.close();
}
Expand All @@ -720,10 +719,12 @@ namespace ParaPara {
show_error_dialog(_("The file does not found."));
});
file_list.updated.connect(() => {
image_view.update();
progress_scale.set_range(0.0, (double) (file_list.size - 1));
progress_scale.set_value(image_view.index);
progress_label.label = _("Location: %d / %d (%d%%)").printf(image_view.index + 1, file_list.size, (int) (image_view.position * 100));
if (!is_update_blocked) {
image_view.update();
progress_scale.set_range(0.0, (double) (file_list.size - 1));
progress_scale.set_value(image_view.index);
progress_label.label = _("Location: %d / %d (%d%%)").printf(image_view.index + 1, file_list.size, (int) (image_view.position * 100));
}
});
file_list.terminated.connect(() => {
if (repeat_updating_file_list) {
Expand All @@ -732,6 +733,7 @@ namespace ParaPara {
}
});
file_list.make_list_async.begin(repeat_updating_file_list, (obj, res) => {
debug("file list was updated");
if (image_view.view_mode != ViewMode.SINGLE_VIEW_MODE) {
disable_controls();
image_view.open_async.begin(file, (obj, res) => {
Expand All @@ -753,7 +755,9 @@ namespace ParaPara {

if (image_view.view_mode == SINGLE_VIEW_MODE || file_list.has_list) {
disable_controls();
is_update_blocked = true;
yield image_view.open_async(file);
is_update_blocked = false;
enable_controls();
image_view.update_title();
}
Expand Down Expand Up @@ -850,6 +854,7 @@ namespace ParaPara {
}

public void update_image_view(ViewMode view_mode) throws Error {
debug("Window.update_image_view");
if (image_view.view_mode != view_mode) {
File file = image_view.get_file();
bottom_box.remove(image_view);
Expand Down

0 comments on commit b4faf34

Please sign in to comment.