import pygtk pygtk.require('2.0') import gtk import gtk.glade import pickle import gobject import time import math from grid import * from joy_manager import * class Selection_Manager: def __init__(self,rows,cols,button_list,cfg_mngr,joy): self.rows=rows self.cols=cols self.start=False self.button_list=button_list self.original_style=self.button_list[0].get_modifier_style().copy() self.cfg_mngr=cfg_mngr self.button_list=button_list #self.id=grid.id self.count=0 self.count2=0 self.to_the_right=True self.to_bottom=True self.maintimer = gobject.timeout_add(800, self.set_color,self.button_list) self.joytimer = gobject.timeout_add(50, self.check_joy,self.button_list) self.joy=joy self.horizontal=True self.vertical=False self.h_selected=None self.real_count=0 self.selection=0 self.count_up_down_times=0 self.running=False self.old=False #def __init__ def check_joy(self,list): if self.old: if self.running: axis=0 buttons=False for item in self.cfg_mngr.list_triggers: type,id=item if type=="axis": axis+=math.fabs(self.joy.get_axis(id)) if type=="buttons": for item2 in range(self.joy.buttons): if self.joy.get_button(item2): buttons=True if axis>=0.1 or buttons: time.sleep(0.8) list[self.selection].print_variables() list[self.selection].modify_style(self.original_style) time.sleep(0.8) #axis=self.joy.get_axis(0) else: if self.running: # print "Clicking Grid ID [%s]"%self.id axis=0 buttons=False for item in self.cfg_mngr.list_triggers: type,id=item if type=="axis": axis+=math.fabs(self.joy.get_axis(id)) if type=="buttons": for item2 in range(self.joy.buttons): if self.joy.get_button(item2): buttons=True #axis=self.joy.get_axis(0) if axis>=0.1 or buttons: if self.horizontal: time.sleep(0.5) self.horizontal=False self.vertical=True self.count2=self.real_count time.sleep(0.5) else : time.sleep(0.5) self.count=0 self.count2=0 self.count_up_down_times=0 self.horizontal=True self.vertical=False list[self.selection].print_variables() list[self.selection].modify_style(self.original_style) #time.sleep(0.5) return True #def check_joy def set_color(self,list): #OLD LOOP TO GO THROUGH EVERY SINGLE BUTTON if self.old: if self.running: self.selection=self.count if self.count == 0: list[len(list)-1].modify_style(self.original_style) list[0].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#FF1700')) else: list[self.count-1].modify_style(self.original_style) list[self.count].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#FF1700')) if self.count < len(list)-1: self.count+=1 else: self.count=0 else: #print "self.count= %s"%self.count if self.running: if self.horizontal: self.real_count=self.count if self.to_the_right: if self.count == 0: list[self.rows-1].modify_style(self.original_style) list[0].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#FF1700')) else: list[self.count-1].modify_style(self.original_style) list[self.count].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#FF1700')) if self.count < self.rows-1: self.count+=1 else: self.to_the_right=False #self.count-=1 else: if self.count == self.rows-1: list[self.rows-1].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#FF1700')) else: list[self.count+1].modify_style(self.original_style) list[self.count].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#FF1700')) if self.count > 0: self.count-=1 else: self.to_the_right=True #self.count+=1 if self.vertical: self.selection=self.count2 if self.to_bottom: if self.count2==self.real_count: list[self.count2].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#003994')) else: list[self.count2].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#003994')) list[self.count2-self.rows].modify_style(self.original_style) if self.count2 +self.rows <= self.real_count+(self.rows*(self.cols-1)): self.count2+=self.rows else: self.to_bottom=False else: if self.count2 >= (self.real_count-1)+(self.rows*(self.cols-1)): list[self.count2].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#003994')) else: list[self.count2].modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#003994')) list[self.count2+self.rows].modify_style(self.original_style) if self.count2>self.real_count: self.count2-=self.rows else: self.to_bottom=True self.count_up_down_times+=1 if self.count_up_down_times==2: self.count=0 self.horizontal=True self.vertical=False self.count_up_down_times=0 list[self.selection].modify_style(self.original_style) return True # def set_color # class Selection_Manager