pyvguicom 1.0.0__py3-none-any.whl → 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyvguicom might be problematic. Click here for more details.

pyvguicom/pggui.py CHANGED
@@ -302,17 +302,24 @@ class Led(Gtk.DrawingArea):
302
302
  #cr.restore()
303
303
 
304
304
  ccc = pgutils.str2float(self.color)
305
+
306
+ cr.set_source_rgba(ccc[0] * 0.5, ccc[1] * 0.5, ccc[2] * 0.5)
307
+ cr.arc(rect.width/2, rect.height/2, rect.width / 2. * .85, 0., 2 * math.pi)
308
+ cr.fill()
309
+
305
310
  cr.set_source_rgba(ccc[0] * 0.7, ccc[1] * 0.7, ccc[2] * 0.7)
306
311
  cr.arc(rect.width/2, rect.height/2., rect.width/2., 0., 2 * math.pi)
307
312
  cr.fill()
308
313
 
309
314
  cr.set_source_rgba(ccc[0], ccc[1], ccc[2])
310
- cr.arc(rect.width/2, rect.height/2, rect.width / 2. * .8, 0., 2 * math.pi)
315
+ cr.arc(rect.width/2, rect.height/2, rect.width / 2. * .7, 0., 2 * math.pi)
311
316
  cr.fill()
312
317
 
313
318
  # Reflection on the r
314
- cr.set_source_rgba(ccc[0], ccc[1] + 0.51, ccc[2])
315
- cr.arc(rect.width/2+1, rect.height/2, rect.width / 2. * .2, 0., 2 * math.pi)
319
+ cdx = 0.2
320
+ colx = [ min(1, ccc[0] + cdx), min(1, ccc[1] + cdx), min(1, ccc[2] + cdx), ]
321
+ cr.set_source_rgba(*colx)
322
+ cr.arc(rect.width/2+1, rect.height/2, rect.width / 2. * .3, 0., 2 * math.pi)
316
323
  cr.fill()
317
324
 
318
325
  # ------------------------------------------------------------------------
@@ -655,15 +662,60 @@ def set_testmode(flag):
655
662
 
656
663
  # ------------------------------------------------------------------------
657
664
  # An N pixel horizontal spacer. Defaults to X pix get_center
665
+ #
666
+ #def hspacer(hbox, xstr = " ", expand = False):
667
+ # lab = Gtk.Label(label=xstr)
668
+ # hbox.pack_start(lab, expand, 0, 0)
669
+ #
670
+ #def vspacer(vbox, xstr = " ", expand = False):
671
+ # lab = Gtk.Label(label=xstr)
672
+ # vbox.pack_start(lab, expand , 0, 0)
673
+ #def vspacer(sp = 8):
674
+ # lab = Gtk.VBox()
675
+ # lab.set_size_request(sp, sp)
676
+ #
677
+ # if gui_testmode:
678
+ # lab.override_background_color(
679
+ # Gtk.StateFlags.NORMAL, Gdk.RGBA(1, .5, .5) )
680
+ # return lab
681
+
682
+ # ------------------------------------------------------------------------
683
+ # An N pixel spacer. Defaults to 1 char height / width
684
+
685
+ class Spacer(Gtk.Label):
686
+
687
+ global box_testmode
688
+
689
+ def __init__(self, sp = 1, title=None, left=False, bottom=False, test=False):
690
+
691
+ GObject.GObject.__init__(self)
692
+
693
+ #sp *= 1000
694
+ #self.set_markup("<span size=\"" + str(sp) + "\"> </span>")
695
+ #self.set_text(" " * sp)
658
696
 
659
- def vspacer(sp = 8):
660
- lab = Gtk.VBox()
661
- lab.set_size_request(sp, sp)
697
+ if title:
698
+ self.set_text(title)
699
+ else:
700
+ self.set_text(" " * sp)
662
701
 
663
- if gui_testmode:
664
- lab.override_background_color(
665
- Gtk.StateFlags.NORMAL, Gdk.RGBA(1, .5, .5) )
666
- return lab
702
+ if left:
703
+ self.set_xalign(0)
704
+
705
+ if bottom:
706
+ self.set_yalign(1)
707
+
708
+ if test or box_testmode:
709
+ self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#888888"))
710
+
711
+ #self.set_property("angle", 15)
712
+ #attr = self.get_property("attributes")
713
+ #attr2 = Pango.AttrList()
714
+ #print ("attr", dir(attr))
715
+ #attr.
716
+ #self.set_property("attributes", attr)
717
+ #self.set_property("label", "wtf")
718
+ #self.set_property("background-set", True)
667
719
 
668
720
  # ------------------------------------------------------------------------
669
721
  # An N pixel horizontal spacer. Defaults to X pix get_center
@@ -680,6 +732,20 @@ class xSpacer(Gtk.HBox):
680
732
  sp = 6
681
733
  self.set_size_request(sp, sp)
682
734
 
735
+ # An N pixel vertical spacer. Defaults to X pix get_center
736
+
737
+ class ySpacer(Gtk.VBox):
738
+
739
+ def __init__(self, sp = None):
740
+ GObject.GObject.__init__(self)
741
+ #self.pack_start()
742
+ if gui_testmode:
743
+ col = randcolstr(100, 200)
744
+ self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(col))
745
+ if sp == None:
746
+ sp = 6
747
+ self.set_size_request(sp, sp)
748
+
683
749
  # ------------------------------------------------------------------------
684
750
  # An N pixel spacer. Defaults to 1 char height / width
685
751
 
@@ -699,13 +765,10 @@ class Spacer(Gtk.Label):
699
765
  self.set_text(title)
700
766
  else:
701
767
  self.set_text(" " * sp)
702
-
703
768
  if left:
704
769
  self.set_xalign(0)
705
-
706
770
  if bottom:
707
771
  self.set_yalign(1)
708
-
709
772
  if test or gui_testmode:
710
773
  self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#888888"))
711
774
 
@@ -829,7 +892,6 @@ class RadioGroup(Gtk.Frame):
829
892
  # Nothing selected ... empty str
830
893
  return ""
831
894
 
832
-
833
895
  # Bug fix in Gtk
834
896
 
835
897
  class SeparatorMenuItem(Gtk.SeparatorMenuItem):
@@ -1317,6 +1379,29 @@ class RCLButt(Gtk.Button):
1317
1379
  #if self.callme:
1318
1380
  # self.callme(arg1)
1319
1381
 
1382
+
1383
+ def message(msg):
1384
+ dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.DESTROY_WITH_PARENT,
1385
+ Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, text=msg)
1386
+
1387
+ # 'Action: "%s" of type "%s"' % (action.get_name(), type(action)))
1388
+
1389
+ # Close dialog on user response
1390
+ dialog.connect ("response", lambda d, r: d.destroy())
1391
+ return dialog.run()
1392
+
1393
+ def yesno(msg):
1394
+ dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.DESTROY_WITH_PARENT,
1395
+ Gtk.MessageType.INFO, Gtk.ButtonsType.YES_NO, text=msg)
1396
+
1397
+ # 'Action: "%s" of type "%s"' % (action.get_name(), type(action)))
1398
+
1399
+ # Close dialog on user response
1400
+ #dialog.connect ("response", lambda d, r: d.destroy())
1401
+ ret = dialog.run()
1402
+ dialog.destroy()
1403
+ return ret
1404
+
1320
1405
  # ------------------------------------------------------------------------
1321
1406
  # Highlite test items
1322
1407
 
