Skip to content

Commit

Permalink
Validate sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Scott committed Jun 8, 2017
1 parent dbb85ce commit f83a8b7
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class Wallpaperize.Window : Gtk.ApplicationWindow {
public Gtk.Entry width;
public Gtk.Entry height;

private File _file;
public File file {
private File? _file;
public File? file {
get {
return _file;
}
Expand All @@ -56,12 +56,15 @@ public class Wallpaperize.Window : Gtk.ApplicationWindow {
pixbuf = pixbuf.scale_simple (image.get_allocated_width (), image.get_allocated_height (), Gdk.InterpType.BILINEAR);

image.set_from_pixbuf (pixbuf);
run_button.sensitive = true;
run_button.label = "Wallpaperize!";
drag_label.visible = false;
drag_label.no_show_all = true;

validate ();
}
}

default = null;
}

public Window (Gtk.Application app) {
Expand All @@ -85,14 +88,14 @@ public class Wallpaperize.Window : Gtk.ApplicationWindow {
grid.expand = true;
grid.row_spacing = 12;

var image_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
var image_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
image_box.get_style_context ().add_class ("frame");

image = new Gtk.Image ();
image.get_style_context ().add_class ("card");
image.hexpand = true;
image.height_request = 200;

image_box.add (image);

drag_label = new Gtk.Label (_("Drop Image Here"));
Expand All @@ -106,18 +109,23 @@ public class Wallpaperize.Window : Gtk.ApplicationWindow {

width = new Gtk.Entry ();
height = new Gtk.Entry ();


width.input_purpose = Gtk.InputPurpose.DIGITS;
height.input_purpose = Gtk.InputPurpose.DIGITS;

width.set_tooltip_text ("Width");
height.set_tooltip_text ("Height");

width.changed.connect (() => {
Wallpaperize.Wallpaperiser.W = int.parse (width.text);
validate ();
});

height.changed.connect (() => {
Wallpaperize.Wallpaperiser.H = int.parse (height.text);
validate ();
});

var reset_button = new Gtk.Button.from_icon_name ("video-display-symbolic");
reset_button.clicked.connect (get_screen_size);
reset_button.set_tooltip_text ("Get resolution");
Expand Down Expand Up @@ -152,6 +160,12 @@ public class Wallpaperize.Window : Gtk.ApplicationWindow {
get_screen_size ();
}

private void validate () {
int w = Wallpaperiser.W;
int h = Wallpaperiser.H;
run_button.sensitive = w > 0 && git@github.com:a-rmz/intro-bots.gith > 0 && w < 15000 && h < 15000 && file != null;
}

private void get_screen_size () {
Wallpaperize.Wallpaperiser.H = Gdk.Screen.height ();
Wallpaperize.Wallpaperiser.W = Gdk.Screen.width ();
Expand Down

0 comments on commit f83a8b7

Please sign in to comment.