@@ -97,14 +97,14 @@ # gtk modules from mygtk import pygtk, gtk, gobject, ui_file, mygtk # custom modules from config import conf # initializes itself, so all conf.vars are available right away +from config import __print__, dbg import http import action # needs workaround... (action.main=main) from channels import * -from channels import __print__ import favicon #from pq import pq @@ -128,24 +128,24 @@ # constructor def __init__(self): # gtkrc stylesheet - self.load_theme(), gui_startup(1/20) + self.load_theme(), gui_startup(1/20.0) # instantiate gtk/glade widgets in current object gtk.Builder.__init__(self) - gtk.Builder.add_from_file(self, conf.find_in_dirs([".", conf.share], ui_file)), gui_startup(2/20) + gtk.Builder.add_from_file(self, conf.find_in_dirs([".", conf.share], ui_file)), gui_startup(2/20.0) # manual gtk operations self.extensionsCTM.set_submenu(self.extensions) # duplicates Station>Extension menu into stream context menu # initialize channels self.channels = { "bookmarks": bookmarks(parent=self), # this the remaining built-in channel "shoutcast": None,#shoutcast(parent=self), } - gui_startup(3/20) + gui_startup(3/20.0) self.load_plugin_channels() # append other channel modules / plugins # load application state (widget sizes, selections, etc.) try: @@ -160,18 +160,18 @@ self.channels[id].shown = winlayout[id+"_list"].get("row:selected", 0) # actually just used as boolean flag (for late loading of stream list), selection bar has been positioned before already except: pass # fails for disabled/reordered plugin channels # display current open channel/notebook tab - gui_startup(17/20) + gui_startup(17/20.0) self.current_channel = self.current_channel_gtk() try: self.channel().first_show() - except: print("channel .first_show() initialization error") + except: __print__(dbg.INIT, "main.__init__: current_channel.first_show() initialization error") # bind gtk/glade event names to functions - gui_startup(19/20) + gui_startup(19/20.0) self.connect_signals(dict( { "gtk_main_quit" : self.gtk_main_quit, # close window # treeviews / notebook "on_stream_row_activated" : self.on_play_clicked, # double click in a streams list "on_category_clicked": self.on_category_clicked, # new selection in category list @@ -221,11 +221,11 @@ "streamedit_new": streamedit.new, "streamedit_cancel": streamedit.cancel, }.items() + self.add_signals.items() )) # actually display main window - gui_startup(99/100) + gui_startup(99/100.0) self.win_streamtuner2.show() # WHY DON'T YOU WANT TO WORK?! #self.shoutcast.gtk_list.set_enable_search(True) #self.shoutcast.gtk_list.set_search_column(4) @@ -281,15 +281,15 @@ else: #if type(page_num) == int: self.current_channel = self.channel_names[page_num] # if first selected, load current category try: - print("try: .first_show", self.channel().module); - print(self.channel().first_show) - print(self.channel().first_show()) + __print__(dbg.PROC, "channel_switch: try .first_show", self.channel().module); + __print__(self.channel().first_show) + __print__(self.channel().first_show()) except: - print("channel .first_show() initialization error") + __print__(dbg.INIT, "channel .first_show() initialization error") # convert ListStore iter to row number def rowno(self): (model, iter) = self.model_iter() @@ -335,17 +335,17 @@ # browse channel def on_homepage_channel_clicked(self, widget, event=2): if event == 2 or event.type == gtk.gdk._2BUTTON_PRESS: - __print__("dblclick") + __print__(dbg.UI, "dblclick") action.browser(self.channel().homepage) # reload stream list in current channel-category def on_reload_clicked(self, widget=None, reload=1): - __print__("reload", reload, self.current_channel, self.channels[self.current_channel], self.channel().current) + __print__(dbg.UI, "reload", reload, self.current_channel, self.channels[self.current_channel], self.channel().current) category = self.channel().current self.thread( lambda: ( self.channel().load(category,reload), reload and self.bookmarks.heuristic_update(self.current_channel,category) ) ) @@ -365,11 +365,11 @@ # click in category list def on_category_clicked(self, widget, event, *more): category = self.channel().currentcat() - __print__("on_category_clicked", category, self.current_channel) + __print__(dbg.UI, "on_category_clicked", category, self.current_channel) self.on_reload_clicked(None, reload=0) pass # add current selection to bookmark store @@ -462,15 +462,15 @@ order = [module.strip() for module in conf.channel_order.lower().replace(".","_").replace("-","_").split(",")] ls = [module for module in (order) if (module in ls)] + [module for module in (ls) if (module not in order)] # step through for module in ls: - gui_startup(2/10 + 7/10 * float(ls.index(module))/len(ls), "loading module "+module) + gui_startup(2/10.0 + 7/10.0 * float(ls.index(module))/len(ls), "loading module "+module) # skip module if disabled if conf.plugins.get(module, 1) == False: - __print__("disabled plugin:", module) + __print__(dbg.STAT, "disabled plugin:", module) continue # load plugin try: plugin = __import__("channels."+module, None, None, [""]) @@ -487,11 +487,11 @@ # other plugin types else: self.features[module] = plugin_class(parent=self) except Exception as e: - print("error initializing:", module, ", exception:") + __print__(dbg.INIT, "load_plugin_channels: error initializing:", module, ", exception:") import traceback traceback.print_exc() # default plugins conf.add_plugin_defaults(self.channels["bookmarks"].config, "bookmarks") @@ -514,11 +514,11 @@ # apply gtkrc stylesheet def load_theme(self): if conf.get("theme"): for dir in (conf.dir, conf.share, "/usr/share"): - f = dir + "/themes/" + conf.theme + "/gtk-2"+".0/gtkrc" + f = dir + "/themes/" + conf.theme + "/gtk-2.0/gtkrc" if os.path.exists(f): gtk.rc_parse(f) pass @@ -774,11 +774,11 @@ def apply(self, config, prefix="config_", save=0): for key,val in config.iteritems(): # map non-alphanumeric chars from config{} to underscores in according gtk widget names id = re.sub("[^\w]", "_", key) w = main.get_widget(prefix + id) - __print__("config_save", save, prefix+id, w, val) + __print__(dbg.CONF, "config", ("save" if save else "load"), prefix+id, w, val) # recurse into dictionaries, transform: conf.play.audio/mp3 => conf.play_audio_mp3 if (type(val) == dict): self.apply(val, prefix + id + "_", save) # load or set gtk.Entry text field elif (w and save and type(w)==gtk.Entry): @@ -797,13 +797,20 @@ # self.theme.combo_box_new_text() # find themes themedirs = (conf.share+"/themes", conf.dir+"/themes", "/usr/share/themes") themes = ["no theme"] [[themes.append(e) for e in os.listdir(dir)] for dir in themedirs if os.path.exists(dir)] + __print__(dbg.STAT, themes) + # prepare liststore + store = gtk.ListStore(gobject.TYPE_STRING) + self.theme.set_model(store) + cell = gtk.CellRendererText() + self.theme.pack_start(cell, True) + self.theme.add_attribute(cell, "text", 0) # add to combobox for num,themename in enumerate(themes): - self.theme.append_text(themename) + store.append([themename]) if conf.theme == themename: self.theme.set_active(num) # erase this function, so it only ever gets called once self.combobox_theme = lambda: None @@ -1006,11 +1013,11 @@ # simplified gtk TreeStore display logic (just one category for the moment, always rebuilt) def load(self, category, force=False): #self.liststore[category] = \ -# print(category, self.streams.keys()) + __print__(dbg.UI, category, self.streams.keys()) mygtk.columns(self.gtk_list, self.datamap, self.prepare(self.streams.get(category,[]))) # select a category in treeview def add_category(self, cat): @@ -1101,11 +1108,11 @@ #-- startup progress bar progresswin, progressbar = 0, 0 -def gui_startup(p=0/100, msg="streamtuner2 is starting"): +def gui_startup(p=0/100.0, msg="streamtuner2 is starting"): global progresswin,progressbar if not progresswin: # GtkWindow "progresswin" @@ -1113,11 +1120,11 @@ progresswin.set_property("title", "streamtuner2") progresswin.set_property("default_width", 300) progresswin.set_property("width_request", 300) progresswin.set_property("default_height", 30) progresswin.set_property("height_request", 30) - progresswin.set_property("window_position", "center") + #progresswin.set_property("window_position", "center") progresswin.set_property("decorated", False) progresswin.set_property("visible", True) # GtkProgressBar "progressbar" progressbar = gtk.ProgressBar() @@ -1149,11 +1156,11 @@ if len(sys.argv) < 2: # prepare for threading in Gtk+ callbacks gobject.threads_init() - gui_startup(1/100) + gui_startup(1/100.0) # prepare main window main = StreamTunerTwo() # module coupling @@ -1166,11 +1173,11 @@ config_dialog.open(None) del conf.firstrun # run - gui_startup(100/100) + gui_startup(100/100.0) gtk.main() # invoke command-line interface else: