Exemple #1
0
    def make_widgets(self):
        self.status = StatusBar(self)
        self.status.right('IDLE')

        self.loaded_list = ObjectList(self,
                                      on_click=self.on_loaded_listbox_click)
        self.loaded_list.pack(side=RIGHT, fill=Y)

        frame = Frame(self)
        frame.pack(side=TOP, fill=X)

        self.file_list = ObjectList(frame,
                                    width=15,
                                    on_click=self.on_file_listbox_click)
        self.file_list.pack(side=RIGHT)

        self.block = EntryBlock(frame,
                                callback=self.on_input_data_change,
                                label_width=8)
        self.block.pack(side=TOP, fill=X, expand=NO)
        self.block.add_line('Url', self.url)
        self.block.add_line('Name', self.name)
        self.block.add_line('Start', self.start)
        self.block.add_line('End', self.end)

        self.buttons = ButtonLine(frame)
        self.buttons.pack(side=TOP)
        self.buttons.add_button('Get', self.on_get_button_click)
        self.buttons.add_button('Stop', self.loader.stop)

        self.preview = PreviewFrame(self, temp_dir='e:/out/')
        self.preview.pack(fill=BOTH, expand=YES)

        self.on_input_data_change()
Exemple #2
0
    def __init__(self, parent, notebook, options):
        gtk.VBox.__init__(self, False, 3)

        self._parent = parent
        self._options = options
        self._notebook = notebook
        self._name = self.__class__.__name__

        # accelerator groups
        self._accelerator_groups = []
        self._configure_accelerators()

        # configure self
        self.set_border_width(2)

        # create tab label
        self._tab_label = TabLabel(self._parent, self)

        # title bar
        self._title_bar = TitleBar(self._parent, self)

        try:
            if getpass.getuser() == 'root':
                self._title_bar.set_mode(TitleBarMode.SUPER_USER)

        except:
            pass

        # create titlebar buttons
        self._create_buttons()

        # status bar
        self._status_bar = StatusBar()

        # show status bar if needed
        if self._parent.options.get('show_status_bar') == StatusVisible.ALWAYS:
            self._status_bar.show()

        # lock options
        self._tab_lock = self._options.get('lock')

        if self.is_tab_locked():
            self.lock_tab()

        # pack interface
        self.pack_start(self._title_bar.get_container(), False, False, 0)
        self.pack_end(self._status_bar, False, False, 0)
Exemple #3
0
    def __init__(self, debug_topic, ctrl_topic):
        super(SonarGui, self).__init__()

        # initialize UI
        self.control_panel = ControlPanel(self.__start_filter,
                                          self.__stop_filter)
        self.ping_plotter = PingPlotter()
        self.particle_plotter = ParticlePlotter()
        self.status_bar = StatusBar()
        self.__init_ui()

        # initialize pubs and subs
        self.debug_sub = rospy.Subscriber(debug_topic, SonarDebug,
                                          self.__debug_cb)
        rospy.loginfo('Listening on sonar debug topic: ' + debug_topic)
        self.ctrl_pub = rospy.Publisher(ctrl_topic,
                                        FilterControl,
                                        queue_size=1)
        rospy.loginfo('Sonar ctrl publishing on: ' + ctrl_topic)

        self.show()
Exemple #4
0
	def __init__(self, parent, notebook, options):
		gtk.VBox.__init__(self, False, 3)

		self._parent = parent
		self._options = options
		self._notebook = notebook
		self._name = self.__class__.__name__

		# accelerator groups
		self._accelerator_groups = []
		self._configure_accelerators()

		# configure self
		self.set_border_width(2)

		# create tab label
		self._tab_label = TabLabel(self._parent, self)

		# title bar
		self._title_bar = TitleBar(self._parent, self)

		try:
			if getpass.getuser() == 'root':
				self._title_bar.set_mode(TitleBarMode.SUPER_USER)

		except:
			pass

		# create titlebar buttons
		self._create_buttons()

		# status bar
		self._status_bar = StatusBar()

		# show status bar if needed
		if self._parent.options.get('show_status_bar') == StatusVisible.ALWAYS:
			self._status_bar.show()

		# lock options
		self._tab_lock = self._options.get('lock')

		if self.is_tab_locked():
			self.lock_tab()

		# pack interface
		self.pack_start(self._title_bar.get_container(), False, False, 0)
		self.pack_end(self._status_bar, False, False, 0)
