Skip to content

Commit dd05dae

Browse files
committed
manage apps
1 parent d0adb21 commit dd05dae

File tree

7 files changed

+152
-27
lines changed

7 files changed

+152
-27
lines changed

openplotterSettings/data/0+debian.png

767 Bytes
Loading

openplotterSettings/data/crowdin.png

1.03 KB
Loading

openplotterSettings/data/package.png

1.02 KB
Loading

openplotterSettings/data/rpi+0.png

1.2 KB
Loading
1.76 KB
Loading

openplotterSettings/openplotterSettings.py

+126-27
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.
1717

18-
import wx, os, webbrowser
18+
import wx, os, webbrowser, subprocess
1919

2020
from .conf import Conf
2121
from .language import Language
22+
from .platform import Platform
2223

2324
class MyFrame(wx.Frame):
2425
def __init__(self):
2526
self.conf = Conf()
2627
self.home = self.conf.home
28+
platform = Platform()
29+
self.isRPI = platform.isRPI
2730
self.currentdir = os.path.dirname(__file__)
2831
currentLanguage = self.conf.get('GENERAL', 'lang')
2932
self.language = Language('openplotter-settings',currentLanguage)
@@ -36,23 +39,29 @@ def __init__(self):
3639
self.toolbar1 = wx.ToolBar(self, style=wx.TB_TEXT)
3740
toolHelp = self.toolbar1.AddTool(101, 'Help', wx.Bitmap(self.currentdir+"/data/help.png"))
3841
self.Bind(wx.EVT_TOOL, self.OnToolHelp, toolHelp)
42+
self.toolbar1.AddSeparator()
3943
langList = []
4044
for i in self.language.available:
4145
langList.append(i[0])
4246
self.languageList = wx.ComboBox(self.toolbar1, 102, _('Language'), choices=langList, size=(150,-1), style=wx.CB_DROPDOWN)
4347
toolLanguage = self.toolbar1.AddControl(self.languageList)
4448
self.Bind(wx.EVT_COMBOBOX, self.OnToolLanguage, toolLanguage)
49+
toolTranslate = self.toolbar1.AddTool(103, 'Translate', wx.Bitmap(self.currentdir+"/data/crowdin.png"))
50+
self.Bind(wx.EVT_TOOL, self.OnToolTranslate, toolTranslate)
4551
self.toolbar1.AddSeparator()
52+
toolUpdate = self.toolbar1.AddTool(104, 'Update Package Data', wx.Bitmap(self.currentdir+"/data/package.png"))
53+
self.Bind(wx.EVT_TOOL, self.OnToolUpdate, toolUpdate)
4654

4755
self.notebook = wx.Notebook(self)
4856
self.apps = wx.Panel(self.notebook)
4957
self.genSettings = wx.Panel(self.notebook)
5058
self.notebook.AddPage(self.apps, _('OpenPlotter Apps'))
5159
self.notebook.AddPage(self.genSettings, 'General Settings')
52-
il = wx.ImageList(24, 24)
53-
img0 = il.Add(wx.Bitmap(self.currentdir+"/data/24x24.png", wx.BITMAP_TYPE_PNG))
54-
img1 = il.Add(wx.Bitmap(self.currentdir+"/data/debian.png", wx.BITMAP_TYPE_PNG))
55-
self.notebook.AssignImageList(il)
60+
self.il = wx.ImageList(24, 24)
61+
img0 = self.il.Add(wx.Bitmap(self.currentdir+"/data/24x24.png", wx.BITMAP_TYPE_PNG))
62+
img1 = self.il.Add(wx.Bitmap(self.currentdir+"/data/debian.png", wx.BITMAP_TYPE_PNG))
63+
img2 = self.il.Add(wx.Bitmap(self.currentdir+"/data/rpi.png", wx.BITMAP_TYPE_PNG))
64+
self.notebook.AssignImageList(self.il)
5665
self.notebook.SetPageImage(0, img0)
5766
self.notebook.SetPageImage(1, img1)
5867

