forked from danielgtaylor/arista
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arista-gtk
executable file
·2522 lines (2069 loc) · 95 KB
/
arista-gtk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
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
393
394
395
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
441
442
443
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
"""
Arista Desktop Transcoder (GTK+ client)
=======================================
An audio/video transcoder based on simple device profiles provided by
presets. This is the GTK+ version.
License
-------
Copyright 2008 - 2011 Daniel G. Taylor <dan@programmer-art.org>
This file is part of Arista.
Arista is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 2.1 of
the License, or (at your option) any later version.
Arista is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Arista. If not, see
<http://www.gnu.org/licenses/>.
"""
import gettext
import locale
import logging
import os
import re
import shutil
import subprocess
import sys
import threading
import time
import webbrowser
from optparse import OptionParser
import gobject
import gio
import gconf
import cairo
import gtk
# FIXME: Stupid hack, see the other fixme comment below!
if __name__ != "__main__":
import gst
_log = logging.getLogger("arista-gtk")
try:
import pynotify
pynotify.init("icon-summary-body")
except ImportError:
pynotify = None
_log.info("Unable to import pynotify - desktop notifications disabled")
try:
import webkit
except ImportError:
webkit = None
_log.info("Unable to import webkit - in-app documentation disabled")
import arista
_ = gettext.gettext
locale.setlocale(locale.LC_ALL, '')
CONFIG_PATH = "/apps/arista"
DEFAULT_CHECK_INPUTS = True
DEFAULT_SHOW_TOOLBAR = True
DEFAULT_SHOW_PREVIEW = True
DEFAULT_PREVIEW_FPS = 10
DEFAULT_OPEN_PATH = os.path.expanduser("~/Desktop")
RE_ENDS_NUM = re.compile(r'^.*(?P<number>[0-9]+)$')
def _new_combo_with_image(extra = []):
"""
Create a new combo box with a list store of a pixbuf, a string, and any
extra passed types.
@type extra: list
@param extra: Extra types to add to the gtk.ListStore
@rtype: gtk.ComboBox
@return: The newly created combo box
"""
store = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING, *extra)
combo = gtk.ComboBox(store)
pixbuf_cell = gtk.CellRendererPixbuf()
text_cell = gtk.CellRendererText()
combo.pack_start(pixbuf_cell, False)
combo.pack_start(text_cell, True)
combo.add_attribute(pixbuf_cell, 'pixbuf', 0)
combo.add_attribute(text_cell, 'text', 1)
return combo
def _get_icon_pixbuf(uri, width, height):
"""
Get a pixbuf from an item with an icon URI set.
@type item: object
@param item: An object with an icon attribute
@type width: int
@param width: The requested width of the pixbuf
@type height: int
@param height: The requested height of the pixbuf
@rtype: gtk.Pixbuf or None
@return: The pixbuf of the icon if it can be found
"""
image = None
theme = gtk.icon_theme_get_default()
if not uri:
return image
if uri.startswith("file://"):
try:
path = arista.utils.get_path("presets", uri[7:])
except IOError:
path = ""
if os.path.exists(path):
image = gtk.gdk.pixbuf_new_from_file_at_size(path, width, height)
elif uri.startswith("stock://"):
image = theme.load_icon(uri[8:], gtk.ICON_SIZE_MENU, 0)
else:
raise ValueError(_("Unknown icon URI %(uri)s") % {
"uri": uri
})
return image
def _get_filename_icon(filename):
"""
Get the icon from a filename using GIO.
>>> icon = _get_filename_icon("test.mp4")
>>> if icon:
>>> # Do something here using icon.load_icon()
>>> ...
@type filename: str
@param filename: The name of the file whose icon to fetch
@rtype: gtk.ThemedIcon or None
@return: The requested unloaded icon or nothing if it cannot be found
"""
theme = gtk.icon_theme_get_default()
names = gio.content_type_get_icon(gio.content_type_guess(filename)).get_property("names")
icon = theme.choose_icon(names, gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)[0], 0)
return icon
class LogoWidget(gtk.Widget):
"""
A widget to show the Arista logo.
See http://svn.gnome.org/viewvc/pygtk/trunk/examples/gtk/widget.py?view=markup
"""
def __init__(self):
gtk.Widget.__init__(self)
# Load the logo overlay
logo_path = arista.utils.get_path("ui", "logo.svg")
self.pixbuf = gtk.gdk.pixbuf_new_from_file(logo_path)
def do_realize(self):
"""
Realize the widget. Setup the window.
"""
self.set_flags(self.flags() | gtk.REALIZED)
self.window = gtk.gdk.Window(
self.get_parent_window(),
width = self.allocation.width,
height = self.allocation.height,
window_type = gtk.gdk.WINDOW_CHILD,
wclass = gtk.gdk.INPUT_OUTPUT,
event_mask = self.get_events() | gtk.gdk.EXPOSURE_MASK | gtk.gdk.BUTTON_PRESS_MASK)
self.window.set_user_data(self)
self.style.attach(self.window)
self.style.set_background(self.window, gtk.STATE_NORMAL)
self.window.move_resize(*self.allocation)
self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
def do_unrealize(self):
"""
Destroy the window.
"""
self.window.destroy()
def do_size_request(self, requisition):
"""
Request a minimum size.
"""
requisition.width = self.pixbuf.get_width()
requisition.height = self.pixbuf.get_height()
def do_size_allocate(self, allocation):
"""
Our size was allocated, save it!
"""
self.allocation = allocation
if self.flags() & gtk.REALIZED:
self.window.move_resize(*allocation)
def do_expose_event(self, event):
"""
Draw the logo.
"""
x, y, w, h = self.allocation
cr = self.window.cairo_create()
# Base the background color on a 50% luminosity version of the theme's
# selected color (the color you usually see in progress bars, for
# example) and make the gradient go from slightly lighter to slightly
# darker.
color = self.style.bg[gtk.STATE_SELECTED]
r, g, b = color.red / 65535.0, color.green / 65535.0, \
color.blue / 65535.0
avg = (r + g + b) / 3.0
r, g, b = [i + 0.5 - avg for i in [r, g, b]]
# Draw a gradient background
gradient = cairo.LinearGradient(0, 0, 0, h)
gradient.add_color_stop_rgb(0.0, r * 1.1, g * 1.1, b * 1.1)
gradient.add_color_stop_rgb(1.0, r, g, b)
cr.rectangle(0, 0, w, h)
cr.set_source(gradient)
cr.fill()
# Draw block shadow area
gradient = cairo.LinearGradient(1, (h / 2) + 5, 1, (h / 2) + 115)
gradient.add_color_stop_rgba(0.0, r * 0.95, g * 0.95, b * 0.95, 0.0)
gradient.add_color_stop_rgba(0.5, r * 0.95, g * 0.95, b * 0.95, 1.0)
gradient.add_color_stop_rgba(0.6, r * 0.9, g * 0.9, b * 0.9, 1.0)
gradient.add_color_stop_rgba(1.0, r * 0.9, g * 0.9, b * 0.9, 0.0)
cr.rectangle(1, (h / 2) + 5, w - 2, 30)
cr.rectangle(1, (h / 2) + 35 + 45, w - 2, 35)
cr.set_source(gradient)
cr.fill()
# Draw a highlighted block
cr.set_source_rgba(1.0, 1.0, 1.0, 0.13)
cr.rectangle(1, (h / 2) + 35, w - 2, 45)
cr.fill()
# Draw a border around the highlighted block
cr.rectangle(1, (h / 2) + 35, w - 2, 1)
cr.rectangle(1, (h / 2) + 35 + 45 - 1, w - 2, 1)
cr.fill()
# Draw the outer border
cr.set_source_rgba(0.0, 0.0, 0.0, 0.5)
cr.set_line_width(1.0)
cr.rectangle(0, 0, w, h)
cr.stroke()
# Draw the logo svg centered in the widget
self.window.draw_pixbuf(self.gc, self.pixbuf, 0, 0,
(w / 2) - (self.pixbuf.get_width() / 2),
(h / 2) - (self.pixbuf.get_height() / 2))
gobject.type_register(LogoWidget)
class MainWindow(object):
"""
Arista Main Window
==================
The main transcoder window. Provides a method of selecting a source,
output device, and preset for transcoding as well as managing the
transcoding queue.
"""
def __init__(self, runoptions):
self.runoptions = runoptions
ui_path = arista.utils.get_path("ui", "main.ui")
# Load the GUI
self.builder = gtk.Builder()
self.builder.add_from_file(ui_path)
self.builder.connect_signals(self)
self.window = self.builder.get_object("main_window")
self.menuitem_toolbar = self.builder.get_object("menuitem_toolbar")
self.toolbar = self.builder.get_object("toolbar")
self.toolbutton_remove = self.builder.get_object("toolbutton_remove")
self.toolbutton_pause = self.builder.get_object("toolbutton_pause")
self.hbox_progress = self.builder.get_object("hbox_progress")
self.progress = self.builder.get_object("progressbar")
self.button_pause = self.builder.get_object("button_pause")
self.button_cancel = self.builder.get_object("button_cancel")
self.preview = self.builder.get_object("video_preview")
self.preview_frame = self.builder.get_object("preview_frame")
self.logo = LogoWidget()
self.logo.connect("button-press-event", self.logo_button_pressed)
self.logo.drag_dest_set(gtk.DEST_DEFAULT_ALL, [('text/plain', 0, 0)], gtk.gdk.ACTION_COPY)
self.logo.connect("drag-data-received", self.drag_data_received)
self.preview.drag_dest_set(gtk.DEST_DEFAULT_ALL, [('text/plain', 0, 0)], gtk.gdk.ACTION_COPY)
self.preview.connect("drag-data-received", self.drag_data_received)
self.image_preview = gtk.Alignment(xscale = 1.0, yscale = 1.0)
self.image_preview.set_padding(0, 5, 0, 0)
self.image_preview.add(self.logo)
self.builder.get_object("vbox_preview").pack_start(self.image_preview)
self.add_dialog = None
self.prefs_dialog = None
self.about_dialog = None
self.transcoder = None
# Setup the transcoding queue and watch for events
self.queue = arista.queue.TranscodeQueue()
self.queue.connect("entry-discovered", self.on_queue_entry_discovered)
self.queue.connect("entry-error", self.on_queue_entry_error)
self.queue.connect("entry-complete", self.on_queue_entry_complete)
# Setup configuration system
client = gconf.client_get_default()
client.add_dir(CONFIG_PATH, gconf.CLIENT_PRELOAD_NONE)
# Update UI to reflect currently stored settings
try:
value = client.get_value(CONFIG_PATH + "/show_toolbar")
if value:
self.toolbar.show()
else:
self.toolbar.hide()
self.menuitem_toolbar.set_active(value)
except ValueError:
if DEFAULT_SHOW_TOOLBAR:
self.toolbar.show()
else:
self.toolbar.hide()
self.menuitem_toolbar.set_active(DEFAULT_SHOW_TOOLBAR)
client.notify_add(CONFIG_PATH + "/show_toolbar",
self.on_gconf_show_toolbar)
try:
value = client.get_value(CONFIG_PATH + "/last_open_path")
if value and os.path.exists(value):
self.last_open_path = value
else:
self.last_open_path = DEFAULT_OPEN_PATH
except ValueError:
self.last_open_path = DEFAULT_OPEN_PATH
# Show the interface!
self.preview.hide()
self.hbox_progress.hide()
self.image_preview.show_all()
self.window.show()
# Are we using the simplified interface? Hide stuff!
if self.runoptions.simple:
self.builder.get_object("menubar").hide()
self.toolbar.hide()
self.window.resize(320, 240)
self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
device = arista.presets.get()[self.runoptions.device]
if not self.runoptions.preset:
preset = device.presets[device.default]
else:
for (id, preset) in device.presets.items():
if preset.name == options.preset:
break
outputs = []
for fname in self.runoptions.files:
output = arista.utils.generate_output_path(fname, preset,
to_be_created=outputs,
device_name=self.runoptions.device)
outputs.append(output)
opts = arista.transcoder.TranscoderOptions(fname, preset, output)
self.queue.append(opts)
def _get_preset_from_coords(self, x, y):
"""
Get a preset from a set of widget-local coordinates on the logo
widget. If a preset is clicked then the name is returned, otherwise
None is returned.
"""
# Get logo dimensions, pixbuf dimensions
w, h = self.logo.allocation.width, self.logo.allocation.height
lw, lh = self.logo.pixbuf.get_width(), self.logo.pixbuf.get_height()
# Convert coordinates from widget-local to pixbuf-local
lx = x - ((w - lw) / 2)
ly = y - ((h - lh) / 2)
# Find the preset that was clicked, if any
preset = None
if lx >= 50 and lx <= 93 and ly >= 155 and ly <= 195:
preset = "DVD Player - DivX Home Theater"
elif lx >= 104 and lx <= 153 and ly >= 154 and ly <= 195:
preset = "Computer - WebM"
elif lx >= 171 and lx <= 212 and ly >= 156 and ly <= 195:
preset = "Computer - H.264"
elif lx >= 229 and lx <= 260 and ly >= 153 and ly <= 195:
preset = "Apple iOS - iPad"
elif lx >= 276 and lx <= 298 and ly >= 157 and ly <= 195:
preset = "Apple iOS - iPhone / iPod Touch"
elif lx >= 316 and lx <= 336 and ly >= 156 and ly <= 195:
preset = "Android - Nexus One / Desire"
elif lx >= 352 and lx <= 399 and ly >= 168 and ly <= 193:
preset = "Sony Playstation - PSP"
return preset
def drag_data_received(self, widget, context, x, y, selection, target_type, time):
"""
Files were dragged and dropped into Arista. Add the first file or
folder as the source and show the add dialog.
"""
filenames = [f.strip()[7:] for f in selection.data.split("\n") if x]
preset = None
if widget == self.logo:
preset = self._get_preset_from_coords(x, y)
self.on_add(None, preset)
self.add_dialog.set_source_to_path(filenames[0])
def logo_button_pressed(self, widget, event):
"""
Listen for button presses on the logo - if one of the preset icons
is pressed then show the add icon with that preset selected.
"""
# See which preset was clicked and launch the create dialog with the
# given preset selected
preset = self._get_preset_from_coords(event.x, event.y)
if preset:
self.on_add(None, preset)
def on_quit(self, widget, *args):
"""
Stop the transcoder and hopefully let it cleanup, then exit.
"""
try:
if self.transcoder:
if self.transcoder.state in [gst.STATE_READY, gst.STATE_PAUSED]:
self.transcoder.start()
self.transcoder.pipe.send_event(gst.event_new_eos())
except:
pass
self.window.hide()
_log.debug(_("Cleaning up and flushing buffers..."))
def waiting_to_quit():
if not self.transcoder or self.transcoder.state == gst.STATE_NULL:
gobject.idle_add(gtk.main_quit)
return False
else:
return True
gobject.idle_add(waiting_to_quit)
return True
def on_pause_toggled(self, widget):
"""
Pause toolbar button clicked.
"""
if widget.get_active():
self.transcoder.pause()
else:
self.transcoder.start()
def on_add(self, widget, selected_preset=None):
"""
Add an item to the queue. This shows a file chooser dialog to
pick the output filename and then adds the item to the queue for
transcoding.
"""
if self.add_dialog:
if self.add_dialog.window.get_property("visible"):
self.add_dialog.window.present()
if selected_preset:
self.add_dialog.select_preset(selected_preset)
return
else:
self.add_dialog.window.destroy()
self.add_dialog = AddDialog(self, selected_preset)
def on_get_new(self, widget):
"""
Go to the presets list page online and let the user download
new presets!
"""
webbrowser.open("http://www.transcoder.org/presets/")
def stop_processing_entry(self, entry):
"""
Stop processing an entry that is currently being processed. This
sends an end-of-stream signal down the pipe, hides the preview,
and makes sure the menu and toolbar is in the proper state.
The item will remain in the queue for up to a few seconds as
GStreamer finishes flushing its buffers, then will be removed.
If another item is in the queue it will start processing then.
"""
entry.stop()
if self.runoptions.simple and len(self.queue) == 1:
# This is the last item in the simplified GUI, so we are done and
# should exit as soon as possible!
gobject.idle_add(gtk.main_quit)
return
# Hide live preview while we wait for the item to finish
self.image_preview.show()
self.preview.hide()
self.hbox_progress.hide()
def on_about(self, widget):
"""
Show the about dialog.
"""
AboutDialog()
def on_prefs(self, widget):
"""
Show the preferences dialog.
"""
PrefsDialog()
def on_show_toolbar_toggled(self, widget):
"""
Update the GConf preference for showing or hiding the toolbar.
"""
client = gconf.client_get_default()
client.set_bool(CONFIG_PATH + "/show_toolbar", widget.get_active())
def on_gconf_show_toolbar(self, client, connection, entry, args):
"""
Show or hide the toolbar and set the menu item to reflect which
has happened when the GConf preference has changed.
"""
self.menuitem_toolbar.set_active(entry.get_value().get_bool())
if entry.get_value().get_bool():
self.toolbar.show()
else:
self.toolbar.hide()
def on_queue_entry_discovered(self, queue, entry, info, is_media):
"""
The queue entry has been discovered, see if it is a valid input
file, if not show an error and remove it from the queue.
"""
if not info.is_video and info.is_audio:
_log.error(_("Input %(infile)s contains no valid streams!") % {
"infile": entry.transcoder.infile,
})
gtk.gdk.threads_enter()
msg = "The input file or device contains no audio or video " \
"streams and will be removed from the queue."
dialog = gtk.MessageDialog(self.window,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_ERROR,
buttons = gtk.BUTTONS_OK,
message_format = msg)
dialog.set_title(_("Error with input!"))
dialog.run()
dialog.destroy()
gtk.gdk.threads_leave()
self.on_queue_entry_complete(queue, entry)
else:
entry.transcoder.connect("pass-setup",
self.on_queue_entry_pass_setup, entry)
def on_queue_entry_pass_setup(self, transcoder, entry):
"""
Called by the queue to start an entry. Setup the correct pass and
start the transcoder after attaching to the video tee so that
we can show a nice preview.
"""
client = gconf.client_get_default()
try:
show_preview = client.get_value(CONFIG_PATH + "/show_preview")
except ValueError:
show_preview = DEFAULT_SHOW_PREVIEW
try:
fps = client.get_value(CONFIG_PATH + "/preview_fps")
except ValueError:
fps = DEFAULT_PREVIEW_FPS
transcoder = entry.transcoder
self.transcoder = transcoder
gobject.timeout_add(500, self.on_status_update)
if show_preview:
element = transcoder.pipe.get_by_name("videotee")
if element:
pipe = gst.parse_launch("queue name=preview_source ! decodebin2 ! videoscale method=bilinear ! videorate ! ffmpegcolorspace ! video/x-raw-yuv, framerate=%d/1; video/x-raw-rgb, framerate=%d/1 ! autovideosink name=preview_sink" % (fps, fps))
psink = pipe.get_by_name("preview_sink")
psink.connect("element-added", self.on_preview_sink_element_added)
transcoder.pipe.add(pipe)
src = pipe.get_by_name("preview_source")
gst.element_link_many(element, src)
bus = transcoder.pipe.get_bus()
bus.enable_sync_message_emission()
bus.connect("sync-message::element", self.on_sync_msg)
self.preview.show()
self.image_preview.hide()
self.hbox_progress.show()
def on_queue_entry_error(self, queue, entry, error_str):
"""
An entry in the queue has had an error. Update the queue model
and inform the user.
"""
entry.transcoder.stop()
if pynotify and not entry.force_stopped:
theme = gtk.icon_theme_get_default()
icon_info = theme.lookup_icon("dialog-error", 64, 0)
if icon_info:
icon = icon_info.get_filename()
else:
icon = ""
notice = pynotify.Notification(_("Error!"), _("Conversion of %(filename)s to %(device)s %(preset)s failed! Reason: %(reason)s") % {
"filename": os.path.basename(entry.options.output_uri),
"device": entry.options.preset.device,
"preset": entry.options.preset.name,
"reason": error_str,
}, icon)
notice.show()
else:
# TODO: Show a dialog or something for people with no notifications
pass
if self.runoptions.simple and len(self.queue) == 1:
# This is the last item in the simplified GUI, so we are done and
# should exit as soon as possible!
gobject.idle_add(gtk.main_quit)
return
self.image_preview.show()
self.preview.hide()
self.hbox_progress.hide()
def on_queue_entry_complete(self, queue, entry):
"""
An entry in the queue is finished. Update the queue model.
"""
if pynotify:
try:
icon = arista.utils.get_path("presets/" + entry.options.preset.device.icon[7:])
except IOError:
icon = ""
notice = pynotify.Notification(_("Job done"), _("Conversion of %(filename)s to %(device)s %(preset)s %(action)s") % {
"filename": os.path.basename(entry.options.output_uri),
"device": entry.options.preset.device.name,
"preset": entry.options.preset.name,
"action": entry.force_stopped and _("canceled") or _("finished")
}, icon)
notice.show()
if self.runoptions.simple and len(self.queue) == 1:
# This is the last item in the simplified GUI, so we are done and
# should exit as soon as possible!
gobject.idle_add(gtk.main_quit)
return
self.image_preview.show()
self.preview.hide()
self.hbox_progress.hide()
def on_preview_sink_element_added(self, autovideosink, element):
"""
Since we let Gstreamer decide which video sink to use, whenever it
has picked one set the sync attribute to false so that the
transcoder runs as fast as possible.
"""
try:
# We don't want to play at the proper speed, just go as fast
# as possible when encoding!
element.set_property("sync", False)
except: pass
def on_sync_msg(self, bus, msg):
"""
Prepare the preview drawing area so that the video preview is
rendered there.
"""
if msg.structure is None:
return
msg_name = msg.structure.get_name()
if msg_name == "prepare-xwindow-id":
gtk.gdk.threads_enter()
imagesink = msg.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_xwindow_id(self.preview.window.xid)
gtk.gdk.threads_leave()
def on_status_update(self):
"""
Update the status progress bar and text.
"""
percent = 0.0
state = self.transcoder.state
if state != gst.STATE_PAUSED:
try:
percent, time_rem = self.transcoder.status
if percent > 1.0:
percent = 1.0
if percent < 0.0:
percent = 0.0
pass_info = ""
if self.transcoder.preset.pass_count > 1:
pass_info = "pass %(pass)d of %(total)d, " % {
"pass": self.transcoder.enc_pass + 1,
"total": self.transcoder.preset.pass_count,
}
time_info = "%(time)s remaining" % {
"time": time_rem,
}
file_info = ""
if len(self.queue) > 1:
file_info = ", %(files)d files left" % {
"files": len(self.queue)
}
info_string = "Transcoding... (%(pass_info)s%(time_info)s%(file_info)s)" % {
"pass_info": pass_info,
"time_info": time_info,
"file_info": file_info,
}
gtk.gdk.threads_enter()
if percent == 0.0:
self.progress.pulse()
else:
self.progress.set_fraction(percent)
self.progress.set_text(info_string)
gtk.gdk.threads_leave()
except arista.transcoder.TranscoderStatusException, e:
_log.debug(str(e))
self.progress.pulse()
return percent < 1.0 and state != gst.STATE_NULL
def on_cancel_clicked(self, widget):
"""
The user clicked the stop button, so stop processing the entry.
"""
if len(self.queue):
self.stop_processing_entry(self.queue[0])
def on_install_device(self, widget):
dialog = gtk.FileChooserDialog(title=_("Choose Source File..."),
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT))
dialog.set_property("local-only", False)
dialog.set_current_folder(self.last_open_path)
response = dialog.run()
dialog.hide()
if response == gtk.RESPONSE_ACCEPT:
filename = dialog.get_filename()
client = gconf.client_get_default()
client.set_string(CONFIG_PATH + "/last_open_path",
os.path.dirname(filename))
try:
devices = arista.presets.extract(open(filename))
except Exception, e:
_log.error(str(e))
dialog = gtk.MessageDialog(self.window, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_CLOSE, message_format=_("Problem importing preset. This file does not appear to be a valid Arista preset!"))
dialog.run()
dialog.destroy()
return
arista.presets.reset()
if pynotify:
for device in devices:
try:
icon = arista.utils.get_path("presets", arista.presets.get()[device].icon[7:])
except:
icon = None
notice = pynotify.Notification(_("Installation Successful"), _("Device preset %(name)s successfully installed.") % {
"name": arista.presets.get()[device].name,
}, icon)
notice.show()
class PrefsDialog(object):
"""
Arista Preferences Dialog
=========================
A dialog to edit preferences and presets.
"""
def __init__(self):
ui_path = arista.utils.get_path("ui", "prefs.ui")
# Load the interface definition file
self.builder = gtk.Builder()
self.builder.add_from_file(ui_path)
# Shortcuts for accessing widgets
self.window = self.builder.get_object("prefs_dialog")
self.check_inputs = self.builder.get_object("check_inputs")
self.check_show_live = self.builder.get_object("check_show_live")
self.spin_live_fps = self.builder.get_object("spin_live_fps")
# Setup configuration system
client = gconf.client_get_default()
client.add_dir(CONFIG_PATH, gconf.CLIENT_PRELOAD_NONE)
# Update UI to reflect currently stored settings
try:
value = client.get_value(CONFIG_PATH + "/check_inputs")
self.check_inputs.set_active(value)
except ValueError:
self.check_inputs.set_active(DEFAULT_CHECK_INPUTS)
try:
value = client.get_value(CONFIG_PATH + "/show_preview")
self.check_show_live.set_active(value)
except ValueError:
self.check_show_live.set_active(DEFAULT_SHOW_PREVIEW)
try:
value = client.get_value(CONFIG_PATH + "/preview_fps")
self.spin_live_fps.set_value(value)
except ValueError:
self.spin_live_fps.set_value(DEFAULT_PREVIEW_FPS)
# Register handlers for when settings are changed
client.notify_add(CONFIG_PATH + "/check_inputs",
self.on_gconf_check_inputs)
client.notify_add(CONFIG_PATH + "/show_preview",
self.on_gconf_show_preview)
client.notify_add(CONFIG_PATH + "/preview_fps",
self.on_gconf_preview_fps)
# Connect to signals defined in UI definition file
self.builder.connect_signals(self)
# Show the window and go!
self.window.show_all()
def on_close(self, widget, response):
"""
Close was clicked, remove the window.
"""
self.window.destroy()
def on_check_inputs_toggled(self, widget):
"""
Update GConf preference for checking DVD drives.
"""
client = gconf.client_get_default()
client.set_bool(CONFIG_PATH + "/check_inputs", widget.get_active())
def on_check_show_live_toggled(self, widget):
"""
Update GConf preference for showing a live preview during encoding.
"""
client = gconf.client_get_default()
client.set_bool(CONFIG_PATH + "/show_preview", widget.get_active())
def on_fps_changed(self, widget):
"""
Update GConf preference for the frames per second to show during
the live preview. The higher the number the more CPU is diverted
from encoding to displaying the video.
"""
client = gconf.client_get_default()
client.set_int(CONFIG_PATH + "/preview_fps", int(widget.get_value()))
def on_gconf_check_inputs(self, client, connection, entry, args):
"""
Update UI when the GConf preference for checking DVD drives has
been modified.
"""
self.check_inputs.set_active(entry.get_value().get_bool())
def on_gconf_show_preview(self, client, connection, entry, args):
"""
Update UI when the GConf preference for showing the live preview
has been modified.
"""
value = entry.get_value().get_bool()
self.check_show_live.set_active(value)
self.spin_live_fps.set_sensitive(value)
def on_gconf_preview_fps(self, client, connection, entry, args):
"""
Update UI when the GConf preference for the preview framerate has
been modified.
"""
self.spin_live_fps.set_value(entry.get_value().get_int())
def on_reset_clicked(self, widget):
dialog = gtk.MessageDialog(self.window, type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_YES_NO, message_format=_("Are you sure you want to reset your device presets? Doing so will permanently remove any modifications you have made to presets that ship with or share a short name with presets that ship with Arista!"))
response = dialog.run()
dialog.destroy()
if response == gtk.RESPONSE_YES:
# Reset all presets that ship with Arista to the factory default.
# This does not touch user-made presets unless the shortname
# matches one of the factory default preset shortnames.
arista.presets.reset(overwrite=True, ignore_initial=True)
class PropertiesDialog(object):
"""
Arista Source Properties Dialog
===============================
A simple dialog to set properties for the input source, such as
subtitles and deinterlacing.
"""
def __init__(self, path, options):
self.path = path
self.options = options
ui_path = arista.utils.get_path("ui", "props.ui")
self.builder = gtk.Builder()
self.builder.add_from_file(ui_path)
self.window = self.builder.get_object("props_dialog")
self.frame_dvd = self.builder.get_object("frame_dvd")
self.table_dvd = self.builder.get_object("table_dvd")
self.combo_title = self.builder.get_object("combo_title")
self.combo_chapter = self.builder.get_object("combo_chapter")
self.combo_audio = self.builder.get_object("combo_audio")
self.subs = self.builder.get_object("filechooserbutton_subs")
self.font = self.builder.get_object("fontbutton")
self.deinterlace = self.builder.get_object("checkbutton_deinterlace")
# GStreamer's DVD handling is VERY limited, to the point of making
# chapter and audio stream selection extremely difficult if not
# impossible when using gst-launch. Hide chapter and audio selection
# until this can be fixed somehow!
self.table_dvd.remove(self.builder.get_object("label_chapter"))
self.table_dvd.remove(self.combo_chapter)
self.table_dvd.remove(self.builder.get_object("label_audio"))
self.table_dvd.remove(self.combo_audio)
if options.subfile:
self.subs.set_filename(options.subfile)
if options.font:
self.font.set_font_name(options.font)
if options.deinterlace:
self.deinterlace.set_active(options.deinterlace)
if path.startswith("dvd://"):
# Setup combo boxes
for combo, handler in [(self.combo_title, self.on_title_changed), (self.combo_chapter, self.on_chapter_changed), (self.combo_audio, self.on_audio_changed)]: