LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2017, 11:38 PM   #1
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Rep: Reputation: 51
Question Works, but does not beep: a story about the Output Screenlet and a question


I have been using the Output screenlet ( https://launchpad.net/screenlets/+announcements ) 0.1.2 for several months.

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.

Anyway, I uninstalled version 0.1.6 and got 0.1.2 again from http://old-releases.ubuntu.com/ubunt.../s/screenlets/.

The story is longer than it needed to be here. But I wanted to tell... hehe

So... what do you think about my "beep problem"?

Last edited by dedec0; 04-23-2017 at 09:01 AM.
 
Old 04-23-2017, 03:24 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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.
 
Old 04-23-2017, 03:42 AM   #3
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
If you have SoX installed:

play -n synth 0.1 sin 880

play can also be used to play specific audio files.
 
3 members found this post helpful.
Old 04-23-2017, 07:46 AM   #4
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by ondoho View Post
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.

Last edited by dedec0; 04-23-2017 at 07:52 AM.
 
Old 04-23-2017, 08:20 AM   #5
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Talking

Quote:
Originally Posted by hydrurga View Post
If you have SoX installed:

play -n synth 0.1 sin 880

play can also be used to play specific audio files.
Great! I have installed sox. Less than 3 MiB for "the Swiss Army knife of audio manipulation"? I could give a bit more!

I changed your command a bit:

play -q -V0 -n synth 0.1 sin 220

- q: be quiet
- V0: zero verbosity, errors shown only by the exit status
- 220 Hz: I find it more graceful (:

Right now I have added that line with 'play' to a script of one of the services I monitor. Working like magic!

Thank you very much, hydrurga!

In the end, this thread did not involve anything about programming, like I imagined it could. Should it be moved? To software forum, I would choose.
 
Old 04-23-2017, 09:19 AM   #6
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
You can also just try this on the command line or shell script with no extra software installed:

Code:
tput bel
 
Old 04-23-2017, 10:19 AM   #7
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Thumbs down

Quote:
Originally Posted by Laserbeak View Post
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.
 
Old 04-23-2017, 11:07 AM   #8
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
Quote:
Originally Posted by dedec0 View Post
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...

Code:
bash -c 'tput bel'
 
Old 04-23-2017, 12:19 PM   #9
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by Laserbeak View Post
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.
 
Old 04-23-2017, 02:36 PM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by hydrurga View Post
If you have SoX installed:

play -n synth 0.1 sin 880

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
 
1 members found this post helpful.
Old 04-23-2017, 03:44 PM   #11
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
BTW -- I installed sox. Handy little program! Thank you!
 
Old 04-23-2017, 03:57 PM   #12
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
Quote:
Originally Posted by dedec0 View Post
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:
Code:
#!/usr/bin/osascript
beep
then chmod 755 it.

Or you could do this:
Code:
 echo "beep" | /usr/bin/osascript

Last edited by Laserbeak; 04-23-2017 at 04:21 PM.
 
Old 04-24-2017, 10:43 AM   #13
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Thumbs down

Quote:
Originally Posted by dedec0 View Post
Quote:
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Flash Videos beep-beep-beep Audio Quantumstate Linux - Desktop 1 07-24-2011 08:57 AM
beep, beep ... waring on java code thuan1975 Linux - Software 0 01-24-2011 01:27 AM
Screenlet dellthinker Linux - Newbie 2 06-11-2008 06:40 PM
Problem with lm sensors, everything works but that damn beep sound objorkum Linux - Software 0 01-07-2004 03:37 PM
success story plus a question drfrankie Linux - Software 0 06-14-2003 02:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration