Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to turn off progress bar and display text #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/avizo_client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ interface AvizoService : GLib.Object
public abstract Gdk.RGBA border_color { owned get; set; }
public abstract Gdk.RGBA bar_fg_color { owned get; set; }
public abstract Gdk.RGBA bar_bg_color { owned get; set; }
public abstract bool disable_progress { owned get;set; }
public abstract string text { owned get; set; }
public abstract int font_size { owned get; set; }

public abstract void show(double seconds) throws DBusError, IOError;
}
Expand Down Expand Up @@ -52,6 +55,9 @@ public class AvizoClient : GLib.Application
private static string _border_color = "";
private static string _bar_fg_color = "";
private static string _bar_bg_color = "";
private static bool _disable_progress = false;
private static string _text = "";
private static int _font_size = 24;

private static double _time = 5.0;

Expand Down Expand Up @@ -80,16 +86,19 @@ public class AvizoClient : GLib.Application
{ "bar-fg-color", 0, 0, OptionArg.STRING, ref _bar_fg_color, "Sets the color of the filled bar blocks in format rgba([0, 255], [0, 255], [0, 255], [0, 1])", "STRING" },
{ "bar-bg-color", 0, 0, OptionArg.STRING, ref _bar_bg_color, "Sets the color of the unfilled bar blocks in format rgba([0, 255], [0, 255], [0, 255], [0, 1])", "STRING" },
{ "time", 0, 0, OptionArg.DOUBLE, ref _time, "Sets the time to show the notification, default is 5", "DOUBLE" },
{ "disable-progress", 0, 0, OptionArg.NONE, ref _disable_progress, "Disable progress indicator", null },
{ "text", 0, 0, OptionArg.STRING, ref _text, "Sets the text in notification, work only if progress is disabled", "STRING" },
{ "font-size", 0, 0, OptionArg.INT, ref _font_size, "Sets the text font size", "INT" },
{ null }
};

public AvizoClient()
{
Object(application_id: "org.danb.avizo.client",
flags: ApplicationFlags.HANDLES_COMMAND_LINE);
flags: ApplicationFlags.HANDLES_COMMAND_LINE);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow the indentation got broken here.


_service = Bus.get_proxy_sync(BusType.SESSION, "org.danb.avizo.service",
"/org/danb/avizo/service");
"/org/danb/avizo/service");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well, but here it was broken before it seems.

}

public override int command_line(ApplicationCommandLine command_line)
Expand Down Expand Up @@ -158,14 +167,17 @@ public class AvizoClient : GLib.Application
if (_image_path != "")
{
_service.image_path = Filename.canonicalize(_image_path, _image_base_dir);
_service.image_resource = "";
}
else
{
_service.image_resource = _image_resource;
_service.image_path = "";
}

_service.image_opacity = _image_opacity;
_service.progress = _progress;
_service.disable_progress = _disable_progress;
_service.width = _width;
_service.height = _height;
_service.padding = _padding;
Expand All @@ -178,6 +190,10 @@ public class AvizoClient : GLib.Application

_service.fade_in = _fade_in;
_service.fade_out = _fade_out;

_service.text = _text;
_service.font_size = _font_size;


if (_background != "")
{
Expand Down
91 changes: 68 additions & 23 deletions src/avizo_service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public class AvizoWindow : Gtk.Window

public double progress { get; set; }

public bool disable_progress { get; set; }

public string text { get; set; }

public int font_size {get; set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before get.



private int _width = 248;
public int width
{
Expand Down Expand Up @@ -151,7 +158,7 @@ public class AvizoWindow : Gtk.Window
}
opacity += animation_sec_elapsed/fade_in;
if (opacity > 1) opacity = 1;
print("Fade in: %f\n", opacity);
//print("Fade in: %f\n", opacity);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you remove it intentionally or was it just while debugging?

widget.set_opacity(opacity);
}
else
Expand All @@ -165,7 +172,7 @@ public class AvizoWindow : Gtk.Window
}
opacity -= animation_sec_elapsed/fade_out;
if (opacity < 0) opacity = 0;
print("Fade out: %f\n", opacity);
//print("Fade out: %f\n", opacity);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here.

