Example #1
0
    def __init__(self, parent, linkmap, navigation):
        Dialog.__init__(self,
                        parent,
                        'LinkMap',
                        defaultwindowsize=(400, 400),
                        buttons=Gtk.ButtonsType.CLOSE)
        self.linkmap = linkmap
        self.navigation = navigation

        hbox = Gtk.HBox(spacing=5)
        self.vbox.pack_start(hbox, True, True, 0)

        self.xdotview = xdot.DotWidget()
        self.xdotview.set_filter('fdp')
        self.xdotview.set_dotcode(linkmap.get_dotcode())
        self.xdotview.connect('clicked', self.on_node_clicked)
        hbox.add(self.xdotview)

        vbox = Gtk.VBox()
        hbox.pack_start(vbox, False, False, 0)
        for stock, method in (
            (Gtk.STOCK_ZOOM_IN, self.xdotview.on_zoom_in),
            (Gtk.STOCK_ZOOM_OUT, self.xdotview.on_zoom_out),
            (Gtk.STOCK_ZOOM_FIT, self.xdotview.on_zoom_fit),
            (Gtk.STOCK_ZOOM_100, self.xdotview.on_zoom_100),
        ):
            button = IconButton(stock)
            button.connect('clicked', method)
            vbox.pack_start(button, False, True, 0)
Example #2
0
File: gui.py Project: Jam71/Zim-QDA
    def __init__(self, ui, linkmap):
        if ui_environment['platform'] == 'maemo':
            defaultsize = (800, 480)
            # The dialog hides the main window, so use all available screen anyway
            # setting defaultsize doesn't work because maemo makes the dialog
            # window as small as possible to fit the window's internal widgets
        else:
            defaultsize = (400, 400)
        Dialog.__init__(self, ui, 'LinkMap',
            defaultwindowsize=defaultsize, buttons=gtk.BUTTONS_CLOSE)
        self.linkmap = linkmap

        hbox = gtk.HBox(spacing=5)
        self.vbox.add(hbox)

        self.xdotview = xdot.DotWidget()
        self.xdotview.set_filter('fdp')
        self.xdotview.set_dotcode(linkmap.get_dotcode())
        self.xdotview.connect('clicked', self.on_node_clicked)
        hbox.add(self.xdotview)

        vbox = gtk.VBox()
        hbox.pack_start(vbox, False)
        for stock, method in (
            (gtk.STOCK_ZOOM_IN,  self.xdotview.on_zoom_in ),
            (gtk.STOCK_ZOOM_OUT, self.xdotview.on_zoom_out),
            (gtk.STOCK_ZOOM_FIT, self.xdotview.on_zoom_fit),
            (gtk.STOCK_ZOOM_100, self.xdotview.on_zoom_100),
        ):
            button = IconButton(stock)
            button.connect('clicked', method)
            vbox.pack_start(button, False)
Example #3
0
    def __init__(self, ui):
        Dialog.__init__(self, ui, _('Custom Tools'), buttons=gtk.BUTTONS_CLOSE) # T: Dialog title
        self.set_help(':Help:Custom Tools')
        self.manager = CustomToolManager()

        self.add_help_text(_(
            'You can configure custom tools that will appear\n'
            'in the tool menu and in the tool bar or context menus.'
        ) ) # T: help text in "Custom Tools" dialog

        hbox = gtk.HBox(spacing=5)
        self.vbox.add(hbox)

        self.listview = CustomToolList(self.manager)
        hbox.add(self.listview)

        vbox = gtk.VBox(spacing=5)
        hbox.pack_start(vbox, False)

        for stock, handler, data in (
            (gtk.STOCK_ADD, self.__class__.on_add, None),
            (gtk.STOCK_EDIT, self.__class__.on_edit, None),
            (gtk.STOCK_DELETE, self.__class__.on_delete, None),
            (gtk.STOCK_GO_UP, self.__class__.on_move, -1),
            (gtk.STOCK_GO_DOWN, self.__class__.on_move, 1),
        ):
            button = IconButton(stock) # TODO tooltips for icon button
            if data:
                button.connect_object('clicked', handler, self, data)
            else:
                button.connect_object('clicked', handler, self)
            vbox.pack_start(button, False)
Example #4
0
    def __init__(self, ui, linkmap, opener):
        Dialog.__init__(self,
                        ui,
                        'LinkMap',
                        defaultwindowsize=(400, 400),
                        buttons=gtk.BUTTONS_CLOSE)
        self.linkmap = linkmap
        self.opener = opener

        hbox = gtk.HBox(spacing=5)
        self.vbox.add(hbox)

        self.xdotview = xdot.DotWidget()
        self.xdotview.set_filter('fdp')
        self.xdotview.set_dotcode(linkmap.get_dotcode())
        self.xdotview.connect('clicked', self.on_node_clicked)
        hbox.add(self.xdotview)

        vbox = gtk.VBox()
        hbox.pack_start(vbox, False)
        for stock, method in (
            (gtk.STOCK_ZOOM_IN, self.xdotview.on_zoom_in),
            (gtk.STOCK_ZOOM_OUT, self.xdotview.on_zoom_out),
            (gtk.STOCK_ZOOM_FIT, self.xdotview.on_zoom_fit),
            (gtk.STOCK_ZOOM_100, self.xdotview.on_zoom_100),
        ):
            button = IconButton(stock)
            button.connect('clicked', method)
            vbox.pack_start(button, False)
Example #5
0
File: linkmap.py Project: gdw2/zim
	def __init__(self, ui, linkmap, opener):
		Dialog.__init__(self, ui, 'LinkMap',
			defaultwindowsize=(400, 400), buttons=gtk.BUTTONS_CLOSE)
		self.linkmap = linkmap
		self.opener = opener

		hbox = gtk.HBox(spacing=5)
		self.vbox.add(hbox)

		self.xdotview = xdot.DotWidget()
		self.xdotview.set_filter('fdp')
		self.xdotview.set_dotcode(linkmap.get_dotcode())
		self.xdotview.connect('clicked', self.on_node_clicked)
		hbox.add(self.xdotview)

		vbox = gtk.VBox()
		hbox.pack_start(vbox, False)
		for stock, method in (
			(gtk.STOCK_ZOOM_IN,  self.xdotview.on_zoom_in ),
			(gtk.STOCK_ZOOM_OUT, self.xdotview.on_zoom_out),
			(gtk.STOCK_ZOOM_FIT, self.xdotview.on_zoom_fit),
			(gtk.STOCK_ZOOM_100, self.xdotview.on_zoom_100),
		):
			button = IconButton(stock)
			button.connect('clicked', method)
			vbox.pack_start(button, False)