Exemple #5
0
    def __init__(self, path, provider, parent):
        self._window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        self.path = path
        self._provider = provider
        self._parent = parent
        self._application = self._parent._parent
        self._page_count = 0

        associations_manager = self._application.associations_manager
        self._mime_type = associations_manager.get_mime_type(path)

        if associations_manager.is_mime_type_unknown(self._mime_type):
            data = associations_manager.get_sample_data(path, provider)
            self._mime_type = associations_manager.get_mime_type(data=data)

        # configure window
        self._window.set_title(
            _('{0} - Viewer').format(os.path.basename(self.path)))
        self._window.set_size_request(800, 600)
        self._window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        self._window.set_resizable(True)
        self._window.set_skip_taskbar_hint(False)
        self._window.set_wmclass('Sunflower', 'Sunflower')
        self._window.set_border_width(0)

        # connect signals
        self._window.connect('destroy', self._handle_destroy)
        self._window.connect('key-press-event', self._handle_key_press)

        # create user interface according to mime type
        vbox = gtk.VBox(homogeneous=False, spacing=0)
        self.status_bar = StatusBar()
        self.status_bar.set_border_width(2)
        self.status_bar.add_group_with_icon('mime_type', 'document-properties',
                                            self._mime_type)
        self.status_bar.show()

        self._notebook = gtk.Notebook()
        self._notebook.set_border_width(2)

        # create page for executables
        if self._mime_type in ('application/x-executable', 'application/x-sharedlib') \
        and executable_exists('nm'):
            # get output from command
            data = ''
            try:
                output = subprocess.Popen(
                    ['nm', '-al', path], stdout=subprocess.PIPE).communicate()

                data = output[0]

            except OSError as error:
                # report error to user
                raise error

            # create new page
            self._create_text_page(_('Executable'), data)

        # create text page if needed
        if associations_manager.is_mime_type_subset(self._mime_type,
                                                    'text/plain'):
            # get data from the file
            raw_file = self._provider.get_file_handle(self.path, FileMode.READ)
            data = raw_file.read()
            raw_file.close()

            # create new page
            self._create_text_page(_('Text'), data)

        # create image page if needed
        if self._mime_type.startswith('image/'):
            container = gtk.ScrolledWindow()
            container.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
            container.set_shadow_type(gtk.SHADOW_NONE)
            container.set_border_width(5)
            viewport = gtk.Viewport()

            image = gtk.Image()
            image.set_from_file(self.path)

            viewport.add(image)
            container.add(viewport)
            self._insert_page(_('Image'), container)

        # create extensions
        self._create_extensions()

        # pack user interface
        vbox.pack_start(self._notebook, True, True, 0)
        vbox.pack_start(self.status_bar, False, False, 0)

        self._window.add(vbox)

        # show all widgets if there are pages present
        if self._page_count > 0:
            self._window.show_all()

        else:
            # show information and close window
            dialog = gtk.MessageDialog(
                self._application, gtk.DIALOG_DESTROY_WITH_PARENT,
                gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
                _('Viewer is unable to display this file type.'))
            dialog.run()
            dialog.destroy()

            self._window.destroy()
Exemple #6
0
class Viewer:
    """Simple file viewer implementation"""
    def __init__(self, path, provider, parent):
        self._window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        self.path = path
        self._provider = provider
        self._parent = parent
        self._application = self._parent._parent
        self._page_count = 0

        associations_manager = self._application.associations_manager
        self._mime_type = associations_manager.get_mime_type(path)

        if associations_manager.is_mime_type_unknown(self._mime_type):
            data = associations_manager.get_sample_data(path, provider)
            self._mime_type = associations_manager.get_mime_type(data=data)

        # configure window
        self._window.set_title(
            _('{0} - Viewer').format(os.path.basename(self.path)))
        self._window.set_size_request(800, 600)
        self._window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        self._window.set_resizable(True)
        self._window.set_skip_taskbar_hint(False)
        self._window.set_wmclass('Sunflower', 'Sunflower')
        self._window.set_border_width(0)

        # connect signals
        self._window.connect('destroy', self._handle_destroy)
        self._window.connect('key-press-event', self._handle_key_press)

        # create user interface according to mime type
        vbox = gtk.VBox(homogeneous=False, spacing=0)
        self.status_bar = StatusBar()
        self.status_bar.set_border_width(2)
        self.status_bar.add_group_with_icon('mime_type', 'document-properties',
                                            self._mime_type)
        self.status_bar.show()

        self._notebook = gtk.Notebook()
        self._notebook.set_border_width(2)

        # create page for executables
        if self._mime_type in ('application/x-executable', 'application/x-sharedlib') \
        and executable_exists('nm'):
            # get output from command
            data = ''
            try:
                output = subprocess.Popen(
                    ['nm', '-al', path], stdout=subprocess.PIPE).communicate()

                data = output[0]

            except OSError as error:
                # report error to user
                raise error

            # create new page
            self._create_text_page(_('Executable'), data)

        # create text page if needed
        if associations_manager.is_mime_type_subset(self._mime_type,
                                                    'text/plain'):
            # get data from the file
            raw_file = self._provider.get_file_handle(self.path, FileMode.READ)
            data = raw_file.read()
            raw_file.close()

            # create new page
            self._create_text_page(_('Text'), data)

        # create image page if needed
        if self._mime_type.startswith('image/'):
            container = gtk.ScrolledWindow()
            container.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
            container.set_shadow_type(gtk.SHADOW_NONE)
            container.set_border_width(5)
            viewport = gtk.Viewport()

            image = gtk.Image()
            image.set_from_file(self.path)

            viewport.add(image)
            container.add(viewport)
            self._insert_page(_('Image'), container)

        # create extensions
        self._create_extensions()

        # pack user interface
        vbox.pack_start(self._notebook, True, True, 0)
        vbox.pack_start(self.status_bar, False, False, 0)

        self._window.add(vbox)

        # show all widgets if there are pages present
        if self._page_count > 0:
            self._window.show_all()

        else:
            # show information and close window
            dialog = gtk.MessageDialog(
                self._application, gtk.DIALOG_DESTROY_WITH_PARENT,
                gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
                _('Viewer is unable to display this file type.'))
            dialog.run()
            dialog.destroy()

            self._window.destroy()

    def _create_extensions(self):
        """Create extension widgets"""
        class_list = self._application.get_viewer_extension_classes(
            self._mime_type)

        # we don't have any registered extensions for this mime type
        if len(class_list) == 0:
            return

        # create all extensions and populate notebook
        for ExtensionClass in class_list:
            extension = ExtensionClass(self)
            self._append_page(extension.get_title(), extension.get_container())

    def _append_page(self, title, container):
        """Append new page to viewer"""
        self._page_count += 1
        self._notebook.append_page(container, gtk.Label(title))
        container.grab_focus()

    def _insert_page(self, title, container, position=0):
        """Insert page at desired position in viewer notebook"""
        self._page_count += 1
        self._notebook.insert_page(container, gtk.Label(title), position)

    def _create_text_page(self, title, content, position=0):
        """Create text page with specified data"""
        container = gtk.ScrolledWindow()
        container.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        container.set_shadow_type(gtk.SHADOW_IN)
        container.set_border_width(5)

        font = pango.FontDescription('monospace 9')
        text_view = gtk.TextView()
        text_view.set_editable(False)
        text_view.set_cursor_visible(True)
        text_view.modify_font(font)

        text_view.get_buffer().set_text(content)

        # add container to notebook
        container.add(text_view)
        self._append_page(title, container)

    def _handle_destroy(self, widget):
        """Handle destroying viewer window"""
        return False

    def _handle_key_press(self, widget, event, data=None):
        """Handle pressing keys in history list"""
        result = False

        if event.keyval == gtk.keysyms.Escape:
            # close window on escape
            self._window.destroy()
            result = True

        elif event.keyval in range(gtk.keysyms._1, gtk.keysyms._9 + 1):
            # switch to specified page
            index = event.keyval - gtk.keysyms._1

            if index <= self._notebook.get_n_pages() - 1:
                self._notebook.set_current_page(index)

            result = True

        return result