@@ -61,29 +70,39 @@ def __init__(self):
6170
vbox.Add(self.notebook, 1, wx.EXPAND)
6271
self.SetSizer(vbox)
6372

64-
rpi = False
65-
try:
66-
modelfile = open('/sys/firmware/devicetree/base/model', 'r', 2000)
67-
rpimodel = modelfile.read()
68-
modelfile.close()
69-
if 'Raspberry' in rpimodel: rpi = True
70-
except: pass
71-
if rpi:
73+
if self.isRPI:
7274
self.raspSettings = wx.Panel(self.notebook)
7375
self.notebook.AddPage(self.raspSettings, 'Raspberry Settings')
74-
img2 = il.Add(wx.Bitmap(self.currentdir+"/data/rpi.png", wx.BITMAP_TYPE_PNG))
7576
self.notebook.SetPageImage(2, img2)
7677

7778
self.CreateStatusBar()
7879
self.Centre(True)
7980
self.Show(True)
8081

8182
self.pageApps()
83+
self.onListAppsDeselected()
8284

8385
def OnToolHelp(self, event):
84-
url = "/usr/share/openplotter-doc/index.html"
86+
url = "/usr/share/openplotter-doc/settings/settings_app.html"
87+
webbrowser.open(url, new=2)
88+
89+
def OnToolHelp2(self, event):
90+
url = "/usr/share/openplotter-doc/settings/settings_app.html"
91+
webbrowser.open(url, new=2)
92+
93+
def OnToolTranslate(self, event):
94+
url = "https://crowdin.com/project/openplotter"
8595
webbrowser.open(url, new=2)
8696

97+
def OnToolUpdate(self, event):
98+
command = 'sudo apt update'
99+
popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=True)
100+
for line in popen.stdout:
101+
self.SetStatusText(_('Updating, please wait: ')+line)
102+
self.readApps()
103+
self.SetStatusText(_('Updated: ')+line)
104+
105+
87106
def OnToolLanguage(self, event):
88107
short = 'en'
89108
name = self.languageList.GetValue()
@@ -93,24 +112,104 @@ def OnToolLanguage(self, event):
93112
wx.MessageBox(_('Close and open again the window to see changes.'), _('Info'), wx.OK | wx.ICON_INFORMATION)
94113

95114
def pageApps(self):
96-
self.listApps = wx.ListCtrl(self.apps, -1, style=wx.LC_REPORT | wx.BORDER_SIMPLE | wx.LC_SINGLE_SEL, size=(-1,200))
97-
self.listApps.InsertColumn(0, '', width=30)
98-
self.listApps.InsertColumn(1, _('Name'), width=100)
99-
self.listApps.InsertColumn(2, _('System'), width=60)
100-
self.listApps.InsertColumn(3, _('Version'), width=60)
101-
self.listApps.InsertColumn(4, _('Update'), width=200)
115+
self.listApps = wx.ListCtrl(self.apps, -1, style=wx.LC_REPORT | wx.LC_SINGLE_SEL, size=(-1,200))
116+
self.listApps.InsertColumn(0, _('Name'), width=250)
117+
self.listApps.InsertColumn(1, _('Installed Version'), width=200)
118+
self.listApps.InsertColumn(2, _('Candidate Version'), width=200)
102119
self.listApps.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onListAppsSelected)
103120
self.listApps.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.onListAppsDeselected)
121+
self.listApps.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
104122

105-
sizer = wx.BoxSizer(wx.VERTICAL)
123+
self.toolbar2 = wx.ToolBar(self.apps, style=wx.TB_TEXT | wx.TB_VERTICAL)
124+
toolHelp2 = self.toolbar2.AddTool(201, 'Help', wx.Bitmap(self.currentdir+"/data/help.png"))
125+
self.Bind(wx.EVT_TOOL, self.OnToolHelp2, toolHelp2)
126+
self.toolbar2.AddSeparator()
127+
128+
sizer = wx.BoxSizer(wx.HORIZONTAL)
106129
sizer.Add(self.listApps, 1, wx.EXPAND, 0)
130+
sizer.Add(self.toolbar2, 0)
107131
self.apps.SetSizer(sizer)
108132