Example #6
0
	def __init__(self, ui, callback=None):
		Dialog.__init__(self, ui, _('Open Notebook')) # T: dialog title
		# TODO set button to "OPEN" instead of "OK"
		self.callback = callback
		self.set_default_size(500, 400)
		self.set_help(':Help:Notebooks')

		# show some art work in an otherwise boring dialog
		path = data_file('globe_banner_small.png').path
		image = gtk.Image()
		image.set_from_file(path) # new_from_file not in 2.6
		align = gtk.Alignment(0,0.5, 0,0)
		align.add(image)
		self.vbox.pack_start(align, False)

		# split between treeview and vbuttonbox
		hbox = gtk.HBox(spacing=12)
		self.vbox.add(hbox)

		# add notebook list - open notebook on clicking a row
		self.treeview = NotebookTreeView()
		self.treeview.connect(
			'row-activated', lambda *a: self.response(gtk.RESPONSE_OK))

		swindow = gtk.ScrolledWindow()
		swindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
		swindow.set_shadow_type(gtk.SHADOW_IN)
		swindow.add(self.treeview)
		hbox.add(swindow)

		# add buttons for modifying the treeview
		vbbox = gtk.VButtonBox()
		vbbox.set_layout(gtk.BUTTONBOX_START)
		hbox.pack_start(vbbox, False)
		add_button = gtk.Button(stock='gtk-add')
		add_button.connect('clicked', self.do_add_notebook)
		#~ edit_button = gtk.Button(stock='gtk-edit')
		#~ edit_button.connect('clicked', self.do_edit_notebook)
		rm_button = gtk.Button(stock='gtk-remove')
		rm_button.connect('clicked', self.do_remove_notebook)
		#~ for b in (add_button, edit_button, rm_button):
		for b in (add_button, rm_button):
			b.set_alignment(0.0, 0.5)
			vbbox.add(b)
		# FIXME buttons for "up" and "down" ?

		# add dropdown to select default
		self.combobox = DefaultNotebookComboBox(self.treeview.get_model())

		# clear button de-selects any item in the combobox
		clear_button = IconButton('gtk-clear')
		clear_button.connect('clicked', lambda o: self.combobox.set_active(-1))

		hbox = gtk.HBox(spacing=5)
		hbox.pack_start(gtk.Label(_('Default notebook')+': '), False)
			# T: Input label in 'open notebook' dialog
		hbox.pack_start(self.combobox, False)
		hbox.pack_start(clear_button, False)
		self.vbox.pack_start(hbox, False)
Example #7
0
    def __init__(self, parent, callback=None):
        Dialog.__init__(self, parent, _('Open Notebook'))  # T: dialog title
        # TODO set button to "OPEN" instead of "OK"
        self.callback = callback
        self.set_default_size(500, 400)
        self.set_help(':Help:Notebooks')

        # show some art work in an otherwise boring dialog
        path = data_file('globe_banner_small.png').path
        image = Gtk.Image()
        image.set_from_file(path)  # new_from_file not in 2.6
        align = Gtk.Alignment.new(0, 0.5, 0, 0)
        align.add(image)
        self.vbox.pack_start(align, False, True, 0)

        # split between treeview and vbuttonbox
        hbox = Gtk.HBox(spacing=12)
        self.vbox.pack_start(hbox, True, True, 0)

        # add notebook list - open notebook on clicking a row
        self.treeview = NotebookTreeView()
        self.treeview.connect('row-activated',
                              lambda *a: self.response(Gtk.ResponseType.OK))

        hbox.add(ScrolledWindow(self.treeview))

        # add buttons for modifying the treeview
        vbbox = Gtk.VButtonBox()
        vbbox.set_layout(Gtk.ButtonBoxStyle.START)
        hbox.pack_start(vbbox, False, True, 0)
        add_button = Gtk.Button.new_with_mnemonic(_('_Add'))  # T: Button label
        add_button.connect('clicked', self.do_add_notebook)
        #~ edit_button = Gtk.Button.new_with_mnemonic(_('_Edit')) # T: Button label
        #~ edit_button.connect('clicked', self.do_edit_notebook)
        rm_button = Gtk.Button.new_with_mnemonic(
            _('_Remove'))  # T: Button label
        rm_button.connect('clicked', self.do_remove_notebook)
        #~ for b in (add_button, edit_button, rm_button):
        for b in (add_button, rm_button):
            b.set_alignment(0.0, 0.5)
            vbbox.add(b)
        # FIXME buttons for "up" and "down" ?

        # add dropdown to select default
        self.combobox = DefaultNotebookComboBox(self.treeview.get_model())

        # clear button de-selects any item in the combobox
        clear_button = IconButton('gtk-clear')
        clear_button.connect('clicked', lambda o: self.combobox.set_active(-1))

        hbox = Gtk.HBox(spacing=5)
        hbox.pack_start(Gtk.Label(_('Default notebook') + ': '), False, True,
                        0)
        # T: Input label in 'open notebook' dialog
        hbox.pack_start(self.combobox, False, True, 0)
        hbox.pack_start(clear_button, False, True, 0)
        self.vbox.pack_start(hbox, False, True, 0)
Example #8
0
    def _button_box(self):
        '''
		Panel which includes buttons for manipulating the current treeview:
		- add / delete
		- move up / move down row
		:return: vbox-panel
		'''
        vbox = Gtk.VBox(spacing=5)
        for stock, handler, data, tooltip in (
            (Gtk.STOCK_ADD, self.on_add_new_column, None,
             _('Add column')),  # T: hoover tooltip
            (Gtk.STOCK_DELETE, self.on_delete_column, None,
             _('Remove column')),  # T: hoover tooltip
            (Gtk.STOCK_GO_UP, self.on_move_column, -1,
             _('Move column ahead')),  # T: hoover tooltip
            (Gtk.STOCK_GO_DOWN, self.on_move_column, 1,
             _('Move column backward')),  # T: hoover tooltip
        ):
            button = IconButton(stock)
            if data:
                button.connect('clicked', handler, data)
            else:
                button.connect('clicked', handler)
            button.set_tooltip_text(tooltip)
            vbox.pack_start(button, False, True, 0)

        vbox.show_all()
        return vbox
    def __init__(self, parent):
        Dialog.__init__(self,
                        parent,
                        _('Custom Tools'),
                        buttons=Gtk.ButtonsType.CLOSE)  # T: Dialog title
        self.set_help(':Help:Custom Tools')
        self.manager = CustomToolManager()

        self.add_help_text(
            _('You can configure custom tools that will appear\n'
              'in the tool menu and in the tool bar or context menus.')
        )  # T: help text in "Custom Tools" dialog

        hbox = Gtk.HBox(spacing=5)
        self.vbox.pack_start(hbox, True, True, 0)

        self.listview = CustomToolList(self.manager)
        hbox.pack_start(self.listview, True, True, 0)

        vbox = Gtk.VBox(spacing=5)
        hbox.pack_start(vbox, False, True, 0)

        for stock, handler, data in (
            (Gtk.STOCK_ADD, self.__class__.on_add, None),
            (Gtk.STOCK_EDIT, self.__class__.on_edit, None),
            (Gtk.STOCK_DELETE, self.__class__.on_delete, None),
            (Gtk.STOCK_GO_UP, self.__class__.on_move, -1),
            (Gtk.STOCK_GO_DOWN, self.__class__.on_move, 1),
        ):
            button = IconButton(stock)  # TODO tooltips for icon button
            if data:
                button.connect_object('clicked', handler, self, data)
            else:
                button.connect_object('clicked', handler, self)
            vbox.pack_start(button, False, True, 0)
