15
15
# You should have received a copy of the GNU General Public License
16
16
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.
17
17
18
- import wx , os , webbrowser
18
+ import wx , os , webbrowser , subprocess
19
19
20
20
from .conf import Conf
21
21
from .language import Language
22
+ from .platform import Platform
22
23
23
24
class MyFrame (wx .Frame ):
24
25
def __init__ (self ):
25
26
self .conf = Conf ()
26
27
self .home = self .conf .home
28
+ platform = Platform ()
29
+ self .isRPI = platform .isRPI
27
30
self .currentdir = os .path .dirname (__file__ )
28
31
currentLanguage = self .conf .get ('GENERAL' , 'lang' )
29
32
self .language = Language ('openplotter-settings' ,currentLanguage )
@@ -36,23 +39,29 @@ def __init__(self):
36
39
self .toolbar1 = wx .ToolBar (self , style = wx .TB_TEXT )
37
40
toolHelp = self .toolbar1 .AddTool (101 , 'Help' , wx .Bitmap (self .currentdir + "/data/help.png" ))
38
41
self .Bind (wx .EVT_TOOL , self .OnToolHelp , toolHelp )
42
+ self .toolbar1 .AddSeparator ()
39
43
langList = []
40
44
for i in self .language .available :
41
45
langList .append (i [0 ])
42
46
self .languageList = wx .ComboBox (self .toolbar1 , 102 , _ ('Language' ), choices = langList , size = (150 ,- 1 ), style = wx .CB_DROPDOWN )
43
47
toolLanguage = self .toolbar1 .AddControl (self .languageList )
44
48
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 )
45
51
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 )
46
54
47
55
self .notebook = wx .Notebook (self )
48
56
self .apps = wx .Panel (self .notebook )
49
57
self .genSettings = wx .Panel (self .notebook )
50
58
self .notebook .AddPage (self .apps , _ ('OpenPlotter Apps' ))
51
59
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 )
56
65
self .notebook .SetPageImage (0 , img0 )
57
66
self .notebook .SetPageImage (1 , img1 )
58
67
@@ -61,29 +70,39 @@ def __init__(self):
61
70
vbox .Add (self .notebook , 1 , wx .EXPAND )
62
71
self .SetSizer (vbox )
63
72
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 :
72
74
self .raspSettings = wx .Panel (self .notebook )
73
75
self .notebook .AddPage (self .raspSettings , 'Raspberry Settings' )
74
- img2 = il .Add (wx .Bitmap (self .currentdir + "/data/rpi.png" , wx .BITMAP_TYPE_PNG ))
75
76
self .notebook .SetPageImage (2 , img2 )
76
77
77
78
self .CreateStatusBar ()
78
79
self .Centre (True )
79
80
self .Show (True )
80
81
81
82
self .pageApps ()
83
+ self .onListAppsDeselected ()
82
84
83
85
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"
85
95
webbrowser .open (url , new = 2 )
86
96
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
+
87
106
def OnToolLanguage (self , event ):
88
107
short = 'en'
89
108
name = self .languageList .GetValue ()
@@ -93,24 +112,104 @@ def OnToolLanguage(self, event):
93
112
wx .MessageBox (_ ('Close and open again the window to see changes.' ), _ ('Info' ), wx .OK | wx .ICON_INFORMATION )
94
113
95
114
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 )
102
119
self .listApps .Bind (wx .EVT_LIST_ITEM_SELECTED , self .onListAppsSelected )
103
120
self .listApps .Bind (wx .EVT_LIST_ITEM_DESELECTED , self .onListAppsDeselected )
121
+ self .listApps .SetImageList (self .il , wx .IMAGE_LIST_SMALL )
104
122
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 )
106
129
sizer .Add (self .listApps , 1 , wx .EXPAND , 0 )
130
+ sizer .Add (self .toolbar2 , 0 )
107
131
self .apps .SetSizer (sizer )
108
132
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 )
114
213
115
214
def main ():
116
215
app = wx .App ()
0 commit comments