-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interfaces.py
180 lines (131 loc) · 5.31 KB
/
Interfaces.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# -*- coding:ISO-8859-1 -*-
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from defs import defs
OPEN_FILE = 'UI/OpenFile.ui'
UI_FILE = 'UI/Basic_UI.ui'
ABOUT = 'UI/About.ui'
class openFileInterface:
def __init__(self):
self.builder = Gtk.Builder()
# create the graphic interface from a file
self.builder.add_from_file(OPEN_FILE)
self.builder.connect_signals(self)
# create the UI
self.windowOpenFile = self.builder.get_object('windowOpenFile')
self.windowOpenFile.connect('destroy', Gtk.main_quit)
self.windowOpenFile.set_name('OpenFile')
self.windowOpenFile.show_all()
# create the object in the interface
self.buttomDownload = self.builder.get_object('buttomDownload')
self.buttomOkReadFile = self.builder.get_object('buttomOkReadFile')
self.filechooserbutton = self.builder.get_object('filechooserbutton')
self.gridFile = self.builder.get_object('gridFile')
self.buttomDownload.set_visible(False)
# position in the grid to insert the next namefile and size
self.line = 2
# clear all content in the grid
def clearGrid(self):
while(self.line >= 3):
self.line -= 1
self.gridFile.remove_row(self.line)
# insert name file and size in the grid
def insertInGrid(self, file, size):
label = Gtk.Label()
label.set_text(file)
label2 = Gtk.Label()
label2.set_text(size)
self.gridFile.attach(label, 0, self.line, 1, 1)
self.gridFile.attach(label2, 1, self.line, 1, 1)
self.gridFile.show_all()
self.line += 1
class About:
def __init__(self):
self.builder = Gtk.Builder()
# create the graphic interface from a file
self.builder.add_from_file(ABOUT)
self.builder.connect_signals(self)
# create the UI
self.windowAbout = self.builder.get_object('windowAbout')
self.windowAbout.set_name('PyTorrent About')
self.windowAbout.show_all()
class MainInterface:
def __init__(self):
self.builder = Gtk.Builder()
# create the graphic interface from a file
self.builder.add_from_file(UI_FILE)
self.builder.connect_signals(self)
# create the UI
self.windowMain = self.builder.get_object('windowMain')
self.windowMain.connect('destroy', Gtk.main_quit)
self.windowMain.set_name('PyTorrent')
self.windowMain.show_all()
# create the object in the interface
self.menuabout = self.builder.get_object('menuabout')
self.menuopen = self.builder.get_object('menuopen')
self.menuquit = self.builder.get_object('menuquit')
# grid of files
self.gridFile = self.builder.get_object('gridFiles')
self.line = 2
Gtk.main()
def addFile(self, torrentName):
# name torrent
labelName = Gtk.Label()
labelName.set_text(torrentName)
# percent downloaded
labelDownloaded = Gtk.Label()
labelDownloaded.set_text('0%')
# qtd peers
labelPeers = Gtk.Label()
labelPeers.set_text('--')
# qtd tracker
labelTracker = Gtk.Label()
labelTracker.set_text('--')
self.gridFile.attach(labelName, 0, self.line, 1, 1)
self.gridFile.attach(labelDownloaded, 1, self.line, 1, 1)
self.gridFile.attach(labelPeers, 2, self.line, 1, 1)
self.gridFile.attach(labelTracker, 3, self.line, 1, 1)
self.gridFile.show_all()
self.line += 1
def updatePercent(self, torrentName):
pass
def updateTracker(self, torrentName, trackers):
for line in range(2, self.line):
label = self.gridFile.get_child_at(0, line)
if(label.get_text().__eq__(torrentName)):
labelTracker = self.gridFile.get_child_at(3, line)
currentPeers = labelTracker.get_text()
if(currentPeers.__eq__('--')):
currentPeers = '0'
qtdPeer = int(currentPeers) + trackers
labelTracker.set_text(str(qtdPeer))
def updatePeer(self, torrentName, peers):
for line in range(2, self.line):
label = self.gridFile.get_child_at(0, line)
if(label.get_text().__eq__(torrentName)):
labelPeer = self.gridFile.get_child_at(2, line)
currentPeers = labelPeer.get_text()
if(currentPeers.__eq__('--')):
currentPeers = '0'
qtdPeer = int(currentPeers) + peers
labelPeer.set_text(str(qtdPeer))
def contains(self, torrentName):
# gridFile.get_child_at(colum, line)
for line in range(2, self.line):
label = self.gridFile.get_child_at(0, line)
if(label.get_text().__eq__(torrentName)):
return True
return False
def createDefsInterface(self):
return defs(self.addFile, self.updatePercent, self.updateTracker, self.updatePeer, self.contains)
# menubar -> File -> open
def openFile(self, widget):
import openFile
openFile.openFile(self.createDefsInterface())
# menubar -> File -> quit
def quit(self, widget):
self.windowMain.destroy()
# menubar -> Help -> about
def about(self, widget):
About()