-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfilechoosers.py
51 lines (42 loc) · 1.47 KB
/
filechoosers.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
from os import path
from kivy.uix.filechooser import FileChooserListView
from popups import ProgressPopup
from netcat import Sender, Receiver, SendingException, ValidationError
class RecvFileChooser(FileChooserListView):
def recv_file(self, src_port, fname):
popup = ProgressPopup(
title='Receiving...',
content="Receiving {0}\n {1}".format(src_port, fname),
size_hint=(1.0, 0.4,))
popup.open()
try:
dirpath = self.selection[0]
except IndexError as e:
popup.show_err('Please select a directory first')
return
fpath = path.join(dirpath, fname)
try:
receiver = Receiver(src_port, popup)
except ValidationError as e:
popup.show_err(e)
return
try:
receiver.receiveFile(fpath)
except Exception as e:
popup.show_err(e)
class SendFileChooser(FileChooserListView):
def send_file(self, dest_ip, dest_port):
progress_popup = ProgressPopup(
title='Sending...',
content='Preparing to send',
size_hint=(1.0, 0.4))
progress_popup.open()
try:
sender = Sender(dest_ip, dest_port, progress_popup)
except ValidationError as e:
progress_popup.show_err(e)
return
try:
sender.sendFile(self.selection[0])
except SendingException as e:
progress_popup.show_err(e)