widget.set_opacity(opacity);
}

Expand Down Expand Up @@ -194,7 +201,16 @@ public class AvizoWindow : Gtk.Window
Gdk.cairo_set_source_rgba(ctx, background);
draw_round_rect(ctx, border_width, border_width, _width - 2 * border_width, _height - 2 * border_width, border_radius - border_width);

Gdk.cairo_set_source_rgba(ctx, bar_bg_color);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many extra lines here.


if(disable_progress)
{
Gdk.cairo_set_source_rgba(ctx, background);
}
else
{
Gdk.cairo_set_source_rgba(ctx, bar_bg_color);
}

for (int i = 0; i < block_count; i++)
{
Expand All @@ -204,29 +220,49 @@ public class AvizoWindow : Gtk.Window
block_height);
}

Gdk.cairo_set_source_rgba(ctx, bar_fg_color);
if(!disable_progress)
{
Gdk.cairo_set_source_rgba(ctx, bar_fg_color);

if (block_spacing > 0)
{
for (int i = 0; i < (int) (block_count * progress); i++)
{
draw_rect(ctx, blocks_x + (block_width + block_spacing) * i,
blocks_y,
block_width,
block_height);
}
}
else {
var width = block_width * block_count * progress;
var height = block_height;
draw_rect(ctx, blocks_x,
blocks_y,
width,
height);
}
}


if (block_spacing > 0)
// Draw text
if(disable_progress && text.length > 0)
{
for (int i = 0; i < (int) (block_count * progress); i++)
{
draw_rect(ctx, blocks_x + (block_width + block_spacing) * i,
blocks_y,
block_width,
block_height);
}
}
else {
var width = block_width * block_count * progress;
var height = block_height;
draw_rect(ctx, blocks_x,
blocks_y,
width,
height);
}
ctx.select_font_face ("Sans", Cairo.FontSlant.NORMAL, Cairo.FontWeight.BOLD);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to be able to choose the font as well? For the font size you added that option, too.

ctx.set_font_size(font_size);
Cairo.TextExtents extents;
ctx.text_extents(text, out extents);
double text_x = _width*0.5-(extents.width/2 + extents.x_bearing);
double text_y = _height*0.9;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.


ctx.move_to(text_x, text_y);
Gdk.cairo_set_source_rgba(ctx, bar_fg_color);
ctx.show_text(text);
}

ctx.set_operator(Cairo.Operator.OVER);


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line not needed.

return false;
}

Expand Down Expand Up @@ -269,9 +305,9 @@ public class AvizoWindow : Gtk.Window
public class AvizoService : GLib.Object
{
private static string[] props = {
"image_path", "image_resource", "image_opacity", "progress", "width", "height", "padding",
"image_path", "image_resource", "image_opacity", "progress", "disable_progress", "width", "height", "padding",
"border_radius", "border_width", "block_height", "block_spacing", "block_count", "fade_in", "fade_out", "background", "border_color",
"bar_fg_color", "bar_bg_color",
"bar_fg_color", "bar_bg_color", "text", "font_size",
};

public string image_path { get; set; default = ""; }
Expand All @@ -293,6 +329,9 @@ public class AvizoService : GLib.Object
public Gdk.RGBA border_color { get; set; default = rgba(90, 90, 90, 0.8); }
public Gdk.RGBA bar_fg_color { get; set; default = rgba(0, 0, 0, 0.8); }
public Gdk.RGBA bar_bg_color { get; set; default = rgba(106, 106, 106, 0.8); }
public bool disable_progress { get; set; default = false; }
public string text { get; set; default = ""; }
public int font_size {get; set; default = 24; }

private Array<AvizoWindow> _windows = new Array<AvizoWindow>();
private int _open_timeouts = 0;
Expand All @@ -315,6 +354,7 @@ public class AvizoService : GLib.Object
window = create_window(display);
_windows.insert_val(i, window);
}

show_window(window, display.get_monitor(i));
}

Expand Down Expand Up @@ -378,6 +418,11 @@ public class AvizoService : GLib.Object
window.set_accept_focus(false);
}

if(image_path!="")
{
window.image_resource ="";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

}

window.show_animated();
window.queue_draw();
}
Expand Down