Example #10
0
    def __init__(self, plugin, window, uistate):
        GObject.GObject.__init__(self)
        self.plugin = plugin
        self.preferences = plugin.preferences
        self.window = window
        self.uistate = uistate
        self._close_button = None

        self.terminalview = ZimTerminal()
        self.terminalview.connect("key-press-event", self.on_key_press_event)
        self.terminalview.spawn_sync(
            Vte.PtyFlags.DEFAULT,
            os.environ['HOME'],
            [self.command_interpreter],
            [],
            GLib.SpawnFlags.DO_NOT_REAP_CHILD,
            None,
            None,
        )

        self.add(ScrolledWindow(self.terminalview, shadow=Gtk.ShadowType.NONE))

        self.on_preferences_changed()
        self.preferences.connect('changed', self.on_preferences_changed)

        self.buttonbox = Gtk.VBox()
        self.pack_end(self.buttonbox, False, True, 0)

        properties_button = IconButton(Gtk.STOCK_PROPERTIES, relief=False)
        properties_button.connect('clicked',
                                  lambda o: self.on_properties_button())
        self.buttonbox.pack_start(properties_button, False, True, 0)

        change_path_button = IconButton(Gtk.STOCK_REFRESH, relief=False)
        change_path_button.connect('clicked',
                                   lambda o: self.on_change_path_button())
        self.buttonbox.pack_start(change_path_button, False, True, 0)
Example #11
0
    def __init__(self, extension, opener, preferences):
        gtk.HBox.__init__(self)
        self.page = None # XXX
        self.extension = extension # XXX
        self.opener = opener
        self.uistate = extension.uistate
        self.preferences = preferences
        self.dir = None
        self._active = True

        self.thumbman = ThumbnailManager(preferences)
        self.thumbman.connect('thumbnail-ready', self.on_thumbnail_ready)

        self.fileview = gtk.IconView()

        self.store = gtk.ListStore(str, gtk.gdk.Pixbuf) # BASENAME_COL, PIXBUF_COL

        self.fileview = gtk.IconView(self.store)
        self.fileview.set_text_column(BASENAME_COL)
        self.fileview.set_pixbuf_column(PIXBUF_COL)

        self.fileview.enable_model_drag_source(
            gtk.gdk.BUTTON1_MASK,
            URI_TARGETS,
            gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE )
        self.fileview.enable_model_drag_dest(
            URI_TARGETS,
            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE )
        self.fileview.connect('drag-data-get', self.on_drag_data_get)
        self.fileview.connect('drag-data-received', self.on_drag_data_received)

        self.add(ScrolledWindow(self.fileview))

        self.buttonbox = gtk.VBox()
        self.pack_end(self.buttonbox, False)

        open_folder_button = IconButton(gtk.STOCK_OPEN, relief=False)
        open_folder_button.connect('clicked', self.on_open_folder)
        self.buttonbox.pack_start(open_folder_button, False)

        refresh_button = IconButton(gtk.STOCK_REFRESH, relief=False)
        refresh_button.connect('clicked', lambda o: self.on_refresh_button())
        self.buttonbox.pack_start(refresh_button, False)

        zoomin = IconButton(gtk.STOCK_ZOOM_IN, relief=False)
        zoomout = IconButton(gtk.STOCK_ZOOM_OUT, relief=False)
        zoomin.connect('clicked', lambda o: self.zoom_in())
        zoomout.connect('clicked', lambda o: self.zoom_out())
        self.buttonbox.pack_end(zoomout, False)
        self.buttonbox.pack_end(zoomin, False)
        self.fileview.connect('button-press-event', self.on_button_press_event)
        self.fileview.connect('item-activated', self.on_item_activated)
        self.zoomin_button = zoomin
        self.zoomout_button = zoomout

        if gtk.gtk_version >= (2, 12):
            # custom tooltip
            self.fileview.props.has_tooltip = True
            self.fileview.connect("query-tooltip", self.query_tooltip_icon_view_cb)

        # Store colors
        self._senstive_color = None
        self._insenstive_color = None

        def _init_base_color(*a):
            # This is handled on expose event, because style does not
            # yet reflect theming on construction
            if self._senstive_color is None:
                self._senstive_color = self.fileview.style.base[gtk.STATE_NORMAL]
                self._insenstive_color = self.fileview.style.base[gtk.STATE_INSENSITIVE]

            self._update_state()

        self.connect('expose-event', _init_base_color)
Example #12
0
class ServerWindow(gtk.Window):
    def __init__(self, notebookinfo=None, port=8080, public=True, **opts):
        '''Constructor
		@param notebookinfo: the notebook location
		@param port: the http port to serve on
		@param public: allow connections to the server from other
		computers - if C{False} can only connect from localhost
		@param opts: options for L{WWWInterface.__init__()}
		'''
        gtk.Window.__init__(self)
        self.set_title('Zim - ' + _('Web Server'))  # T: Window title
        self.set_border_width(10)
        self.connect('destroy', lambda a: gtk.main_quit())
        self.interface_opts = opts
        self.httpd = None
        self._source_id = None

        # Widgets
        self.status_label = gtk.Label()
        self.status_label.set_markup('<i>' + _('Server not started') + '</i>')
        # T: Status in web server gui
        self.start_button = IconButton('gtk-media-play')
        self.start_button.connect('clicked', lambda o: self.start())
        self.stop_button = IconButton('gtk-media-stop')
        self.stop_button.connect('clicked', lambda o: self.stop())
        self.stop_button.set_sensitive(False)

        if gtk.gtk_version >= (2, 10):
            self.link_button = gtk.LinkButton('')
            self.link_button.set_sensitive(False)
            gtk.link_button_set_uri_hook(lambda o, url: webbrowser.open(url))
        else:
            self.link_button = None

        self.notebookcombobox = NotebookComboBox(current=notebookinfo)
        self.open_button = IconButton('gtk-index')
        self.open_button.connect('clicked',
                                 lambda *a: NotebookDialog(self).run())

        self.portentry = gtk.SpinButton()
        self.portentry.set_numeric(True)
        self.portentry.set_range(80, 10000)
        self.portentry.set_increments(1, 80)
        self.portentry.set_value(port)

        self.public_checkbox = gtk.CheckButton(label=_('Allow public access'))
        # T: Checkbox in web server gui
        self.public_checkbox.set_active(public)

        # Build the interface
        vbox = gtk.VBox()
        self.add(vbox)

        hbox = gtk.HBox(spacing=12)
        hbox.pack_start(self.start_button, False)
        hbox.pack_start(self.stop_button, False)
        hbox.pack_start(self.status_label, False)
        vbox.add(hbox)

        table = input_table_factory((
            (_('Notebook'), self.notebookcombobox, self.open_button),
            # T: Field in web server gui
            (_('Port'), self.portentry),
            # T: Field in web server gui for HTTP port (e.g. port 80)
            self.public_checkbox))
        vbox.add(table)

        if self.link_button:
            hbox = gtk.HBox()
            hbox.pack_end(self.link_button, False)
            vbox.add(hbox)

    def open_notebook(self, notebook):
        '''Sets the notebook in the combobox

		This method is called by the NotebookDialog when a notebook is opened.
		'''
        self.notebookcombobox.set_notebook(notebook)

    def start(self):
        # Start server
        try:
            uri = self.notebookcombobox.get_notebook()
            if uri:
                notebook, x = build_notebook(NotebookInfo(uri))
                if not notebook:
                    return
            else:
                return

            port = int(self.portentry.get_value())
            public = self.public_checkbox.get_active()
            self.httpd = make_server(notebook, port, public,
                                     **self.interface_opts)
            if sys.platform == 'win32':
                # glib io watch conflicts with socket use on windows..
                # idle handler uses a bit to much CPU for my taste,
                # timeout every 0.5 sec is better
                self.httpd.timeout = 0.1  # 100 ms
                self._source_id = glib.timeout_add(500, self.do_serve_on_poll)
            else:
                self.httpd.timeout = 3  # if no response after 3 sec, drop it
                self._source_id = glib.io_add_watch(
                    self.httpd.fileno(),
                    glib.IO_IN | glib.IO_OUT | glib.IO_ERR | glib.IO_HUP
                    | glib.IO_PRI,  # any event..
                    self.do_serve_on_io)
            logger.info("Serving HTTP on %s port %i...",
                        self.httpd.server_name, self.httpd.server_port)
        except Exception, error:
            ErrorDialog(self, error).run()
            return

        # Update UI
        self.notebookcombobox.set_sensitive(False)
        self.portentry.set_sensitive(False)
        self.public_checkbox.set_sensitive(False)
        self.open_button.set_sensitive(False)
        self.start_button.set_sensitive(False)
        self.stop_button.set_sensitive(True)

        self.status_label.set_markup('<i>' + _('Server started') + '</i>')
        # T: Status in web server gui
        #if self.public_checkbox.get_active():
        #	url = 'http://%s:%i' % (self.httpd.server_name, self.httpd.server_port)
        #else:
        #	url = 'http://localhost:%i' % self.httpd.server_port
        url = 'http://localhost:%i' % self.httpd.server_port
        if self.link_button:
            self.link_button.set_uri(url)
            self.link_button.set_label(url)
            self.link_button.set_sensitive(True)
Example #13
0
    def __init__(self, notebookinfo=None, port=8080, public=True, **opts):
        '''Constructor
		@param notebookinfo: the notebook location
		@param port: the http port to serve on
		@param public: allow connections to the server from other
		computers - if C{False} can only connect from localhost
		@param opts: options for L{WWWInterface.__init__()}
		'''
        GObject.GObject.__init__(self)
        self.set_title('Zim - ' + _('Web Server'))  # T: Window title
        self.set_border_width(10)
        self.interface_opts = opts
        self.httpd = None
        self._source_id = None

        # Widgets
        self.status_label = Gtk.Label()
        self.status_label.set_markup('<i>' + _('Server not started') + '</i>')
        # T: Status in web server gui
        self.start_button = IconButton('gtk-media-play')
        self.start_button.connect('clicked', lambda o: self.start())
        self.stop_button = IconButton('gtk-media-stop')
        self.stop_button.connect('clicked', lambda o: self.stop())
        self.stop_button.set_sensitive(False)

        self.link_button = Gtk.LinkButton('')
        self.link_button.set_sensitive(False)

        self.notebookcombobox = NotebookComboBox(current=notebookinfo)
        self.open_button = IconButton('gtk-index')
        self.open_button.connect('clicked',
                                 lambda *a: NotebookDialog(self).run())

        self.portentry = Gtk.SpinButton()
        self.portentry.set_numeric(True)
        self.portentry.set_range(80, 10000)
        self.portentry.set_increments(1, 80)
        self.portentry.set_value(port)

        self.public_checkbox = Gtk.CheckButton.new_with_mnemonic(
            _('Allow public access'))
        # T: Checkbox in web server gui
        self.public_checkbox.set_active(public)

        self.templatecombobox = Gtk.ComboBoxText.new()
        template_names = [name for name, _ in list_templates('html')]
        for name in template_names:
            self.templatecombobox.append_text(name)
        self.templatecombobox.set_active(template_names.index('Default'))

        self.auth_checkbox = Gtk.CheckButton.new_with_mnemonic(
            _('Require authentication'))
        # T: checkbox in dialog for starting webserver
        self.username_input = InputEntry()
        self.password_input = InputEntry()
        self.password_input.set_visibility(False)

        # Build the interface
        vbox = Gtk.VBox()
        self.add(vbox)

        hbox = Gtk.HBox(spacing=12)
        hbox.pack_start(self.start_button, False, True, 0)
        hbox.pack_start(self.stop_button, False, True, 0)
        hbox.pack_start(self.status_label, False, True, 0)
        vbox.pack_start(hbox, False, False, 0)

        table = input_table_factory((
            (_('Notebook'), self.notebookcombobox, self.open_button),
            # T: Field in web server gui
            (_('Port'), self.portentry),
            # T: Field in web server gui for HTTP port (e.g. port 80)
            (_('Template'), self.templatecombobox),
            # T: Field in web server gui for webpage template
            self.public_checkbox,
            self.auth_checkbox,
            (_('Username'), self.username_input),
            # T: Field in web server gui
            (_('Password'), self.password_input)
            # T: Field in web server gui
        ))
        vbox.pack_start(table, False, False, 0)

        if self.link_button:
            hbox = Gtk.HBox()
            hbox.pack_end(self.link_button, False, True, 0)
            vbox.pack_start(hbox, False, False, 0)