109-
def onListAppsSelected(self, event):
110-
pass
111-
112-
def onListAppsDeselected(self, event):
113-
pass
133+
self.readApps()
134+
135+
def readApps(self):
136+
self.listApps.DeleteAllItems()
137+
apps = []
138+
139+
app = {
140+
'name': _('Fake app'),
141+
'platform': 'debian',
142+
'package': 'openplotter-fake',
143+
}
144+
apps.append(app)
145+
146+
app = {
147+
'name': _('Network'),
148+
'platform': 'rpi',
149+
'package': 'openplotter-network',
150+
}
151+
apps.append(app)
152+
153+
app = {
154+
'name': _('Documentation'),
155+
'platform': 'both',
156+
'package': 'openplotter-doc',
157+
}
158+
apps.append(app)
159+
160+
app = {
161+
'name': _('Settings'),
162+
'platform': 'both',
163+
'package': 'openplotter-settings',
164+
}
165+
apps.append(app)
166+
167+
for i in apps:
168+
item = self.listApps.InsertItem(0, i['name'])
169+
if i['platform'] == 'rpi': self.listApps.SetItemImage(item, 2)
170+
else: self.listApps.SetItemImage(item, 1)
171+
172+
installed = ''
173+
candidate = ''
174+
command = 'LANG=C apt-cache policy '+i['package']
175+
popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=True)
176+
for line in popen.stdout:
177+
if 'Installed:' in line: installed = line
178+
if 'Candidate:' in line: candidate = line
179+
if installed:
180+
installedL = installed.split(':')
181+
installed = installedL[1]
182+
if candidate:
183+
candidateL = candidate.split(':')
184+
candidate = candidateL[1]
185+
if '(none)' in installed: installed = ''
186+
187+
#last = self.listApps.GetItemCount()-1
188+
if not candidate:
189+
candidate = _('Coming soon')
190+
self.listApps.SetItemBackgroundColour(item,(200,200,200))
191+
192+
if self.isRPI:
193+
if i['platform'] == 'debian':
194+
self.listApps.SetItemBackgroundColour(item,(200,200,200))
195+
candidate = _('App only for non Raspberry machines')
196+
else:
197+
if i['platform'] == 'rpi':
198+
self.listApps.SetItemBackgroundColour(item,(200,200,200))
199+
candidate = _('App only for Raspberry machines')
200+
201+
self.listApps.SetItem(item, 1, installed)
202+
self.listApps.SetItem(item, 2, candidate)
203+
204+
def onListAppsSelected(self, e):
205+
i = e.GetIndex()
206+
valid = e and i >= 0
207+
if not valid: return
208+
st = self.listApps.GetItemBackgroundColour(i) != (200,200,200)
209+
self.toolbar2.EnableTool(201,st)
210+
211+
def onListAppsDeselected(self, event=0):
212+
self.toolbar2.EnableTool(201,False)
114213

115214
def main():
116215
app = wx.App()

openplotterSettings/platform.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
3+
# This file is part of Openplotter.
4+
# Copyright (C) 2019 by sailoog <https://github.com/sailoog/openplotter>
5+
# e-sailing <https://github.com/e-sailing/openplotter>
6+
# Openplotter is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 2 of the License, or
9+
# any later version.
10+
# Openplotter is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.
17+
18+
class Platform:
19+
def __init__(self):
20+
self.isRPI = False
21+
try:
22+
modelfile = open('/sys/firmware/devicetree/base/model', 'r', 2000)
23+
rpimodel = modelfile.read()
24+
modelfile.close()
25+
if 'Raspberry' in rpimodel: self.isRPI = True
26+
except: pass

0 commit comments

Comments
 (0)