Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

working on dialogs

  • Loading branch information...
commit 6cb1319b86e013b4f566e78ea7d8137b7355c4cf 1 parent ef6ca03
FabioDive authored
Showing with 100 additions and 37 deletions.
  1. +3 −3 datastore.py
  2. +90 −34 dialogs.py
  3. +7 −0 utils.py
View
6 datastore.py
@@ -36,10 +36,10 @@ def savetexts(new_texts):
if len(new_texts) > 0:
try:
transaction.begin()
- Program.reset()
- for text,color,effect,effect_time in new_texts.iteritems():
+ Texts.reset()
+ for k,v in new_texts.iteritems():
dbsession = DBSession()
- texts = Texts(text, color, effect, effect_time)
+ texts = Texts(v['text'], v['color'], v['effect'], v['effect_time'])
dbsession.add(text)
dbsession.commit()
View
124 dialogs.py
@@ -29,11 +29,33 @@
from pgu import gui
from datastore import savetexts
from models import Texts, Effects
+from utils import rgb_to_hex
+"""
+structure of the resulting program dictionary:
+
+self.program = {
+ 0: {
+ 'text': 'aaa',
+ 'color': '#ffffff',
+ 'effect': 'flash',
+ 'effect_time': 20,
+ },
+
+ 1: {
+ 'text': 'bbb',
+ 'color': '#ffffff',
+ 'effect': 'flash',
+ 'effect_time': 30,
+ },
+ ...
+ }
+"""
class EditProgram(gui.Dialog):
def __init__(self, **params):
+ self.program = {}
title = gui.Label("Impostazione scritte")
main = gui.Container()
@@ -50,51 +72,49 @@ def __init__(self, **params):
c.td(gui.Label("Impostazione scritte", cls="h1"), align=-1, colspan=5)
c.tr()
- c.td(gui.Label("Inserire in lista le scritte in ordine di apparizione, poi confermare con SALVA."),
+ c.td(gui.Label("Inserire in lista le scritte in ordine di apparizione."),
align=-1, colspan=5)
default_color = "#ffffff"
- color = gui.Color(default_color,width=100,height=65, name='color')
+ self.color = gui.Color(default_color,width=100,height=65, name='color')
color_d = ColorDialog()
- color.connect(gui.CLICK,color_d.open,None)
+ self.color.connect(gui.CLICK,color_d.open,None)
# Updates the toolbox color picker with the value in the color dialog box
def update_color():
- color.value = color_d.value
+ self.color.value = color_d.value
color_d.connect(gui.CHANGE, update_color)
+
+ self.inputbox = gui.Input(value='',size=54)
+ self.inputbox.connect("activate", self.add_list)
btnadd = gui.Button("Aggiungi", height=65)
btnadd.connect(gui.CLICK, self.add_list)
- self.inputbox = gui.Input(value='',size=54)
- self.inputbox.connect("activate", self.add_list)
-
c.tr()
- c.td(color, align=-1, rowspan=2)
+ c.td(self.color, align=-1, rowspan=2)
c.td(self.inputbox, align=-1, colspan=3)
c.td(btnadd, rowspan=2)
- effselector = gui.Select()
+ self.effselector = gui.Select()
for item in Effects.list_effects():
- effselector.add(str(item.effect), int(item.id))
- if not effselector.value:
- effselector.value = item.id
+ self.effselector.add(str(item.effect), int(item.id))
+ if not self.effselector.value:
+ self.effselector.value = item.id
default_speed = 50
default_speed_label = 'Velocita: 50'
- def change_speed():
- speed_indicator.value = 'Velocita: %s' % speed.value
-
- self.speed = speed = gui.HSlider(value=default_speed,min=0,max=100,size=32,width=160,height=25)
- speed.connect(gui.CHANGE,change_speed)
-
+ self.speed = gui.HSlider(value=default_speed,min=0,max=100,size=32,width=160,height=25)
speed_indicator = gui.Input(value=default_speed_label,size=12)
+ def change_speed():
+ speed_indicator.value = 'Velocita: %s' % self.speed.value
+ self.speed.connect(gui.CHANGE,change_speed)
c.tr()
- c.td(effselector, align=-1)
+ c.td(self.effselector, align=-1)
c.td(speed_indicator, align=-1)
- c.td(speed)
+ c.td(self.speed)
c.tr()
c.td(self.textlist, align=-1, colspan=5)
@@ -102,13 +122,13 @@ def change_speed():
btn_el = gui.Button("Elimina Riga")
btn_el.connect(gui.CLICK, self.remove_list_item)
btn_su = gui.Button("Muovi Riga SU")
- btn_su.connect(gui.CLICK, self.clear_list)
+ btn_su.connect(gui.CLICK, self.updown_list, -1)
btn_elt = gui.Button("Elimina Tutto")
btn_elt.connect(gui.CLICK, self.clear_list)
btn_giu = gui.Button("Muovi Riga GIU")
- btn_giu.connect(gui.CLICK, self.clear_list)
- btn_sav = gui.Button("SALVA")
- btn_sav.connect(gui.CLICK, self.save_list)
+ btn_giu.connect(gui.CLICK, self.updown_list, 1)
+ btn_sav = gui.Button("Chiudi")
+ btn_sav.connect(gui.CLICK, self.close)
c.tr()
c.td(btn_el, align=-1)
@@ -127,26 +147,62 @@ def add_list(self):
self.textlist.add(self.inputbox.value, value=self.inputbox.value)
self.textlist.resize()
self.textlist.repaint()
+ self.add_to_program(self.inputbox.value,
+ rgb_to_hex(self.color.value),
+ self.effselector.value,
+ self.speed.value)
self.inputbox.value=''
-
+
def clear_list(self):
self.textlist.clear()
self.textlist.resize()
self.textlist.repaint()
+ self.program = {}
+
+ def updown_list(self, pos):
+ l = self.textlist.items
+ for item in l:
+ if item.value == self.textlist.value: obj = item
+
+ idx = l.index(obj)
+ #print 'pos: %s' % idx
+ newpos = idx + pos
+ #print 'newpos: %s' % newpos
+ #print 'len: %s' % len(l)
+ if newpos in range(len(l)):
+ #print 'newpos: %s' % newpos
+ l.insert(newpos, l.pop(idx))
+
+ tmp_list = []
+ for item in l:
+ tmp_list.append(item.value)
+
+ #print tmp_list
+ self.textlist.clear()
+ for item in tmp_list:
+ self.textlist.add(item, value=item)
+
+ self.textlist.repaint()
+
def remove_list_item(self):
- v = self.textlist.value
- if v:
- item = v
+ item = self.textlist.value
+ if item:
self.textlist.remove(item)
self.textlist.resize()
self.textlist.repaint()
-
- def save_list(self):
- program = {}
-
- #if saveprogram(new_program):
- #else:
+ self.program = {}
+
+
+ def add_to_program(self, text, color, effect, effect_time):
+ d = {
+ 'text': text,
+ 'color': color,
+ 'effect': effect,
+ 'effect_time': effect_time
+ }
+ self.program[len(self.program)] = d
+ print self.program
class ColorDialog(gui.Dialog):
View
7 utils.py
@@ -0,0 +1,7 @@
+def hex_to_rgb(value):
+ value = value.lstrip('#')
+ lv = len(value)
+ return tuple(int(value[i:i+lv/3], 16) for i in range(0, lv, lv/3))
+
+def rgb_to_hex(rgb):
+ return '#%02x%02x%02x' % rgb[:3]
Please sign in to comment.
Something went wrong with that request. Please try again.