Example #14
0
class ServerWindow(Gtk.Window):
    def __init__(self, notebookinfo=None, port=8080, public=True, **opts):
        '''Constructor
		@param notebookinfo: the notebook location
		@param port: the http port to serve on
		@param public: allow connections to the server from other
		computers - if C{False} can only connect from localhost
		@param opts: options for L{WWWInterface.__init__()}
		'''
        GObject.GObject.__init__(self)
        self.set_title('Zim - ' + _('Web Server'))  # T: Window title
        self.set_border_width(10)
        self.interface_opts = opts
        self.httpd = None
        self._source_id = None

        # Widgets
        self.status_label = Gtk.Label()
        self.status_label.set_markup('<i>' + _('Server not started') + '</i>')
        # T: Status in web server gui
        self.start_button = IconButton('gtk-media-play')
        self.start_button.connect('clicked', lambda o: self.start())
        self.stop_button = IconButton('gtk-media-stop')
        self.stop_button.connect('clicked', lambda o: self.stop())
        self.stop_button.set_sensitive(False)

        self.link_button = Gtk.LinkButton('')
        self.link_button.set_sensitive(False)

        self.notebookcombobox = NotebookComboBox(current=notebookinfo)
        self.open_button = IconButton('gtk-index')
        self.open_button.connect('clicked',
                                 lambda *a: NotebookDialog(self).run())

        self.portentry = Gtk.SpinButton()
        self.portentry.set_numeric(True)
        self.portentry.set_range(80, 10000)
        self.portentry.set_increments(1, 80)
        self.portentry.set_value(port)

        self.public_checkbox = Gtk.CheckButton.new_with_mnemonic(
            _('Allow public access'))
        # T: Checkbox in web server gui
        self.public_checkbox.set_active(public)

        self.templatecombobox = Gtk.ComboBoxText.new()
        template_names = [name for name, _ in list_templates('html')]
        for name in template_names:
            self.templatecombobox.append_text(name)
        self.templatecombobox.set_active(template_names.index('Default'))

        self.auth_checkbox = Gtk.CheckButton.new_with_mnemonic(
            _('Require authentication'))
        # T: checkbox in dialog for starting webserver
        self.username_input = InputEntry()
        self.password_input = InputEntry()
        self.password_input.set_visibility(False)

        # Build the interface
        vbox = Gtk.VBox()
        self.add(vbox)

        hbox = Gtk.HBox(spacing=12)
        hbox.pack_start(self.start_button, False, True, 0)
        hbox.pack_start(self.stop_button, False, True, 0)
        hbox.pack_start(self.status_label, False, True, 0)
        vbox.pack_start(hbox, False, False, 0)

        table = input_table_factory((
            (_('Notebook'), self.notebookcombobox, self.open_button),
            # T: Field in web server gui
            (_('Port'), self.portentry),
            # T: Field in web server gui for HTTP port (e.g. port 80)
            (_('Template'), self.templatecombobox),
            # T: Field in web server gui for webpage template
            self.public_checkbox,
            self.auth_checkbox,
            (_('Username'), self.username_input),
            # T: Field in web server gui
            (_('Password'), self.password_input)
            # T: Field in web server gui
        ))
        vbox.pack_start(table, False, False, 0)

        if self.link_button:
            hbox = Gtk.HBox()
            hbox.pack_end(self.link_button, False, True, 0)
            vbox.pack_start(hbox, False, False, 0)

    def open_notebook(self, notebook):
        '''Sets the notebook in the combobox

		This method is called by the NotebookDialog when a notebook is opened.
		'''
        self.notebookcombobox.set_notebook(notebook)

    def start(self):
        # Start server
        try:
            uri = self.notebookcombobox.get_notebook()
            if uri:
                notebook, x = build_notebook(NotebookInfo(uri))
                if not notebook:
                    return
            else:
                return

            if not notebook.index.is_uptodate:
                for info in notebook.index.update_iter():
                    #logger.info('Indexing %s', info)
                    pass  # TODO meaningful info for above message

            port = int(self.portentry.get_value())
            public = self.public_checkbox.get_active()
            self.interface_opts[
                'template'] = self.templatecombobox.get_active_text()

            require_auth = self.auth_checkbox.get_active()
            auth_creds = None
            if require_auth:
                auth_creds = (self.username_input.get_text(),
                              self.password_input.get_text())
            self.httpd = make_server(notebook,
                                     port,
                                     public,
                                     auth_creds=auth_creds,
                                     **self.interface_opts)

            if sys.platform == 'win32':
                # GObject io watch conflicts with socket use on windows..
                # idle handler uses a bit to much CPU for my taste,
                # timeout every 0.5 sec is better
                self.httpd.timeout = 0.1  # 100 ms
                self._source_id = GObject.timeout_add(500,
                                                      self.do_serve_on_poll)
            else:
                self.httpd.timeout = 3  # if no response after 3 sec, drop it
                self._source_id = GObject.io_add_watch(
                    self.httpd.fileno(),
                    GObject.IO_IN | GObject.IO_OUT | GObject.IO_ERR
                    | GObject.IO_HUP | GObject.IO_PRI,  # any event..
                    self.do_serve_on_io)
            logger.info("Serving HTTP on %s port %i...",
                        self.httpd.server_name, self.httpd.server_port)
        except Exception as error:
            ErrorDialog(self, error).run()
            return

        # Update UI
        self.notebookcombobox.set_sensitive(False)
        self.portentry.set_sensitive(False)
        self.public_checkbox.set_sensitive(False)
        self.templatecombobox.set_sensitive(False)
        self.open_button.set_sensitive(False)
        self.start_button.set_sensitive(False)
        self.stop_button.set_sensitive(True)
        self.auth_checkbox.set_sensitive(False)
        self.username_input.set_sensitive(False)
        self.password_input.set_sensitive(False)

        self.status_label.set_markup('<i>' + _('Server started') + '</i>')
        # T: Status in web server gui
        #if self.public_checkbox.get_active():
        #	url = 'http://%s:%i' % (self.httpd.server_name, self.httpd.server_port)
        #else:
        #	url = 'http://localhost:%i' % self.httpd.server_port
        url = 'http://localhost:%i' % self.httpd.server_port
        if self.link_button:
            self.link_button.set_uri(url)
            self.link_button.set_label(url)
            self.link_button.set_sensitive(True)

    def do_serve_on_io(self, fd, event):
        try:
            if event & GObject.IO_HUP:
                self.stop()
                raise Exception('Socket disconnected')
            else:
                self.httpd.handle_request()
        except:
            logger.exception('Exception while handling IO request:')

        return True  # keep event running

    def do_serve_on_poll(self):
        self.httpd.handle_request()
        return True  # keep event running

    def stop(self):
        # Stop server
        logger.debug('Stop server')
        if self._source_id is not None:
            GObject.source_remove(self._source_id)
            self._source_id = None

        if self.httpd:
            self.httpd.socket.close()
            # There is also a httpd.server_close(), but undocumented (!?)
            self.httpd = None

        # Update UI
        self.status_label.set_markup('<i>' + _('Server stopped') + '</i>')
        # T: Status in web server gui
        if self.link_button:
            self.link_button.set_sensitive(False)
        self.notebookcombobox.set_sensitive(True)
        self.portentry.set_sensitive(True)
        self.public_checkbox.set_sensitive(True)
        self.templatecombobox.set_sensitive(True)
        self.open_button.set_sensitive(True)
        self.stop_button.set_sensitive(False)
        self.start_button.set_sensitive(True)
        self.auth_checkbox.set_sensitive(True)
        self.username_input.set_sensitive(True)
        self.password_input.set_sensitive(True)
