From: <sig...@us...> - 2011-04-26 23:33:17
|
Revision: 780 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=780&view=rev Author: siggipals Date: 2011-04-26 23:33:11 +0000 (Tue, 26 Apr 2011) Log Message: ----------- #111 - Added capability for specifying graph display color for sports Modified Paths: -------------- pytrainer/trunk/glade/profile.glade pytrainer/trunk/pytrainer/gui/drawArea.py pytrainer/trunk/pytrainer/gui/windowmain.py pytrainer/trunk/pytrainer/gui/windowprofile.py pytrainer/trunk/pytrainer/lib/ddbb.py pytrainer/trunk/pytrainer/main.py pytrainer/trunk/pytrainer/monthgraph.py pytrainer/trunk/pytrainer/profile.py pytrainer/trunk/pytrainer/timegraph.py pytrainer/trunk/pytrainer/totalgraph.py pytrainer/trunk/pytrainer/weekgraph.py pytrainer/trunk/pytrainer/yeargraph.py Modified: pytrainer/trunk/glade/profile.glade =================================================================== --- pytrainer/trunk/glade/profile.glade 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/glade/profile.glade 2011-04-26 23:33:11 UTC (rev 780) @@ -591,6 +591,7 @@ <widget class="GtkTreeView" id="sportTreeView"> <property name="visible">True</property> <property name="can_focus">True</property> + <signal name="row_activated" handler="on_sporttreeview_row_activated"/> </widget> </child> </widget> @@ -808,8 +809,8 @@ </widget> <packing> <property name="right_attach">3</property> - <property name="top_attach">4</property> - <property name="bottom_attach">5</property> + <property name="top_attach">5</property> + <property name="bottom_attach">6</property> <property name="x_options">GTK_FILL</property> <property name="y_options"></property> </packing> @@ -841,6 +842,42 @@ <property name="y_options"></property> </packing> </child> + <child> + <widget class="GtkHBox" id="hboxcolor"> + <property name="visible">True</property> + <child> + <widget class="GtkImage" id="newcolor"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + </widget> + <packing> + </packing> + </child> + <child> + <widget class="GtkButton" id="buttoncolor"> + <property name="label">gtk-edit</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="on_editcolor_clicked"/> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> + <property name="y_options"></property> + </packing> + </child> <child> <placeholder/> </child> @@ -1188,8 +1225,8 @@ </widget> <packing> <property name="right_attach">2</property> - <property name="top_attach">4</property> - <property name="bottom_attach">5</property> + <property name="top_attach">5</property> + <property name="bottom_attach">6</property> <property name="x_options">GTK_FILL</property> <property name="y_options"></property> </packing> @@ -1198,7 +1235,7 @@ <widget class="GtkLabel" id="label-9"> <property name="visible">True</property> <property name="xalign">0</property> - <property name="label" translatable="yes">Maxiumum Pace</property> + <property name="label" translatable="yes">Maximum Pace</property> </widget> <packing> <property name="top_attach">3</property> @@ -1221,6 +1258,55 @@ <property name="y_options"></property> </packing> </child> + <child> + <widget class="GtkLabel" id="label-10"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Color</property> + </widget> + <packing> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkHBox" id="hboxcolor"> + <property name="visible">True</property> + <child> + <widget class="GtkImage" id="editcolor"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + </widget> + <packing> + </packing> + </child> + <child> + <widget class="GtkButton" id="buttoncolor"> + <property name="label">gtk-edit</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="on_editcolor_clicked"/> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> + <property name="y_options"></property> + </packing> + </child> </widget> <packing> <property name="position">0</property> Modified: pytrainer/trunk/pytrainer/gui/drawArea.py =================================================================== --- pytrainer/trunk/pytrainer/gui/drawArea.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/gui/drawArea.py 2011-04-26 23:33:11 UTC (rev 780) @@ -171,7 +171,7 @@ else: return '%1.1f' % x - def drawStackedBars(self,xvalues,yvalues,ylabel,title, valuesAreTime=False): + def drawStackedBars(self,xvalues,yvalues,ylabel,title, valuesAreTime=False, colors={}): '''function to draw stacked bars xvalues needs to be a list of lists of strings, e.g. [0]["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] yvalues needs to be a list of dicts e.g. [0]{'Kayak': {'Tue': 10.08, 'Fri': 17.579999999999998, 'Thu': 15.66, 'Sat': 30.619999999999997}, {'Run': {'Mon': 9.65, 'Sun': 15.59}} @@ -218,7 +218,9 @@ for ind in inds: ybottoms[ind] += yheights[ind] yheights[ind] = 0 #Zero heights - color = self.getColor(keys.index(key)) + color = "#"+colors.get(key, '') + if len(color)<2: + color = self.getColor(keys.index(key)) for xvalue in xvalues[0]: index = xvalues[0].index(xvalue) if xvalue in yvalues[0][key]: @@ -255,7 +257,9 @@ for ind in inds: ybottoms[ind] += yheights[ind] yheights[ind] = 0.0 #Zero heights - color = self.getColor(keys.index(key)) + color = "#"+colors.get(key, '') + if len(color)<2: + color = self.getColor(keys.index(key)) for xvalue in xvalues[0]: index = xvalues[0].index(xvalue) if xvalue in yvalues[1][key]: Modified: pytrainer/trunk/pytrainer/gui/windowmain.py =================================================================== --- pytrainer/trunk/pytrainer/gui/windowmain.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/gui/windowmain.py 2011-04-26 23:33:11 UTC (rev 780) @@ -246,10 +246,10 @@ self.drawareaheartrate = HeartRateGraph(self.heartrate_vbox, self.window1, self.heartrate_vbox2, pytrainer_main=self.pytrainer_main) #self.drawareaday = DayGraph(self.day_vbox, self.day_combovalue) self.day_vbox.hide() - self.drawareaweek = WeekGraph(self.weekview, self.window1, self.week_combovalue, self.week_combovalue2) - self.drawareamonth = MonthGraph(self.month_vbox, self.window1, self.month_combovalue,self.month_combovalue2) - self.drawareayear = YearGraph(self.year_vbox, self.window1, self.year_combovalue,self.year_combovalue2) - self.drawareatotal = TotalGraph(self.total_vbox, self.window1, self.total_combovalue,self.total_combovalue2) + self.drawareaweek = WeekGraph(self.weekview, self.window1, self.week_combovalue, self.week_combovalue2, self.pytrainer_main) + self.drawareamonth = MonthGraph(self.month_vbox, self.window1, self.month_combovalue,self.month_combovalue2, self.pytrainer_main) + self.drawareayear = YearGraph(self.year_vbox, self.window1, self.year_combovalue,self.year_combovalue2, self.pytrainer_main) + self.drawareatotal = TotalGraph(self.total_vbox, self.window1, self.total_combovalue,self.total_combovalue2, self.pytrainer_main) def createMap(self,MapViewer,waypoint): self.waypoint = waypoint @@ -298,9 +298,9 @@ def create_treeview(self,treeview,columns): for column_index, column_dict in enumerate(columns): if 'pixbuf' in column_dict: - renderer = gtk.CellRendererPixbuf() + renderer = gtk.CellRendererPixbuf() else: - renderer = gtk.CellRendererText() + renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(column_dict['name']) column.pack_start(renderer, expand=False) if 'pixbuf' in column_dict: @@ -433,10 +433,10 @@ # Use grey color for "rest" laps for c in self.lapsTreeView.get_columns()[:-1]: - for cr in c.get_cell_renderers(): - if type(cr)==gtk.CellRendererText: - c.add_attribute(cr, 'foreground', 11) - + for cr in c.get_cell_renderers(): + if type(cr)==gtk.CellRendererText: + c.add_attribute(cr, 'foreground', 11) + self.frame_laps.show() else: self.frame_laps.hide() Modified: pytrainer/trunk/pytrainer/gui/windowprofile.py =================================================================== --- pytrainer/trunk/pytrainer/gui/windowprofile.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/gui/windowprofile.py 2011-04-26 23:33:11 UTC (rev 780) @@ -35,6 +35,7 @@ self.data_path = data_path SimpleGladeApp.__init__(self, data_path+glade_path, root, domain) self.conf_options = parent.profile_options + self.stored_color = "000000" def new(self): self.gender_options = { @@ -56,9 +57,18 @@ self.prf_ddbb.insert_text(i,self.ddbb_type[i]) #preparamos la lista sports: - column_names=[_("Sport"),_("MET"),_("Extra Weight"), _("Maximum Pace")] + column_names=[_("Sport"),_("MET"),_("Extra Weight"), _("Maximum Pace"), _("Color")] for column_index, column_name in enumerate(column_names): - column = gtk.TreeViewColumn(column_name, gtk.CellRendererText(), text=column_index) + if column_index==4: + renderer = gtk.CellRendererPixbuf() + else: + renderer = gtk.CellRendererText() + column = gtk.TreeViewColumn(column_name, text=column_index) + column.pack_start(renderer, expand=False) + if column_index==4: + column.add_attribute(renderer, 'pixbuf', column_index) + else: + column.add_attribute(renderer, 'text', column_index) column.set_resizable(True) self.sportTreeView.append_column(column) @@ -153,6 +163,7 @@ gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, + gtk.gdk.Pixbuf, object) for i in sport_list: try: @@ -171,6 +182,8 @@ #print type(e), e max_pace = "" + colorPixBuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 25, 15) + colorPixBuf.fill(0 if i[5] in (None,'') else long(i[5]+'00',16)) iter = store.append() store.set ( @@ -179,6 +192,7 @@ 1, met, 2, weight, 3, max_pace, + 4, colorPixBuf, ) self.sportTreeView.set_model(store) self.sportTreeView.set_cursor(0) @@ -328,7 +342,7 @@ md.run() md.destroy() return - self.parent.addNewSport(sport,met,weight,maxpace) + self.parent.addNewSport(sport,met,weight,maxpace,self.stored_color) self.parent.actualize_mainsportlist() self.on_switch_page(None,None,2) self.hidesportsteps() @@ -358,7 +372,7 @@ if iter: self.buttonbox.set_sensitive(0) sport = selected.get_value(iter,0) - name,met,weight,maxpace = self.parent.getSportInfo(sport) + name,met,weight,maxpace,color = self.parent.getSportInfo(sport) self.editsportentry.set_text(sport) self.sportnameedit.set_text(sport) if weight is not None: @@ -373,8 +387,39 @@ self.editmaxpace.set_text(str(maxpace)) else: self.editmaxpace.set_text("") + if color == None: + color = "0000" + + colorPixBuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 250, 20) + colorPixBuf.fill(long("0x%s00" % color, 16)) + self.editcolor.set_from_pixbuf(colorPixBuf) + self.hidesportsteps() self.editsport.show() + + def on_editcolor_clicked(self, widget): + selected,iter = self.sportTreeView.get_selection().get_selected() + if iter: + sport = selected.get_value(iter,0) + name,met,weight,maxpace,color = self.parent.getSportInfo(sport) + if color==None: + color = "000000" + colorseldlg = gtk.ColorSelectionDialog("test") + colorseldlg.colorsel.set_has_palette(True) + colorseldlg.colorsel.set_current_color(gtk.gdk.color_parse("#"+color)) + colorseldlg.run() + col = colorseldlg.colorsel.get_current_color() + self.stored_color = ("%02x" % col.red)[:2] + ("%02x" % col.green)[:2] + ("%02x" % col.blue)[:2] + + colorPixBuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 250, 20) + colorPixBuf.fill(long("0x%s00" % self.stored_color, 16)) + self.newcolor.set_from_pixbuf(colorPixBuf) + self.editcolor.set_from_pixbuf(colorPixBuf) + + colorseldlg.hide() + + def on_sporttreeview_row_activated(self, widget, path, column): + self.on_editsport_clicked(None) def on_editsport_accept_clicked(self,widget): oldnamesport = self.sportnameedit.get_text() @@ -382,7 +427,7 @@ newmetsport = self.editmetentry.get_text() newweightsport = self.editweightentry.get_text() newmaxpace = self.editmaxpace.get_text() - self.parent.updateSport(oldnamesport,newnamesport,newmetsport,newweightsport, newmaxpace) + self.parent.updateSport(oldnamesport,newnamesport,newmetsport,newweightsport, newmaxpace, self.stored_color) self.parent.actualize_mainsportlist() self.on_switch_page(None,None,2) self.hidesportsteps() Modified: pytrainer/trunk/pytrainer/lib/ddbb.py =================================================================== --- pytrainer/trunk/pytrainer/lib/ddbb.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/lib/ddbb.py 2011-04-26 23:33:11 UTC (rev 780) @@ -54,6 +54,7 @@ "weight":"float", "met":"float", "max_pace":"integer", + "color":"char(6)", }, "waypoints":{ "id_waypoint":"integer primary key autoincrement", "lat":"float", Modified: pytrainer/trunk/pytrainer/main.py =================================================================== --- pytrainer/trunk/pytrainer/main.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/main.py 2011-04-26 23:33:11 UTC (rev 780) @@ -55,7 +55,7 @@ def __init__(self,filename = None, data_path = None): #Version constants self.version ="1.8.0-svn#774" - self.DB_version = 7 + self.DB_version = 8 #Process command line options self.startup_options = self.get_options() self.environment = Environment(platform.get_platform(), self.startup_options.conf_dir) Modified: pytrainer/trunk/pytrainer/monthgraph.py =================================================================== --- pytrainer/trunk/pytrainer/monthgraph.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/monthgraph.py 2011-04-26 23:33:11 UTC (rev 780) @@ -30,8 +30,8 @@ (_("day"),_("Calories"), _("Daily Calories"),"b"), ] - def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None): - TimeGraph.__init__(self, vbox=vbox, window=window) + def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None, main = None): + TimeGraph.__init__(self, vbox=vbox, window=window, main=main) self.combovalue = combovalue self.combovalue2 = combovalue2 self.KEY_FORMAT = "%d" Modified: pytrainer/trunk/pytrainer/profile.py =================================================================== --- pytrainer/trunk/pytrainer/profile.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/profile.py 2011-04-26 23:33:11 UTC (rev 780) @@ -225,11 +225,11 @@ #connection = self.pytrainer_main.ddbb.connect() #if (connection == 1): logging.debug("retrieving sports info") - return self.pytrainer_main.ddbb.select("sports","name,met,weight,id_sports,max_pace",None) + return self.pytrainer_main.ddbb.select("sports","name,met,weight,id_sports,max_pace,color",None) #else: # return connection - def addNewSport(self,sport,met,weight,maxpace): + def addNewSport(self,sport,met,weight,maxpace,color): """31.08.2008 - dgranda It adds a new sport. arguments: @@ -238,9 +238,9 @@ weight: returns: id_sports from new sport""" logging.debug(">>") - logging.debug("Adding new sport: "+sport+"|"+weight+"|"+met+"|"+maxpace) - sport = [sport,met,weight,maxpace] - self.pytrainer_main.ddbb.insert("sports","name,met,weight,max_pace",sport) + logging.debug("Adding new sport: "+sport+"|"+weight+"|"+met+"|"+maxpace+"|"+str(color)) + sport = [sport,met,weight,maxpace,color] + self.pytrainer_main.ddbb.insert("sports","name,met,weight,max_pace,color",sport) sport_id = self.pytrainer_main.ddbb.select("sports","id_sports","name=\"%s\"" %(sport)) logging.debug("<<") return sport_id @@ -254,13 +254,13 @@ self.pytrainer_main.ddbb.delete("sports","id_sports=\"%d\""%id_sport) logging.debug("<<") - def updateSport(self,oldnamesport,newnamesport,newmetsport,newweightsport,newmaxpace=None): + def updateSport(self,oldnamesport,newnamesport,newmetsport,newweightsport,newmaxpace=None,newcolor=None): logging.debug("--") - self.pytrainer_main.ddbb.update("sports","name,met,weight,max_pace",[newnamesport,newmetsport,newweightsport, newmaxpace],"name=\"%s\""%oldnamesport) + self.pytrainer_main.ddbb.update("sports","name,met,weight,max_pace,color",[newnamesport,newmetsport,newweightsport, newmaxpace, newcolor],"name=\"%s\""%oldnamesport) def getSportInfo(self,namesport): logging.debug("--") - return self.pytrainer_main.ddbb.select("sports","name,met,weight,max_pace","name=\"%s\""%namesport)[0] + return self.pytrainer_main.ddbb.select("sports","name,met,weight,max_pace,color","name=\"%s\""%namesport)[0] def build_ddbb(self): logging.debug("--") Modified: pytrainer/trunk/pytrainer/timegraph.py =================================================================== --- pytrainer/trunk/pytrainer/timegraph.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/timegraph.py 2011-04-26 23:33:11 UTC (rev 780) @@ -20,9 +20,10 @@ from gui.drawArea import DrawArea class TimeGraph(object): - def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None): + def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None, main = None): self.drawarea = DrawArea(vbox, window) self.SPORT_FIELD = 9 + self.sportlist = dict([(s[0],s[5]) for s in main.profile.getSportList()]) def getFloatValue(self, value): try: @@ -49,6 +50,7 @@ def get_values(self, values, value_selected, key_format, sportfield=9): valueDict = {} #Stores the totals valueCount = {} #Counts the totals to allow for averaging if needed + sportColors = {} for record in values: day = unicode(datetime.datetime.strptime(record[0], "%Y-%m-%d").strftime(key_format)) # Gives year for this record @@ -118,8 +120,7 @@ xlab.append(xvalues) valsAreTime.append(valuesAreTime) #Draw chart - - self.drawarea.drawStackedBars(xlab,yval,ylab,tit,valsAreTime) + self.drawarea.drawStackedBars(xlab,yval,ylab,tit,valsAreTime, colors = self.sportlist) def get_value_params(self,value): return self.value_params[value] Modified: pytrainer/trunk/pytrainer/totalgraph.py =================================================================== --- pytrainer/trunk/pytrainer/totalgraph.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/totalgraph.py 2011-04-26 23:33:11 UTC (rev 780) @@ -28,8 +28,8 @@ (_("year"),_("Calories"), _("Annual Calories"),"b"), ] - def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None): - TimeGraph.__init__(self, vbox=vbox, window=window) + def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None, main = None): + TimeGraph.__init__(self, vbox=vbox, window=window, main=main) self.combovalue = combovalue self.combovalue2 = combovalue2 self.KEY_FORMAT = "%Y" Modified: pytrainer/trunk/pytrainer/weekgraph.py =================================================================== --- pytrainer/trunk/pytrainer/weekgraph.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/weekgraph.py 2011-04-26 23:33:11 UTC (rev 780) @@ -32,8 +32,8 @@ (None, _("Calories"), _("Daily Calories"), None), ] - def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None): - TimeGraph.__init__(self, vbox=vbox, window=window) + def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None, main = None): + TimeGraph.__init__(self, vbox=vbox, window=window, main=main) self.combovalue = combovalue self.combovalue2 = combovalue2 self.KEY_FORMAT = "%a" Modified: pytrainer/trunk/pytrainer/yeargraph.py =================================================================== --- pytrainer/trunk/pytrainer/yeargraph.py 2011-04-26 23:16:34 UTC (rev 779) +++ pytrainer/trunk/pytrainer/yeargraph.py 2011-04-26 23:33:11 UTC (rev 780) @@ -30,8 +30,8 @@ (_("month"),_("Calories"), _("Monthly Calories"),"b"), ] - def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None): - TimeGraph.__init__(self, vbox=vbox, window=window) + def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None, main = None): + TimeGraph.__init__(self, vbox=vbox, window=window, main=main) self.combovalue = combovalue self.combovalue2 = combovalue2 self.KEY_FORMAT = "%m" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |