From 8e77b4370570133356111bf651709db80fdc42e6 Mon Sep 17 00:00:00 2001 From: SAMdroid Date: Sat, 30 Nov 2013 11:10:16 +0000 Subject: Changed ui to bring it in line with sugar --- diff --git a/record.py b/record.py index 6926b6f..7d1ac09 100755 --- a/record.py +++ b/record.py @@ -27,6 +27,7 @@ from gettext import ngettext import gtk from gtk import gdk +import gio import cairo import pango import pangocairo @@ -72,61 +73,6 @@ else: class Record(activity.Activity): - - DIALOG_OK = 13 - - def _getDirs(self, path, parent_item, tree_data_store, path_to_file): - """Gets all of the folders and adds them to - tree_data_store""" - logging.debug(path) - if os.path.exists(path): - for File in os.listdir(path): - filepath = os.path.join(path, File) - if os.path.isdir(filepath): - item = tree_data_store.append(parent_item, [File]) - item_path = tree_data_store.get_path(item) - path_to_file[str(item_path)] = filepath - self._getDirs(filepath, item, tree_data_store, path_to_file) - - def _getDirsWithoutRootFolder(self, path, tree_data_store, path_to_file): - """Like getDirs except omits the first folder in the tree""" - logging.debug(path) - if os.path.exists(path): - logging.debug(path) - for File in os.listdir(path): - filepath = os.path.join(path, File) - if os.path.isdir(filepath): - tree_data_store = self._getDirs(filepath, None, tree_data_store, path_to_file) - - def _genFileTree(self, path_to_file): - """Generates the file tree of the external devices directory - and returns a tree data store""" - tree_data_store = gtk.TreeStore(str) - - self._getDirsWithoutRootFolder("/run/media", tree_data_store, path_to_file) - self._getDirsWithoutRootFolder("/media", tree_data_store, path_to_file) - - internal_item = tree_data_store.append(None, ["Internal Storage"]) - path = tree_data_store.get_path(internal_item) - path_to_file[str(path)] = None - return tree_data_store - - def _init_dialog(self): - """Returns a dialog with a folder picker - picks between /media folders or just 'internal' - also returns a tree view used""" - path_to_file = {} - tree_data_store = self._genFileTree(path_to_file) - tree_view = gtk.TreeView(tree_data_store) - renderer = gtk.CellRendererText() - column = gtk.TreeViewColumn("Media Folders", renderer, text=0) - tree_view.append_column(column) - - folder_dialog = gtk.Dialog("Chose a folder") - folder_dialog.add_button("Use selected folder", self.DIALOG_OK) - folder_dialog.get_content_area().add(tree_view) - folder_dialog.get_content_area().show_all() - return folder_dialog, tree_view, path_to_file def __init__(self, handle): super(Record, self).__init__(handle) @@ -169,7 +115,7 @@ class Record(activity.Activity): self.model.glive.stop() super(Record, self).close() - def _visibility_changed(self, widget, event): + def _visibility_changed(self, wisdget, event): self.model.set_visible(event.state != gtk.gdk.VISIBILITY_FULLY_OBSCURED) def _shared_cb(self, activity): @@ -227,13 +173,8 @@ class Record(activity.Activity): self._toolbar.insert(self._audio_button, -1) self._toolbar.insert(gtk.SeparatorToolItem(), -1) - - self._set_path_button = ToolButton() - self._set_path_button.props.label = _('Set Output File') - self._set_path_button.connect('clicked', self._set_path_button_clicked) - self._toolbar.insert(self._set_path_button, -1) - self._toolbar_controls = RecordControl(self._toolbar) + self._toolbar_controls = RecordControl(self._toolbar, self) separator = gtk.SeparatorToolItem() separator.props.draw = False @@ -428,16 +369,6 @@ class Record(activity.Activity): def _mode_button_clicked(self, button): self.model.change_mode(button.mode) - - def _set_path_button_clicked(self, button): - folder_dialog, tree_view, path_to_file = self._init_dialog() - dialog_responce = folder_dialog.run() - if dialog_responce == self.DIALOG_OK: - tree_sel = tree_view.get_selection() - (tree_store, ti) = tree_sel.get_selected() - ids = tree_store.get_path(ti) - self.Instance.savePath = path_to_file[str(ids)] - folder_dialog.destroy() def _shutter_clicked(self, arg): self.model.do_shutter() @@ -925,29 +856,98 @@ class PlayButton(gtk.Button): class RecordControl(): - - def __init__(self, toolbar): + def __init__(self, toolbar, activity): + self.activity = activity + self.toolbar = toolbar self._timer_value = TIMER_VALUES[0] self._timer_button = ToolButton('timer-0') self._timer_button.set_tooltip(_('Select timer')) self._timer_button.connect('clicked', self._timer_selection_cb) - toolbar.insert(self._timer_button, -1) + self.toolbar.insert(self._timer_button, -1) self._setup_timer_palette() self._duration_value = DURATION_VALUES[0] self._duration_button = ToolButton('duration-2') self._duration_button.set_tooltip(_('Select duration')) self._duration_button.connect('clicked', self._duration_selection_cb) - toolbar.insert(self._duration_button, -1) + self.toolbar.insert(self._duration_button, -1) self._setup_duration_palette() self._quality_value = 0 self._quality_button = ToolButton('low-quality') self._quality_button.set_tooltip(_('Select quality')) self._quality_button.connect('clicked', self._quality_selection_cb) - toolbar.insert(self._quality_button, -1) + self.toolbar.insert(self._quality_button, -1) self._setup_quality_palette() + + self._setup_output_palette(False) + return + + def _output_selection_cb(self, widget): + if self._output_palette: + if not self._output_palette.is_up(): + self._output_palette.popup(immediate=True, + state=self._timer_palette.SECONDARY) + else: + self._output_palette.popdown(immediate=True) + return + + def _setup_output_palette(self, notFirst): + if notFirst: + self.toolbar.remove(self._output_button) + self._output_button = ToolButton('user-documents') + self._output_button.set_tooltip(_('Select output device')) + self._output_button.connect('clicked', self._output_selection_cb) + self._output_button.show() + self.toolbar.insert(self._output_button, -2 if notFirst else -1) + self._output_palette = self._output_button.get_palette() + + volume_monitor = gio.volume_monitor_get() + self._mount_added_hid = volume_monitor.connect('mount-added', + self.__mount_change_cb) + self._mount_removed_hid = volume_monitor.connect('mount-removed', + self.__mount_change_cb) + + button = MenuItem(icon_name='activity-journal', + text_label='Journal') + self._output_palette.menu.append(button) + button.connect('activate', self._output_selected_cb, None) + button.show() + self._output_palette.menu.append(button) + + for mount in volume_monitor.get_mounts(): + self._add_button(mount) + + def __mount_change_cb(self, volume_monitor, mount): + self._setup_output_palette(True) + + def _get_mount_icon_name(self, mount, size): + icon = mount.get_icon() + if isinstance(icon, gio.ThemedIcon): + icon_theme = gtk.icon_theme_get_default() + for icon_name in icon.props.names: + if icon_theme.lookup_icon(icon_name, size, 0) is not None: + return icon_name + logging.error('Cannot find icon name for %s, %s', icon, mount) + return 'drive' + + def _add_button(self, mount): + logging.debug('VolumeToolbar._add_button: %r', mount.get_name()) + + button = MenuItem(icon_name= + self._get_mount_icon_name(mount, gtk.ICON_SIZE_LARGE_TOOLBAR), + text_label=mount.get_name()) + self._output_palette.menu.append(button) + button.connect('activate', self._output_selected_cb, mount) + button.show() + self._output_palette.menu.append(button) + + def _output_selected_cb(self, button, mount): + if mount: + self.activity.Instance.savePath = mount.get_root().get_path() + else: + self.activity.Instance.savePath = None def _timer_selection_cb(self, widget): if self._timer_palette: -- cgit v0.9.1