[SOLVED] Works, but does not beep: a story about the Output Screenlet and a question
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
For those who do not know it, screenlets are owner drawn programs to do several things. Output is one that displays the output of anything we want, any command, and repeat it with a chosen interval. Their window can be smaller than usual ones, and can be made always on top of everything else - which is very nice for a few uses! (:
In the last few days, I have made a couple of shell scripts to monitor services where I use long sessions. It monitors new messages, for example. It does not matter for this discussion. The scripts monitor some data we want and output a "signal" of their existence. For example, the output of one could be "2G" to say there are 2 games in my turn.
To use just one Output to write about all services I want, I have made two helper scripts: one of them to call a service script with regular and chosen interval, controled by a file; another one to mix the output of several others, whenever they happen.
These descriptions are a bit too simple, but do not focus on how these scripts work!
For one of those service scripts, I decided that I want it to show the value it found with beeps, one for each unit. I have done this before with shell's echo, so I just repeated it there:
Code:
for((i=0; i<$number; i++)); do
if ! [ -e $quiet ]; then
echo -ne "\a" # beep!
# bash /some/dir/beep.txt # second try to beep
sleep 1
fi
done
All scripts work perfectly when I run them from a terminal, it beeps. But when Output runs it, all it does is to write the textual character [0007] together with the rest of the outputs, instead of doing a beep for each of these. :-/ And output runs the "mixer" script, which calls the other scripts indirectly.
The commented line in the code above is a second try I did to make it work: a text file (with the echo command inside) given to bash execute. No change: Output just writes the char [0007] which represents the beep sent to script's standard output.
I opened Output source, which is a small Python program, hoping to find a way to make a beep there (the same beep as my terminal does when I "echo -e '\a'" in them, for example.
No use. I understand what most of the code does by reading it, but that is all.
Maybe someone here can suggest one of:
1. Show me a simple command that can make a chosen beep (which is playing an audio file)
2. Make the "warning" event of my window manager, which is Gnome 2, using a Python 2.6 program
3. Show me a FOSS program that is simple, but can only make its own sounds
For the curious, here is the full Output source. Just 158 lines in the version I am using:
Code:
1 #!/usr/bin/env python
2
3 # This application is released under the GNU General Public License
4 # v3 (or, at your option, any later version). You can find the full
5 # text of the license under http://www.gnu.org/licenses/gpl.txt.
6 # By using, editing and/or distributing this software you agree to
7 # the terms and conditions of this license.
8 # Thank you for using free software!
9
10 # OutputScreenlet (c) Whise <helder.fraga@hotmail.com>
11 #
12 # INFO:
13 # - A screenlet that searches the most popular search engines sites
14
15
16 import screenlets
17 from screenlets.options import ColorOption, StringOption, IntOption
18 import cairo
19 import pango
20 import gtk
21 import gobject
22 from screenlets import DefaultMenuItem
23 import commands
24
25
26
27 class OutputScreenlet(screenlets.Screenlet):
28 """A screenlet displays output from any unix command"""
29
30 # default meta-info for Screenlets
31 __name__ = 'OutputScreenlet'
32 __version__ = '0.1'
33 __author__ = 'Helder Fraga aka whise'
34 __desc__ = 'A screenlet displays output from any unix command'
35
36 # a list of the converter class objects
37 __timeout = None
38 update_interval = 5
39 __has_focus = False
40 __query = ''
41 frame_color = (0, 0, 0, 0.7)
42 iner_frame_color = (0,0,0,0.3)
43 shadow_color = (0,0,0,0.5)
44 text_color = (1,1,1, 0.7)
45 # editable options
46 # the name, i.e., __title__ of the active converter
47 p_fdesc = None
48 p_layout = None
49 run = 'dmesg'
50 output = ''
51 ctxx = None
52 w = 350
53 h = 100
54 # constructor
55 def __init__(self, **keyword_args):
56 #call super
57 screenlets.Screenlet.__init__(self, width=350, height=100,ask_on_option_override = False,
58 **keyword_args)
59 # set theme
60 self.theme_name = "default"
61
62 # add options
63 self.add_options_group('Options', 'Options')
64 self.add_option(StringOption('Options', 'run',
65 self.run, 'Command to run',
66 'Command to run'), realtime=False)
67
68 self.add_option(IntOption('Options', 'update_interval',
69 self.update_interval, 'Update interval seconds',
70 'The interval for refreshing RSS feed (in seconds)', min=1, max=10000))
71
72 self.add_option(IntOption('Options', 'w',
73 self.w, 'Width',
74 'width', min=10, max=10000))
75
76
77 self.add_option(IntOption('Options', 'h',
78 self.h, 'Height',
79 'height', min=10, max=10000))
80
81
82 self.add_option(ColorOption('Options','frame_color',
83 self.frame_color, 'Background Frame color',
84 'Frame color'))
85
86 self.add_option(ColorOption('Options','iner_frame_color',
87 self.iner_frame_color, 'Iner Frame color',
88 'Iner Frame color'))
89
90 self.add_option(ColorOption('Options','shadow_color',
91 self.shadow_color, 'Shadow color',
92 'Shadow color'))
93
94 self.add_option(ColorOption('Options','text_color',
95 self.text_color, 'Text color',
96 'Text color'))
97
98 self.__timeout = gobject.timeout_add(1000, self.update)
99 self.update()
100
101 def __setattr__(self, name, value):
102 # call Screenlet.__setattr__ in baseclass (ESSENTIAL!!!!)
103 screenlets.Screenlet.__setattr__(self, name, value)
104 if name == "update_interval":
105 if value > 0:
106 self.__dict__['update_interval'] = value
107 if self.__timeout:
108 gobject.source_remove(self.__timeout)
109 self.__timeout = gobject.timeout_add(int(value * 1000), self.update)
110 else:
111 self.__dict__['update_interval'] = 1
112 pass
113 if name == 'w':
114 self.width = value
115 if name == 'h':
116 self.height = value
117 if name == 'run':
118 self.update()
119
120
121 def on_init(self):
122
123 self.add_default_menuitems()
124
125
126
127
128 def update(self):
129 self.output = commands.getoutput(self.run).replace('&','').replace('<','').replace('@','')
130 if len(self.output) > 300:
131 self.output = self.output[len(self.output)-300:]
132 self.redraw_canvas()
133 return True
134
135 def on_draw(self, ctx):
136 self.ctxx = ctx
137 # if a converter or theme is not yet loaded, there's no way to continue
138 # set scale relative to scale-attribute
139 ctx.scale(self.scale, self.scale)
140 # render background
141 ctx.set_source_rgba(*self.frame_color)
142 self.draw_rectangle_advanced (ctx, 0, 0, self.width-12, self.height-12, rounded_angles=(5,5,5,5), fill=True, border_size=2, border_color=(self.iner_frame_color[0],self.iner_frame_color[1],self.iner_frame_color[2],self.iner_frame_color[3]), shadow_size=6, shadow_color=(self.shadow_color[0],self.shadow_color[1],self.shadow_color[2],self.shadow_color[3]))
143 #self.theme['background.svg'].render_cairo(ctx)
144 # compute space between fields
145 ctx.set_source_rgba(*self.text_color)
146 self.draw_text(ctx, str(self.output), 10,10, 'FreeSans',8, self.width-20,allignment=pango.ALIGN_LEFT,justify = True,weight = 0)
147
148
149 def on_draw_shape(self, ctx):
150 self.on_draw(ctx)
151
152
153
154 # If the program is run directly or passed as an argument to the python
155 # interpreter then create a Screenlet instance and show it
156 if __name__ == "__main__":
157 import screenlets.session
158 screenlets.session.create_session(OutputScreenlet)
I tried updating to Output 0.1.6 today. It broke the settings I had to Output! It did not work at all. It came with no screenlets and could not find the page (that probably worked sometime, in the past, but does not today), to find them in. The official screenlets.org website is abandoned and did not get indexed by archive.org with some of its past content... :-/ Sad.
tl;dr
can you bring your computer to beep at all? mine doesn't.
i don't think this has anything to do with screenlets.
Yes, my computer surely beeps with the actions I described! But it is not that beep the CPU boxes usually have and makes (also) at boot start (my current CPU does not have that piece of hardware to make beeps).
The beep I am refering to is:
- one that happens for several actions in the terminal in Ubuntu: "already in the beginning of line"; "already in the end of line"; "already in the last history line".
- the one that happens when programs executed from a shell write "\a" in their standard output
- a sound chosen by Gnome in the menu "System -> Preferences -> Sounds" -> "Choose an alert sound"
.......-> I have seen this behaviour in Gnome 2 and in Mate, at least
- when I use CTRL + ALT + F[1-6] interfaces, no beep happens for the same actions (in other machines I had, the hardware beep would happen)
I am pretty confident that the problem is something the Output screenlet is not doing, but could do. I will make it do it, if I discover what it is.
The fact that it writes [0007] in its window, but making no sound for it, cannot be something else, I think. It keeps all the program output in something just textual and, when the program ends, it writes that in its window.
You can also just try this on the command line or shell script with no extra software installed:
Code:
tput bel
No extra software installed? Just use echo! Too much typing? Make an alias for it, like I did:
alias bipa='echo -ne "\a"'
^,^
And tput works in a shell script we call ourselves, or in the command line. But not in a script called from Output screenlet. In such situation, tput gives this error: "tput: No value for $TERM and no -T specified". A strange use for something made for "initialize a terminal or query terminfo database", in my opinion, as read in the manual.
And tput works in a shell script we call ourselves, or in the command line. But not in a script called from Output screenlet. In such situation, tput gives this error: "tput: No value for $TERM and no -T specified". A strange use for something made for "initialize a terminal or query terminfo database", in my opinion, as read in the manual.
I've never worked with Output screenlets... maybe this would work, try it out...
I've never worked with Output screenlets... maybe this would work, try it out...
Code:
bash -c 'tput bel'
Why should it work? Calling bash with a file containing a proper echo command did not work, it was my second try:
Code:
# file contains the line: echo -ne "\a"
echo -n "began "
bash file # beep?
echo -n " ended"
# do not work when this script is called by Output screenlet
Next time I am on a "beeping situation" I will test it too, anyway.
play can also be used to play specific audio files.
OMG!
more examples from the play man page:
Code:
play -n synth 2.5 sin 333 gain 1 bend .35,180,.25 .15,740,.53 0,-520,.3
play -n -c1 synth sin %-12 sin %-9 sin %-5 sin %-2 fade h 0.1 1 0.1
play -n synth -j 3 sin %3 sin %-2 sin %-5 sin %-9 \
sin %-14 sin %-21 fade h .01 2 1.5 delay \
1.3 1 .76 .54 .27 remix - fade h 0 2.7 2.5 norm -1
play -n synth pl G2 pl B2 pl D3 pl G3 pl D4 pl G4 \
delay 0 .05 .1 .15 .2 .25 remix - fade 0 4 .1 norm -1
for n in E2 A2 D3 G3 B3 E4; do play -n synth 1 pluck $n; done
play -n synth 0.5 sine 200-500 synth 0.5 sine fmod 700-100
Why should it work? Calling bash with a file containing a proper echo command did not work, it was my second try:
Code:
# file contains the line: echo -ne "\a"
echo -n "began "
bash file # beep?
echo -n " ended"
# do not work when this script is called by Output screenlet
Next time I am on a "beeping situation" I will test it too, anyway.
If that doesn't work, can you open a terminal window and send it this command within that environment? In Mac OS X, you could use AppleScript to do it thusly:
Code:
tell application "Terminal"
do script "tput bel"
activate
end tell
Of course under AppleScript, it would be much easier, this is the program to create the system beep:
Code:
beep
If you wanted it to run on the command line as an executable:
Originally Posted by Laserbeak:
I've never worked with Output screenlets... maybe this would work, try it out...
Code:
bash -c 'tput bel'
Why should it work? Calling bash with a file containing a proper echo command did not work, it was my second try:
Code:
# file contains the line: echo -ne "\a"
echo -n "began "
bash file # beep?
echo -n " ended"
# do not work when this script is called by Output screenlet
Next time I am on a "beeping situation" I will test it too, anyway.
Just tested it. As I imagined, it did not work. Same error of executing 'tput bel' directly:
"tput: No value for $TERM and no -T specified"
Does this problem exist because Output expects the command it watches write only text, while we want a terminal with beeps, colors and text? This idea gives an imaginary path to a solution, but I do not know how to reach it, how to go for that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.