Exemple #7
0
class PluginBase(gtk.VBox):
    """Abstract plugin class

    This class provides basic and common GUI components for
    other plugins. Do NOT change this class!

    """

    def __init__(self, parent, notebook, options):
        gtk.VBox.__init__(self, False, 3)

        self._parent = parent
        self._options = options
        self._notebook = notebook
        self._name = self.__class__.__name__

        # accelerator groups
        self._accelerator_groups = []
        self._configure_accelerators()

        # configure self
        self.set_border_width(2)

        # create tab label
        self._tab_label = TabLabel(self._parent, self)

        # title bar
        self._title_bar = TitleBar(self._parent, self)

        try:
            if getpass.getuser() == 'root':
                self._title_bar.set_mode(TitleBarMode.SUPER_USER)

        except:
            pass

        # status bar
        self._status_bar = StatusBar()

        # show status bar if needed
        if self._parent.options.get('show_status_bar') == StatusVisible.ALWAYS:
            self._status_bar.show()

        # pack interface
        self.pack_start(self._title_bar.get_container(), False, False, 0)
        self.pack_end(self._status_bar, False, False, 0)

    def _change_title_text(self, text):
        """Change title label text"""
        self._title_bar.set_title(text)

    def _change_tab_text(self, text):
        """Change tab text"""
        self._tab_label.set_text(text)

    def _connect_main_object(self, object_):
        """Create focus chain and connect basic events"""
        self._main_object = object_

        # connect events
        self._main_object.connect('focus-in-event', self._control_got_focus)
        self._main_object.connect('focus-out-event', self._control_lost_focus)
        self._main_object.connect('key-press-event', self._handle_key_press)

        # set focus chain only to main object
        self.set_focus_chain((self._main_object,))

        # configure drag and drop support
        types = self._get_supported_drag_types()
        actions = self._get_supported_drag_actions()

        if actions is not None:
            # configure drag and drop features
            self._main_object.drag_dest_set(
                                        gtk.DEST_DEFAULT_ALL,
                                        types,
                                        actions
                                    )

            self._main_object.drag_source_set(
                                        gtk.gdk.BUTTON1_MASK,
                                        types,
                                        actions
                                    )

            # connect drag and drop events
            self._main_object.connect('drag-begin', self._drag_begin)
            self._main_object.connect('drag-motion', self._drag_motion)
            self._main_object.connect('drag-drop', self._drag_drop)
            self._main_object.connect('drag-data-received', self._drag_data_received)
            self._main_object.connect('drag-data-get', self._drag_data_get)
            self._main_object.connect('drag-data-delete', self._drag_data_delete)
            self._main_object.connect('drag-end', self._drag_end)

    def _configure_accelerators(self):
        """Configure accelerator group"""
        group = AcceleratorGroup(self._parent)
        keyval = gtk.gdk.keyval_from_name

        # configure accelerator group
        group.set_name('plugin_base')
        group.set_title(_('Plugin Base'))

        # add all methods to group
        group.add_method('focus_opposite_object', _('Focus opposite object'), self._parent.focus_opposite_object)
        group.add_method('next_tab', _('Next tab'), self._notebook_next_tab)
        group.add_method('previous_tab', _('Previous tab'), self._notebook_previous_tab)
        group.add_method('duplicate_tab', _('Duplicate tab'), self._duplicate_tab)
        group.add_method('close_tab', _('Close tab'), self._close_tab)
        group.add_method('focus_command_entry', _('Focus command entry'), self._focus_command_entry)
        group.add_method('focus_left_object', _('Focus left object'), self._focus_left_object)
        group.add_method('focus_right_object', _('Focus right object'), self._focus_right_object)

        # configure accelerators
        group.set_accelerator('focus_opposite_object', keyval('Tab'), 0)
        group.set_accelerator('next_tab', keyval('Tab'), gtk.gdk.CONTROL_MASK)
        group.set_accelerator('previous_tab', keyval('Tab'), gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK)
        group.set_accelerator('duplicate_tab', keyval('t'), gtk.gdk.CONTROL_MASK)
        group.set_accelerator('close_tab', keyval('w'), gtk.gdk.CONTROL_MASK)
        group.set_accelerator('focus_command_entry', keyval('Down'), gtk.gdk.MOD1_MASK)
        group.set_accelerator('focus_left_object', keyval('Left'), gtk.gdk.MOD1_MASK)
        group.set_accelerator('focus_right_object', keyval('Right'), gtk.gdk.MOD1_MASK)

        # add accelerator group to the list
        self._accelerator_groups.append(group)

    def _drag_begin(self, widget, drag_context):
        """Handle start of drag and drop operation"""
        return True

    def _drag_motion(self, widget, drag_context, x, y, timestamp):
        """Handle dragging data over widget"""
        return True

    def _drag_drop(self, widget, drag_context, x, y, timestamp):
        """Handle dropping data over widget"""
        return True

    def _drag_data_received(self, widget, drag_context, x, y, selection_data, info, timestamp):
        """Handle drop of data"""
        return True

    def _drag_data_get(self, widget, drag_context, selection_data, info, time):
        """Respond to get-data request from destination widget"""
        return True

    def _drag_data_delete(self, widget, drag_context):
        """Handle delete data after move operation"""
        return True

    def _drag_end(self, widget, drag_context, data=None):
        """Handle the end of drag and drop operation"""
        return True

    def _get_supported_drag_types(self):
        """Return list of supported data for drag'n'drop events"""
        return []

    def _get_supported_drag_actions(self):
        """Return integer representing supported drag'n'drop actions

        Returning None will disable drag and drop functionality for
        specified main object.

        """
        return None

    def _control_got_focus(self, widget, data=None):
        """List focus in event"""
        self._title_bar.set_state(gtk.STATE_SELECTED)
        self._parent._set_active_object(self)

        # deactivate scheduled accelerators
        deactivated = self._parent.accelerator_manager.deactivate_scheduled_groups(self)

        # activate accelerators only if previous groups were deactivated
        if deactivated:
            for group in self._accelerator_groups:
                group.activate(self._parent)

    def _control_lost_focus(self, widget, data=None):
        """List focus out event"""
        self._title_bar.set_state(gtk.STATE_NORMAL)

        # schedule accelerator groups for deactivation
        self._parent.accelerator_manager.schedule_groups_for_deactivation(self._accelerator_groups, self)

    def _enable_object_block(self, widget=None, data=None):
        """Block main object signals"""
        self._main_object.handler_block_by_func(self._control_lost_focus)

    def _disable_object_block(self, widget=None, data=None):
        """Block main object signals"""
        self._main_object.handler_unblock_by_func(self._control_lost_focus)

    def _notebook_next_tab(self, widget, data=None):
        """Go to next tab in parent Notebook"""
        self._parent.next_tab(self._notebook)
        return True

    def _notebook_previous_tab(self, widget, data=None):
        """Go to previous tab in parent Notebook"""
        self._parent.previous_tab(self._notebook)
        return True

    def _focus_command_entry(self, widget=None, data=None):
        """Focus command entry in main window"""
        self._parent.focus_command_entry()
        return True

    def _focus_left_object(self, widget=None, data=None):
        """Focus left object"""
        self._parent.focus_left_object()
        return True

    def _focus_right_object(self, widget=None, data=None):
        """Focus right object"""
        self._parent.focus_right_object()
        return True

    def _show_status_bar(self):
        """Show status bar"""
        self._status_bar.show()

    def _hide_status_bar(self):
        """Hide status bar"""
        self._status_bar.hide()

    def _duplicate_tab(self, widget, data=None):
        """Creates new tab with same path"""
        self._parent.create_tab(self._notebook, self.__class__, self._options.copy())
        return True

    def _close_tab(self, widget=None, data=None):
        """Ask parent to kill this tab"""
        self._parent.close_tab(self._notebook, self)
        return True

    def _handle_key_press(self, widget, event):
        """Handles key events in item list"""
        result = False

        special_keys = (
                gtk.keysyms.Tab,
                gtk.keysyms.Left,
                gtk.keysyms.Right,
                gtk.keysyms.Up,
                gtk.keysyms.Down
            )

        keyval = event.keyval
        state = event.state

        # pressing Shift + Tab gives ISO_Left_Tab
        # we need to override this behavior
        if keyval == gtk.keysyms.ISO_Left_Tab:
            keyval = gtk.keysyms.Tab

        if keyval in special_keys:
            for group in self._accelerator_groups:
                result = group.trigger_accelerator(keyval, state)

                if result:
                    break

        return result

    def _handle_tab_close(self):
        """Method called before tab is removed"""
        for group in self._accelerator_groups:
            group.deactivate()

    def get_tab_label(self):
        """Return tab label container"""
        return self._tab_label.get_container()

    def apply_settings(self):
        """Method called after settings were changed"""
        self._title_bar.apply_settings()
        self._tab_label.apply_settings()

    def update_status(self, status):
        """Change status text"""
        self._status_bar.set_text(status)

    def update_notebook(self, notebook=None):
        """Update notebook and/or page number"""
        if notebook is not None:
            self._notebook = notebook
