Internet radio browser GUI for music/video streams from various directory services.

⌈⌋ branch:  streamtuner2


Check-in [7f51022370]

Overview
Comment:Make uikit.do() manage a task spool itself. Run new tasks immediately if invoked already within gtk_idle callback. Move uikit.tree column creation into separate function, for immediate use through GenericChannel.gui() - instead of destroying+repopulating it on category-list reloads.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7f51022370291dd9a3bd045674c3d6325ba9a9eb
User & Date: mario on 2015-04-23 18:57:52
Other Links: manifest | tags
Context
2015-04-23
18:58
Statusbar updates via uikit.do, immediate=True. check-in: 7aa0ce2a25 user: mario tags: trunk
18:57
Make uikit.do() manage a task spool itself. Run new tasks immediately if invoked already within gtk_idle callback. Move uikit.tree column creation into separate function, for immediate use through GenericChannel.gui() - instead of destroying+repopulating it on category-list reloads. check-in: 7f51022370 user: mario tags: trunk
01:09
Remove some print statements, and switch to log.FUNC where necessary. check-in: ecc88e5d3e user: mario tags: trunk
Changes

Modified uikit.py from [025a11079e] to [2a34911ea4].

223
224
225
226
227
228
229













230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
        for entry in entries:
            if isinstance(entry, (str,unicode)):
                main = ls.append(None, [str(entry), icon])
            else:
                for sub_title in entry:
                    ls.append(main, [str(sub_title), icon])














        # just one column
        tvcolumn = gtk.TreeViewColumn(title);
        widget.append_column(tvcolumn)

        # inner display: icon & string
        pix = gtk.CellRendererPixbuf()
        txt = gtk.CellRendererText()

        # position
        tvcolumn.pack_start(pix, expand=False)
        tvcolumn.pack_end(txt, expand=True)

        # select array content source in treestore
        tvcolumn.add_attribute(pix, "stock_id", 1)
        tvcolumn.add_attribute(txt, "text", 0)

        # finalize
        widget.set_model(ls)
        tvcolumn.set_sort_column_id(0)
        widget.set_search_column(0)
        #tvcolumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
        #tvcolumn.set_fixed_width(125])
        #widget.expand_all()
        #widget.expand_row("3", False)
        #print(widget.row_expanded("3"))

        return ls




    #-- save window size and widget properties
    #
    # needs a list of widgetnames
    # e.g. pickle.dump(uikit.app_state(...), open(os.environ["HOME"]+"/.config/app_winstate", "w"))







>
>
>
>
>
>
>
>
>
>
>
>
>















<
<
<

<
<
<
<
<
<
<
<
<







223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257



258









259
260
261
262
263
264
265
        for entry in entries:
            if isinstance(entry, (str,unicode)):
                main = ls.append(None, [str(entry), icon])
            else:
                for sub_title in entry:
                    ls.append(main, [str(sub_title), icon])

        # finalize
        widget.set_model(ls)
        widget.set_search_column(0)
        #tvcolumn.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
        #tvcolumn.set_fixed_width(125])
        #widget.expand_all()
        #widget.expand_row("3", False)
        #print(widget.row_expanded("3"))
        return ls


    @staticmethod
    def tree_column(widget, title="Category"):
        # just one column
        tvcolumn = gtk.TreeViewColumn(title);
        widget.append_column(tvcolumn)

        # inner display: icon & string
        pix = gtk.CellRendererPixbuf()
        txt = gtk.CellRendererText()

        # position
        tvcolumn.pack_start(pix, expand=False)
        tvcolumn.pack_end(txt, expand=True)

        # select array content source in treestore
        tvcolumn.add_attribute(pix, "stock_id", 1)
        tvcolumn.add_attribute(txt, "text", 0)



        tvcolumn.set_sort_column_id(0)












    #-- save window size and widget properties
    #
    # needs a list of widgetnames
    # e.g. pickle.dump(uikit.app_state(...), open(os.environ["HOME"]+"/.config/app_winstate", "w"))
395
396
397
398
399
400
401
402














403



404

405




406



407
408
409
410
411
412
413
414
    def save_file_filterchange(c):
        fn, ext = c.get_filename(), c.get_filter().get_name()
        if fn and ext:
            fn = os.path.basename(fn)
            c.set_current_name(re.sub(r"\.(m3u|pls|xspf|jspf|asx|json|smil|wpl)$", ext.strip("*"), fn))
        
    
    














    



    # pass updates from another thread, ensures that it is called just once

    @staticmethod




    def do(callback, *args, **kwargs):



        gobject.idle_add(lambda: callback(*args, **kwargs) and False)


    # adds background color to widget,
    # eventually wraps it into a gtk.Window, if it needs a container
    @staticmethod
    def bg(w, color="", where=["bg"]):
        """ this method should be called after widget creation, and before .add()ing it to container """







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
|
>

>
>
>
>
|
>
>
>
|







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
    def save_file_filterchange(c):
        fn, ext = c.get_filename(), c.get_filter().get_name()
        if fn and ext:
            fn = os.path.basename(fn)
            c.set_current_name(re.sub(r"\.(m3u|pls|xspf|jspf|asx|json|smil|wpl)$", ext.strip("*"), fn))
        
    

    # Spool gtk update calls from non-main threads (optional immediate=1 flag to run task next, not last)
    @staticmethod
    def do(callback, *args, **kwargs):
        pos = kwargs.get("immediate", -1)
        if pos and pos >= 0:
            del kwargs["immediate"]
            pos = 0
        if uikit.idle_run:
            log.UIKIT_DORUN(str(callback))
            callback(*args, **kwargs)
        else:
            log.UIKIT_SPOOL(str(callback))
            uikit.idle_tasks.insert(pos, [lambda: callback(*args, **kwargs), str(callback)])
            gobject.idle_add(uikit.idle_do)
    
    # Collect tasks to perform in gtk.main loop
    idle_tasks = []
    idle_run = False
    
    # Execute UI updating tasks in order
    @staticmethod
    def idle_do():
        uikit.idle_run = True
        if uikit.idle_tasks:
            task, callback = uikit.idle_tasks.pop(0)
            log.UIKIT_EXEC(callback)
            task()
        uikit.idle_run = False
        return len(uikit.idle_tasks) > 0
        


    # adds background color to widget,
    # eventually wraps it into a gtk.Window, if it needs a container
    @staticmethod
    def bg(w, color="", where=["bg"]):
        """ this method should be called after widget creation, and before .add()ing it to container """