あなたの「耳年齢」測ります (2)



あなたの「耳年齢」測ります

で書いたスクリプトを実行ファイルに変換してみました。


exeだからって、どういうわけでもないのですが、一応公開します。

Webページ


一応ついでにsetup.pyと本体ソースも掲載。


#encoding:utf-8
#setup.py
from distutils.core import setup
import py2exe

py2exe_options = dict(
    compressed = 1,
    optimize = 0,
    includes = [],
    excludes = "unicodedata select ssl socket bz2 bz".split(),
    dll_excludes = [],
    packages = [],
    bundle_files = 3,
)

setup(
    options = {'py2exe': py2exe_options},
    windows = [
            dict(
                script = 'mosquito.py',
                other_resources = [],
                icon_resources  = [(1, "mos.ico")],
            )
        ],
    data_files = [],
    zipfile = None
)
#encoding:utf-8
#mosquito.py
from __future__ import (
    with_statement, 
    division,
    print_function,
)

import os
import sys
from functools import partial

from Tkinter import *
from tkFont import *
import webbrowser

Author  = u"doloop"
Webpage = u"http://doloopwhile.blogspot.com/"

import winsound
def beepsound(frequency, duration):
    winsound.Beep(frequency, duration)

##try:
##    import winsound
##except ImportError:
##    import subprocess
##    def beepsound(frequency, duration):
##        #apt-get install beep
##        subprocess.call("beep -f {0} -l {1}".format(frequency, duration))
##else:
##    def beepsound(frequency, duration):
##        winsound.Beep(frequency, duration)

class MainFrame(Frame):
    def __init__(self, *a, **kw):
        Frame.__init__(self, *a, **kw)
        
        self.duration_var = IntVar(self, 1000)
        
        beep_panel = LabelFrame(self, text=u"Beep the PC窶冱 speaker(Hz).")
        beep_panel.pack()
        
        self.beep_buttons = []
        buttons = Frame(beep_panel)
        for freq in xrange(1000, 20000 + 1, 1000):
            row    = (freq - 1000) // 5000
            column = (freq - 1000) %  5000
            
            text = unicode(freq).center(5)
            btn = Button(buttons, 
                text=text,
                command=partial(self.beep, freq)
            )
            btn.grid(row=row, column=column, sticky=N+S+W+E)
        buttons.pack()
        
        dur_panel = LabelFrame(self, text=u"duration of sound(milliseconds).")
        dur_panel.pack()
        
        dur_scale = Scale(
            dur_panel, 
            orient=HORIZONTAL,
            from_=0,
            to=2000,
            resolution=100,
            tickinterval=500,
            variable=self.duration_var
        )
        dur_scale.pack(fill=BOTH)
        
        url_label = Label(
            self,
            cursor="hand2",
            fg="blue",
            text="{0}({1})".format(Author, Webpage),
            takefocus=True,
        )
        
        font = Font(font=url_label["font"])
        font["underline"] = True
        url_label["font"] = font
        url_label.bind('', self.on_url_clicked)
        
        url_label.pack()
    
    def on_url_clicked(self, event):
        webbrowser.open(Webpage)
    
    def beep(self, freq):
        beepsound(freq, self.duration_var.get())
    
def main():
    root = Tk()
    for freq in xrange(1000, 20000 + 1, 1000):
        beepsound(freq, 100)
    root.title(os.path.basename(sys.argv[0]))
    f = MainFrame(root)
    f.pack()
    root.mainloop()

if __name__ == "__main__":
    main()


広告を非表示にする