Exemple #8
0
	def __init__(self, path, provider, parent):
		self._window = gtk.Window(gtk.WINDOW_TOPLEVEL)

		self.path = path
		self._provider = provider
		self._parent = parent
		self._application = self._parent._parent
		self._page_count = 0

		associations_manager = self._application.associations_manager
		self._mime_type = associations_manager.get_mime_type(path)

		if associations_manager.is_mime_type_unknown(self._mime_type):
			data = associations_manager.get_sample_data(path, provider)
			self._mime_type = associations_manager.get_mime_type(data=data)

		# configure window
		self._window.set_title(_('{0} - Viewer').format(os.path.basename(self.path)))
		self._window.set_size_request(800, 600)
		self._window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
		self._window.set_resizable(True)
		self._window.set_skip_taskbar_hint(False)
		self._window.set_wmclass('Sunflower', 'Sunflower')
		self._window.set_border_width(0)

		# connect signals
		self._window.connect('destroy', self._handle_destroy)
		self._window.connect('key-press-event', self._handle_key_press)

		# create user interface according to mime type
		vbox = gtk.VBox(homogeneous=False, spacing=0)
		self.status_bar = StatusBar()
		self.status_bar.set_border_width(2)
		self.status_bar.add_group_with_icon('mime_type', 'document-properties', self._mime_type)
		self.status_bar.show()

		self._notebook = gtk.Notebook()
		self._notebook.set_border_width(2)

		# create page for executables
		if self._mime_type in ('application/x-executable', 'application/x-sharedlib') \
		and executable_exists('nm'):
			# get output from command
			data = ''
			try:
				output = subprocess.Popen(
									['nm', '-al', path],
									stdout=subprocess.PIPE
								).communicate()

				data = output[0]

			except OSError as error:
				# report error to user
				raise error

			# create new page
			self._create_text_page(_('Executable'), data)

		# create text page if needed
		if associations_manager.is_mime_type_subset(self._mime_type, 'text/plain'):
			# get data from the file
			raw_file = self._provider.get_file_handle(self.path, FileMode.READ)
			data = raw_file.read()
			raw_file.close()

			# create new page
			self._create_text_page(_('Text'), data)

		# create image page if needed
		if self._mime_type.startswith('image/'):
			container = gtk.ScrolledWindow()
			container.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
			container.set_shadow_type(gtk.SHADOW_NONE)
			container.set_border_width(5)
			viewport = gtk.Viewport()

			image = gtk.Image()
			image.set_from_file(self.path)

			viewport.add(image)
			container.add(viewport)
			self._insert_page(_('Image'), container)

		# create extensions
		self._create_extensions()

		# pack user interface
		vbox.pack_start(self._notebook, True, True, 0)
		vbox.pack_start(self.status_bar, False, False, 0)

		self._window.add(vbox)
		
		# show all widgets if there are pages present
		if self._page_count > 0:
			self._window.show_all()

		else:
			# show information and close window
			dialog = gtk.MessageDialog(
									self._application,
									gtk.DIALOG_DESTROY_WITH_PARENT,
									gtk.MESSAGE_INFO,
									gtk.BUTTONS_OK,
									_('Viewer is unable to display this file type.')
								)
			dialog.run()
			dialog.destroy()

			self._window.destroy()
Exemple #9
0
class Viewer:
	"""Simple file viewer implementation"""

	def __init__(self, path, provider, parent):
		self._window = gtk.Window(gtk.WINDOW_TOPLEVEL)

		self.path = path
		self._provider = provider
		self._parent = parent
		self._application = self._parent._parent
		self._page_count = 0

		associations_manager = self._application.associations_manager
		self._mime_type = associations_manager.get_mime_type(path)

		if associations_manager.is_mime_type_unknown(self._mime_type):
			data = associations_manager.get_sample_data(path, provider)
			self._mime_type = associations_manager.get_mime_type(data=data)

		# configure window
		self._window.set_title(_('{0} - Viewer').format(os.path.basename(self.path)))
		self._window.set_size_request(800, 600)
		self._window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
		self._window.set_resizable(True)
		self._window.set_skip_taskbar_hint(False)
		self._window.set_wmclass('Sunflower', 'Sunflower')
		self._window.set_border_width(0)

		# connect signals
		self._window.connect('destroy', self._handle_destroy)
		self._window.connect('key-press-event', self._handle_key_press)

		# create user interface according to mime type
		vbox = gtk.VBox(homogeneous=False, spacing=0)
		self.status_bar = StatusBar()
		self.status_bar.set_border_width(2)
		self.status_bar.add_group_with_icon('mime_type', 'document-properties', self._mime_type)
		self.status_bar.show()

		self._notebook = gtk.Notebook()
		self._notebook.set_border_width(2)

		# create page for executables
		if self._mime_type in ('application/x-executable', 'application/x-sharedlib') \
		and executable_exists('nm'):
			# get output from command
			data = ''
			try:
				output = subprocess.Popen(
									['nm', '-al', path],
									stdout=subprocess.PIPE
								).communicate()

				data = output[0]

			except OSError as error:
				# report error to user
				raise error

			# create new page
			self._create_text_page(_('Executable'), data)

		# create text page if needed
		if associations_manager.is_mime_type_subset(self._mime_type, 'text/plain'):
			# get data from the file
			raw_file = self._provider.get_file_handle(self.path, FileMode.READ)
			data = raw_file.read()
			raw_file.close()

			# create new page
			self._create_text_page(_('Text'), data)

		# create image page if needed
		if self._mime_type.startswith('image/'):
			container = gtk.ScrolledWindow()
			container.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
			container.set_shadow_type(gtk.SHADOW_NONE)
			container.set_border_width(5)
			viewport = gtk.Viewport()

			image = gtk.Image()
			image.set_from_file(self.path)

			viewport.add(image)
			container.add(viewport)
			self._insert_page(_('Image'), container)

		# create extensions
		self._create_extensions()

		# pack user interface
		vbox.pack_start(self._notebook, True, True, 0)
		vbox.pack_start(self.status_bar, False, False, 0)

		self._window.add(vbox)
		
		# show all widgets if there are pages present
		if self._page_count > 0:
			self._window.show_all()

		else:
			# show information and close window
			dialog = gtk.MessageDialog(
									self._application,
									gtk.DIALOG_DESTROY_WITH_PARENT,
									gtk.MESSAGE_INFO,
									gtk.BUTTONS_OK,
									_('Viewer is unable to display this file type.')
								)
			dialog.run()
			dialog.destroy()

			self._window.destroy()

	def _create_extensions(self):
		"""Create extension widgets"""
		class_list = self._application.get_viewer_extension_classes(self._mime_type)

		# we don't have any registered extensions for this mime type
		if len(class_list) == 0:
			return

		# create all extensions and populate notebook
		for ExtensionClass in class_list:
			extension = ExtensionClass(self)
			self._append_page(extension.get_title(), extension.get_container())

	def _append_page(self, title, container):
		"""Append new page to viewer"""
		self._page_count += 1
		self._notebook.append_page(container, gtk.Label(title))
		container.grab_focus()

	def _insert_page(self, title, container, position=0):
		"""Insert page at desired position in viewer notebook"""
		self._page_count += 1
		self._notebook.insert_page(container, gtk.Label(title), position)

	def _create_text_page(self, title, content, position=0):
		"""Create text page with specified data"""
		container = gtk.ScrolledWindow()
		container.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		container.set_shadow_type(gtk.SHADOW_IN)
		container.set_border_width(5)

		font = pango.FontDescription('monospace 9')
		text_view = gtk.TextView()
		text_view.set_editable(False)
		text_view.set_cursor_visible(True)
		text_view.modify_font(font)
		
		text_view.get_buffer().set_text(content)

		# add container to notebook
		container.add(text_view)
		self._append_page(title, container)

	def _handle_destroy(self, widget):
		"""Handle destroying viewer window"""
		return False

	def _handle_key_press(self, widget, event, data=None):
		"""Handle pressing keys in history list"""
		result = False

		if event.keyval == gtk.keysyms.Escape:
			# close window on escape
			self._window.destroy()
			result = True

		elif event.keyval in range(gtk.keysyms._1, gtk.keysyms._9 + 1):
			# switch to specified page
			index = event.keyval - gtk.keysyms._1

			if index <= self._notebook.get_n_pages() - 1:
				self._notebook.set_current_page(index)

			result = True

		return result
