Skip to content

Commit 77ef832

Browse files
committed
move kivy to settings and use system tray
1 parent 3e85891 commit 77ef832

File tree

7 files changed

+363
-159
lines changed

7 files changed

+363
-159
lines changed

Pipfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ pygments = "*"
1414
pypiwin32 = "*"
1515
"kivy.deps.sdl2" = "*"
1616
"kivy.deps.glew" = "*"
17-
pyenchant = "*"
18-
opencv-python = "*"
19-
wheel = "*"
20-
setuptools = "*"
2117
"kivy-deps.gstreamer" = "*"
18+
pystray = "*"
2219

2320
[requires]
2421
python_version = "3.8"

Pipfile.lock

Lines changed: 18 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.py

Lines changed: 56 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,67 @@
1-
from kivy.app import App
2-
from kivy.lang import Builder
3-
from kivy.uix.popup import Popup
4-
from kivy.uix.boxlayout import BoxLayout
5-
from kivy.properties import StringProperty, ObjectProperty
6-
from kivy.core.window import Window
7-
from windows import windowsStartup
1+
2+
from windows import is_admin
83
from nebula import runNebula
94
import threading
105
import os
11-
from plyer import filechooser
126
from storage import Storage
7+
import pystray
8+
from PIL import Image, ImageDraw
9+
from pystray import Menu, MenuItem
10+
from settings import SettingsApp
1311

1412
store = Storage()
13+
thread = None
14+
logStr = ''
1515

16-
if os.name == 'nt':
17-
windowsStartup()
18-
19-
class NebulaGUI(BoxLayout):
20-
state = StringProperty("off")
21-
logs = StringProperty()
22-
executablePath = StringProperty("No Executable Selected")
23-
configPath = StringProperty("No Config Selected")
24-
the_popup = ObjectProperty(None)
25-
thread = None
26-
shouldDisconnect = False
27-
config = StringProperty()
28-
29-
def __init__(self, *args, **kwargs):
30-
super(NebulaGUI, self).__init__(*args, **kwargs)
31-
if store.exists('executable_path'):
32-
self.executablePath = store.get('executable_path')
33-
if store.exists('config_path'):
34-
self.configPath = store.get('config_path')
35-
36-
def changeState(self, state):
37-
self.state = state
38-
39-
def connect(self):
40-
if self.state == "off":
41-
self.changeState("on")
42-
print(self.state)
43-
self.thread = threading.Thread(target=runNebula, args=("nebula", self.log, self.executablePath, self.configPath))
44-
self.thread.daemon = True
45-
self.thread.start()
46-
47-
def disconnect(self):
48-
pass
49-
50-
def log(self, line):
51-
if line.decode('utf-8') != "":
52-
print(line.decode('utf-8'))
53-
54-
55-
def chooseExecutable(self):
56-
paths = filechooser.open_file(title="Choose Nebula Executable")
57-
58-
if len(paths) > 0:
59-
store.add('executable_path', paths[0])
60-
self.executablePath = store.get('executable_path')
61-
62-
def chooseConfig(self):
63-
paths = filechooser.open_file(title="Choose Nebula Config")
64-
65-
if len(paths) > 0:
66-
store.add('config_path', paths[0])
67-
self.configPath = store.get('config_path')
16+
def create_image(color=250):
17+
# Generate an image and draw a pattern
18+
width=16
19+
height=16
20+
color1=20
21+
color2=color
22+
image = Image.new('RGB', (width, height), color1)
23+
dc = ImageDraw.Draw(image)
24+
dc.rectangle(
25+
(width // 2, 0, width, height // 2),
26+
fill=color2)
27+
dc.rectangle(
28+
(0, height // 2, width // 2, height),
29+
fill=color2)
6830

69-
class NebulaGUIApp(App):
70-
def build(self):
71-
return NebulaGUI()
31+
return image
7232

33+
def setup(icon):
34+
icon.visible = True
35+
def log(line):
36+
global logStr
37+
if line.decode('utf-8') != '':
38+
logStr=logStr+line.decode('utf-8')
39+
print(line.decode('utf-8'))
40+
def connect(icon, item):
41+
global thread
42+
if thread is None:
43+
thread = threading.Thread(target=runNebula, args=("nebula", log, store.get('executable_path'), store.get('config_path')))
44+
thread.daemon = True
45+
thread.start()
46+
icon.icon = create_image((51,255,51))
47+
def settings(icon, item):
48+
SettingsApp().run()
49+
def quit(icon, item):
50+
icon.stop()
51+
def menu():
52+
return Menu(
53+
MenuItem(
54+
'Connect',
55+
connect),
56+
MenuItem(
57+
'Settings',
58+
settings),
59+
MenuItem(
60+
'Quit',
61+
quit)
62+
)
7363

7464
if __name__ == '__main__':
75-
NebulaGUIApp().run()
65+
icon = pystray.Icon('test name', create_image(), menu=menu())
66+
#create_image().show()
67+
icon.run(setup)

nebula_gui.zip

76.7 MB
Binary file not shown.

nebulagui.kv renamed to settings.kv

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
#:kivy 1.0.9
22

3-
<NebulaGUI>:
3+
<Settings>:
44
orientation: 'vertical'
55
BoxLayout:
6-
orientation: 'horizontal'
7-
Button:
8-
text: 'Connect'
9-
on_release: root.connect()
10-
Label:
11-
text: root.state
12-
BoxLayout:
13-
orientation: 'horizontal'
6+
orientation: 'vertical'
147
BoxLayout:
15-
orientation: 'vertical'
8+
orientation: 'horizontal'
169
Label:
1710
text: root.executablePath
1811
Button:
1912
text: 'Choose Executable'
2013
on_release: root.chooseExecutable()
2114
BoxLayout:
22-
orientation: 'vertical'
15+
orientation: 'horizontal'
2316
Label:
2417
text: root.configPath
2518
Button:

settings.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from kivy.app import App
2+
from kivy.lang import Builder
3+
from kivy.uix.boxlayout import BoxLayout
4+
from kivy.properties import StringProperty, ObjectProperty
5+
from storage import Storage
6+
from plyer import filechooser
7+
8+
store = Storage()
9+
class Settings(BoxLayout):
10+
state = StringProperty("off")
11+
executablePath = StringProperty("No Executable Selected")
12+
configPath = StringProperty("No Config Selected")
13+
config = StringProperty()
14+
15+
def __init__(self, *args, **kwargs):
16+
super(Settings, self).__init__(*args, **kwargs)
17+
if store.exists('executable_path'):
18+
self.executablePath = store.get('executable_path')
19+
if store.exists('config_path'):
20+
self.configPath = store.get('config_path')
21+
22+
def chooseExecutable(self):
23+
paths = filechooser.open_file(title="Choose Nebula Executable")
24+
25+
if len(paths) > 0:
26+
store.add('executable_path', paths[0])
27+
self.executablePath = store.get('executable_path')
28+
29+
def chooseConfig(self):
30+
paths = filechooser.open_file(title="Choose Nebula Config")
31+
32+
if len(paths) > 0:
33+
store.add('config_path', paths[0])
34+
self.configPath = store.get('config_path')
35+
36+
class SettingsApp(App):
37+
def build(self):
38+
from kivy.core.window import Window
39+
Window.bind(on_request_close=self.on_request_close)
40+
return Settings()
41+
def on_request_close(self, *args):
42+
from kivy.core.window import Window
43+
Window.hide()

0 commit comments

Comments
 (0)