[
  {
    "path": ".gitignore",
    "content": "*.pyc\n.DS_Store\n/tests/\n/product/\n/.eggs/\n/build/\n/dist/\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.,\n 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Lesser General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n                            NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) year name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.\n"
  },
  {
    "path": "README.md",
    "content": "![GitHub release (latest by date)](https://img.shields.io/github/v/release/TomSchimansky/GuitarTuner)\n![GitHub all releases](https://img.shields.io/github/downloads/TomSchimansky/GuitarTuner/total?color=green&label=macOS%20release%20downloads)\n![GitHub Release Date](https://img.shields.io/github/release-date/TomSchimansky/GuitarTuner?color=green)\n\n# GuitarTuner App\n\n![](documentation/readme_images/Preview_Dark.png)\n\nThis is a simple **chromatic tuner** designed for guitar tuning, but it should also work with every other instrument.\nThe played note is automatically recognized through the microphone, and an acoustic signal is\nheard when the tuning is correct. If you want you can also change the reference-tone to another\nfrequency. At the moment, a compiled version is only available for macOS, but you can use it on\nWindows too if you run it in the command line.\n\n* Automatic tone detection\n* High accuracy: < 0.5 cents (around the A4 area)\n* Working from 60 to 2000 Hz (C2 to C7)\n* High stability of the pitch indicator\n* Support for macOS light and dark-mode\n\n### **➜️ Download macOS app (Intel only):** [<u>Download here</u>](https://github.com/TomSchimansky/GuitarTuner/releases/tag/3.2)\n\n![](documentation/readme_images/Icon_Banner.png)\n\n### Functionality\n\nThe app is written in Python with Tkinter, PyAudio and numpy. It uses PyAudio to get access to the raw audio-stream coming from the microphone.\nThen a **fast-fourier-transformation** (```numpy.fft```) is applied on the audio-data, which is buffered for about 1.5 seconds.\nThen a HPS (Harmonic Product Spectrum) operation is applied to filter the harmonic frequencies.\nFrom the HPS output, you can get the loudest frequency and convert it to a musical note by applying the following\nformula: ```12 * numpy.log2(f / a4_frequency) + 69```.\n\n### Run GuitarTuner with python\nFirst you need to install all necessary libraries:\n```\npip3 install -r requirements.txt\n```\nThen you can do:\n```\npython3 main.py\n```\n\n### Create standalone application\nYou can also create a standalone application for macOS or Windows by yourself. For macOS you can use py2app:\n```\npython3.8 setup.py py2app\n```\nFor windows, you would need to use py2exe instead and modify the setup.py file.\n\nTo keep application size as small as possible, make sure you create a virtual environment where you install\nonly the necessary libraries. The macOS dark-mode currently **only** works with the **anaconda python** Version.\nIf you compile the app with a python.org version, you have to disable the dark-mode by deleting\nthe ```'NSRequiresAquaSystemAppearance': False```entry in setup.py, which causes the application window to go\ninto dark-mode.\n\n![](documentation/readme_images/Preview_Light.png)\n"
  },
  {
    "path": "assets/user_settings/user_settings.json",
    "content": "{\"check_for_updates\": true, \"bell_muted\": false, \"agreed_on_usage_stats\": true, \"open_times\": 0, \"id\": null}"
  },
  {
    "path": "documentation/test_custom_button.py",
    "content": "\"\"\" This is a small program to demonstrate the use\n    of the TkinterCustomButton class, which is used\n    in this project \"\"\"\n\nimport tkinter\nimport tkinter.messagebox\nimport os\nimport sys\nfrom distutils.version import StrictVersion as Version\n\nfrom tkinter_custom_button import TkinterCustomButton\n\nMAIN_PATH = os.path.dirname(__file__)\n\nAPP_NAME = \"Rounded Tkinter custom button test\"\nABOUT_TEXT = \"Simple Test-App\"\nWIDTH = 600\nHEIGHT = 400\n\n\nclass App(tkinter.Tk):\n    def __init__(self, *args, **kwargs):\n        if sys.platform == \"darwin\":  # macOS\n            if Version(tkinter.Tcl().call(\"info\", \"patchlevel\")) >= Version(\"8.6.9\"):  # Tcl/Tk >= 8.6.9\n                os.system(\"defaults write -g NSRequiresAquaSystemAppearance -bool No\")  # turn on dark mode for all apps\n                # Currently this works only with anaconda python version (python.org Tcl/Tk version is only 8.6.8).\n\n        tkinter.Tk.__init__(self, *args, **kwargs)\n\n        self.minsize(WIDTH, HEIGHT)\n        self.resizable(True, True)\n        self.title(APP_NAME)\n        self.geometry(str(WIDTH) + \"x\" + str(HEIGHT))\n\n        self.protocol(\"WM_DELETE_WINDOW\", self.on_closing)\n        self.bind(\"<Command-q>\", self.on_closing)\n        self.bind(\"<Command-w>\", self.on_closing)\n\n        if sys.platform == \"darwin\":  # macOS\n            self.menubar = tkinter.Menu(master=self)\n            self.app_menu = tkinter.Menu(self.menubar, name='apple')\n            self.menubar.add_cascade(menu=self.app_menu)\n\n            self.app_menu.add_command(label='About ' + APP_NAME, command=self.about_dialog)\n            self.app_menu.add_separator()\n\n            self.config(menu=self.menubar)\n            self.createcommand('tk::mac::Quit', self.on_closing)\n\n        # ========== slightly rounded corners =============\n\n        self.button_1 = TkinterCustomButton(master=self,\n                                            bg_color=None,\n                                            fg_color=\"#2874A6\",\n                                            hover_color=\"#5499C7\",\n                                            text_font=None,\n                                            text=\"Test Button 1\",\n                                            text_color=\"white\",\n                                            corner_radius=10,\n                                            width=120,\n                                            height=45,\n                                            hover=True,\n                                            command=self.test_function)\n        self.button_1.place(relx=0.33, rely=0.2, anchor=tkinter.CENTER)\n\n        self.button_2 = TkinterCustomButton(master=self,\n                                            bg_color=None,\n                                            fg_color=\"#922B21\",\n                                            border_color=\"white\",\n                                            hover_color=\"#CD6155\",\n                                            text_font=None,\n                                            text=\"Test Button 2\",\n                                            text_color=\"white\",\n                                            corner_radius=10,\n                                            border_width=2,\n                                            width=150,\n                                            height=45,\n                                            hover=True,\n                                            command=self.test_function)\n        self.button_2.place(relx=0.66, rely=0.2, anchor=tkinter.CENTER)\n\n        # ========== fully rounded corners =============\n\n        self.button_3 = TkinterCustomButton(master=self,\n                                            bg_color=None,\n                                            fg_color=\"#1E8449\",\n                                            hover_color=\"#2ECC71\",\n                                            text_font=None,\n                                            text=\"Test Button 3\",\n                                            text_color=\"white\",\n                                            corner_radius=20,\n                                            width=120,\n                                            height=40,\n                                            hover=True,\n                                            command=self.test_function)\n        self.button_3.place(relx=0.33, rely=0.4, anchor=tkinter.CENTER)\n\n        self.button_4 = TkinterCustomButton(master=self,\n                                            bg_color=None,\n                                            border_color=\"#BB8FCE\",\n                                            fg_color=\"#6C3483\",\n                                            hover_color=\"#A569BD\",\n                                            text_font=None,\n                                            text=\"Test Button 4\",\n                                            text_color=\"white\",\n                                            corner_radius=20,\n                                            border_width=2,\n                                            width=150,\n                                            height=40,\n                                            hover=True,\n                                            command=self.test_function)\n        self.button_4.place(relx=0.66, rely=0.4, anchor=tkinter.CENTER)\n\n        # ========== no rounded corners =============\n\n        self.button_5 = TkinterCustomButton(master=self,\n                                            bg_color=None,\n                                            fg_color=\"#A93226\",\n                                            hover_color=\"#CD6155\",\n                                            text_font=None,\n                                            text=\"Test Button 5\",\n                                            text_color=\"black\",\n                                            corner_radius=0,\n                                            width=120,\n                                            height=40,\n                                            hover=True,\n                                            command=self.test_function)\n        self.button_5.place(relx=0.33, rely=0.6, anchor=tkinter.CENTER)\n\n        self.button_6 = TkinterCustomButton(master=self,\n                                            bg_color=None,\n                                            fg_color=self.cget(\"bg\"),\n                                            border_color=\"#ABB2B9\",\n                                            hover_color=\"#566573\",\n                                            text_font=None,\n                                            text=\"Test Button 6\",\n                                            text_color=\"#ABB2B9\",\n                                            corner_radius=0,\n                                            border_width=2,\n                                            width=120,\n                                            height=40,\n                                            hover=True,\n                                            command=self.test_function)\n        self.button_6.place(relx=0.66, rely=0.6, anchor=tkinter.CENTER)\n\n        # ========== other shapes =============\n\n        from PIL import Image, ImageTk\n\n        play_image = ImageTk.PhotoImage(Image.open(\"button_test_images/play_button_image.png\").resize((30, 30)))\n\n        self.button_7 = TkinterCustomButton(master=self,\n                                            bg_color=None,\n                                            fg_color=\"#58636F\",\n                                            border_color=None,\n                                            hover_color=\"#808B96\",\n                                            image=play_image,  # <- add image (class PhotoImage)\n                                            corner_radius=10,\n                                            border_width=0,\n                                            width=50,\n                                            height=50,\n                                            hover=True,\n                                            command=self.test_function)\n        self.button_7.place(relx=0.33, rely=0.8, anchor=tkinter.CENTER)\n\n        self.button_8 = TkinterCustomButton(master=self,\n                                            bg_color=None,\n                                            fg_color=\"#212F3D\",\n                                            border_color=\"#117A65\",\n                                            hover_color=\"#34495E\",\n                                            text_font=None,\n                                            text=\"Button 8\",\n                                            text_color=\"white\",\n                                            corner_radius=12,\n                                            border_width=4,\n                                            width=100,\n                                            height=60,\n                                            hover=True,\n                                            command=self.test_function)\n        self.button_8.place(relx=0.66, rely=0.8, anchor=tkinter.CENTER)\n\n        self.running = False\n\n    def test_function(self):\n        tkinter.messagebox.showwarning(title=\"Button Test\",\n                                       message=\"Button pressed\")\n\n    def about_dialog(self):\n        tkinter.messagebox.showinfo(title=APP_NAME,\n                                    message=ABOUT_TEXT)\n\n    def on_closing(self, event=0):\n        if sys.platform == \"darwin\":  # macOS\n            if Version(tkinter.Tcl().call(\"info\", \"patchlevel\")) >= Version(\"8.6.9\"):  # Tcl/Tk >= 8.6.9\n                os.system(\"defaults delete -g NSRequiresAquaSystemAppearance\")  # turn off dark mode for all apps\n\n        self.destroy()\n        self.running = False\n        exit()\n\n    def start(self):\n        self.running = True\n        self.mainloop()\n\n\nif __name__ == \"__main__\":\n    app = App()\n    app.start()\n"
  },
  {
    "path": "documentation/test_custom_button_images.py",
    "content": "import tkinter\nfrom tkinter_custom_button import TkinterCustomButton\nfrom PIL import Image, ImageTk\n\napp = tkinter.Tk()\napp.geometry(\"300x200\")\napp.title(\"TkinterCustomButton\")\n\ndef button_function():\n    print(\"Button pressed\")\n\nplay_image = ImageTk.PhotoImage(Image.open(\"button_test_images/play_button_image.png\").resize((40, 40)))\nskip_image = ImageTk.PhotoImage(Image.open(\"button_test_images/skip_button_image.png\").resize((40, 40)))\n\nbutton_1 = TkinterCustomButton(image=play_image, width=60, height=60, corner_radius=12, command=button_function)\nbutton_1.place(relx=0.33, rely=0.5, anchor=tkinter.CENTER)\n\nbutton_2 = TkinterCustomButton(image=skip_image, width=60, height=60, corner_radius=12, command=button_function)\nbutton_2.place(relx=0.66, rely=0.5, anchor=tkinter.CENTER)\n\napp.mainloop()"
  },
  {
    "path": "documentation/test_custom_button_simple.py",
    "content": "import tkinter\nfrom tkinter_custom_button import TkinterCustomButton\n\napp = tkinter.Tk()\napp.geometry(\"300x200\")\napp.title(\"TkinterCustomButton\")\n\n\ndef button_function():\n    print(\"Button pressed\")\n\n\nbutton_1 = TkinterCustomButton(text=\"My Button\", corner_radius=10, command=button_function)\nbutton_1.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)\n\napp.mainloop()"
  },
  {
    "path": "documentation/tkinter_custom_button.py",
    "content": "import tkinter\nimport sys\n\n\nclass TkinterCustomButton(tkinter.Frame):\n    \"\"\" tkinter custom button with border, rounded corners and hover effect\n\n        Arguments:  master= where to place button\n                    bg_color= background color, None is standard,\n                    fg_color= foreground color, blue is standard,\n                    hover_color= foreground color, lightblue is standard,\n                    border_color= foreground color, None is standard,\n                    border_width= border thickness, 0 is standard,\n                    command= callback function, None is standard,\n                    width= width of button, 110 is standard,\n                    height= width of button, 35 is standard,\n                    corner_radius= corner radius, 10 is standard,\n                    text_font= (<Name>, <Size>),\n                    text_color= text color, white is standard,\n                    text= text of button,\n                    hover= hover effect, True is standard,\n                    image= PIL.PhotoImage, standard is None\"\"\"\n\n    def __init__(self,\n                 bg_color=None,\n                 fg_color=\"#2874A6\",\n                 hover_color=\"#5499C7\",\n                 border_color=None,\n                 border_width=0,\n                 command=None,\n                 width=120,\n                 height=40,\n                 corner_radius=10,\n                 text_font=None,\n                 text_color=\"white\",\n                 text=\"CustomButton\",\n                 hover=True,\n                 image=None,\n                 *args, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        if bg_color is None:\n            self.bg_color = self.master.cget(\"bg\")\n        else:\n            self.bg_color = bg_color\n\n        self.fg_color = fg_color\n        self.hover_color = hover_color\n        self.border_color = border_color\n\n        self.width = width\n        self.height = height\n\n        if corner_radius*2 > self.height:\n            self.corner_radius = self.height/2\n        elif corner_radius*2 > self.width:\n            self.corner_radius = self.width/2\n        else:\n            self.corner_radius = corner_radius\n\n        self.border_width = border_width\n\n        if self.corner_radius >= self.border_width:\n            self.inner_corner_radius = self.corner_radius - self.border_width\n        else:\n            self.inner_corner_radius = 0\n\n        self.text = text\n        self.text_color = text_color\n        if text_font is None:\n            if sys.platform == \"darwin\":  # macOS\n                self.text_font = (\"Avenir\", 13)\n            elif \"win\" in sys.platform:  # Windows\n                self.text_font = (\"Century Gothic\", 11)\n            else:\n                self.text_font = (\"TkDefaultFont\")\n        else:\n            self.text_font = text_font\n\n        self.image = image\n\n        self.function = command\n        self.hover = hover\n\n        self.configure(width=self.width, height=self.height)\n\n        if sys.platform == \"darwin\" and self.function is not None:\n            self.configure(cursor=\"pointinghand\")\n\n        self.canvas = tkinter.Canvas(master=self,\n                                     highlightthicknes=0,\n                                     background=self.bg_color,\n                                     width=self.width,\n                                     height=self.height)\n        self.canvas.place(x=0, y=0)\n\n        if self.hover is True:\n            self.canvas.bind(\"<Enter>\", self.on_enter)\n            self.canvas.bind(\"<Leave>\", self.on_leave)\n\n        self.canvas.bind(\"<Button-1>\", self.clicked)\n        self.canvas.bind(\"<Button-1>\", self.clicked)\n\n        self.canvas_fg_parts = []\n        self.canvas_border_parts = []\n        self.text_part = None\n        self.text_label = None\n        self.image_label = None\n\n        self.draw()\n\n    def draw(self):\n        self.canvas.delete(\"all\")\n        self.canvas_fg_parts = []\n        self.canvas_border_parts = []\n        self.canvas.configure(bg=self.bg_color)\n\n        # border button parts\n        if self.border_width > 0:\n\n            if self.corner_radius > 0:\n                self.canvas_border_parts.append(self.canvas.create_oval(0,\n                                                                        0,\n                                                                        self.corner_radius * 2,\n                                                                        self.corner_radius * 2))\n                self.canvas_border_parts.append(self.canvas.create_oval(self.width - self.corner_radius * 2,\n                                                                        0,\n                                                                        self.width,\n                                                                        self.corner_radius * 2))\n                self.canvas_border_parts.append(self.canvas.create_oval(0,\n                                                                        self.height - self.corner_radius * 2,\n                                                                        self.corner_radius * 2,\n                                                                        self.height))\n                self.canvas_border_parts.append(self.canvas.create_oval(self.width - self.corner_radius * 2,\n                                                                        self.height - self.corner_radius * 2,\n                                                                        self.width,\n                                                                        self.height))\n\n            self.canvas_border_parts.append(self.canvas.create_rectangle(0,\n                                                                         self.corner_radius,\n                                                                         self.width,\n                                                                         self.height - self.corner_radius))\n            self.canvas_border_parts.append(self.canvas.create_rectangle(self.corner_radius,\n                                                                         0,\n                                                                         self.width - self.corner_radius,\n                                                                         self.height))\n\n        # inner button parts\n\n        if self.corner_radius > 0:\n            self.canvas_fg_parts.append(self.canvas.create_oval(self.border_width,\n                                                                self.border_width,\n                                                                self.border_width + self.inner_corner_radius * 2,\n                                                                self.border_width + self.inner_corner_radius * 2))\n            self.canvas_fg_parts.append(self.canvas.create_oval(self.width - self.border_width - self.inner_corner_radius * 2,\n                                                                self.border_width,\n                                                                self.width - self.border_width,\n                                                                self.border_width + self.inner_corner_radius * 2))\n            self.canvas_fg_parts.append(self.canvas.create_oval(self.border_width,\n                                                                self.height - self.border_width - self.inner_corner_radius * 2,\n                                                                self.border_width + self.inner_corner_radius * 2,\n                                                                self.height-self.border_width))\n            self.canvas_fg_parts.append(self.canvas.create_oval(self.width - self.border_width - self.inner_corner_radius * 2,\n                                                                self.height - self.border_width - self.inner_corner_radius * 2,\n                                                                self.width - self.border_width,\n                                                                self.height - self.border_width))\n\n        self.canvas_fg_parts.append(self.canvas.create_rectangle(self.border_width + self.inner_corner_radius,\n                                                                 self.border_width,\n                                                                 self.width - self.border_width - self.inner_corner_radius,\n                                                                 self.height - self.border_width))\n        self.canvas_fg_parts.append(self.canvas.create_rectangle(self.border_width,\n                                                                 self.border_width + self.inner_corner_radius,\n                                                                 self.width - self.border_width,\n                                                                 self.height - self.inner_corner_radius - self.border_width))\n\n        for part in self.canvas_fg_parts:\n            self.canvas.itemconfig(part, fill=self.fg_color, width=0)\n\n        for part in self.canvas_border_parts:\n            self.canvas.itemconfig(part, fill=self.border_color, width=0)\n\n        # no image given\n        if self.image is None:\n            # create tkinter.Label with text\n            self.text_label = tkinter.Label(master=self,\n                                            text=self.text,\n                                            font=self.text_font,\n                                            bg=self.fg_color,\n                                            fg=self.text_color)\n            self.text_label.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)\n\n            # bind events the the button click and hover events also to the text_label\n            if self.hover is True:\n                self.text_label.bind(\"<Enter>\", self.on_enter)\n                self.text_label.bind(\"<Leave>\", self.on_leave)\n\n            self.text_label.bind(\"<Button-1>\", self.clicked)\n            self.text_label.bind(\"<Button-1>\", self.clicked)\n\n            self.set_text(self.text)\n\n        # use the given image\n        else:\n            # create tkinter.Label with image on it\n            self.image_label = tkinter.Label(master=self,\n                                             image=self.image,\n                                             bg=self.fg_color)\n\n            self.image_label.place(relx=0.5,\n                                   rely=0.5,\n                                   anchor=tkinter.CENTER)\n\n            # bind events the the button click and hover events also to the image_label\n            if self.hover is True:\n                self.image_label.bind(\"<Enter>\", self.on_enter)\n                self.image_label.bind(\"<Leave>\", self.on_leave)\n\n            self.image_label.bind(\"<Button-1>\", self.clicked)\n            self.image_label.bind(\"<Button-1>\", self.clicked)\n\n    def configure_color(self, bg_color=None, fg_color=None, hover_color=None, text_color=None):\n        if bg_color is not None:\n            self.bg_color = bg_color\n        else:\n            self.bg_color = self.master.cget(\"bg\")\n\n        if fg_color is not None:\n            self.fg_color = fg_color\n\n            # change background color of image_label\n            if self.image is not None:\n                self.image_label.configure(bg=self.fg_color)\n\n        if hover_color is not None:\n            self.hover_color = hover_color\n\n        if text_color is not None:\n            self.text_color = text_color\n            if self.text_part is not None:\n                self.canvas.itemconfig(self.text_part, fill=self.text_color)\n\n        self.draw()\n\n    def set_text(self, text):\n        if self.text_label is not None:\n            self.text_label.configure(text=text)\n\n    def on_enter(self, event=0):\n        for part in self.canvas_fg_parts:\n            self.canvas.itemconfig(part, fill=self.hover_color, width=0)\n\n        if self.text_label is not None:\n            # change background color of image_label\n            self.text_label.configure(bg=self.hover_color)\n\n        if self.image_label is not None:\n            # change background color of image_label\n            self.image_label.configure(bg=self.hover_color)\n\n    def on_leave(self, event=0):\n        for part in self.canvas_fg_parts:\n            self.canvas.itemconfig(part, fill=self.fg_color, width=0)\n\n        if self.text_label is not None:\n            # change background color of image_label\n            self.text_label.configure(bg=self.fg_color)\n\n        if self.image_label is not None:\n            # change background color of image_label\n            self.image_label.configure(bg=self.fg_color)\n\n    def clicked(self, event=0):\n        if self.function is not None:\n            self.function()\n            self.on_leave()\n"
  },
  {
    "path": "main.py",
    "content": "import tkinter\nimport tkinter.messagebox\nimport os\nimport sys\nimport json\nimport requests\nimport webbrowser\nimport time\nimport numpy as np\nimport random\nfrom distutils.version import StrictVersion as Version\n\nfrom tuner_audio.audio_analyzer import AudioAnalyzer\nfrom tuner_audio.threading_helper import ProtectedList\nfrom tuner_audio.sound_thread import SoundThread\n\nfrom tuner_appearance_manager.color_manager import ColorManager\nfrom tuner_appearance_manager.image_manager import ImageManager\nfrom tuner_appearance_manager.font_manager import FontManager\nfrom tuner_appearance_manager.timing import Timer\n\nfrom tuner_ui_parts.main_frame import MainFrame\nfrom tuner_ui_parts.settings_frame import SettingsFrame\n\ntry:\n    from usage_monitoring import usage_monitor\nexcept ImportError:\n    \"\"\" Usage monitoring not possible, because the module is missing\n     (Github Version is missing the module because of private API key) \"\"\"\n    usage_monitor = None\n\nfrom settings import Settings\n\n\nclass App(tkinter.Tk):\n    def __init__(self, *args, **kwargs):\n        if not Settings.COMPILED_APP_MODE:\n            if sys.platform == \"darwin\":  # macOS\n                if Version(tkinter.Tcl().call(\"info\", \"patchlevel\")) >= Version(\"8.6.9\"):  # Tcl/Tk >= 8.6.9\n                    os.system(\"defaults write -g NSRequiresAquaSystemAppearance -bool No\")  # Only for dark-mode testing!\n                    # WARNING: This command applies macOS dark-mode on all programs. This can cause bugs on some programs.\n                    # Currently this works only with anaconda python version (python.org Tcl/Tk version is only 8.6.8).\n                    pass\n\n        tkinter.Tk.__init__(self, *args, **kwargs)\n\n        self.main_path = os.path.dirname(os.path.abspath(__file__))\n\n        self.color_manager = ColorManager()\n        self.font_manager = FontManager()\n        self.image_manager = ImageManager(self.main_path)\n        self.frequency_queue = ProtectedList()\n\n        self.main_frame = MainFrame(self)\n        self.settings_frame = SettingsFrame(self)\n\n        self.audio_analyzer = AudioAnalyzer(self.frequency_queue)\n        self.audio_analyzer.start()\n\n        self.play_sound_thread = SoundThread(self.main_path + \"/assets/sounds/drop.wav\")\n        self.play_sound_thread.start()\n\n        self.timer = Timer(Settings.FPS)\n\n        self.needle_buffer_array = np.zeros(Settings.NEEDLE_BUFFER_LENGTH)\n        self.tone_hit_counter = 0\n        self.note_number_counter = 0\n        self.nearest_note_number_buffered = 69\n        self.a4_frequency = 440\n\n        self.dark_mode_active = False\n\n        self.title(Settings.APP_NAME)\n        self.geometry(str(Settings.WIDTH) + \"x\" + str(Settings.HEIGHT))\n        self.resizable(True, True)\n        self.minsize(Settings.WIDTH, Settings.HEIGHT)\n        self.maxsize(Settings.MAX_WIDTH, Settings.MAX_HEIGHT)\n        self.configure(background=self.color_manager.background_layer_1)\n\n        self.protocol(\"WM_DELETE_WINDOW\", self.on_closing)\n\n        if sys.platform == \"darwin\":  # macOS\n            self.bind(\"<Command-q>\", self.on_closing)\n            self.bind(\"<Command-w>\", self.on_closing)\n            self.createcommand('tk::mac::Quit', self.on_closing)\n            self.createcommand('tk::mac::ShowPreferences', self.draw_settings_frame)\n\n            menu_bar = tkinter.Menu(master=self)\n            app_menu = tkinter.Menu(menu_bar, name='apple')\n            menu_bar.add_cascade(menu=app_menu)\n\n            app_menu.add_command(label='About ' + Settings.APP_NAME, command=self.about_dialog)\n            app_menu.add_separator()\n\n            self.config(menu=menu_bar)\n\n        elif \"win\" in sys.platform:  # Windows\n            self.bind(\"<Alt-Key-F4>\", self.on_closing)\n\n        self.draw_main_frame()\n\n        if self.read_user_setting(\"bell_muted\") is True:\n            self.main_frame.button_mute.set_pressed(True)\n\n        self.open_app_time = time.time()\n\n    @staticmethod\n    def about_dialog():\n        tkinter.messagebox.showinfo(title=Settings.APP_NAME,\n                                    message=Settings.ABOUT_TEXT)\n\n    def draw_settings_frame(self, event=0):\n        self.main_frame.place_forget()\n        self.settings_frame.place(relx=0, rely=0, relheight=1, relwidth=1)\n\n    def draw_main_frame(self, event=0):\n        self.settings_frame.place_forget()\n        self.main_frame.place(relx=0, rely=0, relheight=1, relwidth=1)\n\n    def manage_usage_stats(self, open_times, id):\n        if Settings.COMPILED_APP_MODE:\n\n            # check usage_monitor module could be loaded\n            if usage_monitor is not None:\n\n                # check if user agreed on usage statistics\n                if self.read_user_setting(\"agreed_on_usage_stats\") is True:\n\n                    # send log message with option and open_times data\n                    usage_monitor.UsageMonitor.new_log_msg(open_times, id)\n                else:\n                    # open dialog to ask for usage statistics permission\n                    answer = tkinter.messagebox.askyesno(title=Settings.APP_NAME,\n                                                         message=Settings.STATISTICS_AGREEMENT)\n                    if answer is True:\n                        # save user permission\n                        self.write_user_setting(\"agreed_on_usage_stats\", True)\n\n                        # send log message with option and open_times data\n                        usage_monitor.UsageMonitor.new_log_msg(open_times, id)\n                    else:\n                        # close program if user doesnt agree\n                        self.on_closing()\n\n    def check_for_updates(self):\n        # check if user agreed on update checking\n        if self.read_user_setting(\"check_for_updates\") is True:\n            try:\n                # use github API to get latest version string\n                response = requests.get(Settings.GITHUB_API_URL + \"/releases/latest\")\n                latest_version = response.json()[\"tag_name\"]\n            except Exception as err:\n                sys.stderr.write(str(err) + \"/n\")\n                return\n\n            if Version(latest_version) > Version(Settings.VERSION):\n                answer = tkinter.messagebox.askyesno(title=Settings.APP_NAME,\n                                                     message=\"A new version of this app is available. \\n\\n\" +\n                                                             \"Do you want to download it?\")\n                if answer is True:\n                    webbrowser.open(Settings.GITHUB_URL + \"/releases/latest\")\n                else:\n                    answer = tkinter.messagebox.askyesno(title=Settings.APP_NAME,\n                                                         message=\"Ask again next time? \\n\\n\")\n                    if answer is False:\n                        self.write_user_setting(\"check_for_updates\", False)\n\n    def write_user_setting(self, setting, value):\n        with open(self.main_path + Settings.USER_SETTINGS_PATH, \"r\") as file:\n            user_settings = json.load(file)\n\n        user_settings[setting] = value\n\n        with open(self.main_path + Settings.USER_SETTINGS_PATH, \"w\") as file:\n            json.dump(user_settings, file)\n\n    def read_user_setting(self, setting):\n        with open(self.main_path + Settings.USER_SETTINGS_PATH) as file:\n            user_settings = json.load(file)\n\n        return user_settings[setting]\n\n    def on_closing(self, event=0):\n        self.write_user_setting(\"bell_muted\", self.main_frame.button_mute.is_pressed())\n        self.check_for_updates()\n\n        if not Settings.COMPILED_APP_MODE:\n            if sys.platform == \"darwin\":  # macOS\n                if Version(tkinter.Tcl().call(\"info\", \"patchlevel\")) >= Version(\"8.6.9\"):  # Tcl/Tk >= 8.6.9\n                    os.system(\"defaults delete -g NSRequiresAquaSystemAppearance\")  # Only for dark-mode testing!\n                    # This command reverts the dark-mode setting for all programs.\n                    pass\n\n        self.audio_analyzer.running = False\n        self.play_sound_thread.running = False\n        self.destroy()\n\n    def update_color(self):\n        self.main_frame.update_color()\n        self.settings_frame.update_color()\n\n    def handle_appearance_mode_change(self):\n        dark_mode_state = self.color_manager.detect_os_dark_mode()\n\n        if dark_mode_state is not self.dark_mode_active:\n            if dark_mode_state is True:\n                self.color_manager.set_mode(\"Dark\")\n            else:\n                self.color_manager.set_mode(\"Light\")\n\n            self.dark_mode_active = dark_mode_state\n            self.update_color()\n\n    def start(self):\n        self.handle_appearance_mode_change()\n\n        # handle new usage statistics when program is started\n        if self.read_user_setting(\"id\") is None: self.write_user_setting(\"id\", random.randint(10**20, (10**21)-1))  # generate random id\n        self.write_user_setting(\"open_times\", self.read_user_setting(\"open_times\")+1)  # increase open_times counter\n        self.manage_usage_stats(self.read_user_setting(\"open_times\"), self.read_user_setting(\"id\"))  # send open_times value and id\n\n        while self.audio_analyzer.running:\n\n            try:\n                # handle the change from dark to light mode, light to dark mode\n                self.handle_appearance_mode_change()\n\n                # get the current frequency from the queue\n                freq = self.frequency_queue.get()\n                if freq is not None:\n\n                    # convert frequency to note number\n                    number = self.audio_analyzer.frequency_to_number(freq, self.a4_frequency)\n\n                    # calculate nearest note number, name and frequency\n                    nearest_note_number = round(number)\n                    nearest_note_freq = self.audio_analyzer.number_to_frequency(nearest_note_number, self.a4_frequency)\n\n                    # calculate frequency difference from freq to nearest note\n                    freq_difference = nearest_note_freq - freq\n\n                    # calculate the frequency difference to the next note (-1)\n                    semitone_step = nearest_note_freq - self.audio_analyzer.number_to_frequency(round(number-1),\n                                                                                                self.a4_frequency)\n\n                    # calculate the angle of the display needle\n                    needle_angle = -90 * ((freq_difference / semitone_step) * 2)\n\n                    # buffer the current nearest note number change\n                    if nearest_note_number != self.nearest_note_number_buffered:\n                        self.note_number_counter += 1\n                        if self.note_number_counter >= Settings.HITS_TILL_NOTE_NUMBER_UPDATE:\n                            self.nearest_note_number_buffered = nearest_note_number\n                            self.note_number_counter = 0\n\n                    # if needle in range +-5 degrees then make it green, otherwise red\n                    if abs(freq_difference) < 0.25:\n                        self.main_frame.set_needle_color(\"green\")\n                        self.tone_hit_counter += 1\n                    else:\n                        self.main_frame.set_needle_color(\"red\")\n                        self.tone_hit_counter = 0\n\n                    # after 7 hits of the right note in a row play the sound\n                    if self.tone_hit_counter > 7:\n                        self.tone_hit_counter = 0\n\n                        if self.main_frame.button_mute.is_pressed() is not True:\n                            self.play_sound_thread.play_sound()\n\n                    # update needle buffer array\n                    self.needle_buffer_array[:-1] = self.needle_buffer_array[1:]\n                    self.needle_buffer_array[-1:] = needle_angle\n\n                    # update ui note labels and display needle\n                    self.main_frame.set_needle_angle(np.average(self.needle_buffer_array))\n                    self.main_frame.set_note_names(note_name=self.audio_analyzer.number_to_note_name(self.nearest_note_number_buffered),\n                                                   note_name_lower=self.audio_analyzer.number_to_note_name(self.nearest_note_number_buffered - 1),\n                                                   note_name_higher=self.audio_analyzer.number_to_note_name(self.nearest_note_number_buffered + 1))\n\n                    # calculate difference in cents\n                    if semitone_step == 0:\n                        diff_cents = 0\n                    else:\n                        diff_cents = (freq_difference / semitone_step) * 100\n                    freq_label_text = f\"+{round(-diff_cents, 1)} cents\" if -diff_cents > 0 else f\"{round(-diff_cents, 1)} cents\"\n                    self.main_frame.set_frequency_difference(freq_label_text)\n\n                    # set current frequency\n                    if freq is not None: self.main_frame.set_frequency(freq)\n\n                self.update()\n                self.timer.wait()\n\n            except IOError as err:\n                sys.stderr.write('Error: Line {} {} {}\\n'.format(sys.exc_info()[-1].tb_lineno, type(err).__name__, err))\n                self.update()\n                self.timer.wait()\n\n\nif __name__ == \"__main__\":\n    app = App()\n    app.start()\n"
  },
  {
    "path": "requirements.txt",
    "content": "numpy~=1.22.1\nsetuptools~=52.0.0\nPyAudio~=0.2.11\npy2app~=0.21\nPillow~=9.0.0\ndarkdetect~=0.1.1\nrequests~=2.25.1"
  },
  {
    "path": "settings.py",
    "content": "\nclass Settings:\n    \"\"\" GuitarTuner global app configuration \"\"\"\n\n    COMPILED_APP_MODE = False\n\n    \"\"\" general settings \"\"\"\n    APP_NAME = \"GuitarTuner\"\n    VERSION = \"3.2\"\n    AUTHOR = \"Tom Schimansky\"\n    YEAR = \"2021\"\n\n    GITHUB_API_URL = \"https://api.github.com/repos/TomSchimansky/GuitarTuner\"\n    GITHUB_URL = \"https://github.com/TomSchimansky/GuitarTuner\"\n    GITHUB_URL_README = \"https://github.com/TomSchimansky/GuitarTuner#readme\"\n\n    STATISTICS_AGREEMENT = f\"{APP_NAME} tracks how often the app is being opened.\\n\\n\" + \\\n                           \"Do you agree on sending this anonymous data?\"\n\n    USER_SETTINGS_PATH = \"/assets/user_settings/user_settings.json\"\n\n    ABOUT_TEXT = \"{} Version {}  © {} {}\".format(APP_NAME, VERSION, YEAR, AUTHOR)\n    CF_BUNDLE_IDENTIFIER = \"com.{}.{}\".format(AUTHOR, APP_NAME)\n\n    WIDTH = 450  # window size when starting the app\n    HEIGHT = 440\n\n    MAX_WIDTH = 600  # max window size\n    MAX_HEIGHT = 500\n\n    FPS = 60  # canvas update rate\n    CANVAS_SIZE = 300  # size of the audio-display\n\n    NEEDLE_BUFFER_LENGTH = 30\n    HITS_TILL_NOTE_NUMBER_UPDATE = 15\n"
  },
  {
    "path": "setup.py",
    "content": "\"\"\" this setup.py file is build for compilation on macOS with py2app\"\"\"\n\nimport os\nimport getpass\nfrom setuptools import setup\nfrom settings import Settings\n\nREMOVE_OLD_BUILD = True  # delete /build and /dist\n\nAPP = ['main.py']\nUSER_NAME = getpass.getuser()\n\nSOUND_FILES = [\"assets/sounds/drop.wav\"]\n\nDATA_FILES = [\"assets/user_settings/user_settings.json\"]\n\nIMAGE_FILES = [\"assets/images/arrowDown_hovered.png\",\n               \"assets/images/arrowDown.png\",\n               \"assets/images/arrowUp_hovered.png\",\n               \"assets/images/arrowUp.png\",\n               \"assets/images/bell_hovered.png\",\n               \"assets/images/bell.png\",\n               \"assets/images/mutedBell_hovered.png\",\n               \"assets/images/mutedBell.png\"]\n\nOPTIONS = {'argv_emulation': False,\n           'includes': 'numpy, tkinter, PIL, pyaudio, darkdetect, requests',\n           'excludes': '',\n           'frameworks': '/Users/{}/miniconda3/lib/libffi.6.dylib,'.format(USER_NAME) +\n                         '/Users/{}/miniconda3/lib/libtk8.6.dylib,'.format(USER_NAME) +\n                         '/Users/{}/miniconda3/lib/libtcl8.6.dylib'.format(USER_NAME),\n           # For whatever reason, py2app didn't include these 3 frameworks automatically. (path can be different)\n           'iconfile': 'assets/images/GuitarTuner_Icon.icns',\n           'plist': {\n               'CFBundleName': Settings.APP_NAME,\n               'CFBundleDisplayName': Settings.APP_NAME,\n               'CFBundleExecutable': Settings.APP_NAME,\n               'CFBundleGetInfoString': \"Tune your instrument with {}\".format(Settings.APP_NAME),\n               'CFBundleIdentifier': Settings.CF_BUNDLE_IDENTIFIER,\n               'CFBundleVersion': Settings.VERSION,\n               'CFBundleShortVersionString': Settings.VERSION,\n               'NSRequiresAquaSystemAppearance': False,\n               'NSHumanReadableCopyright': u\"Copyright {}, {}, All Rights Reserved\".format(Settings.YEAR, Settings.AUTHOR)\n           }}\n\n\nif REMOVE_OLD_BUILD is True:\n    os.system(\"rm -r build\")\n    os.system(\"rm -r dist\")\n\nsetup(name=Settings.APP_NAME,\n      app=APP,\n      author=Settings.AUTHOR,\n      data_files=[(\"assets/images\", IMAGE_FILES),\n                  (\"assets/sounds\", SOUND_FILES),\n                  (\"assets/user_settings\", DATA_FILES)],\n      options={'py2app': OPTIONS},\n      setup_requires=['py2app'])\n"
  },
  {
    "path": "tuner_appearance_manager/color_manager.py",
    "content": "import darkdetect\nimport sys\n\n\nclass ColorManager(object):\n    def __init__(self):\n        self.set_mode(\"Light\")\n\n    def set_mode(self, mode):\n        if mode == \"Dark\":\n            self.background_layer_1 = self.rgb_to_hex((50, 50, 50))\n            self.background_layer_0 = self.rgb_to_hex((33, 33, 33))\n            self.text_main = self.rgb_to_hex((255, 255, 255))\n            self.text_2 = self.rgb_to_hex((169, 169, 169))\n            self.text_2_highlight = self.rgb_to_hex((240, 240, 240))\n            self.theme_main = self.rgb_to_hex((51, 94, 145))\n            self.theme_dark = self.rgb_to_hex((26, 51, 82))\n            self.theme_light = self.rgb_to_hex((85, 140, 200))\n            self.needle = self.rgb_to_hex((107, 42, 28))\n            self.needle_hit = self.rgb_to_hex((43, 113, 53))\n\n        elif mode == \"Light\":\n            self.background_layer_1 = self.rgb_to_hex((241, 239, 238))\n            self.background_layer_0 = self.rgb_to_hex((209, 208, 206))\n            self.text_main = self.rgb_to_hex((0, 0, 0))\n            self.text_2 = self.rgb_to_hex((36, 36, 36))\n            self.text_2_highlight = self.rgb_to_hex((0, 0, 0))\n            self.theme_main = self.rgb_to_hex((83, 147, 213))\n            self.theme_dark = self.rgb_to_hex((51, 94, 145))\n            self.theme_light = self.rgb_to_hex((128, 175, 223))\n            self.needle = self.rgb_to_hex((107, 42, 28))\n            self.needle_hit = self.rgb_to_hex((43, 113, 53))\n\n    @staticmethod\n    def rgb_to_hex(rgb):\n        return \"#%02x%02x%02x\" % rgb\n\n    @staticmethod\n    def detect_os_dark_mode():\n        if sys.platform == \"darwin\":\n            if darkdetect.theme() == \"Dark\":\n                return True\n            else:\n                return False\n        else:\n            return True\n"
  },
  {
    "path": "tuner_appearance_manager/font_manager.py",
    "content": "import sys\n\n\nclass FontManager(object):\n    \"\"\" font sizes need to be different on operating systems\n        because on windows the text is displayed much larger \"\"\"\n\n    def __init__(self):\n\n        if sys.platform == \"darwin\":  # macOS\n            self.button_font = (\"Avenir\", 16)\n            self.note_display_font = (\"Avenir\", 72)  # main note Text\n            self.note_display_font_medium = (\"Avenir\", 26)  # text on left and right site\n            self.frequency_text_font = (\"Avenir\", 15)\n            self.info_text_font = (\"Avenir\", 14)\n            self.settings_text_font = (\"Avenir\", 24)\n\n        elif \"win\" in sys.platform:  # Windows\n            self.button_font = (\"Century Gothic\", 14)\n            self.note_display_font = (\"Century Gothic\", 62)\n            self.note_display_font_medium = (\"Century Gothic\", 24)  # text on left and right site\n            self.frequency_text_font = (\"Century Gothic\", 13)\n            self.info_text_font = (\"Century Gothic\", 12)\n            self.settings_text_font = (\"Century Gothic\", 20)\n\n        else:  # Linux or other\n            self.button_font = (\"Century Gothic\", 14)\n            self.note_display_font = (\"Century Gothic\", 62)\n            self.note_display_font_medium = (\"Century Gothic\", 24)  # text on left and right site\n            self.frequency_text_font = (\"Century Gothic\", 13)\n            self.info_text_font = (\"Century Gothic\", 12)\n            self.settings_text_font = (\"Century Gothic\", 20)"
  },
  {
    "path": "tuner_appearance_manager/image_manager.py",
    "content": "\ntry:\n    import Image\nexcept ImportError:\n    from PIL import Image\n\ntry:\n    import ImageTk\nexcept ImportError:\n    from PIL import ImageTk\n\n\nclass ImageManager(object):\n    def __init__(self, main_path):\n        self.bell_image = ImageTk.PhotoImage(\n            Image.open(main_path + \"/assets/images/bell.png\").resize((50, 50), Image.ANTIALIAS))\n\n        self.bell_hovered_image = ImageTk.PhotoImage(\n            Image.open(main_path + \"/assets/images/bell_hovered.png\").resize((50, 50), Image.ANTIALIAS))\n\n        self.bell_muted_image = ImageTk.PhotoImage(\n            Image.open(main_path + \"/assets/images/mutedBell.png\").resize((50, 50), Image.ANTIALIAS))\n\n        self.bell_muted_hovered_image = ImageTk.PhotoImage(\n            Image.open(main_path + \"/assets/images/mutedBell_hovered.png\").resize((50, 50), Image.ANTIALIAS))\n\n        self.arrowUp_image = ImageTk.PhotoImage(\n            Image.open(main_path + \"/assets/images/arrowUp.png\").resize((147, 46), Image.ANTIALIAS))\n\n        self.arrowUp_image_hovered = ImageTk.PhotoImage(\n            Image.open(main_path + \"/assets/images/arrowUp_hovered.png\").resize((147, 46), Image.ANTIALIAS))\n\n        self.arrowDown_image = ImageTk.PhotoImage(\n            Image.open(main_path + \"/assets/images/arrowDown.png\").resize((147, 46), Image.ANTIALIAS))\n\n        self.arrowDown_image_hovered = ImageTk.PhotoImage(\n            Image.open(main_path + \"/assets/images/arrowDown_hovered.png\").resize((147, 46), Image.ANTIALIAS))\n"
  },
  {
    "path": "tuner_appearance_manager/timing.py",
    "content": "import time\nimport sys\n\n\nclass Timer(object):\n    \"\"\" Timer makes current thread sleep until time\n        of set FPS is over. If time is already over\n        the Timer does nothing or prints a warning\n        if specified \"\"\"\n    \n    def __init__(self, fps, warnings=False):\n        self.fps = fps\n        self.wait_time = 1/self.fps\n        self.last_time = time.time()\n        self.warnings = warnings\n\n    def wait(self):\n        spend_time = time.time() - self.last_time\n        sleep_time = self.wait_time - spend_time\n\n        if sleep_time < 0:\n            if self.warnings:\n                sys.stderr.write(\"Warning: Timer delay of {} secs\\n\".format(round(-sleep_time, 4)))\n        else:\n            time.sleep(sleep_time)\n\n        self.last_time = time.time()\n"
  },
  {
    "path": "tuner_audio/__init__.py",
    "content": ""
  },
  {
    "path": "tuner_audio/audio_analyzer.py",
    "content": "import copy\nfrom pyaudio import PyAudio, paInt16\nfrom threading import Thread\nimport numpy as np\nimport sys\n\n\nclass AudioAnalyzer(Thread):\n    \"\"\" This AudioAnalyzer reads the microphone and finds the frequency of the loudest tone.\n        To use it, you also need the ProtectedList class from the file threading_helper.py.\n        You need to created an instance of the ProtectedList, which acts as a queue, and you\n        have to pass this queue to the AudioAnalyzer. Then you can read the values from the queue:\n\n        queue = ProtectedList()\n        analyzer = AudioAnalyzer(queue)\n        analyzer.start()\n\n        while True:\n            freq = queue.get()\n            print(\"loudest frequency:\", q_data, \"nearest note:\", a.frequency_to_note_name(q_data, 440))\n            time.sleep(0.02) \"\"\"\n\n    # settings: (are tuned for best detecting string instruments like guitar)\n    SAMPLING_RATE = 48000  # mac hardware: 44100, 48000, 96000\n    CHUNK_SIZE = 1024  # number of samples\n    BUFFER_TIMES = 50  # buffer length = CHUNK_SIZE * BUFFER_TIMES\n    ZERO_PADDING = 3  # times the buffer length\n    NUM_HPS = 3  # Harmonic Product Spectrum\n\n    # overall frequency accuracy (step-size):  SAMPLING_RATE / (CHUNK_SIZE * BUFFER_TIMES * (1 + ZERO_PADDING)) Hz\n    #               buffer length in seconds:  (CHUNK_SIZE * BUFFER_TIMES) / SAMPLING_RATE sec\n\n    NOTE_NAMES = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']\n\n    def __init__(self, queue, *args, **kwargs):\n        Thread.__init__(self, *args, **kwargs)\n\n        self.queue = queue  # queue should be instance of ProtectedList (threading_helper.ProtectedList)\n        self.buffer = np.zeros(self.CHUNK_SIZE * self.BUFFER_TIMES)\n        self.hanning_window = np.hanning(len(self.buffer))\n        self.running = False\n\n        try:\n            self.audio_object = PyAudio()\n            self.stream = self.audio_object.open(format=paInt16,\n                                                 channels=1,\n                                                 rate=self.SAMPLING_RATE,\n                                                 input=True,\n                                                 output=False,\n                                                 frames_per_buffer=self.CHUNK_SIZE)\n        except Exception as e:\n            sys.stderr.write('Error: Line {} {} {}\\n'.format(sys.exc_info()[-1].tb_lineno, type(e).__name__, e))\n            return\n\n    @staticmethod\n    def frequency_to_number(freq, a4_freq):\n        \"\"\" converts a frequency to a note number (for example: A4 is 69)\"\"\"\n\n        if freq == 0:\n            sys.stderr.write(\"Error: No frequency data. Program has potentially no access to microphone\\n\")\n            return 0\n\n        return 12 * np.log2(freq / a4_freq) + 69\n\n    @staticmethod\n    def number_to_frequency(number, a4_freq):\n        \"\"\" converts a note number (A4 is 69) back to a frequency \"\"\"\n\n        return a4_freq * 2.0**((number - 69) / 12.0)\n\n    @staticmethod\n    def number_to_note_name(number):\n        \"\"\" converts a note number to a note name (for example: 69 returns 'A', 70 returns 'A#', ... ) \"\"\"\n\n        return AudioAnalyzer.NOTE_NAMES[int(round(number) % 12)]\n\n    @staticmethod\n    def frequency_to_note_name(frequency, a4_freq):\n        \"\"\" converts frequency to note name (for example: 440 returns 'A') \"\"\"\n\n        number = AudioAnalyzer.frequency_to_number(frequency, a4_freq)\n        note_name = AudioAnalyzer.number_to_note_name(number)\n        return note_name\n\n    def run(self):\n        \"\"\" Main function where the microphone buffer gets read and\n            the fourier transformation gets applied \"\"\"\n\n        self.running = True\n\n        while self.running:\n            try:\n                # read microphone data\n                data = self.stream.read(self.CHUNK_SIZE, exception_on_overflow=False)\n                data = np.frombuffer(data, dtype=np.int16)\n\n                # append data to audio buffer\n                self.buffer[:-self.CHUNK_SIZE] = self.buffer[self.CHUNK_SIZE:]\n                self.buffer[-self.CHUNK_SIZE:] = data\n\n                # apply the fourier transformation on the whole buffer (with zero-padding + hanning window)\n                magnitude_data = abs(np.fft.fft(np.pad(self.buffer * self.hanning_window,\n                                                       (0, len(self.buffer) * self.ZERO_PADDING),\n                                                       \"constant\")))\n                # only use the first half of the fft output data\n                magnitude_data = magnitude_data[:int(len(magnitude_data) / 2)]\n\n                # HPS: multiply data by itself with different scalings (Harmonic Product Spectrum)\n                magnitude_data_orig = copy.deepcopy(magnitude_data)\n                for i in range(2, self.NUM_HPS+1, 1):\n                    hps_len = int(np.ceil(len(magnitude_data) / i))\n                    magnitude_data[:hps_len] *= magnitude_data_orig[::i]  # multiply every i element\n\n                # get the corresponding frequency array\n                frequencies = np.fft.fftfreq(int((len(magnitude_data) * 2) / 1),\n                                             1. / self.SAMPLING_RATE)\n\n                # set magnitude of all frequencies below 60Hz to zero\n                for i, freq in enumerate(frequencies):\n                    if freq > 60:\n                        magnitude_data[:i - 1] = 0\n                        break\n\n                # put the frequency of the loudest tone into the queue\n                self.queue.put(round(frequencies[np.argmax(magnitude_data)], 2))\n\n            except Exception as e:\n                sys.stderr.write('Error: Line {} {} {}\\n'.format(sys.exc_info()[-1].tb_lineno, type(e).__name__, e))\n\n        self.stream.stop_stream()\n        self.stream.close()\n        self.audio_object.terminate()\n\n\nif __name__ == \"__main__\":\n    # Only for testing:\n    from tuner_audio.threading_helper import ProtectedList\n    import time\n\n    q = ProtectedList()\n    a = AudioAnalyzer(q)\n    a.start()\n\n    while True:\n        q_data = q.get()\n        if q_data is not None:\n            print(\"loudest frequency:\", q_data, \"nearest note:\", a.frequency_to_note_name(q_data, 440))\n            time.sleep(0.02)\n"
  },
  {
    "path": "tuner_audio/sound_thread.py",
    "content": "from threading import Thread\nimport pyaudio\nimport wave\nimport time\n\n\nclass SoundThread(Thread):\n    \"\"\" Simple threaded class that takes a path to an audio.wav file\n        and the plays it when SoundThread.play_sound() is called. \"\"\"\n\n    def __init__(self, path_to_file):\n        Thread.__init__(self)\n\n        self.running = False\n        self.data_chunk_size = 1024\n\n        self.audio_file = wave.open(path_to_file, \"rb\")\n        self.audio_file_data = []\n\n        # load audio file into audio_file_data\n        while True:\n            data = self.audio_file.readframes(self.data_chunk_size)\n            if data != b'':\n                self.audio_file_data.append(data)\n            else:\n                break\n\n        self.py_audio_object = pyaudio.PyAudio()\n\n        audio_format = self.py_audio_object.get_format_from_width(self.audio_file.getsampwidth())\n        self.audio_stream = self.py_audio_object.open(format=audio_format,\n                                                      channels=self.audio_file.getnchannels(),\n                                                      rate=self.audio_file.getframerate(),\n                                                      input=False,\n                                                      output=True)\n        self.play_sound_now = False\n        self.audio_file.close()\n\n    def play_sound(self):\n        self.play_sound_now = True\n\n    def run(self):\n        self.running = True\n        while self.running:\n\n            if self.play_sound_now is True:\n                for audio_chunk in self.audio_file_data:\n                    self.audio_stream.write(audio_chunk)\n\n                self.play_sound_now = False\n                time.sleep(1)\n            else:\n                time.sleep(0.1)\n\n        self.audio_stream.stop_stream()\n        self.audio_stream.close()\n        self.py_audio_object.terminate()"
  },
  {
    "path": "tuner_audio/threading_helper.py",
    "content": "from threading import Lock\n\n\nclass ProtectedList(object):\n    \"\"\" Simple queue to share data between Threads with lock protection.\n        Standard buffer length is only 8! \"\"\"\n\n    def __init__(self, buffer_size=8):\n        self.elements = []\n        self.buffer_size = buffer_size\n        self.lock = Lock()\n\n    def put(self, element):\n        self.lock.acquire()\n\n        # append new element at the end of the list\n        self.elements.append(element)\n\n        # delete oldest element if list is too long\n        if len(self.elements) > self.buffer_size:\n            self.elements.pop(0)\n\n        self.lock.release()\n\n    def get(self):\n        self.lock.acquire()\n\n        # check if something is in the list\n        if len(self.elements) > 0:\n            element = self.elements[0]\n            del self.elements[0]\n\n        # if list is empty return None\n        else:\n            element = None\n\n        self.lock.release()\n        return element\n\n    def __repr__(self):\n        self.lock.acquire()\n\n        string = str(self.elements)\n\n        self.lock.release()\n        return string\n"
  },
  {
    "path": "tuner_ui_parts/__init__.py",
    "content": ""
  },
  {
    "path": "tuner_ui_parts/main_frame.py",
    "content": "import tkinter\nfrom math import sin, radians\n\nfrom tuner_ui_parts.tkinter_custom_button_imageset import TkinterCustomButtonImageset\nfrom tuner_ui_parts.tkinter_custom_button import TkinterCustomButton\nfrom settings import Settings\n\n\nclass MainFrame(tkinter.Frame):\n    def __init__(self, master, *args, **kwargs):\n        tkinter.Frame.__init__(self, master, *args, **kwargs)\n\n        self.app_pointer = master\n        self.color_manager = self.app_pointer.color_manager\n        self.font_manager = self.app_pointer.font_manager\n        self.image_manager = self.app_pointer.image_manager\n\n        self.configure(bg=self.color_manager.background_layer_1)\n\n        self.under_canvas = tkinter.Canvas(master=self,\n                                           bg=self.color_manager.background_layer_1,\n                                           highlightthickness=0,\n                                           height=Settings.CANVAS_SIZE,\n                                           width=Settings.CANVAS_SIZE)\n\n        self.under_canvas.place(anchor=tkinter.CENTER, relx=0.5, rely=0.5)\n\n        self.display_outer_circle = self.under_canvas.create_oval(0,\n                                                                  0,\n                                                                  Settings.CANVAS_SIZE - 1,\n                                                                  Settings.CANVAS_SIZE - 1,\n                                                                  fill=self.color_manager.theme_main,\n                                                                  width=0)\n\n        self.display_background_line = self.under_canvas.create_line(Settings.CANVAS_SIZE * 0.5,\n                                                                     Settings.CANVAS_SIZE * 0.5,\n                                                                     Settings.CANVAS_SIZE * 0.5,\n                                                                     -Settings.CANVAS_SIZE * 0.5,\n                                                                     fill=self.color_manager.background_layer_1,\n                                                                     width=Settings.CANVAS_SIZE * 0.05)\n\n        self.needle_width = 8\n        self.display_needle = self.under_canvas.create_line(Settings.CANVAS_SIZE * 0.5,\n                                                            Settings.CANVAS_SIZE * 0.5,\n                                                            Settings.CANVAS_SIZE * 0.5,\n                                                            Settings.CANVAS_SIZE * 0.05,\n                                                            fill=self.color_manager.needle,\n                                                            width=self.needle_width,\n                                                            capstyle=tkinter.ROUND)\n\n        self.display_inner_circle_1 = self.under_canvas.create_oval(Settings.CANVAS_SIZE * 0.2,\n                                                                    Settings.CANVAS_SIZE * 0.2,\n                                                                    Settings.CANVAS_SIZE * 0.8,\n                                                                    Settings.CANVAS_SIZE * 0.8,\n                                                                    fill=self.color_manager.theme_dark,\n                                                                    width=0)\n\n        self.botton_frame = tkinter.Frame(master=self, bg=self.color_manager.background_layer_0)\n        self.botton_frame.place(relx=0, rely=0.5, relheight=0.5, relwidth=1)\n\n        self.upper_canvas = tkinter.Canvas(master=self.botton_frame,\n                                           bg=self.color_manager.background_layer_0,\n                                           highlightthickness=0,\n                                           height=Settings.CANVAS_SIZE / 2,\n                                           width=Settings.CANVAS_SIZE)\n        self.upper_canvas.place(anchor=tkinter.N, relx=0.5, rely=0)\n\n        self.display_inner_circle_2 = self.upper_canvas.create_oval(Settings.CANVAS_SIZE * 0.2,\n                                                                    -Settings.CANVAS_SIZE * 0.3,\n                                                                    Settings.CANVAS_SIZE * 0.8,\n                                                                    Settings.CANVAS_SIZE * 0.3,\n                                                                    fill=self.color_manager.theme_dark,\n                                                                    width=0)\n\n        self.note_label = tkinter.Label(master=self,\n                                        text=\"A\",\n                                        bg=self.color_manager.theme_dark,\n                                        fg=self.color_manager.text_2,\n                                        font=self.font_manager.note_display_font)\n        self.note_label.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)\n\n        self.higher_note_text = self.upper_canvas.create_text(Settings.CANVAS_SIZE * 0.95, Settings.CANVAS_SIZE * 0.1,\n                                                              anchor=tkinter.E,\n                                                              text=\"A#\",\n                                                              fill=self.color_manager.text_2,\n                                                              font=self.font_manager.note_display_font_medium)\n\n        self.lower_note_text = self.upper_canvas.create_text(Settings.CANVAS_SIZE * 0.05, Settings.CANVAS_SIZE * 0.1,\n                                                             anchor=tkinter.W,\n                                                             text=\"B#\",\n                                                             fill=self.color_manager.text_2,\n                                                             font=self.font_manager.note_display_font_medium)\n\n        self.frequency_text = self.upper_canvas.create_text(Settings.CANVAS_SIZE * 0.5, Settings.CANVAS_SIZE * 0.16,\n                                                            anchor=tkinter.N,\n                                                            text=\"- Hz\",\n                                                            fill=self.color_manager.text_2,\n                                                            font=self.font_manager.frequency_text_font)\n\n        self.button_frequency = TkinterCustomButton(master=self.botton_frame,\n                                                    bg_color=self.color_manager.background_layer_0,\n                                                    fg_color=self.color_manager.theme_main,\n                                                    hover_color=self.color_manager.theme_light,\n                                                    text_font=self.font_manager.button_font,\n                                                    text=\"440 Hz\",\n                                                    text_color=self.color_manager.text_main,\n                                                    corner_radius=10,\n                                                    width=110,\n                                                    height=40,\n                                                    hover=False,\n                                                    command=None)\n        self.button_frequency.place(anchor=tkinter.SW, relx=0.05, rely=0.9)\n\n        self.button_info = TkinterCustomButton(master=self.botton_frame,\n                                               bg_color=self.color_manager.background_layer_0,\n                                               fg_color=self.color_manager.theme_main,\n                                               hover_color=self.color_manager.theme_light,\n                                               text_font=self.font_manager.button_font,\n                                               text=\"Info\",\n                                               text_color=self.color_manager.text_main,\n                                               corner_radius=10,\n                                               width=110,\n                                               height=40,\n                                               command=self.master.draw_settings_frame)\n        self.button_info.place(anchor=tkinter.SE, relx=0.95, rely=0.9)\n\n        self.button_mute = TkinterCustomButtonImageset(master=self,\n                                                       bg_color=self.color_manager.background_layer_1,\n                                                       image_dict={\"standard\": self.image_manager.bell_image,\n                                                                   \"clicked\": self.image_manager.bell_muted_image,\n                                                                   \"standard_hover\": self.image_manager.bell_hovered_image,\n                                                                   \"clicked_hover\": self.image_manager.bell_muted_hovered_image},\n                                                       height=self.image_manager.bell_image.height(),\n                                                       width=self.image_manager.bell_image.width())\n        self.button_mute.place(anchor=tkinter.NE, relx=0.95, rely=0.05)\n\n    def update_color(self):\n        self.configure(bg=self.color_manager.background_layer_1)\n\n        self.under_canvas.configure(bg=self.color_manager.background_layer_1)\n        self.under_canvas.itemconfig(self.display_background_line, fill=self.color_manager.background_layer_1)\n        self.under_canvas.itemconfig(self.display_outer_circle, fill=self.color_manager.theme_main)\n        self.under_canvas.itemconfig(self.display_inner_circle_1, fill=self.color_manager.theme_dark)\n\n        self.upper_canvas.configure(bg=self.color_manager.background_layer_0)\n        self.upper_canvas.itemconfig(self.display_inner_circle_2, fill=self.color_manager.theme_dark)\n\n        self.note_label.configure(bg=self.color_manager.theme_dark, fg=self.color_manager.text_2)\n\n        self.upper_canvas.itemconfig(self.higher_note_text, fill=self.color_manager.text_2)\n        self.upper_canvas.itemconfig(self.lower_note_text, fill=self.color_manager.text_2)\n        self.upper_canvas.itemconfig(self.frequency_text, fill=self.color_manager.text_2)\n\n        self.button_mute.label.configure(bg=self.color_manager.background_layer_1)\n\n        self.botton_frame.configure(bg=self.color_manager.background_layer_0)\n\n        self.button_frequency.configure_color(bg_color=self.color_manager.background_layer_0,\n                                              fg_color=self.color_manager.theme_main,\n                                              hover_color=self.color_manager.theme_light,\n                                              text_color=self.color_manager.text_main)\n\n        self.button_info.configure_color(bg_color=self.color_manager.background_layer_0,\n                                         fg_color=self.color_manager.theme_main,\n                                         hover_color=self.color_manager.theme_light,\n                                         text_color=self.color_manager.text_main)\n\n    def set_needle_color(self, color):\n        if color == \"green\":\n            self.under_canvas.itemconfig(self.display_needle, fill=self.color_manager.needle_hit)\n            self.note_label.configure(fg=self.color_manager.text_2_highlight, font=self.font_manager.note_display_font)\n        elif color == \"red\":\n            self.under_canvas.itemconfig(self.display_needle, fill=self.color_manager.needle)\n            self.note_label.configure(fg=self.color_manager.text_2, font=self.font_manager.note_display_font)\n\n    def set_needle_angle(self, deg):\n        x = sin(radians(180 - deg))\n        y = sin(radians(270 - deg))\n\n        self.under_canvas.coords(self.display_needle,\n                                 Settings.CANVAS_SIZE * 0.5,\n                                 Settings.CANVAS_SIZE * 0.5,\n                                 Settings.CANVAS_SIZE * 0.5 + (Settings.CANVAS_SIZE * 0.45 * x),\n                                 Settings.CANVAS_SIZE * 0.5 + (Settings.CANVAS_SIZE * 0.45 * y))\n        return x, y\n\n    def set_note_names(self, note_name, note_name_lower, note_name_higher):\n        self.note_label.configure(text=note_name, width=3)\n        self.upper_canvas.itemconfig(self.higher_note_text, text=note_name_higher)\n        self.upper_canvas.itemconfig(self.lower_note_text, text=note_name_lower)\n\n    def set_frequency(self, frequency):\n        self.upper_canvas.itemconfig(self.frequency_text, text=str(round(frequency, 1)) + \" Hz\")\n\n    def set_frequency_difference(self, frequency):\n        self.button_frequency.set_text(str(frequency))\n"
  },
  {
    "path": "tuner_ui_parts/settings_frame.py",
    "content": "import tkinter\nimport webbrowser\n\nfrom tuner_ui_parts.tkinter_custom_button_imageset import TkinterCustomButtonImageset\nfrom tuner_ui_parts.tkinter_custom_button import TkinterCustomButton\nfrom settings import Settings\n\n\nclass SettingsFrame(tkinter.Frame):\n    def __init__(self, master, *args, **kwargs):\n        tkinter.Frame.__init__(self, master, *args, **kwargs)\n\n        self.app_pointer = master\n        self.color_manager = self.app_pointer.color_manager\n        self.font_manager = self.app_pointer.font_manager\n        self.image_manager = self.app_pointer.image_manager\n\n        self.configure(bg=self.color_manager.background_layer_1)\n\n        self.bottom_frame = tkinter.Frame(master=self,\n                                          bg=self.color_manager.background_layer_0)\n        self.bottom_frame.place(anchor=tkinter.S, relx=0.5, rely=1, relheight=0.2, relwidth=1)\n\n        self.button_back = TkinterCustomButton(master=self.bottom_frame,\n                                               bg_color=self.color_manager.background_layer_0,\n                                               fg_color=self.color_manager.theme_main,\n                                               hover_color=self.color_manager.theme_light,\n                                               text_font=self.font_manager.button_font,\n                                               text=\"Back\",\n                                               text_color=self.color_manager.text_main,\n                                               corner_radius=10,\n                                               width=110,\n                                               height=40,\n                                               command=self.master.draw_main_frame)\n        self.button_back.place(anchor=tkinter.SE, relx=0.95, rely=0.75)\n\n        self.button_website = TkinterCustomButton(master=self.bottom_frame,\n                                                  bg_color=self.color_manager.background_layer_0,\n                                                  fg_color=self.color_manager.theme_main,\n                                                  hover_color=self.color_manager.theme_light,\n                                                  text_font=self.font_manager.button_font,\n                                                  text=\"Website\",\n                                                  text_color=self.color_manager.text_main,\n                                                  corner_radius=10,\n                                                  width=110,\n                                                  height=40,\n                                                  command=self.website_button)\n        self.button_website.place(anchor=tkinter.SW, relx=0.05, rely=0.75)\n\n        self.label_info_text = tkinter.Label(master=self,\n                                             bg=self.color_manager.background_layer_1,\n                                             fg=self.color_manager.text_2,\n                                             font=self.font_manager.info_text_font,\n                                             text=Settings.ABOUT_TEXT)\n        self.label_info_text.place(anchor=tkinter.CENTER, relx=0.5, rely=0.12, relheight=0.2, relwidth=0.8)\n\n        self.label_note_text = tkinter.Label(master=self,\n                                             bg=self.color_manager.background_layer_1,\n                                             fg=self.color_manager.text_2,\n                                             font=self.font_manager.settings_text_font,\n                                             text=\"A4 =\")\n        self.label_note_text.place(relx=0.2, rely=0.45, relheight=0.1, relwidth=0.2, anchor=tkinter.CENTER)\n\n        self.label_frequency = TkinterCustomButton(master=self,\n                                                   bg_color=self.color_manager.background_layer_1,\n                                                   fg_color=self.color_manager.theme_main,\n                                                   hover_color=self.color_manager.theme_main,\n                                                   text_font=self.font_manager.settings_text_font,\n                                                   text=\"440 Hz\",\n                                                   text_color=self.color_manager.text_main,\n                                                   corner_radius=10,\n                                                   width=170,\n                                                   height=65,\n                                                   hover=False)\n        self.label_frequency.place(anchor=tkinter.CENTER, relx=0.5, rely=0.45)\n\n        self.button_frequency_up = TkinterCustomButtonImageset(master=self,\n                                                               height=50,\n                                                               width=150,\n                                                               bg_color=self.color_manager.background_layer_1,\n                                                               image_dict={\"standard\": self.image_manager.arrowUp_image,\n                                                                           \"clicked\": self.image_manager.arrowUp_image,\n                                                                           \"standard_hover\": self.image_manager.arrowUp_image_hovered,\n                                                                           \"clicked_hover\": self.image_manager.arrowUp_image_hovered},\n                                                               command=self.frequency_button_up)\n        self.button_frequency_up.place(anchor=tkinter.CENTER, relx=0.5, rely=0.3)\n\n        self.button_frequency_down = TkinterCustomButtonImageset(master=self,\n                                                                 height=50,\n                                                                 width=150,\n                                                                 bg_color=self.color_manager.background_layer_1,\n                                                                 image_dict={\"standard\": self.image_manager.arrowDown_image,\n                                                                             \"clicked\": self.image_manager.arrowDown_image,\n                                                                             \"standard_hover\": self.image_manager.arrowDown_image_hovered,\n                                                                             \"clicked_hover\": self.image_manager.arrowDown_image_hovered},\n                                                                 command=self.frequency_button_down)\n        self.button_frequency_down.place(anchor=tkinter.CENTER, relx=0.5, rely=0.6)\n\n    def update_color(self):\n        self.configure(bg=self.color_manager.background_layer_1)\n        self.bottom_frame.configure(bg=self.color_manager.background_layer_0)\n\n        self.button_back.configure_color(bg_color=self.color_manager.background_layer_0,\n                                         fg_color=self.color_manager.theme_main,\n                                         hover_color=self.color_manager.theme_light,\n                                         text_color=self.color_manager.text_main)\n\n        self.button_website.configure_color(bg_color=self.color_manager.background_layer_0,\n                                            fg_color=self.color_manager.theme_main,\n                                            hover_color=self.color_manager.theme_light,\n                                            text_color=self.color_manager.text_main)\n\n        self.label_info_text.configure(bg=self.color_manager.background_layer_1, fg=self.color_manager.text_2)\n        self.label_note_text.configure(bg=self.color_manager.background_layer_1, fg=self.color_manager.text_2)\n\n        self.label_frequency.configure_color(bg_color=self.color_manager.background_layer_1,\n                                             fg_color=self.color_manager.theme_main,\n                                             hover_color=self.color_manager.theme_light,\n                                             text_color=self.color_manager.text_main)\n\n        self.button_frequency_up.label.configure(bg=self.color_manager.background_layer_1)\n        self.button_frequency_down.label.configure(bg=self.color_manager.background_layer_1)\n\n    def frequency_button_up(self):\n        self.master.a4_frequency += 1\n        self.label_frequency.set_text(str(self.master.a4_frequency) + \" Hz\")\n\n    def frequency_button_down(self):\n        if self.master.a4_frequency > 1:\n            self.master.a4_frequency -= 1\n            self.label_frequency.set_text(str(self.master.a4_frequency) + \" Hz\")\n\n    def website_button(self):\n        webbrowser.open(Settings.GITHUB_URL_README)\n"
  },
  {
    "path": "tuner_ui_parts/tkinter_custom_button.py",
    "content": "import tkinter\nimport sys\n\n\nclass TkinterCustomButton(tkinter.Frame):\n    \"\"\" tkinter custom button with border, rounded corners and hover effect\n\n        Arguments:  master= where to place button\n                    bg_color= background color, None is standard,\n                    fg_color= foreground color, blue is standard,\n                    hover_color= foreground color, lightblue is standard,\n                    border_color= foreground color, None is standard,\n                    border_width= border thickness, 0 is standard,\n                    command= callback function, None is standard,\n                    width= width of button, 110 is standard,\n                    height= width of button, 35 is standard,\n                    corner_radius= corner radius, 10 is standard,\n                    text_font= (<Name>, <Size>),\n                    text_color= text color, white is standard,\n                    text= text of button,\n                    hover= hover effect, True is standard,\n                    image= PIL.PhotoImage, standard is None\"\"\"\n\n    def __init__(self,\n                 bg_color=None,\n                 fg_color=\"#2874A6\",\n                 hover_color=\"#5499C7\",\n                 border_color=None,\n                 border_width=0,\n                 command=None,\n                 width=120,\n                 height=40,\n                 corner_radius=10,\n                 text_font=None,\n                 text_color=\"white\",\n                 text=\"CustomButton\",\n                 hover=True,\n                 image=None,\n                 *args, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        if bg_color is None:\n            self.bg_color = self.master.cget(\"bg\")\n        else:\n            self.bg_color = bg_color\n\n        self.fg_color = fg_color\n        self.hover_color = hover_color\n        self.border_color = border_color\n\n        self.width = width\n        self.height = height\n\n        if corner_radius * 2 > self.height:\n            self.corner_radius = self.height / 2\n        elif corner_radius * 2 > self.width:\n            self.corner_radius = self.width / 2\n        else:\n            self.corner_radius = corner_radius\n\n        self.border_width = border_width\n\n        if self.corner_radius >= self.border_width:\n            self.inner_corner_radius = self.corner_radius - self.border_width\n        else:\n            self.inner_corner_radius = 0\n\n        self.text = text\n        self.text_color = text_color\n        if text_font is None:\n            if sys.platform == \"darwin\":  # macOS\n                self.text_font = (\"Avenir\", 13)\n            elif \"win\" in sys.platform:  # Windows\n                self.text_font = (\"Century Gothic\", 11)\n            else:\n                self.text_font = (\"TkDefaultFont\")\n        else:\n            self.text_font = text_font\n\n        self.image = image\n\n        self.function = command\n        self.hover = hover\n\n        self.configure(width=self.width, height=self.height)\n\n        if sys.platform == \"darwin\" and self.hover is True:\n            self.configure(cursor=\"pointinghand\")\n\n        self.canvas = tkinter.Canvas(master=self,\n                                     highlightthicknes=0,\n                                     background=self.bg_color,\n                                     width=self.width,\n                                     height=self.height)\n        self.canvas.place(x=0, y=0)\n\n        if self.hover is True:\n            self.canvas.bind(\"<Enter>\", self.on_enter)\n            self.canvas.bind(\"<Leave>\", self.on_leave)\n\n        self.canvas.bind(\"<Button-1>\", self.clicked)\n        self.canvas.bind(\"<Button-1>\", self.clicked)\n\n        self.canvas_fg_parts = []\n        self.canvas_border_parts = []\n        self.text_label = None\n        self.image_label = None\n\n        # no image given\n        if self.image is None:\n            # create tkinter.Label with text\n            self.text_label = tkinter.Label(master=self,\n                                            font=self.text_font,\n                                            bg=self.fg_color,\n                                            fg=self.text_color)\n            self.text_label.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)\n\n            # bind events the the button click and hover events also to the text_label\n            if self.hover is True:\n                self.text_label.bind(\"<Enter>\", self.on_enter)\n                self.text_label.bind(\"<Leave>\", self.on_leave)\n\n            self.text_label.bind(\"<Button-1>\", self.clicked)\n            self.text_label.bind(\"<Button-1>\", self.clicked)\n\n            self.set_text(self.text)\n\n        # use the given image\n        else:\n            # create tkinter.Label with image on it\n            self.image_label = tkinter.Label(master=self,\n                                             image=self.image,\n                                             bg=self.fg_color)\n\n            self.image_label.place(relx=0.5,\n                                   rely=0.5,\n                                   anchor=tkinter.CENTER)\n\n            # bind events the the button click and hover events also to the image_label\n            if self.hover is True:\n                self.image_label.bind(\"<Enter>\", self.on_enter)\n                self.image_label.bind(\"<Leave>\", self.on_leave)\n\n            self.image_label.bind(\"<Button-1>\", self.clicked)\n            self.image_label.bind(\"<Button-1>\", self.clicked)\n\n        self.draw()\n\n    def draw(self):\n        self.canvas.delete(\"all\")\n        self.canvas_fg_parts = []\n        self.canvas_border_parts = []\n        self.canvas.configure(bg=self.bg_color)\n\n        # border button parts\n        if self.border_width > 0:\n\n            if self.corner_radius > 0:\n                self.canvas_border_parts.append(self.canvas.create_oval(0,\n                                                                        0,\n                                                                        self.corner_radius * 2,\n                                                                        self.corner_radius * 2))\n                self.canvas_border_parts.append(self.canvas.create_oval(self.width - self.corner_radius * 2,\n                                                                        0,\n                                                                        self.width,\n                                                                        self.corner_radius * 2))\n                self.canvas_border_parts.append(self.canvas.create_oval(0,\n                                                                        self.height - self.corner_radius * 2,\n                                                                        self.corner_radius * 2,\n                                                                        self.height))\n                self.canvas_border_parts.append(self.canvas.create_oval(self.width - self.corner_radius * 2,\n                                                                        self.height - self.corner_radius * 2,\n                                                                        self.width,\n                                                                        self.height))\n\n            self.canvas_border_parts.append(self.canvas.create_rectangle(0,\n                                                                         self.corner_radius,\n                                                                         self.width,\n                                                                         self.height - self.corner_radius))\n            self.canvas_border_parts.append(self.canvas.create_rectangle(self.corner_radius,\n                                                                         0,\n                                                                         self.width - self.corner_radius,\n                                                                         self.height))\n\n        # inner button parts\n\n        if self.corner_radius > 0:\n            self.canvas_fg_parts.append(self.canvas.create_oval(self.border_width,\n                                                                self.border_width,\n                                                                self.border_width + self.inner_corner_radius * 2,\n                                                                self.border_width + self.inner_corner_radius * 2))\n            self.canvas_fg_parts.append(self.canvas.create_oval(self.width - self.border_width - self.inner_corner_radius * 2,\n                                                                self.border_width,\n                                                                self.width - self.border_width,\n                                                                self.border_width + self.inner_corner_radius * 2))\n            self.canvas_fg_parts.append(self.canvas.create_oval(self.border_width,\n                                                                self.height - self.border_width - self.inner_corner_radius * 2,\n                                                                self.border_width + self.inner_corner_radius * 2,\n                                                                self.height-self.border_width))\n            self.canvas_fg_parts.append(self.canvas.create_oval(self.width - self.border_width - self.inner_corner_radius * 2,\n                                                                self.height - self.border_width - self.inner_corner_radius * 2,\n                                                                self.width - self.border_width,\n                                                                self.height - self.border_width))\n\n        self.canvas_fg_parts.append(self.canvas.create_rectangle(self.border_width + self.inner_corner_radius,\n                                                                 self.border_width,\n                                                                 self.width - self.border_width - self.inner_corner_radius,\n                                                                 self.height - self.border_width))\n        self.canvas_fg_parts.append(self.canvas.create_rectangle(self.border_width,\n                                                                 self.border_width + self.inner_corner_radius,\n                                                                 self.width - self.border_width,\n                                                                 self.height - self.inner_corner_radius - self.border_width))\n\n        for part in self.canvas_fg_parts:\n            self.canvas.itemconfig(part, fill=self.fg_color, width=0)\n\n        for part in self.canvas_border_parts:\n            self.canvas.itemconfig(part, fill=self.border_color, width=0)\n\n    def configure_color(self, bg_color=None, fg_color=None, hover_color=None, text_color=None):\n        if bg_color is not None:\n            self.bg_color = bg_color\n        else:\n            self.bg_color = self.master.cget(\"bg\")\n\n        if fg_color is not None:\n            self.fg_color = fg_color\n\n            # change background color of image_label\n            if self.image is not None:\n                self.image_label.configure(bg=self.fg_color)\n\n            if self.text_label is not None:\n                self.text_label.configure(bg=self.fg_color)\n\n        if hover_color is not None:\n            self.hover_color = hover_color\n\n        if text_color is not None:\n            self.text_color = text_color\n\n            if self.text_label is not None:\n                self.text_label.configure(fg=self.text_color)\n\n        self.draw()\n\n    def set_text(self, text):\n        if self.text_label is not None:\n            self.text_label.configure(text=text, width=len(text))\n\n    def on_enter(self, event=0):\n        for part in self.canvas_fg_parts:\n            self.canvas.itemconfig(part, fill=self.hover_color, width=0)\n\n        if self.text_label is not None:\n            # change background color of image_label\n            self.text_label.configure(bg=self.hover_color)\n\n        if self.image_label is not None:\n            # change background color of image_label\n            self.image_label.configure(bg=self.hover_color)\n\n    def on_leave(self, event=0):\n        for part in self.canvas_fg_parts:\n            self.canvas.itemconfig(part, fill=self.fg_color, width=0)\n\n        if self.text_label is not None:\n            # change background color of image_label\n            self.text_label.configure(bg=self.fg_color)\n\n        if self.image_label is not None:\n            # change background color of image_label\n            self.image_label.configure(bg=self.fg_color)\n\n    def clicked(self, event=0):\n        if self.function is not None:\n            self.function()\n            self.on_leave()\n"
  },
  {
    "path": "tuner_ui_parts/tkinter_custom_button_imageset.py",
    "content": "import tkinter\nimport sys\n\n\nclass TkinterCustomButtonImageset(tkinter.Frame):\n    \"\"\" tkinter custom button with image, takes a\n        image_dict with images like the following:\n\n        image_dict = {\"standard\": ImageTk.PhotoImage,\n                      \"clicked\": ImageTk.PhotoImage,\n                      \"standard_hover\": ImageTk.PhotoImage,\n                      \"clicked_hover\": ImageTk.PhotoImage} \"\"\"\n\n    def __init__(self,\n                 image_dict=None,\n                 hover=True,\n                 bg_color=\"black\",\n                 command=None,\n                 *args, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        self.image_dict = image_dict\n        self.pressed = False\n        self.bg_color = bg_color\n        self.function = command\n        self.hover = hover\n\n        self.configure(bg=self.bg_color)\n\n        self.label = tkinter.Label(master=self,\n                                   image=image_dict[\"standard\"],\n                                   bg=self.bg_color)\n\n        self.label.place(relx=0.5,\n                         rely=0.5,\n                         anchor=tkinter.CENTER)\n\n        if sys.platform == \"darwin\" and self.hover is True:\n            self.configure(cursor=\"pointinghand\")\n\n        if self.hover is True:\n            self.bind(\"<Enter>\", self.on_enter)\n            self.bind(\"<Leave>\", self.on_leave)\n\n        self.bind(\"<Button-1>\", self.clicked)\n        self.label.bind(\"<Button-1>\", self.clicked)\n\n    def configure_color(self, bg_color=None):\n        if bg_color is not None:\n            self.bg_color = bg_color\n            self.label.configure(bg=self.bg_color)\n\n    def on_enter(self, event):\n        if self.pressed is False:\n            self.label.configure(image=self.image_dict[\"standard_hover\"])\n        if self.pressed:\n            self.label.configure(image=self.image_dict[\"clicked_hover\"])\n\n    def on_leave(self, enter):\n        if self.pressed is False:\n            self.label.configure(image=self.image_dict[\"standard\"])\n        if self.pressed:\n            self.label.configure(image=self.image_dict[\"clicked\"])\n\n    def clicked(self, event):\n        if self.pressed is False:\n            self.pressed = True\n            self.label.configure(image=self.image_dict[\"clicked\"])\n        else:\n            self.pressed = False\n            self.label.configure(image=self.image_dict[\"standard\"])\n\n        if self.function:\n            self.function()\n\n    def is_pressed(self):\n        return self.pressed\n\n    def set_pressed(self, pressed):\n        if pressed is True:\n            self.pressed = True\n            self.label.configure(image=self.image_dict[\"clicked\"])\n        else:\n            self.pressed = False\n            self.label.configure(image=self.image_dict[\"standard\"])\n"
  },
  {
    "path": "usage_monitoring/__init__.py",
    "content": ""
  },
  {
    "path": "usage_monitoring/usage_monitor.py",
    "content": "import smtplib\nimport sys\nimport json\nimport threading\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\n\ntry:\n    from usage_monitoring.usage_monitor_credentials import UsageMonitorCredentials as Credentials\nexcept ImportError:\n    Credentials = None\n\n\nclass UsageMonitor:\n    \"\"\" Simple class to send log information from python via mail.\n        The mails are send and received by the same address, so only on mail\n        address is needed. \"\"\"\n\n    @classmethod\n    def send_msg(cls, subject, msg_dict):\n        try:\n            if Credentials is not None:\n\n                with smtplib.SMTP(Credentials.get(\"server\"), Credentials.get(\"port\")) as server:\n\n                    server.starttls()\n                    server.login(Credentials.get(\"mail\"),\n                                 Credentials.get(\"token\"))\n\n                    msg = MIMEMultipart()\n                    msg['From'] = Credentials.get(\"mail\")\n                    msg['To'] = Credentials.get(\"mail\")\n                    msg['Subject'] = subject\n\n                    msg.attach(MIMEText(json.dumps(msg_dict, indent=4), 'plain'))\n                    server.send_message(msg)\n\n        except Exception as err:\n            # sys.stderr.write('Error: Line {} {} {}\\n'.format(sys.exc_info()[-1].tb_lineno, type(err).__name__, err))\n            pass\n\n    @classmethod\n    def new_log_msg_thread(cls, open_times, user_id):\n\n        # only the random user id (10 digits) and the open_times are send\n        msg_dict = {\"user_id\": user_id,\n                    \"opening_times\": open_times}\n\n        cls.send_msg(\"GuitarTuner-LOG\", msg_dict)\n\n    @classmethod\n    def new_log_msg(cls, open_times, user_id):\n        try:\n            new_thread = threading.Thread(daemon=True, target=cls.new_log_msg_thread, args=(open_times, user_id))\n            new_thread.start()\n        except Exception as err:\n            # sys.stderr.write('Error: Line {} {} {}\\n'.format(sys.exc_info()[-1].tb_lineno, type(err).__name__, err))\n            pass\n"
  }
]