Exemple #10
0
class SonarGui(QtWidgets.QWidget):
    def __init__(self, debug_topic, ctrl_topic):
        super(SonarGui, self).__init__()

        # initialize UI
        self.control_panel = ControlPanel(self.__start_filter,
                                          self.__stop_filter)
        self.ping_plotter = PingPlotter()
        self.particle_plotter = ParticlePlotter()
        self.status_bar = StatusBar()
        self.__init_ui()

        # initialize pubs and subs
        self.debug_sub = rospy.Subscriber(debug_topic, SonarDebug,
                                          self.__debug_cb)
        rospy.loginfo('Listening on sonar debug topic: ' + debug_topic)
        self.ctrl_pub = rospy.Publisher(ctrl_topic,
                                        FilterControl,
                                        queue_size=1)
        rospy.loginfo('Sonar ctrl publishing on: ' + ctrl_topic)

        self.show()

    def __init_ui(self):
        self.resize(786, 1024)
        self.setWindowTitle('Sonar GUI')

        # add everything to layout
        layout = QtGui.QVBoxLayout()
        self.setLayout(layout)
        layout.addWidget(self.control_panel)
        plotter_size_policy = QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        plotter_size_policy.setVerticalStretch(1)
        self.ping_plotter.setSizePolicy(plotter_size_policy)
        layout.addWidget(self.ping_plotter)
        layout.addWidget(self.particle_plotter)
        layout.addWidget(self.status_bar)
        layout.setContentsMargins(10, 10, 10, 0)

    def __debug_cb(self, data):
        raw_data = [data.h_a, data.h_refa, data.h_b, data.h_refb]
        fft_data = [data.fft_freq, data.fft_mag]
        self.ping_plotter.update_data(raw_data, fft_data, data.actual_freq,
                                      data.shift_a, data.shift_b,
                                      data.rel_heading, data.abs_heading)
        robot_pos = [data.robot_pose.x, data.robot_pose.y]
        particle_data = np.vstack([data.particles_x, data.particles_y])
        self.particle_plotter.update(robot_pos, particle_data)
        if data.filter_running:
            self.control_panel.disable_fields(True)
            self.status_bar.filter_on(data.pinger_location, data.filter_cov)
        else:
            self.control_panel.disable_fields(False)
            self.status_bar.filter_off()

    def __start_filter(self, x, y, stdev):
        msg = FilterControl()
        msg.enable = True
        msg.x = x
        msg.y = y
        msg.stdev = stdev
        if self.ctrl_pub is not None:
            self.ctrl_pub.publish(msg)
        rospy.logdebug("starting filter with {},{} with dev {}".format(
            x, y, stdev))

    def __stop_filter(self):
        msg = FilterControl()
        msg.enable = False
        if self.ctrl_pub is not None:
            self.ctrl_pub.publish(msg)
        rospy.logdebug("stopping filter")
