コード例 #1
0
 def populate(self):
     """
         Setup an initial widget based on current request
     """
     sql = App().playlists.get_smart_sql(self.__playlist_id)
     if sql is None:
         return
     try:
         if sql.find(" UNION ") != -1:
             operand = "OR"
         else:
             operand = "AND"
         self.__operand_combobox.set_active_id(operand)
     except Exception as e:
         self.__operand_combobox.set_active(0)
         Logger.warning("SmartPlaylistView::populate: %s", e)
     # Setup rows
     for line in sql.split("((")[1:]:
         widget = SmartPlaylistRow(self.__size_group)
         try:
             widget.set(line.split("))")[0])
         except Exception as e:
             Logger.error("SmartPlaylistView::populate: %s", e)
         widget.show()
         self.__listbox.add(widget)
     try:
         split_limit = sql.split("LIMIT")
         limit = int(split_limit[1].split(" ")[1])
         self.__limit_spin.set_value(limit)
     except Exception as e:
             Logger.warning("SmartPlaylistView::populate: %s", e)
     try:
         split_order = sql.split("ORDER BY")
         split_spaces = split_order[1].split(" ")
         orderby = split_spaces[1]
         # UNION does not support RANDOM() in OrderBy
         if orderby == "rand":
             orderby = "random()"
         if split_spaces[2] in ["ASC", "DESC"]:
             orderby += " %s" % split_spaces[2]
         self.__select_combobox.set_active_id(orderby)
     except Exception as e:
             self.__select_combobox.set_active(0)
             Logger.warning("SmartPlaylistView::populate: %s", e)