pyvguicom/pgsel.py ADDED
@@ -0,0 +1,439 @@
1
+
2
+ #!/usr/bin/python
3
+
4
+ import sys
5
+
6
+ import gi
7
+ gi.require_version("Gtk", "3.0")
8
+ from gi.repository import Gtk
9
+ from gi.repository import Gdk
10
+ from gi.repository import GObject
11
+ from gi.repository import Pango
12
+
13
+ ''' Simplified controls '''
14
+
15
+ gui_testmode = False
16
+
17
+ import pgutils, pggui
18
+
19
+ # ------------------------------------------------------------------------
20
+ # Letter selection control
21
+
22
+ class LetterNumberSel(Gtk.VBox):
23
+
24
+ ''' Letter Number selector '''
25
+
26
+ def __init__(self, callb = None, font="Mono 13", pad = ""):
27
+
28
+ Gtk.VBox.__init__(self)
29
+
30
+ self.set_can_focus(True)
31
+ self.set_focus_on_click(True)
32
+ self.set_can_default(True)
33
+
34
+ self.callb = callb
35
+
36
+ self.frame = Gtk.Frame()
37
+
38
+ hbox3a = Gtk.HBox()
39
+ hbox3a.pack_start(Gtk.Label(label=" "), 1, 1, 0)
40
+
41
+ strx = "abcdefghijklmnopqrstuvwxyz"
42
+ self.simsel = internal_SimpleSel(strx, self.lettercb, font, pad)
43
+ #self.override_background_color(Gtk.StateFlags.FOCUSED, Gdk.RGBA(.9,.9,.9))
44
+
45
+ self.connect("key-press-event", self.simsel_key)
46
+ self.connect("key-release-event", self.simsel_key_rel)
47
+
48
+ hbox3a.pack_start(self.simsel, 0, 0, 0)
49
+ hbox3a.pack_start(Gtk.Label(label=" "), 1, 1, 0)
50
+
51
+ strn2 = ""
52
+ hbox3b = Gtk.HBox()
53
+ hbox3b.pack_start(Gtk.Label(label=" "), 1, 1, 0)
54
+ strn = "1234567890!@#$^*_-+"
55
+ self.simsel2 = internal_SimpleSel(strn, self.lettercb, font, pad)
56
+ hbox3b.pack_start(self.simsel2, 0, 0, 0)
57
+
58
+ self.simall = internal_AllSel("All", self.lettercb, font, pad)
59
+ hbox3b.pack_start(self.simall, 0, 0, 0)
60
+ hbox3b.pack_start(Gtk.Label(label=" "), 1, 1, 0)
61
+
62
+ self.simsel2.other = self.simsel
63
+ self.simsel.other = self.simsel2
64
+
65
+ self.simsel2.other2 = self.simall
66
+ self.simsel.other2 = self.simall
67
+
68
+ self.simall.other = self.simsel
69
+ self.simall.other2 = self.simsel2
70
+
71
+ self.curr = self.simsel
72
+ # Commit changes
73
+ self.simsel.exec_index(True)
74
+
75
+ self.hand_cursor = Gdk.Cursor(Gdk.CursorType.HAND2)
76
+ self.simsel.connect("enter_notify_event", self.enter_label)
77
+ self.simsel.connect("leave_notify_event", self.leave_label)
78
+ self.simsel2.connect("enter_notify_event", self.enter_label)
79
+ self.simsel2.connect("leave_notify_event", self.leave_label)
80
+
81
+ self.connect("focus_in_event", self.focus_label)
82
+ self.connect("focus_out_event", self.focus_out_label)
83
+
84
+ vbox = Gtk.VBox()
85
+ vbox.pack_start(hbox3a, 0, 0, False)
86
+ vbox.pack_start(pggui.ySpacer(4), 0, 0, False)
87
+ vbox.pack_start(hbox3b, 0, 0, False)
88
+
89
+ self.frame = Gtk.Frame()
90
+ self.frame.set_shadow_type(Gtk.ShadowType.NONE)
91
+
92
+ self.frame.add(vbox)
93
+ self.pack_start(self.frame, 0, 0, False)
94
+
95
+ def focus_label(self, arg, arg2):
96
+ #print("focus in")
97
+ self.frame.set_shadow_type(Gtk.ShadowType.OUT)
98
+
99
+ def focus_out_label(self, arg, arg2):
100
+ #print("focus out")
101
+ self.frame.set_shadow_type(Gtk.ShadowType.NONE)
102
+
103
+ def simsel_key_rel(self, arg, event):
104
+ if event.keyval == Gdk.KEY_Return or event.keyval == Gdk.KEY_space:
105
+ return True
106
+
107
+ def simsel_key(self, arg, event):
108
+
109
+ # print(event.keyval)
110
+
111
+ if event.keyval == Gdk.KEY_Left:
112
+ self.curr.idx -= 1
113
+ if self.curr.idx < 0:
114
+ #print("Skip left")
115
+ if self.curr == self.simsel:
116
+ self.curr = self.simall
117
+ self.curr.idx = len(self.curr.textarr)-1
118
+ elif self.curr == self.simall:
119
+ self.curr = self.simsel2
120
+ self.curr.idx = len(self.curr.textarr)-1
121
+ else:
122
+ self.curr = self.simsel
123
+ self.curr.idx = len(self.curr.textarr)-1
124
+ self.curr.exec_index(True)
125
+ return True
126
+
127
+ if event.keyval == Gdk.KEY_Right:
128
+ self.curr.idx += 1
129
+ if self.curr.idx >= len(self.curr.textarr):
130
+ #print("Skip right")
131
+ if self.curr == self.simsel:
132
+ self.curr = self.simsel2
133
+ self.curr.idx = 0
134
+ elif self.curr == self.simsel2:
135
+ self.curr = self.simall
136
+ self.curr.idx = 0
137
+ else:
138
+ self.curr = self.simsel
139
+ self.curr.idx = 0
140
+ self.curr.exec_index(True)
141
+ return True
142
+
143
+ if event.keyval == Gdk.KEY_Down:
144
+ if self.curr == self.simsel:
145
+ self.curr = self.simsel2
146
+ else:
147
+ self.curr = self.simsel
148
+ self.curr.exec_index(True)
149
+ return True
150
+
151
+ if event.keyval == Gdk.KEY_Up:
152
+ if self.curr == self.simsel:
153
+ self.curr = self.simsel2
154
+ else:
155
+ self.curr = self.simsel
156
+ self.curr.exec_index(True)
157
+ return True
158
+
159
+ if event.keyval == Gdk.KEY_Home:
160
+ self.curr.idx = 0
161
+ self.curr.exec_index(True)
162
+ return True
163
+
164
+ if event.keyval == Gdk.KEY_End:
165
+ self.curr.idx = len(self.curr.textarr) - 1
166
+ self.curr.exec_index(True)
167
+ return True
168
+
169
+ if event.keyval == Gdk.KEY_Return or event.keyval == Gdk.KEY_space:
170
+ self.curr.exec_index(False)
171
+ return True
172
+
173
+ if event.keyval >= Gdk.KEY_a and event.keyval <= Gdk.KEY_z:
174
+ self.curr.idx = event.keyval - Gdk.KEY_a
175
+ self.curr.exec_index(True)
176
+ return True
177
+
178
+ def enter_label(self, arg, arg2):
179
+ #print("Enter")
180
+ self.get_window().set_cursor(self.hand_cursor)
181
+
182
+ def leave_label(self, arg, arg2):
183
+ #print("Leave")
184
+ self.get_window().set_cursor()
185
+
186
+ def lettercb(self, letter):
187
+ #print("LetterSel::letterx:", letter)
188
+ if self.callb:
189
+ self.callb(letter)
190
+
191
+ # Select character by index (do not call directly)
192
+
193
+ class internal_AllSel(Gtk.Label):
194
+
195
+ ''' Internal class for selectors '''
196
+
197
+ def __init__(self, textx = " ", callb = None, font="Mono 13", pad = ""):
198
+
199
+ Gtk.Label.__init__(self, "")
200
+
201
+ self.set_events(Gdk.EventMask.ALL_EVENTS_MASK )
202
+ self.connect("button-press-event", self.area_button)
203
+ self.modify_font(Pango.FontDescription(font))
204
+ self.set_has_window(True)
205
+ self.text = textx
206
+ #self.textarr = [" " + textx + " ", "[" + textx + "]"]
207
+ self.textarr = [textx]
208
+ self.org = " " + textx + " "
209
+ self.callb = callb
210
+ self.lastsel = ""
211
+ self.lastidx = 0
212
+ self.other = None
213
+ self.other2 = None
214
+ self.pad = pad
215
+ self.newtext = pad
216
+ self.idx = -1
217
+ self.set_can_focus(True)
218
+ self.set_focus_on_click(True)
219
+ self.fill() #self.set_text(self.org)
220
+
221
+ def fill(self):
222
+ if self.idx == 0:
223
+ self.text = "[" + self.org[1:-1] + "]"
224
+ else:
225
+ self.text = " " + self.org[1:-1] + " "
226
+ self.set_text(self.text)
227
+
228
+ def area_button(self, but, event):
229
+
230
+ self.get_parent().get_parent().grab_focus()
231
+ #print("allbutt")
232
+ self.idx = 0
233
+ self.fill()
234
+ if 1: #not fromkey:
235
+ if self.callb:
236
+ self.callb(self.textarr[self.idx])
237
+
238
+ def exec_index(self, fromkey):
239
+
240
+ self.fill()
241
+
242
+ # Fill others, if allocated
243
+ if self.other:
244
+ self.other.idx = -1
245
+ self.other.fill()
246
+ if self.other2:
247
+ self.other2.idx = -1
248
+ self.other2.fill()
249
+
250
+ if not fromkey:
251
+ if self.callb:
252
+ self.callb(self.textarr[self.idx])
253
+
254
+ class internal_SimpleSel(Gtk.Label):
255
+
256
+ ''' Internal class for selectors '''
257
+
258
+ def __init__(self, textx = " ", callb = None, font="Mono 13", pad = ""):
259
+
260
+ Gtk.Label.__init__(self, "")
261
+
262
+ self.set_events(Gdk.EventMask.ALL_EVENTS_MASK )
263
+ self.connect("button-press-event", self.area_button)
264
+ self.modify_font(Pango.FontDescription(font))
265
+ self.set_has_window(True)
266
+
267
+ self.callb = callb
268
+
269
+ self.lastsel = ""
270
+ self.lastidx = 0
271
+ self.other = None
272
+ self.other2 = None
273
+ self.pad = pad
274
+ self.newtext = pad
275
+ self.idx = 0
276
+ self.set_can_focus(True)
277
+ self.set_focus_on_click(True)
278
+
279
+ self.textarr = []
280
+ for aa in textx:
281
+ self.textarr.append(aa)
282
+
283
+ self.fill()
284
+
285
+ def area_button(self, but, event):
286
+
287
+ self.get_parent().get_parent().grab_focus()
288
+ www = self.get_allocation().width
289
+ pitch = float(www) / len(self.textarr)
290
+ #print("pitch", pitch, "www", www, "len",
291
+ # len(self.textarr), "event.x", event.x)
292
+
293
+ # Map point to position
294
+ self.idx = int(event.x / pitch)
295
+ #print("idxx:", idxx, self.idx)
296
+ self.exec_index(False)
297
+
298
+ def _fill2(self, xarr, xidx, padx):
299
+ ''' Internal '''
300
+ cnt = 0
301
+ newtext = ""
302
+ for aa in xarr:
303
+ if cnt == xidx:
304
+ newtext += self.pad + "<span weight='bold' " \
305
+ "underline='double'>" + aa.upper() + "</span>"
306
+ else:
307
+ newtext += self.pad + aa
308
+ cnt += 1
309
+ newtext += self.pad
310
+ return newtext
311
+
312
+ def fill(self):
313
+ self.newtext = self._fill2(self.textarr, self.idx, self.pad)
314
+ self.set_markup(self.newtext)
315
+
316
+ def exec_index(self, fromkey):
317
+
318
+ if self.idx < 0:
319
+ self.idx = 0
320
+ if self.idx > len(self.textarr) - 1:
321
+ self.idx = len(self.textarr) - 1
322
+ #print("index:", self.idx)
323
+ self.fill()
324
+
325
+ # Fill others, if allocated
326
+ if self.other:
327
+ self.other.idx = -1
328
+ self.other.fill()
329
+ if self.other2:
330
+ self.other2.idx = -1
331
+ self.other2.fill()
332
+
333
+ if not fromkey:
334
+ if self.callb:
335
+ self.callb(self.textarr[self.idx])
336
+
337
+ class NumberSel(Gtk.Label):
338
+
339
+ ''' Number selector. Give a proportional answer from mouse position '''
340
+
341
+ def __init__(self, text = " ", callb = None, font="Mono 13"):
342
+ self.text = text
343
+ self.callb = callb
344
+ self.axx = self.text.find("[All]")
345
+ Gtk.Label.__init__(self, text)
346
+ self.set_has_window(True)
347
+ self.set_events(Gdk.EventMask.ALL_EVENTS_MASK )
348
+ self.connect("button-press-event", self.area_button)
349
+ self.override_font(Pango.FontDescription(font))
350
+ self.lastsel = 0
351
+
352
+ def area_button(self, but, event):
353
+
354
+ #print("sss =", self.get_allocation().width)
355
+ #print("click", event.x, event.y)
356
+
357
+ prop = event.x / float(self.get_allocation().width)
358
+ idx = int(prop * len(self.text))
359
+
360
+ # Navigate to IDX
361
+ if self.text[idx] == " ":
362
+ idx += 1
363
+ else:
364
+ if self.text[idx-1] != " ":
365
+ idx -= 1
366
+ if idx >= len(self.text):
367
+ return
368
+ if idx < 0:
369
+ idx = 0
370
+ try:
371
+ # See of it is all
372
+ if self.axx >= 0:
373
+ if idx > self.axx:
374
+ #print("all", idx, self.text[idx-5:idx+7])
375
+ self.lastsel = "All"
376
+ self.newtext = self.text[:self.axx] + self.text[self.axx:].upper()
377
+ self.set_text(self.newtext)
378
+ else:
379
+ self.newtext = self.text[:self.axx] + self.text[self.axx:].lower()
380
+ self.set_text(self.newtext)
381
+
382
+ else:
383
+ self.lastsel = self.text[idx:idx+2]
384
+ #print("lastsel", self.lastsel)
385
+ self.newtext = self.text[:idx] + self.text[idx].upper() + self.text[idx+1:]
386
+ self.set_text(self.newtext)
387
+
388
+ if self.callb:
389
+ self.callb(self.lastsel)
390
+
391
+ except:
392
+ print(sys.exc_info())
393
+
394
+ class HourSel(Gtk.VBox):
395
+
396
+ ''' Hour selector '''
397
+
398
+ def __init__(self, callb = None):
399
+
400
+ Gtk.VBox.__init__(self)
401
+ self.callb = callb
402
+
403
+ strx = " 8 10 12 14 16 "
404
+ hbox3a = Gtk.HBox()
405
+ hbox3a.pack_start(Gtk.Label(label=" "), 1, 1, 0)
406
+ self.simsel = NumberSel(strx, self.lettercb)
407
+ hbox3a.pack_start(self.simsel, 0, 0, 0)
408
+ hbox3a.pack_start(Gtk.Label(label=" "), 1, 1, 0)
409
+
410
+ self.pack_start(hbox3a, 0, 0, False)
411
+
412
+ def lettercb(self, letter):
413
+ #print("LetterSel::letterx:", letter)
414
+ if self.callb:
415
+ self.callb(letter)
416
+
417
+ class MinSel(Gtk.VBox):
418
+
419
+ ''' Minute selector '''
420
+
421
+ def __init__(self, callb = None):
422
+
423
+ Gtk.VBox.__init__(self)
424
+ self.callb = callb
425
+
426
+ strx = " 0 10 20 30 40 50 "
427
+ hbox3a = Gtk.HBox()
428
+ hbox3a.pack_start(Gtk.Label(label=" "), 1, 1, 0)
429
+ self.simsel = NumberSel(strx, self.lettercb)
430
+ hbox3a.pack_start(self.simsel, 0, 0, 0)
431
+ hbox3a.pack_start(Gtk.Label(label=" "), 1, 1, 0)
432
+
433
+ self.pack_start(hbox3a, 0, 0, False)
434
+
435
+ def lettercb(self, letter):
436
+ #print("LetterSel::letterx:", letter)
437
+ if self.callb:
438
+ self.callb(letter)
439
+