Exemple #11
0
class PluginBase(gtk.VBox):
    """Abstract plugin class

	This class provides basic and common GUI components for
	other plugins. Do NOT change this class!

	"""
    def __init__(self, parent, notebook, options):
        gtk.VBox.__init__(self, False, 3)

        self._parent = parent
        self._options = options
        self._notebook = notebook
        self._name = self.__class__.__name__

        # accelerator groups
        self._accelerator_groups = []
        self._configure_accelerators()

        # configure self
        self.set_border_width(2)

        # create tab label
        self._tab_label = TabLabel(self._parent, self)

        # title bar
        self._title_bar = TitleBar(self._parent, self)

        try:
            if getpass.getuser() == 'root':
                self._title_bar.set_mode(TitleBarMode.SUPER_USER)

        except:
            pass

        # status bar
        self._status_bar = StatusBar()

        # show status bar if needed
        if self._parent.options.get('show_status_bar') == StatusVisible.ALWAYS:
            self._status_bar.show()

        # lock options
        self._tab_lock = self._options.get('lock')

        if self.is_tab_locked():
            self.lock_tab()

        # pack interface
        self.pack_start(self._title_bar.get_container(), False, False, 0)
        self.pack_end(self._status_bar, False, False, 0)

    def _change_title_text(self, text):
        """Change title label text"""
        self._title_bar.set_title(text)

    def _change_tab_text(self, text):
        """Change tab text"""
        self._tab_label.set_text(text)

    def _connect_main_object(self, object_):
        """Create focus chain and connect basic events"""
        self._main_object = object_

        # connect events
        self._main_object.connect('focus-in-event', self._control_got_focus)
        self._main_object.connect('focus-out-event', self._control_lost_focus)
        self._main_object.connect('key-press-event', self._handle_key_press)

        # set focus chain only to main object
        self.set_focus_chain((self._main_object, ))

        # configure drag and drop support
        types = self._get_supported_drag_types()
        actions = self._get_supported_drag_actions()

        if actions is not None:
            # configure drag and drop features
            self._main_object.drag_dest_set(gtk.DEST_DEFAULT_ALL, types,
                                            actions)

            self._main_object.drag_source_set(
                gtk.gdk.BUTTON1_MASK | gtk.gdk.BUTTON3_MASK, types, actions)

            # connect drag and drop events
            self._main_object.connect('drag-begin', self._drag_begin)
            self._main_object.connect('drag-motion', self._drag_motion)
            self._main_object.connect('drag-drop', self._drag_drop)
            self._main_object.connect('drag-data-received',
                                      self._drag_data_received)
            self._main_object.connect('drag-data-get', self._drag_data_get)
            self._main_object.connect('drag-data-delete',
                                      self._drag_data_delete)
            self._main_object.connect('drag-end', self._drag_end)

    def _configure_accelerators(self):
        """Configure accelerator group"""
        group = AcceleratorGroup(self._parent)
        keyval = gtk.gdk.keyval_from_name

        # configure accelerator group
        group.set_name('plugin_base')
        group.set_title(_('Plugin Base'))

        # add all methods to group
        group.add_method('focus_opposite_object', _('Focus opposite object'),
                         self._parent.focus_opposite_object)
        group.add_method('next_tab', _('Next tab'), self._notebook_next_tab)
        group.add_method('previous_tab', _('Previous tab'),
                         self._notebook_previous_tab)
        group.add_method('duplicate_tab', _('Duplicate tab'),
                         self._duplicate_tab)
        group.add_method('close_tab', _('Close tab'), self._close_tab)
        group.add_method('focus_command_entry', _('Focus command entry'),
                         self._focus_command_entry)
        group.add_method('focus_left_object', _('Focus left object'),
                         self._focus_left_object)
        group.add_method('focus_right_object', _('Focus right object'),
                         self._focus_right_object)

        # configure accelerators
        group.set_accelerator('focus_opposite_object', keyval('Tab'), 0)
        group.set_accelerator('next_tab', keyval('Tab'), gtk.gdk.CONTROL_MASK)
        group.set_accelerator('previous_tab', keyval('Tab'),
                              gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK)
        group.set_accelerator('duplicate_tab', keyval('t'),
                              gtk.gdk.CONTROL_MASK)
        group.set_accelerator('close_tab', keyval('w'), gtk.gdk.CONTROL_MASK)
        group.set_accelerator('focus_command_entry', keyval('Down'),
                              gtk.gdk.MOD1_MASK)
        group.set_accelerator('focus_left_object', keyval('Left'),
                              gtk.gdk.MOD1_MASK)
        group.set_accelerator('focus_right_object', keyval('Right'),
                              gtk.gdk.MOD1_MASK)

        # add accelerator group to the list
        self._accelerator_groups.append(group)

    def _drag_begin(self, widget, drag_context):
        """Handle start of drag and drop operation"""
        return True

    def _drag_motion(self, widget, drag_context, x, y, timestamp):
        """Handle dragging data over widget"""
        return True

    def _drag_drop(self, widget, drag_context, x, y, timestamp):
        """Handle dropping data over widget"""
        return True

    def _drag_data_received(self, widget, drag_context, x, y, selection_data,
                            info, timestamp):
        """Handle drop of data"""
        return True

    def _drag_data_get(self, widget, drag_context, selection_data, info, time):
        """Respond to get-data request from destination widget"""
        return True

    def _drag_data_delete(self, widget, drag_context):
        """Handle delete data after move operation"""
        return True

    def _drag_end(self, widget, drag_context, data=None):
        """Handle the end of drag and drop operation"""
        return True

    def _get_supported_drag_types(self):
        """Return list of supported data for drag'n'drop events"""
        return []

    def _get_supported_drag_actions(self):
        """Return integer representing supported drag'n'drop actions

		Returning None will disable drag and drop functionality for
		specified main object.

		"""
        return None

    def _control_got_focus(self, widget, data=None):
        """List focus in event"""
        self._parent._set_active_object(self)

        # update states
        self.update_state(gtk.STATE_SELECTED)
        self._parent.get_opposite_object(self).update_state(gtk.STATE_NORMAL)

        # deactivate scheduled accelerators
        deactivated = self._parent.accelerator_manager.deactivate_scheduled_groups(
            self)

        # activate accelerators only if previous groups were deactivated
        if deactivated:
            for group in self._accelerator_groups:
                group.activate(self._parent)

    def _control_lost_focus(self, widget, data=None):
        """List focus out event"""
        # schedule accelerator groups for deactivation
        self._parent.accelerator_manager.schedule_groups_for_deactivation(
            self._accelerator_groups, self)

    def _notebook_next_tab(self, widget, data=None):
        """Go to next tab in parent Notebook"""
        self._parent.next_tab(self._notebook)
        return True

    def _notebook_previous_tab(self, widget, data=None):
        """Go to previous tab in parent Notebook"""
        self._parent.previous_tab(self._notebook)
        return True

    def _focus_command_entry(self, widget=None, data=None):
        """Focus command entry in main window"""
        self._parent.focus_command_entry()
        return True

    def _focus_left_object(self, widget=None, data=None):
        """Focus left object"""
        self._parent.focus_left_object()
        return True

    def _focus_right_object(self, widget=None, data=None):
        """Focus right object"""
        self._parent.focus_right_object()
        return True

    def _show_status_bar(self):
        """Show status bar"""
        self._status_bar.show()

    def _hide_status_bar(self):
        """Hide status bar"""
        self._status_bar.hide()

    def _duplicate_tab(self, widget, data=None):
        """Creates new tab with same path"""
        self._parent.create_tab(self._notebook, self.__class__,
                                self._options.copy())
        return True

    def _close_tab(self, widget=None, data=None):
        """Ask parent to kill this tab"""
        self._parent.close_tab(self._notebook, self)
        return True

    def _move_tab(self, widget=None, data=None):
        """Move tab to opposite panel"""
        notebook = self._parent.get_opposite_notebook(self._notebook)
        page_num = self._notebook.page_num(self)
        self._notebook.remove_page(page_num)
        notebook.append_page(self, self.get_tab_label())

    def _handle_key_press(self, widget, event):
        """Handles key events in item list"""
        result = False

        special_keys = (gtk.keysyms.Tab, gtk.keysyms.Left, gtk.keysyms.Right,
                        gtk.keysyms.Up, gtk.keysyms.Down)

        keyval = event.keyval
        state = event.state

        # pressing Shift + Tab gives ISO_Left_Tab
        # we need to override this behavior
        if keyval == gtk.keysyms.ISO_Left_Tab:
            keyval = gtk.keysyms.Tab

        if keyval in special_keys:
            for group in self._accelerator_groups:
                result = group.trigger_accelerator(keyval, state)

                if result:
                    break

        return result

    def _handle_tab_close(self):
        """Method called before tab is removed"""
        self._options.set('lock', self._tab_lock)
        for group in self._accelerator_groups:
            group.deactivate()

    def get_tab_label(self):
        """Return tab label container"""
        return self._tab_label.get_container()

    def apply_settings(self):
        """Method called after settings were changed"""
        self._title_bar.apply_settings()
        self._tab_label.apply_settings()

    def update_status(self, status):
        """Change status text"""
        self._status_bar.set_text(status)

    def update_notebook(self, notebook=None):
        """Update notebook and/or page number"""
        if notebook is not None:
            self._notebook = notebook

    def update_state(self, state):
        """Update plugin state"""
        self._title_bar.set_state(state)

    def focus_main_object(self):
        """Give focus to main object"""
        result = False

        if self._main_object is not None and hasattr(self._main_object,
                                                     'grab_focus'):
            self._main_object.grab_focus()
            result = True

        return result

    def lock_tab(self):
        """Lock tab"""
        self._tab_lock = True
        self._tab_label.lock_tab()

    def unlock_tab(self):
        """Unlock tab"""
        self._tab_lock = False
        self._tab_label.unlock_tab()

    def is_tab_locked(self):
        """Return the status of lock"""
        return self._tab_lock