Example #15
0
    def __init__(self, extension, opener, preferences):
        GObject.GObject.__init__(self)
        self.extension = extension  # XXX
        self.opener = opener
        self.uistate = extension.uistate
        self.preferences = preferences
        self._close_button = None

        self.iconview = FileBrowserIconView(opener, self.icon_size)
        self.add(ScrolledWindow(self.iconview, shadow=Gtk.ShadowType.NONE))

        self.on_preferences_changed()
        self.preferences.connect('changed', self.on_preferences_changed)

        self.buttonbox = Gtk.VBox()
        self.pack_end(self.buttonbox, False, True, 0)

        open_folder_button = IconButton(Gtk.STOCK_OPEN, relief=False)
        open_folder_button.connect('clicked', self.on_open_folder)
        self.buttonbox.pack_start(open_folder_button, False, True, 0)

        refresh_button = IconButton(Gtk.STOCK_REFRESH, relief=False)
        refresh_button.connect('clicked', lambda o: self.on_refresh_button())
        self.buttonbox.pack_start(refresh_button, False, True, 0)

        zoomin = IconButton(Gtk.STOCK_ZOOM_IN, relief=False)
        zoomout = IconButton(Gtk.STOCK_ZOOM_OUT, relief=False)
        zoomin.connect('clicked', lambda o: self.on_zoom_in())
        zoomout.connect('clicked', lambda o: self.on_zoom_out())
        self.buttonbox.pack_end(zoomout, False, True, 0)
        self.buttonbox.pack_end(zoomin, False, True, 0)
        self.zoomin_button = zoomin
        self.zoomout_button = zoomout

        self.set_icon_size(self.icon_size)

        self.iconview.connect('folder-changed', lambda o: self.update_title())
Example #16
0
File: server.py Project: gdw2/zim
class ServerWindow(gtk.Window):

	def __init__(self, notebookinfo=None, port=8080, public=True, **opts):
		'''Constructor
		@param notebookinfo: the notebook location
		@param port: the http port to serve on
		@param public: allow connections to the server from other
		computers - if C{False} can only connect from localhost
		@param opts: options for L{WWWInterface.__init__()}
		'''
		gtk.Window.__init__(self)
		self.set_title('Zim - ' + _('Web Server')) # T: Window title
		self.set_border_width(10)
		self.connect('destroy', lambda a: gtk.main_quit())
		self.interface_opts = opts
		self.httpd = None
		self._source_id = None

		# Widgets
		self.status_label = gtk.Label()
		self.status_label.set_markup('<i>'+_('Server not started')+'</i>')
			# T: Status in web server gui
		self.start_button = IconButton('gtk-media-play')
		self.start_button.connect('clicked', lambda o: self.start())
		self.stop_button = IconButton('gtk-media-stop')
		self.stop_button.connect('clicked', lambda o: self.stop())
		self.stop_button.set_sensitive(False)

		if gtk.gtk_version >= (2, 10):
			self.link_button = gtk.LinkButton('')
			self.link_button.set_sensitive(False)
			gtk.link_button_set_uri_hook(lambda o, url: webbrowser.open(url))
		else:
			self.link_button = None

		self.notebookcombobox = NotebookComboBox(current=notebookinfo)
		self.open_button = IconButton('gtk-index')
		self.open_button.connect('clicked', lambda *a: NotebookDialog(self).run())

		self.portentry = gtk.SpinButton()
		self.portentry.set_numeric(True)
		self.portentry.set_range(80, 10000)
		self.portentry.set_increments(1, 80)
		self.portentry.set_value(port)

		self.public_checkbox = gtk.CheckButton(label=_('Allow public access'))
			# T: Checkbox in web server gui
		self.public_checkbox.set_active(public)


		# Build the interface
		vbox = gtk.VBox()
		self.add(vbox)

		hbox = gtk.HBox(spacing=12)
		hbox.pack_start(self.start_button, False)
		hbox.pack_start(self.stop_button, False)
		hbox.pack_start(self.status_label, False)
		vbox.add(hbox)

		table = input_table_factory((
			(_('Notebook'), self.notebookcombobox, self.open_button),
				# T: Field in web server gui
			(_('Port'), self.portentry),
				# T: Field in web server gui for HTTP port (e.g. port 80)
			self.public_checkbox
		))
		vbox.add(table)

		if self.link_button:
			hbox = gtk.HBox()
			hbox.pack_end(self.link_button, False)
			vbox.add(hbox)


	def open_notebook(self, notebook):
		'''Sets the notebook in the combobox

		This method is called by the NotebookDialog when a notebook is opened.
		'''
		self.notebookcombobox.set_notebook(notebook)

	def start(self):
		# Start server
		try:
			uri = self.notebookcombobox.get_notebook()
			if uri:
				notebook, x = build_notebook(NotebookInfo(uri))
				if not notebook:
					return
			else:
				return

			port = int(self.portentry.get_value())
			public = self.public_checkbox.get_active()
			self.httpd = make_server(notebook, port, public, **self.interface_opts)
			if sys.platform == 'win32':
				# glib io watch conflicts with socket use on windows..
				# idle handler uses a bit to much CPU for my taste,
				# timeout every 0.5 sec is better
				self.httpd.timeout = 0.1 # 100 ms
				self._source_id = glib.timeout_add(500, self.do_serve_on_poll)
			else:
				self.httpd.timeout = 3 # if no response after 3 sec, drop it
				self._source_id = glib.io_add_watch(
					self.httpd.fileno(),
					glib.IO_IN | glib.IO_OUT | glib.IO_ERR | glib.IO_HUP | glib.IO_PRI, # any event..
					self.do_serve_on_io
				)
			logger.info("Serving HTTP on %s port %i...", self.httpd.server_name, self.httpd.server_port)
		except Exception, error:
			ErrorDialog(self, error).run()
			return

		# Update UI
		self.notebookcombobox.set_sensitive(False)
		self.portentry.set_sensitive(False)
		self.public_checkbox.set_sensitive(False)
		self.open_button.set_sensitive(False)
		self.start_button.set_sensitive(False)
		self.stop_button.set_sensitive(True)

		self.status_label.set_markup('<i>'+_('Server started')+'</i>')
			# T: Status in web server gui
		#if self.public_checkbox.get_active():
		#	url = 'http://%s:%i' % (self.httpd.server_name, self.httpd.server_port)
		#else:
		#	url = 'http://localhost:%i' % self.httpd.server_port
		url = 'http://localhost:%i' % self.httpd.server_port
		if self.link_button:
			self.link_button.set_uri(url)
			self.link_button.set_label(url)
			self.link_button.set_sensitive(True)
