359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384 | pass
#-- Save-As dialog
#
@staticmethod
def save_file(title="Save As", parent=None, fn="", formats=[("*","*")]):
c = gtk.FileChooserDialog(title, parent, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=(gtk.STOCK_CANCEL, 0, gtk.STOCK_SAVE, 1))
# params
if fn:
c.set_current_name(fn)
fn = ""
for fname,ftype in formats:
f = gtk.FileFilter()
f.set_name(fname)
f.add_pattern(ftype)
c.add_filter(f)
# display
if c.run():
fn = c.get_filename() # return filaname
c.destroy()
return fn
|
|
>
>
|
>
>
>
|
>
>
>
|
| 359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392 | pass
#-- Save-As dialog
#
@staticmethod
def save_file(title="Save As", parent=None, fn="", formats=[("*.pls", "*.pls"), ("*.xspf", "*.xpsf"), ("*.m3u", "*.m3u"), ("*.jspf", "*.jspf"), ("*.asx", "*.asx"), ("*.json", "*.json"), ("*.smil", "*.smil"), ("*.wpl", "*.wpl"), ("*","*")]):
# With overwrite confirmation
c = gtk.FileChooserDialog(title, parent, action=gtk.FILE_CHOOSER_ACTION_SAVE,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK))
c.set_do_overwrite_confirmation(True)
# Params
if fn:
c.set_current_name(fn)
fn = ""
for fname,ftype in formats:
f = gtk.FileFilter()
f.set_name(fname)
f.add_pattern(ftype)
c.add_filter(f)
# Filter handlers don't work either.
# Display and wait
if c.run():
fn = c.get_filename() # return filaname
c.destroy()
return fn
|
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471 | where.insert(m, insert)
else:
where.add(m)
# gtk.messagebox
@staticmethod
def msg(text, style=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_CLOSE):
m = gtk.MessageDialog(None, 0, style, buttons, message_format=text)
m.show()
m.connect("response", lambda *w: m.destroy())
# manual signal binding with a dict of { (widget, signal): callback }
@staticmethod
def add_signals(builder, map):
for (widget,signal),func in map.items():
builder.get_widget(widget).connect(signal, func)
# Pixbug loader (from inline string, as in `logo.png`)
@staticmethod
def pixbuf(buf, fmt="png", decode=True, gzip=False):
if not buf or len(buf) < 16:
return None
if fmt and ver==3:
p = GdkPixbuf.PixbufLoader.new_with_type(fmt)
elif fmt: |
|
>
>
>
>
>
|
>
|
| 452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485 | where.insert(m, insert)
else:
where.add(m)
# gtk.messagebox
@staticmethod
def msg(text, style=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_CLOSE, yes=None):
m = gtk.MessageDialog(None, 0, style, buttons, message_format=text)
m.show()
if yes:
response = m.run()
m.destroy()
return response in (gtk.RESPONSE_OK, gtk.RESPONSE_ACCEPT, gtk.RESPONSE_YES)
else:
m.connect("response", lambda *w: m.destroy())
pass
# manual signal binding with a dict of { (widget, signal): callback }
@staticmethod
def add_signals(builder, map):
for (widget,signal),func in map.items():
builder.get_widget(widget).connect(signal, func)
# Pixbug loader (from inline string, as in `logo.png`, automatic base64 decoding, and gunzipping of raw data)
@staticmethod
def pixbuf(buf, fmt="png", decode=True, gzip=False):
if not buf or len(buf) < 16:
return None
if fmt and ver==3:
p = GdkPixbuf.PixbufLoader.new_with_type(fmt)
elif fmt: |