|
Post by barryk on Mar 6, 2014 0:42:58 GMT 1
As mentioned in some recent posts to this forum, I have been working on a general-purpose 'popup' utility. It seems to be mostly finished, maybe might need a few tweaks. Most appropriately, the executable is named 'popup'! It is written with HUG, with some GTK function imports and some embedded C. It runs as a daemon, that is, as a separate process, and once started you can optionally send more controls (commands) and text to to -- not by stdin or whatever, but by writing to a file. I had originally thought that 'popup' could watch the file for modifications using inotify, but soon decided that is not suitable, for various reasons. Now, the GTK timer function is used, called every 500 msec, which is also convenient as a "terminate=<number>" control can be sent to tell it to quit after so many seconds. Anyway, showing how it works by example, here is an invocation: # ./popup "name=bk1 background='#00ffff' placement=top-middle|This text allows Pango Text Attribute Markup Language, for example <b>bold</b>, <big>big</big>, <small>small</small>, <i>italic</i>, <tt>monospace</tt>" Which will look like: Then this: # echo "background='#ff0000' level=top flash=on writemode=append-newline|Now the message is on top layer and flashing, to draw attention" The popup comes to top layer and background flashes: Then to terminate it: # echo "terminate=now|" >> /tmp/popup_bk1 To find out all that it can do, just type "./popup" and hit ENTER key, or "-h" or "--help" then ENTER. The binary needs /usr/lib/hug.so, so I have attached that also. If anyone can think of improvements/enhancements for popup, go for it! Note, the binary is 54KB after stripping. Sometime ago, vovchik showed me how to compile smaller, but those methods don't seem to work with latest 2.5.1beta BaCon (I am using source downloaded on Feb. 7, 2014). Regards, Barry Kauler Attachments:hug.so.gz (66.44 KB)
popup.gz (15.75 KB)
popup.bac.gz (4.52 KB)
|
|
|
Post by barryk on Mar 6, 2014 1:17:19 GMT 1
A technical note about 'popup':
I would have preferred to have used inotify. Using the GTK timer callback every 500 msec is potentially error-prone.
You might have to take care when writing to the file, that the previous has been consumed (the file will be zero bytes).
File writes under 4KB are, as I understand it, atomic, so there is no problem of popup reading partial-messages. But then, that does work for inotify, not 100% sure about reading file with current timer method.
You can't just put an inotify file-wait into the timer callback function, it will cause the window to not get updated, which in some circumstances will cause the window to get overwritten by other desktop activity. If we had some way of running a separate thread in the popup utility, that can do the inotify wait-on-file-modify, then trigger the window updating...
|
|
|
Post by Pjot on Mar 6, 2014 21:38:16 GMT 1
Thanks barry! Looks nice.
For your problem, maybe using the 'fork' function from libc can help you out?
Regards Peter
|
|
|
Post by barryk on Mar 7, 2014 1:41:09 GMT 1
Problem solved! Simple solution, allow messages to queue. Each message is a line, that is appended to the input file, and success relies upon atomicity of writes. This script is a stress-test: #!/bin/sh
./popup "name=bk2 placement=top-middle background=#ffff00 writemode=append|start, "
echo "testing queuing of messages: " >> /tmp/popup_bk2 echo "1" >> /tmp/popup_bk2 echo "2" >> /tmp/popup_bk2 echo "3" >> /tmp/popup_bk2 echo "4" >> /tmp/popup_bk2 echo "5" >> /tmp/popup_bk2
sleep 0.2 echo "6" >> /tmp/popup_bk2
sleep 1 echo "7" >> /tmp/popup_bk2 echo "8" >> /tmp/popup_bk2
echo "terminate=10| ending..." >> /tmp/popup_bk2 Although the GTK callback function is only executing every 500msec, it can handle queued messages (multiple lines) in /tmp/popup_* Latest code and binary attached. Attachments:popup.gz (15.95 KB)
popup.bac.gz (4.62 KB)
|
|
|
Post by bigbass on Mar 8, 2014 5:23:52 GMT 1
Hello barryk
First, Thank you for posting your popup code! here is a feed back report
Tech details only using linux mint 16 32bit compiled using "hug.bac" with the latest bacon beta of the time of posting BaCon version 2.5.4 beta - (c) Peter van Eerten - GPL v3.
I know that you prefer to use hug.so please note the next comment is only for those that may try to compile with hug.bac confirmed to compile with hug.bac with a very minor adjustment move the include close to the top of the code to avoid a compile time error
' (c) Copyright Barry Kauler March 2014, license GPL v3 /usr/share/doc/legal '140301 created '140303 peter eerten: showed how to replace low-level C open() with OPEN. ref: http://basic-converter.proboards.com/thread/637/usec-substitution-bug '140304 run as a daemon, pass 1st msg on commandline. '140305 remove inotify, polling only. '140307 handle queued messages (multiple lines in input file).
'INCLUDE "/usr/share/BaCon/hug_imports.bac" INCLUDE "hug.bac" INIT
1.) The first message dialog works correctly. 2.) the second red message never appears.Why? I don't know yet . 3.) the kill or terminate has to be done as a su user (this is expected and normal)
all of the stress test messages worked correctly
Thank you again for taking the time to document and post example code to test with and the sources
Joe
|
|
|
Post by barryk on Mar 8, 2014 9:07:29 GMT 1
bigbass, That "red message" flashes red and yellow background, every half second. I will test it again. I have added more features, a "closebox" and realtime count-up and count-down, see example usage and snapshots on my blog: bkhome.org/news/?viewDetailed=00072I want to add some more features, then will post the code. Yeah, I will post the next binary without needing hug.so.
|
|
|
Post by barryk on Mar 9, 2014 1:47:32 GMT 1
I tested the flashing, works fine: # ./popup "name=bk1 background=#ffff00 level=top justify=center width=360|this is a simple message. the quick brown fox jumped over the lazy dog. how now brown cow." # echo "background=#ff0000 terminate=10 flash=on writemode=append-newline|now flashing" >> /tmp/popup_bk1 The latest code and binary are here: bkhome.org/bacon/popup/hug.so is not needed by the binary (which is why it is so big).
|
|
|
Post by bigbass on Mar 9, 2014 2:32:25 GMT 1
Hello barryk
I found out why the red flashing message didn't work as expected it is because if you look at your first post in this thread about the flashing code then and select copy paste this part of the code is missing
>> /tmp/popup_bk1 looks like it got cut off when you pasted to the forum
*I noticed on your blog that the information is correct though
the second point I commented about is still valid too if you decide to use the latest beta it will give you this error if the include isn't moved to the top
./bacon popup Converting 'hug.bac'... 1165 Syntax error: variable 'i' in LOCAL statement at line 1165 in file 'hug.bac' was defined previously!
which can be easily adjusted
Thanks for the new code everything I tested worked correctly
P.S I know that puppy runs as root but you commented that this would work on any distro so as a suggestion I tested this to be working
PROTO geteuid IF (geteuid() != 0) THEN PRINT "Error: Must be root (su user) to use the popup daemon " END END IF Joe
|
|
|
Post by bigbass on Mar 10, 2014 18:15:59 GMT 1
Hello barryk This is a progress report for your popup app I forgot to mention this is using your latest as of the post date First off, everything is looking really good! Now using BaCon version 2.5.5 beta - (c) Peter van Eerten - GPL v3. and it looks like Peter fixed it so it will compile correctly without moving the include for hug to the top These are minor tweaks which will be based on the distro/window manager but anyway they maybe useful to get the settings fine tuned for the window manager in use This is what I get before on mint 16 and xfce as the window manager This is after the small adjustments below HUGOPTIONS("FONT DejaVu Sans 10")
button_x=BUTTON("x",-1,-1)
ATTACH(mainwin,button_x,sizereq.req_width+20,20) Getting everything fined tuned for every distro and every window manger can only be done by user feedback so here is a progress report Joe
|
|
|
Post by bigbass on Mar 12, 2014 15:31:21 GMT 1
Hello barryk
One more progress report
I tested all of the examples on your blog in reference to popup and they all worked correctly as advertised
That is a very useful app you got there ! An excellent job
Tech notes only : I had installed LMDE that is a debian based mint (instead of an ubuntu base) meaning that all the packages are debian
and your popup app worked perfectly with all the tests that were posted congratulations
Joe
|
|
|
Post by vovchik on Mar 12, 2014 16:57:53 GMT 1
Dear Barry, Very nice and useful. It could, however, be made extremely attractive (with no performance loss or appreciable increase in size) by using inline svgs as the window background - opacity is also supported. I have attached a little example showing how to use those inline svgs with gtk/gdk. No external libs. And the user could much more control over appearance. With kind regards, vovchik Attachments:bg_svg.tar.gz (42.03 KB)
|
|
|
Post by bigbass on Mar 12, 2014 18:15:57 GMT 1
Hey vovchik
Yes, I agree.
Once you got the app going adding themes and more options would give it a magical quality that would get some attention and still keep things light
An excellent demo vovchik with svg
*Just as a tech side note we now can get down below gtk using Xlib directly so a lot can be done and there are many possible options if you have to keep things light
Joe
|
|
|
Post by vovchik on Mar 12, 2014 23:47:54 GMT 1
Dear Joe and Barry,
I am thinking that the text can also be done within the SVG, since font family, size, weight, position and opacity can also be adjusted programatically, so very little in terms of widgets (only, perhaps, the window and an eventbox). This is a little SVG template for popup messages that might come in handy:
<svg width="660" height="100"> <defs> <linearGradient id="l1" gradientUnits="objectBoundingBox" x1="1" x2="1" y1="0" y2="1"> <stop stop-color="ghostwhite" offset="0"/> <stop stop-color="dimgray" offset="0.34"/> </linearGradient> </defs> <rect x="5" y="5" rx="15" ry="15" width="650" height="90" fill="url(#l1)" stroke="dimgray" fill-opacity="0.4" stroke-opacity="0.6"/> <text x="50%" y="68%" text-anchor="middle" fill="white" fill-opacity="0.8" font-family="Sans" font-size="50" font-weight="600">Sample SVG Message</text> </svg>
Now I am thinking how best to implement it. I think dismissal by mouse click would also be nice...
With kind regards, vovchik
|
|
|
Post by vovchik on Mar 13, 2014 11:15:26 GMT 1
Dear guys, Here is what I am basically after. It is a tiny python script that uses PyGtk. I modded it to use svgs, to allow x,y coordinate placement and to allow for dismissal by mouse click. Now we have to BaConize it, preferably with PROTO/PRAGMA to make it tiny, use gdk_pixbuf_loader to allow inline svgs and then include command-line parameters to adjust placement, size, colour and text attributes. If combined then with Barry's great daemon, it will be a great-looking and useful app on all *nix boxes. I made a start at converting the python, but I am about as good at python as I am at Ironman marathons. Anybody willing to have a look? With kind regards, vovchik PS. This scheme could also be used to create beautiful "windowless" widgets (clocks, weather indicators) Attachments:
svg_msg.tar.gz (1.99 KB)
|
|
|
Post by konaexpress on Mar 13, 2014 15:15:11 GMT 1
Wow that looks sharp! Nice job Vovchik!
Wish Air hung out here, he is great with Python. If no one here can help, check the other forum. Those guys are good at many languages.
John
|
|