Skip to content

Commit

Permalink
handle invalid config inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrigu123 committed Apr 1, 2017
1 parent f34af09 commit 33c50c0
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 80 deletions.
46 changes: 6 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A linux application with a very convinient GUI. Build with Python Gtk+3 (gi).
# Installation
You can either download an [AppImage](http://appimage.org/) or install from source.

## AppImage
## AppImage (Old version. For latest veriosn , install from source)

AppImage runs on most of the Linux distros.

Expand Down Expand Up @@ -64,11 +64,7 @@ Shown below is installation and running with Python 2.
### For Ubuntu/Debian based systems:

``` sh
sudo apt install python-gi python-dbus gir1.2-appindicator3-0.1
```

``` sh
sudo apt install python-requests python-bs4 python-lxml
sudo apt install python-gi python-dbus gir1.2-appindicator3-0.1 python-requests python-bs4 python-lxml
```

(requests, lxml and bs4 can be install from `pip` also: `pip install requests lxml beautifiulsoup4`)
Expand Down Expand Up @@ -103,43 +99,13 @@ The icon will appear in the system tray (indicator panel). You can start using t

# Creating a launcher shortcut

If you have installed from source, you can either use the application from the terminal, or create a launcher shortcut (which will add the application in your launcher menu):

![Launcher](https://cloud.githubusercontent.com/assets/6123105/23824317/4735e83e-069a-11e7-8b1e-2814632bb3aa.jpeg)

You can find several ways of doing so. You can also follow the below steps:

(From the terminal)

* `sudo touch /usr/share/applications/instant-lyrics.desktop`. (Creates a new file in /usr/share/applications).

* Open this new file with an editor. Eg. opening with gedit: `gedit /usr/share/applications/instant-lyrics.desktop`. Paste the following in it:

```
[Desktop Entry]
Version=1.0
Type=Application
Name=Instant Lyrics
Comment=Show lyrics of songs instantly
Icon=[path of icon]
Exec=python [path of python file]
Terminal=false
```

Replace `[path of icon]` with the complete path of the icon. The icon is present in `icons/instant-lyrics.svg` inside the root directory of the repository.

Replace `[path of python file]` with the complete path of the file `InstantLyrics.py` which is also in the root directory of the repo.

These two lines should look something like:
If you have installed from source, you can go to **Preferences** from the menu options, and click on the button `Create Desktop Entry`.

```
Icon=/home/ubuntu/Instant-Lyrics/icons/instant-lyrics.svg
Exec=python /home/ubuntu/Instant-Lyrics/InstantLyrics.py
```
You should be able to see the `Instant Lyrics` application shortcut in your launcher menu.

* Save the file.
You can also find several manual ways of doing so from the web.

You should be able to see the `Instant Lyrics` application shortcut in your launcher menu.
![Launcher](https://cloud.githubusercontent.com/assets/6123105/23824317/4735e83e-069a-11e7-8b1e-2814632bb3aa.jpeg)


# Contribution
Expand Down
14 changes: 8 additions & 6 deletions src/appIndicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
import threading

from src.windows import LyricsWindow, PreferenceWindow
from src.utils import get_icon_path
from . import utils
from src.settings import APPINDICATOR_ID, CONFIG_PATH

APPINDICATOR_ID = 'lyricsappindicator'

class AppIndicator():

def __init__(self):
signal.signal(signal.SIGINT, signal.SIG_DFL)

indicator = appindicator.Indicator.new(APPINDICATOR_ID, get_icon_path(
indicator = appindicator.Indicator.new(APPINDICATOR_ID, utils.get_icon_path(
'../icons/instant-lyrics-24.png'), appindicator.IndicatorCategory.SYSTEM_SERVICES)
indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
indicator.set_menu(self.build_menu())

self.Config = utils.get_config()
Gtk.main()

def build_menu(self):
Expand All @@ -46,16 +48,16 @@ def build_menu(self):
return menu

def fetch_lyrics(self, source):
win = LyricsWindow("get")
win = LyricsWindow("get", self)

def spotify_lyrics(self, source):
win = LyricsWindow("spotify")
win = LyricsWindow("spotify", self)
thread = threading.Thread(target=win.get_spotify)
thread.daemon = True
thread.start()

def preferences(self, source):
win = PreferenceWindow()
win = PreferenceWindow(self)

def quit(self, source):
Gtk.main_quit()
5 changes: 5 additions & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os

APPINDICATOR_ID = 'lyricsappindicator'

CONFIG_PATH = os.getenv("HOME") + "/.config/instant-lyrics/config"
65 changes: 47 additions & 18 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,58 @@
except ImportError:
import ConfigParser as configparser

CONFIG_PATH = os.getenv("HOME") + "/.confg/instant-lyrics/config"
from src.settings import CONFIG_PATH

def create_default_config():
if not os.path.isdir(os.path.dirname(CONFIG_PATH)):
os.makedirs(os.path.dirname(CONFIG_PATH))

Config = configparser.ConfigParser()

Config.add_section('Main')
Config.set('Main', "window width", "350")
Config.set('Main', "window height", "650")

with open(CONFIG_PATH, 'w') as config_file:
Config.write(config_file)

def get_config():
if not os.path.isfile(CONFIG_PATH):
create_default_config()

Config = configparser.ConfigParser()
Config.read(CONFIG_PATH)
return Config

def get_icon_path(rel_path):
dir_of_py_file = os.path.dirname(__file__)
rel_path_to_resource = os.path.join(dir_of_py_file, rel_path)
abs_path_to_resource = os.path.abspath(rel_path_to_resource)
return abs_path_to_resource

def ConfigSectionMap(Config, section):
dict1 = {}
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1

def read_config(config_file):
Config = ConfigParser.ConfigParser()
Config.read(config_file)
return Config
def create_desktop_entry():
#path of scr folder
src_path = os.path.dirname(os.path.realpath(__file__))
# path of base folder
base_path = os.path.dirname(src_path)

entry = "[Desktop Entry]\n"
v = "Version=1.0\n"
tp = "Type=Application\n"
nm = "Name=Instant Lyrics\n"
ic = "Icon="+base_path+"/icons/instant-lyrics-256.png\n"
ex = "Exec=python2 "+base_path+"/InstantLyrics.py\n"
cm = "Comment=Shows lyrics of songs instantly\n"
tm = "Terminal=false\n"

entry_path = os.getenv("HOME") + "/.local/share/applications/instant-lyrics.desktop"

with open(entry_path, 'w') as file:
file.write(entry)
file.write(v)
file.write(tp)
file.write(nm)
file.write(ic)
file.write(ex)
file.write(cm)
file.write(tm)
Loading

0 comments on commit 33c50c0

Please sign in to comment.