-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·133 lines (111 loc) · 4.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/python
# -*- coding: utf-8 -*-
# MIT License
#
# Copyright (c) 2015 vagnum08
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import gtk
from subprocess import call, check_call
from pywb import Btsync
# from token_read import init, get_folders
import sys
import btsync_lib as bt
if sys.platform == 'darwin':
def openFolder(path):
check_call(['open', path])
elif sys.platform == 'linux2':
def openFolder(path):
check_call(['xdg-open', path])
elif sys.platform == 'win32':
def openFolder(path):
check_call(['explorer', path])
class SystrayIconApp:
def __init__(self, client):
self.tray = gtk.StatusIcon()
self.tray.set_from_stock(gtk.STOCK_ABOUT)
self.tray.set_from_file('btsync.png')
self.tray.connect('popup-menu', self.on_right_click)
self.tray.set_tooltip(('BtSync 2.0'))
self.btclient = client
self.f_list = self.btclient.sync_folders
def on_right_click(self, icon, event_button, event_time):
self.make_menu(event_button, event_time)
def make_menu(self, event_button, event_time):
menu = gtk.Menu()
# show about dialog
about = gtk.MenuItem("About")
about.show()
menu.append(about)
about.connect('activate', self.show_about_dialog)
# add quit item
quit = gtk.MenuItem("Quit")
quit.show()
menu.append(quit)
quit.connect('activate', self.exit)
# add btsync item
bt = gtk.MenuItem("Open BtSync GUI")
bt.show()
menu.append(bt)
bt.connect('activate', self.show_bt)
# add foldermenu item
# add foldersubmenu item
folder_menu = gtk.Menu()
for f in self.f_list:
mi = gtk.MenuItem(f['name'])
folder_menu.append(mi)
mi.show()
mi.connect('activate', self.open_folder, f['path'])
folder_menu.show()
sf = gtk.MenuItem("Synced Folders")
sf.set_submenu(folder_menu)
sf.show()
menu.append(sf)
# bt.connect('activate', self.show_bt)
menu.popup(None, None, gtk.status_icon_position_menu,
event_button, event_time, self.tray)
def show_about_dialog(self, widget):
about_dialog = gtk.AboutDialog()
about_dialog.set_destroy_with_parent (True)
# about_dialog.set_icon_name ("SystrayIcon")
about_dialog.set_icon_from_file("favicon.ico")
about_dialog.set_name('Btsync Python GUI')
about_dialog.set_version('0.1')
about_dialog.set_copyright("(C) 2015 vagnum08")
about_dialog.set_comments(("Python gui with systray for btsync 2.0"))
about_dialog.set_authors(['vagnum08 <vagnum08@gmail.com>'])
about_dialog.run()
about_dialog.destroy()
def exit(self, menu):
call(["killall", "btsync"])
gtk.main_quit(menu)
def show_bt(self, widget):
Btsync()
def open_folder(self,widget, fpath):
openFolder(fpath)
if __name__ == "__main__":
if len(sys.argv) < 3:
sys.exit('Usage: python %s username password' % sys.argv[0])
call(["./btsync"])
client = bt.Client(host='127.0.0.1',
port='8888',
username=sys.argv[1],
password=sys.argv[2])
SystrayIconApp(client)
gtk.main()