Example #17
0
File: server.py Project: gdw2/zim
	def __init__(self, notebookinfo=None, port=8080, public=True, **opts):
		'''Constructor
		@param notebookinfo: the notebook location
		@param port: the http port to serve on
		@param public: allow connections to the server from other
		computers - if C{False} can only connect from localhost
		@param opts: options for L{WWWInterface.__init__()}
		'''
		gtk.Window.__init__(self)
		self.set_title('Zim - ' + _('Web Server')) # T: Window title
		self.set_border_width(10)
		self.connect('destroy', lambda a: gtk.main_quit())
		self.interface_opts = opts
		self.httpd = None
		self._source_id = None

		# Widgets
		self.status_label = gtk.Label()
		self.status_label.set_markup('<i>'+_('Server not started')+'</i>')
			# T: Status in web server gui
		self.start_button = IconButton('gtk-media-play')
		self.start_button.connect('clicked', lambda o: self.start())
		self.stop_button = IconButton('gtk-media-stop')
		self.stop_button.connect('clicked', lambda o: self.stop())
		self.stop_button.set_sensitive(False)

		if gtk.gtk_version >= (2, 10):
			self.link_button = gtk.LinkButton('')
			self.link_button.set_sensitive(False)
			gtk.link_button_set_uri_hook(lambda o, url: webbrowser.open(url))
		else:
			self.link_button = None

		self.notebookcombobox = NotebookComboBox(current=notebookinfo)
		self.open_button = IconButton('gtk-index')
		self.open_button.connect('clicked', lambda *a: NotebookDialog(self).run())

		self.portentry = gtk.SpinButton()
		self.portentry.set_numeric(True)
		self.portentry.set_range(80, 10000)
		self.portentry.set_increments(1, 80)
		self.portentry.set_value(port)

		self.public_checkbox = gtk.CheckButton(label=_('Allow public access'))
			# T: Checkbox in web server gui
		self.public_checkbox.set_active(public)


		# Build the interface
		vbox = gtk.VBox()
		self.add(vbox)

		hbox = gtk.HBox(spacing=12)
		hbox.pack_start(self.start_button, False)
		hbox.pack_start(self.stop_button, False)
		hbox.pack_start(self.status_label, False)
		vbox.add(hbox)

		table = input_table_factory((
			(_('Notebook'), self.notebookcombobox, self.open_button),
				# T: Field in web server gui
			(_('Port'), self.portentry),
				# T: Field in web server gui for HTTP port (e.g. port 80)
			self.public_checkbox
		))
		vbox.add(table)

		if self.link_button:
			hbox = gtk.HBox()
			hbox.pack_end(self.link_button, False)
			vbox.add(hbox)
Example #18
0
	def __init__(self, server):
		'''Constructor needs a Server object to control'''
		gtk.Window.__init__(self)
		self.set_icon_from_file(data_file('zim.png').path)
			# TODO new icon for WWW frontend
		self.set_border_width(10)
		self.connect('destroy', lambda a: gtk.main_quit())

		self.server = server
		self.server.connect_after('started', self.do_server_started)
		self.server.connect_after('stopped', self.do_server_stopped)

		def _start(*a):
			self.server.set_notebook(
				self.notebookcombobox.get_notebook() )
			self.server.start()

		def _stop(*a): self.server.stop()

		# Build the interface
		vbox = gtk.VBox()
		self.add(vbox)

		# first some art work
		#~ path = data_file('globe_banner_small.png').path
		#~ image = gtk.Image()
		#~ image.set_from_file(path) # new_from_file not in 2.6
		#~ align = gtk.Alignment(0,0.5, 0,0)
		#~ align.add(image)
		#~ vbox.add(align)

		# Table with status
		table = gtk.Table(4, 2, False)
		table.set_col_spacings(12)
		table.set_row_spacings(5)
		hbox = gtk.HBox()
		hbox.pack_start(table, False)
		vbox.pack_start(hbox, False)

		self.status_icon = gtk.image_new_from_stock(*stock_stopped)
		table.attach(self.status_icon, 0,2, 0,2)
		self.status_label = gtk.Label()
		self.status_label.set_markup('<i>'+_('Server not started')+'</i>')
			# T: Status in web server gui
		table.attach(self.status_label, 4,5, 0,1)
		self.link_button = gtk.LinkButton('') # FIXME since 2.10
		self.link_button.set_sensitive(False)
		gtk.link_button_set_uri_hook(lambda o, url: webbrowser.open(url))
		table.attach(self.link_button, 4,5, 1,2)

		start_button = IconButton('gtk-media-play')
		start_button.connect('clicked', _start)
		table.attach(start_button, 2,3, 0,1)
		stop_button = IconButton('gtk-media-stop')
		stop_button.connect('clicked', _stop)
		table.attach(stop_button, 3,4, 0,1)

		# Table with server properties
		table = gtk.Table(3, 3, False)
		table.set_col_spacings(12)
		table.set_row_spacings(5)
		vbox.add(table)

		table.attach(gtk.Label(_('Notebook')+': '), 0,1, 0,1)
			# T: Field in web server gui
		self.notebookcombobox = NotebookComboBox(current=server.interface.notebook)
		self.notebookcombobox.connect('changed', _stop)
		table.attach(self.notebookcombobox, 1,2, 0,1)

		open_button = IconButton('gtk-index')
		open_button.connect('clicked', lambda *a: NotebookDialog(self).run())
		table.attach(open_button, 2,3, 0,1)

		table.attach(gtk.Label(_('Port')+': '), 0,1, 1,2)
			# T: Field in web server gui for HTTLP port (e.g. port 80)
		self.portentry = gtk.SpinButton()
		self.portentry.set_numeric(True)
		self.portentry.set_range(80, 10000)
		self.portentry.set_increments(1, 80)
		self.portentry.set_value(self.server.port)
		self.portentry.connect('value-changed', _stop)
		self.portentry.connect('value-changed',
			lambda o: self.server.set_port(self.portentry.get_value_as_int()))
		table.attach(self.portentry, 1,2, 1,2)
Example #19
0
    def __init__(self, notebookinfo=None, port=8080, public=True, **opts):
        '''Constructor
		@param notebookinfo: the notebook location
		@param port: the http port to serve on
		@param public: allow connections to the server from other
		computers - if C{False} can only connect from localhost
		@param opts: options for L{WWWInterface.__init__()}
		'''
        gtk.Window.__init__(self)
        self.set_title('Zim - ' + _('Web Server'))  # T: Window title
        self.set_border_width(10)
        self.connect('destroy', lambda a: gtk.main_quit())
        self.interface_opts = opts
        self.httpd = None
        self._source_id = None

        # Widgets
        self.status_label = gtk.Label()
        self.status_label.set_markup('<i>' + _('Server not started') + '</i>')
        # T: Status in web server gui
        self.start_button = IconButton('gtk-media-play')
        self.start_button.connect('clicked', lambda o: self.start())
        self.stop_button = IconButton('gtk-media-stop')
        self.stop_button.connect('clicked', lambda o: self.stop())
        self.stop_button.set_sensitive(False)

        if gtk.gtk_version >= (2, 10):
            self.link_button = gtk.LinkButton('')
            self.link_button.set_sensitive(False)
            gtk.link_button_set_uri_hook(lambda o, url: webbrowser.open(url))
        else:
            self.link_button = None

        self.notebookcombobox = NotebookComboBox(current=notebookinfo)
        self.open_button = IconButton('gtk-index')
        self.open_button.connect('clicked',
                                 lambda *a: NotebookDialog(self).run())

        self.portentry = gtk.SpinButton()
        self.portentry.set_numeric(True)
        self.portentry.set_range(80, 10000)
        self.portentry.set_increments(1, 80)
        self.portentry.set_value(port)

        self.public_checkbox = gtk.CheckButton(label=_('Allow public access'))
        # T: Checkbox in web server gui
        self.public_checkbox.set_active(public)

        # Build the interface
        vbox = gtk.VBox()
        self.add(vbox)

        hbox = gtk.HBox(spacing=12)
        hbox.pack_start(self.start_button, False)
        hbox.pack_start(self.stop_button, False)
        hbox.pack_start(self.status_label, False)
        vbox.add(hbox)

        table = input_table_factory((
            (_('Notebook'), self.notebookcombobox, self.open_button),
            # T: Field in web server gui
            (_('Port'), self.portentry),
            # T: Field in web server gui for HTTP port (e.g. port 80)
            self.public_checkbox))
        vbox.add(table)

        if self.link_button:
            hbox = gtk.HBox()
            hbox.pack_end(self.link_button, False)
            vbox.add(hbox)
Example #20
0
    def __init__(self, extension, opener, preferences):
        gtk.HBox.__init__(self)
        self.page = None  # XXX
        self.extension = extension  # XXX
        self.opener = opener
        self.uistate = extension.uistate
        self.preferences = preferences
        self.dir = None
        self._active = True

        self.thumbman = ThumbnailManager(preferences)
        self.thumbman.connect('thumbnail-ready', self.on_thumbnail_ready)

        self.fileview = gtk.IconView()

        self.store = gtk.ListStore(str,
                                   gtk.gdk.Pixbuf)  # BASENAME_COL, PIXBUF_COL

        self.fileview = gtk.IconView(self.store)
        self.fileview.set_text_column(BASENAME_COL)
        self.fileview.set_pixbuf_column(PIXBUF_COL)

        self.fileview.enable_model_drag_source(
            gtk.gdk.BUTTON1_MASK, URI_TARGETS,
            gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
        self.fileview.enable_model_drag_dest(
            URI_TARGETS, gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
        self.fileview.connect('drag-data-get', self.on_drag_data_get)
        self.fileview.connect('drag-data-received', self.on_drag_data_received)

        self.add(ScrolledWindow(self.fileview))

        self.buttonbox = gtk.VBox()
        self.pack_end(self.buttonbox, False)

        open_folder_button = IconButton(gtk.STOCK_OPEN, relief=False)
        open_folder_button.connect('clicked', self.on_open_folder)
        self.buttonbox.pack_start(open_folder_button, False)

        refresh_button = IconButton(gtk.STOCK_REFRESH, relief=False)
        refresh_button.connect('clicked', lambda o: self.on_refresh_button())
        self.buttonbox.pack_start(refresh_button, False)

        zoomin = IconButton(gtk.STOCK_ZOOM_IN, relief=False)
        zoomout = IconButton(gtk.STOCK_ZOOM_OUT, relief=False)
        zoomin.connect('clicked', lambda o: self.zoom_in())
        zoomout.connect('clicked', lambda o: self.zoom_out())
        self.buttonbox.pack_end(zoomout, False)
        self.buttonbox.pack_end(zoomin, False)
        self.fileview.connect('button-press-event', self.on_button_press_event)
        self.fileview.connect('item-activated', self.on_item_activated)
        self.zoomin_button = zoomin
        self.zoomout_button = zoomout

        if gtk.gtk_version >= (2, 12) \
        and gtk.pygtk_version >= (2, 12):
            # custom tooltip
            self.fileview.props.has_tooltip = True
            self.fileview.connect("query-tooltip",
                                  self.query_tooltip_icon_view_cb)

        # Store colors
        self._senstive_color = None
        self._insenstive_color = None

        def _init_base_color(*a):
            # This is handled on expose event, because style does not
            # yet reflect theming on construction
            if self._senstive_color is None:
                self._senstive_color = self.fileview.style.base[
                    gtk.STATE_NORMAL]
                self._insenstive_color = self.fileview.style.base[
                    gtk.STATE_INSENSITIVE]

            self._update_state()

        self.connect('expose-event', _init_base_color)
Example #21
0
	def __init__(self, extension, opener, preferences):
		gtk.HBox.__init__(self)
		self.extension = extension # XXX
		self.opener = opener
		self.uistate = extension.uistate
		self.preferences = preferences

		use_thumbs = self.preferences.setdefault('use_thumbnails', True) # Hidden setting
		self.iconview = FileBrowserIconView(opener, self.icon_size, use_thumbs)
		self.add(ScrolledWindow(self.iconview, shadow=gtk.SHADOW_NONE))

		self.buttonbox = gtk.VBox()
		self.pack_end(self.buttonbox, False)

		open_folder_button = IconButton(gtk.STOCK_OPEN, relief=False)
		open_folder_button.connect('clicked', self.on_open_folder)
		self.buttonbox.pack_start(open_folder_button, False)

		refresh_button = IconButton(gtk.STOCK_REFRESH, relief=False)
		refresh_button.connect('clicked', lambda o: self.on_refresh_button())
		self.buttonbox.pack_start(refresh_button, False)

		zoomin = IconButton(gtk.STOCK_ZOOM_IN, relief=False)
		zoomout = IconButton(gtk.STOCK_ZOOM_OUT, relief=False)
		zoomin.connect('clicked', lambda o: self.on_zoom_in())
		zoomout.connect('clicked', lambda o: self.on_zoom_out())
		self.buttonbox.pack_end(zoomout, False)
		self.buttonbox.pack_end(zoomin, False)
		self.zoomin_button = zoomin
		self.zoomout_button = zoomout

		self.set_icon_size(self.icon_size)

		self.iconview.connect('folder-changed', lambda o: self.extension._refresh_statusbar())
Example #22
0
	def __init__(self, extension, opener, preferences):
		gtk.HBox.__init__(self)
		self.extension = extension # XXX
		self.opener = opener
		self.uistate = extension.uistate
		self.preferences = preferences

		use_thumbs = self.preferences.setdefault('use_thumbnails', True) # Hidden setting
		self.iconview = FileBrowserIconView(opener, self.icon_size, use_thumbs)
		self.add(ScrolledWindow(self.iconview, shadow=gtk.SHADOW_NONE))

		self.buttonbox = gtk.VBox()
		self.pack_end(self.buttonbox, False)

		open_folder_button = IconButton(gtk.STOCK_OPEN, relief=False)
		open_folder_button.connect('clicked', self.on_open_folder)
		self.buttonbox.pack_start(open_folder_button, False)

		refresh_button = IconButton(gtk.STOCK_REFRESH, relief=False)
		refresh_button.connect('clicked', lambda o: self.on_refresh_button())
		self.buttonbox.pack_start(refresh_button, False)

		zoomin = IconButton(gtk.STOCK_ZOOM_IN, relief=False)
		zoomout = IconButton(gtk.STOCK_ZOOM_OUT, relief=False)
		zoomin.connect('clicked', lambda o: self.on_zoom_in())
		zoomout.connect('clicked', lambda o: self.on_zoom_out())
		self.buttonbox.pack_end(zoomout, False)
		self.buttonbox.pack_end(zoomin, False)
		self.zoomin_button = zoomin
		self.zoomout_button = zoomout

		self.set_icon_size(self.icon_size)

		self.iconview.connect('folder-changed', lambda o: self.extension._refresh_statusbar())