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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [1569b57c42]

Overview
Comment:Prepare bookmarks-category DND as target (for internal stream moving). Fix FILE_NAME being passed as text not uris XSelection type. Use underscores in place of spaces to avoid urlencoding file:// references. Move log.DND colorization to config.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1569b57c426c03c2d806889970cffbdbf63393f5
User & Date: mario on 2015-04-24 19:20:15
Other Links: manifest | tags
Context
2015-04-24
19:21
Document current reuse_m3u and nothreads config behaviour. Rewrite placeholder and application help pages to be more understandable. Mention GUI alternatives to streamripper. check-in: 497073df0d user: mario tags: trunk
19:20
Prepare bookmarks-category DND as target (for internal stream moving). Fix FILE_NAME being passed as text not uris XSelection type. Use underscores in place of spaces to avoid urlencoding file:// references. Move log.DND colorization to config. check-in: 1569b57c42 user: mario tags: trunk
05:01
Add .desktop and .url to export format file extensions probing and SaveAs dialog. check-in: a35c889740 user: mario tags: trunk
Changes

Modified channels/dnd.py from [d216a79da8] to [aebf24e232].

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128






129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

157
158
159
160

161
162
163
164
165
166
167


    # Hook to main, and extend channel tabs
    def __init__(self, parent):
        self.parent = parent
        parent.hooks["init"].append(self.add_dnd)
        conf.add_plugin_defaults(self.meta, self.module)
        log.colors["DND"] = "1;33;41m"


    # Attach drag and drop handlers to each channels´ station TreeView
    def add_dnd(self, parent):

        # visit each module
        for cn,module in parent.channels.items():
            w = module.gtk_list
            # bind SOURCE events
            w.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, self.drag_types, gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_COPY)
            w.connect('drag-begin', self.begin)
            w.connect('drag-data-get', self.data_get)
            # bind DESTINATION events
            w.enable_model_drag_dest(self.drag_types, gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_COPY)
            w.connect('drag-drop', self.drop)
            w.connect('drag-data-received', self.data_received)









    # -- SOURCE, drag'n'drop from ST2 to elsewhere --

    # Starting to drag a row
    def begin(self, widget, context):
        log.DND("source→out: begin-drag, store current row")
        self.row = self.treelist_row()
        self.buf = {}

        uikit.do(context.set_icon_stock, gtk.STOCK_ADD, 16, 16)
        return "url" in self.row

    # Keep currently selected row when source dragging starts
    def treelist_row(self):
        cn = self.parent.channel()
        row = copy.copy(cn.row())
        row.setdefault("format", cn.audioformat)
        row.setdefault("listformat", cn.listformat)
        row.setdefault("url", row.get("homepage"))
        row.update({"_origin": [cn.module, cn.current, cn.rowno()]}) # internal: origin channel+genre+rowid
        return row
    
    # Target window/app requests data for offered drop
    def data_get(self, widget, context, selection, info, time):
        log.DND("source→out: data-get, send and convert to requested target type:", info, selection.get_target())
        # Return prepared data
        func, data = self.export_row(info, self.row)

        if func.find("text") >= 0:
            # Yay for trial and error. Nay for docs. PyGtks selection.set_text() doesn't
            # actually work unless the requested target type is an Atom. Therefore "STRING".
            selection.set("STRING", 8, data)

        if func.find("uris") >= 0:
            selection.set_uris(data)
        return True

    # Handles the conversion from the stored .row to the desired selection data
    def export_row(self, info, r):








<
















>
>
>
>
>
>










>
|

















>




>







