00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 import gtk
00031 from time import strftime, gmtime, time, sleep
00032 from math import floor
00033 from modules import clWidgets, clThreadedDownload, clEntry
00034
00035 class AlbumBrowser(gtk.Layout):
00036
00037 def __init__(self, pyjama):
00038 self.pyjama = pyjama
00039
00040 gtk.Layout.__init__(self)
00041 self.set_size(700,400)
00042
00043
00044 self.results_per_page = 10
00045 self.ordering = "ratingweek"
00046 self.tag = "all"
00047 self.cur_page = 1
00048
00049
00050 self.albuminfos={}
00051
00052 self.pyjama.Events.connect_event("scrolled_window_resized", self.ev_scrolled_window_resized)
00053
00054
00055 self.pyjama.window.setcolor(self)
00056
00057
00058
00059 def draw(self, num=None, mode="ratingweek", page=1, tag="all"):
00060
00061 self.check_next_possible(page, num)
00062 self.check_prev_possible(page)
00063
00064
00065
00066
00067
00068 self.pyjama.layouts.toolbars['top'].cbOrder.set_item(mode)
00069 show_tag = tag
00070 if tag == "all": show_tag = _("--all--")
00071 if not tag in self.pyjama.layouts.toolbars['top'].cbTags.modelist and tag != "all":
00072 self.pyjama.layouts.toolbars['top'].cbTags.entry.set_text(tag.replace("+", " "))
00073 else:
00074 self.pyjama.layouts.toolbars['top'].cbTags.set_item(show_tag)
00075 self.pyjama.layouts.toolbars['top'].cbResultsPerPage.set_item(num)
00076
00077 if tag == "all":
00078
00079 txt = _("Showing top %i albums in '%s'") % (int(num), mode)
00080 self.pyjama.layouts.toolbars['top'].lCurPage.set_text(_("Page %i of %i") % (page, (self.pyjama.db.albums/num)))
00081 else:
00082
00083 txt = _("Showing %i albums tagged '%s' ordered by '%s'") % (int(num), tag.replace("+", " "), mode)
00084 self.pyjama.layouts.toolbars['top'].lCurPage.set_text(_("Page %i") % page)
00085
00086 self.cur_page = page
00087
00088 self.pyjama.window.LayoutInfo.set_text(txt)
00089 self.pyjama.window.LayoutInfo.set_image("folder_06.png")
00090
00091 if num==None:num=self.results_per_page
00092 for albuminfo in self.albuminfos:
00093 self.albuminfos[albuminfo].destroy()
00094
00095 self.albuminfos = {}
00096
00097 top = self.pyjama.jamendo.top(num, mode, page, tag)
00098 if top == None:
00099 clWidgets.tofast(self.pyjama.window)
00100 return None
00101 elif top == -1:
00102 return None
00103
00104
00105
00106
00107 counter = 0
00108 threads = {}
00109
00110
00111 for album in top:
00112
00113
00114
00115
00116
00117 if self.pyjama.debug:
00118 print "(%i/%i)" % (counter + 1, len(top))
00119
00120 if clThreadedDownload.threadLimiter(threads):
00121 print ("Waiting for threads (%i seconds)") % self.pyjama.settings.get_value("PERFORMANCE", "THREAD_WAIT")
00122 sleep(self.pyjama.settings.get_value("PERFORMANCE", "THREAD_WAIT"))
00123
00124 threads[counter] = clThreadedDownload.Download(self.pyjama, ("album", album['album_id']), counter)
00125 threads[counter].start()
00126 counter += 1
00127 counter = 0
00128 for album in top:
00129
00130
00131 self.albuminfos[counter] = clWidgets.AlbumInfo(self.pyjama, album)
00132 self.albuminfos[counter].show()
00133 self.put(self.albuminfos[counter], counter, counter)
00134 counter += 1
00135
00136 self.arrange_topoftheweek()
00137 self.show()
00138
00139
00140 def arrange_topoftheweek(self):
00141 if self.albuminfos == {}: return None
00142
00143 width = self.pyjama.window.scrolledwindow_width
00144 hspace = 20
00145 vspacer = 20
00146
00147 imgwidth = 150
00148 imgheight = 160
00149
00150 starty = -10
00151
00152 y = 0
00153 x = 0
00154 for counter in self.albuminfos:
00155 if ((x+1) * imgwidth) + hspace*(x+1) >= width:
00156 y += 1
00157 x = 0
00158 self.move(self.albuminfos[counter], (imgwidth * x) + hspace*(x+1), (vspacer*(y+1) + (y * imgheight))+starty)
00159 x += 1
00160 height = (y+1) * (imgheight + vspacer) +starty
00161 self.set_size(width-20,height+vspacer)
00162
00163
00164
00165
00166
00167
00168
00169
00170 def check_next_possible(self, page=None, rpp=None):
00171 if page == None: page = self.cur_page
00172 if rpp == None: rpp = self.results_per_page
00173 if page >= floor(self.pyjama.db.albums / rpp) - 2:
00174 self.pyjama.layouts.toolbars['top'].sbNextPage.set_sensitive(False)
00175 else:
00176 self.pyjama.layouts.toolbars['top'].sbNextPage.set_sensitive(True)
00177
00178 def check_prev_possible(self, page=None):
00179 if page == None: page = self.cur_page
00180 if page == 1:
00181 self.pyjama.layouts.toolbars['top'].sbPrevPage.set_sensitive(False)
00182 else:
00183 self.pyjama.layouts.toolbars['top'].sbPrevPage.set_sensitive(True)
00184
00185 def ev_scrolled_window_resized(self):
00186
00187
00188
00189 self.arrange_topoftheweek()
00190
00191
00192
00193 class ToolBar(gtk.HBox):
00194 def __init__(self, pyjama):
00195 gtk.HBox.__init__(self)
00196 self.pyjama = pyjama
00197 self.layout = self.pyjama.layouts.layouts['top']
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 self.cbOrder = clWidgets.OrderCombo()
00211 self.cbOrder.show()
00212 self.cbOrder.connect("changed", self.cbOrder_changed)
00213 self.pack_start(self.cbOrder, False, True, 0)
00214
00215 self.cbTags = clWidgets.TagsCombo(self.pyjama)
00216
00217
00218 self.cbTags.connect("changed", self.cbTags_changed)
00219 self.cbTags.entry.connect("activate", self.cbTagsEntry_activate)
00220 self.pack_start(self.cbTags, False, True, 0)
00221
00222 self.cbResultsPerPage = clWidgets.ResultsPerPageCombo()
00223 self.cbResultsPerPage.connect("changed", self.cbResultsPerPage_changed)
00224 self.pack_start(self.cbResultsPerPage, False, True, 0)
00225
00226
00227 self.sbNextPage = clWidgets.StockButton(gtk.STOCK_GO_FORWARD)
00228 self.sbNextPage.set_tooltip_text(_("Next page"))
00229 self.sbNextPage.connect("clicked", self.on_sbNextPage_clicked)
00230 self.pack_end(self.sbNextPage, False, True, 0)
00231
00232 self.lCurPage = gtk.Label("")
00233 self.pack_end(self.lCurPage, False, True, 0)
00234
00235 self.sbPrevPage = clWidgets.StockButton(gtk.STOCK_GO_BACK)
00236 self.sbPrevPage.set_tooltip_text(_("Previous page"))
00237 self.sbPrevPage.connect("clicked", self.on_sbPrevPage_clicked)
00238 self.sbPrevPage.set_sensitive(False)
00239 self.pack_end(self.sbPrevPage, False, True, 0)
00240
00241 self.sbJumpToPage = clWidgets.StockButton(gtk.STOCK_JUMP_TO)
00242 self.sbJumpToPage.set_tooltip_text(_("Jump to page..."))
00243 self.sbJumpToPage.connect("clicked", self.on_sbJumpToPage_clicked)
00244 self.pack_end(self.sbJumpToPage, False, True, 0)
00245
00246
00247
00248
00249
00250
00251
00252 self.show_all()
00253
00254
00255
00256
00257 def cbOrder_changed(self, widget):
00258 self.layout.ordering = self.pyjama.window.get_active_text(self.cbOrder)
00259 if widget is not None:
00260 if widget.auto_setting_item: return
00261
00262 self.pyjama.layouts.show_layout("top", self.layout.results_per_page, self.layout.ordering, 1, self.layout.tag)
00263
00264 def cbResultsPerPage_changed(self, widget=None):
00265 self.layout.results_per_page = int(self.pyjama.window.get_active_text(self.cbResultsPerPage))
00266 if widget is not None:
00267 if widget.auto_setting_item: return
00268
00269
00270 self.pyjama.layouts.show_layout("top", self.layout.results_per_page, self.layout.ordering, 1, self.layout.tag, who_called = "cbResultsPerPage_changed")
00271
00272
00273 def cbTags_key_press_event(self, ev1, ev2=None):
00274 print "KEYPRESS"
00275
00276 def cbTagsEntry_activate(self, widget):
00277 self.cbTags_changed(None, force=True)
00278
00279 def cbTags_changed(self, widget, force=False):
00280 tag_entry = self.cbTags.entry.get_text()
00281 tag_box = self.pyjama.window.get_active_text(self.cbTags)
00282 if tag_entry != tag_box and force == False: return
00283 tag_box = tag_entry
00284 if tag_box == _("--all--"): tag_box = "all"
00285 self.layout.tag = tag_box
00286 if widget is not None:
00287 if widget.auto_setting_item: return
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 self.pyjama.layouts.show_layout("top", self.layout.results_per_page, self.layout.ordering, 1, self.layout.tag.replace(" ", "+"), who_called = "cbTags_changed")
00302
00303 def on_sbJumpToPage_clicked(self, ev):
00304 result = clEntry.input_box(title=_('Jump to page'),
00305 message=_('Enter Page'),
00306 default_text="%i" % (self.layout.cur_page+10))
00307 if result is None:
00308 return None
00309 elif not result.isdigit():
00310 dia = clWidget.MyDialog(_('invalid expression'),
00311 self.get_toplevel(),
00312 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00313 (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT), gtk.STOCK_DIALOG_WARNING, _('\'%s\' is not a valid page') % str(result))
00314 dia.run()
00315 dia.destroy()
00316 return None
00317 else:
00318 page = int(result)
00319 self.pyjama.layouts.show_layout("top", self.layout.results_per_page, self.layout.ordering, page, self.layout.tag, who_called = "on_sbjumptopage_clicked")
00320 self.layout.check_next_possible()
00321 self.layout.check_prev_possible()
00322
00323 def on_sbNextPage_clicked(self, ev):
00324 self.pyjama.layouts.show_layout("top", self.layout.results_per_page, self.layout.ordering, self.layout.cur_page+1, self.layout.tag, who_called = "on_sbnextpage_clicked")
00325 self.layout.check_next_possible()
00326
00327 def on_sbPrevPage_clicked(self, ev):
00328 self.pyjama.layouts.show_layout("top", self.layout.results_per_page, self.layout.ordering, self.layout.cur_page-1, self.layout.tag, who_called = "on_sbprevpage_clicked")
00329 self.layout.check_prev_possible()