-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (56 loc) · 2.09 KB
/
main.py
File metadata and controls
74 lines (56 loc) · 2.09 KB
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
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.core.clipboard import Clipboard
import time
import webbrowser
from filesharer import FileSharer
Builder.load_file('frontend.kv')
class CameraScreen(Screen):
def start(self):
"""Starts camera and changes Button text"""
self.ids.camera.opacity = 1
self.ids.camera.play = True
self.ids.camera_button.text = "Stop Camera"
self.ids.camera.texture = self.ids.camera._camera.texture
def stop(self):
"""Stops camera and changes Button text"""
self.ids.camera.opacity = 0
self.ids.camera.play = False
self.ids.camera_button.text = "Start Camera"
self.ids.camera.texture = None
def capture(self):
"""Creates a filename with the current time and captures
and saves a photo image under that filename"""
current_time = time.strftime('%Y%m%d-%H%M%S')
self.filepath = f"files/{current_time}.png"
self.ids.camera.export_to_png(self.filepath)
self.manager.current = 'image_screen'
self.manager.current_screen.ids.img.source = self.filepath
class ImageScreen(Screen):
link_message = "Create a Link First"
def create_link(self):
"""Accesses the photo filepath, uploads it to the web,
and inserts the link in the Label widget"""
file_path = App.get_running_app().root.ids.camera_screen.filepath
filesharer = FileSharer(filepath = file_path)
self.url = filesharer.share()
self.ids.link.text = self.url
def copy_link(self):
"""Copy link to the clipboard available for pasting"""
try:
Clipboard.copy(self.url)
except:
self.ids.link.text = self.link_message
def open_link(self):
"""Open link with default browser"""
try:
webbrowser.open(self.url)
except:
self.ids.link.text = self.link_message
class RootWidget(ScreenManager):
pass
class MainApp(App):
def build(self):
return RootWidget()
MainApp().run()