105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175


    # Hook to main, and extend channel tabs
    def __init__(self, parent):
        self.parent = parent
        parent.hooks["init"].append(self.add_dnd)
        conf.add_plugin_defaults(self.meta, self.module)



    # Attach drag and drop handlers to each channels´ station TreeView
    def add_dnd(self, parent):

        # visit each module
        for cn,module in parent.channels.items():
            w = module.gtk_list
            # bind SOURCE events
            w.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, self.drag_types, gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_COPY)
            w.connect('drag-begin', self.begin)
            w.connect('drag-data-get', self.data_get)
            # bind DESTINATION events
            w.enable_model_drag_dest(self.drag_types, gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_COPY)
            w.connect('drag-drop', self.drop)
            w.connect('drag-data-received', self.data_received)
            
        # register bookmarks category as destination too
        w = parent.bookmarks.gtk_cat
        w.enable_model_drag_dest([self.drag_types[0]], gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_MOVE)
        w.connect('drag-data-received', self.data_received)
        



    # -- SOURCE, drag'n'drop from ST2 to elsewhere --

    # Starting to drag a row
    def begin(self, widget, context):
        log.DND("source→out: begin-drag, store current row")
        self.row = self.treelist_row()
        self.buf = {}
        if "set_icon_stock" in dir(context):
            uikit.do(context.set_icon_stock, gtk.STOCK_ADD, 16, 16)
        return "url" in self.row

    # Keep currently selected row when source dragging starts
    def treelist_row(self):
        cn = self.parent.channel()
        row = copy.copy(cn.row())
        row.setdefault("format", cn.audioformat)
        row.setdefault("listformat", cn.listformat)
        row.setdefault("url", row.get("homepage"))
        row.update({"_origin": [cn.module, cn.current, cn.rowno()]}) # internal: origin channel+genre+rowid
        return row
    
    # Target window/app requests data for offered drop
    def data_get(self, widget, context, selection, info, time):
        log.DND("source→out: data-get, send and convert to requested target type:", info, selection.get_target())
        # Return prepared data
        func, data = self.export_row(info, self.row)
        log.DND("data==", func, data)
        if func.find("text") >= 0:
            # Yay for trial and error. Nay for docs. PyGtks selection.set_text() doesn't
            # actually work unless the requested target type is an Atom. Therefore "STRING".
            selection.set("STRING", 8, data)
            # Neither gtk.gdk.TARGET_STRING nor selection.get_target() satisfy Gtk3 however
        if func.find("uris") >= 0:
            selection.set_uris(data)
        return True

    # Handles the conversion from the stored .row to the desired selection data
    def export_row(self, info, r):

184
185
186
187
188
189
190

191

192

193


194
195
196
197
198
199
200
            #buf = 'uris', urls
            buf = 'text', urls[0]
        # Text sources are assumed to understand the literal URL or expect a description block
        elif info >= 5:
            buf = 'text', "{url}\n# Title: {title}\n# Homepage: {homepage}\n\n".format(**r)
        # Create temporary PLS file, because "text/uri-list" is widely misunderstood and just implemented for file:// IRLs
        else:

            tmpfn = "{}/{}.{}".format(conf.tmp, re.sub("[^\w-]+", " ", r["title"]).strip(), conf.dnd_format)

            cnv.file(rows=[r], dest=conf.dnd_format, fn=tmpfn)

            buf = 'uris', ["file://{}".format(tmpfn)] if (info==4) else tmpfn



        # Keep in type request buffer
        self.buf[info] = buf
        return buf










>
|
>

>
|
>
>







192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
            #buf = 'uris', urls
            buf = 'text', urls[0]
        # Text sources are assumed to understand the literal URL or expect a description block
        elif info >= 5:
            buf = 'text', "{url}\n# Title: {title}\n# Homepage: {homepage}\n\n".format(**r)
        # Create temporary PLS file, because "text/uri-list" is widely misunderstood and just implemented for file:// IRLs
        else:
            title = re.sub("[^\w-]+", "_", r["title"]).strip()
            tmpfn = "{}/{}.{}".format(conf.tmp, title, conf.dnd_format)
            log.DND("tmpfn", tmpfn)
            cnv.file(rows=[r], dest=conf.dnd_format, fn=tmpfn)
            if info == 4:
                buf = 'uris', ["file://{}".format(tmpfn)]
            else:
                buf = 'text', tmpfn

        # Keep in type request buffer
        self.buf[info] = buf
        return buf



Modified config.py from [1bfcbd774c] to [ae59bddda4].

498
499
500
501
502
503
504

505
506
507
508
509
510
511

    # Colors
    colors = {
        "ERR":  "31m", # red    ERROR
        "INIT": "31m", # red    INIT ERROR
        "PROC": "32m", # green  PROCESS
        "CONF": "33m", # brown  CONFIG DATA

        "UI":   "34m", # blue   USER INTERFACE BEHAVIOUR
        "UIKIT":"38;5;222;48;5;235m", # THREAD/UIKIT/IDLE TASKS
        "HTTP": "35m", # magenta HTTP REQUEST
        "DATA": "36m", # cyan   DATA
        "INFO": "37m", # gray   INFO
        "STAT": "37m", # gray   CONFIG STATE
    }







>







498
499
500
501
502
503
504
505
506
507
508
509
510
511
512

    # Colors
    colors = {
        "ERR":  "31m", # red    ERROR
        "INIT": "31m", # red    INIT ERROR
        "PROC": "32m", # green  PROCESS
        "CONF": "33m", # brown  CONFIG DATA
        "DND":  "1;33;41m", #   DRAG'N'DROP
        "UI":   "34m", # blue   USER INTERFACE BEHAVIOUR
        "UIKIT":"38;5;222;48;5;235m", # THREAD/UIKIT/IDLE TASKS
        "HTTP": "35m", # magenta HTTP REQUEST
        "DATA": "36m", # cyan   DATA
        "INFO": "37m", # gray   INFO
        "STAT": "37m", # gray   CONFIG STATE
    }