Exemple #12
0
class FGetMain(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)

        self.url = StringVar(
            value='http://www.bravoerotica.com/hegre/luba/table-for-two/')
        self.name = StringVar(value='%02d.jpg')
        self.start = IntVar(value=1)
        self.end = IntVar(value=12)

        self.base_path = 'e:/out/'

        self.loader = BadFileLoader(self.on_file_loaded,
                                    self.on_all_files_loaded,
                                    self.on_loading_started,
                                    self.on_load_error)

        self.make_widgets()

    def make_widgets(self):
        self.status = StatusBar(self)
        self.status.right('IDLE')

        self.loaded_list = ObjectList(self,
                                      on_click=self.on_loaded_listbox_click)
        self.loaded_list.pack(side=RIGHT, fill=Y)

        frame = Frame(self)
        frame.pack(side=TOP, fill=X)

        self.file_list = ObjectList(frame,
                                    width=15,
                                    on_click=self.on_file_listbox_click)
        self.file_list.pack(side=RIGHT)

        self.block = EntryBlock(frame,
                                callback=self.on_input_data_change,
                                label_width=8)
        self.block.pack(side=TOP, fill=X, expand=NO)
        self.block.add_line('Url', self.url)
        self.block.add_line('Name', self.name)
        self.block.add_line('Start', self.start)
        self.block.add_line('End', self.end)

        self.buttons = ButtonLine(frame)
        self.buttons.pack(side=TOP)
        self.buttons.add_button('Get', self.on_get_button_click)
        self.buttons.add_button('Stop', self.loader.stop)

        self.preview = PreviewFrame(self, temp_dir='e:/out/')
        self.preview.pack(fill=BOTH, expand=YES)

        self.on_input_data_change()

    def on_input_data_change(self):
        self.file_list.clear()

        url = self.url.get()
        path = urlparse(url)
        if path[0] == '': url = 'http://' + url

        filepath = path[1] + '/' + path[2].strip(' /').replace('/', '..')
        fullpath = self.base_path + filepath + '/'

        for i in range(self.start.get(), self.end.get() + 1):
            fname = self.name.get() % i
            fullname = fullpath + fname
            self.file_list.add(FileData(url + fname, fullname, fname))

    def on_get_button_click(self):
        for item in self.file_list:
            self.loader.add(item.url(), item.filename())
        self.loader.start()

    def on_load_error(self, text):
        self.status.center(text)

    def on_file_loaded(self, address, fname):
        self.status.center('Loaded: ' + address)
        self.loaded_list.add(ViewString(fname, 30))

    def on_loading_started(self):
        self.status.left('Loading...')
        self.status.right('BUSY')

    def on_all_files_loaded(self, n):
        self.status.left('Loaded ' + str(n) + ' files')
        self.status.right('IDLE')

    def on_loaded_listbox_click(self, item):
        self.preview.set_picture_from_file(item.get())

    def on_file_listbox_click(self, item):
        print('Click', item.url())
        self.preview.set_picture_from_url(item.url(), str(item))