Exemplo n.º 1
0
 def add_chooser(self, box):
     hbox_csv_export = gtk.HBox()
     box.pack_start(hbox_csv_export, False, True, 0)
     if hasattr(gtk, 'ComboBoxText'):
         self.saveas = gtk.ComboBoxText()
     else:
         self.saveas = gtk.combo_box_new_text()
     hbox_csv_export.pack_start(self.saveas, True, True, 0)
     self.saveas.append_text(_("Open"))
     self.saveas.append_text(_("Save"))
     self.saveas.set_active(0)
Exemplo n.º 2
0
    def __init__(self, name, listcontents):
        gtk.VBox.__init__(self, spacing=8)

        self.mod = None
        self.args = {}
        self.validators = {}

        self.combo = gtk.ComboBoxText()
        self.combo.connect('changed', self.changed_cb)
        for i in listcontents:
            self.combo.append_text(i)

        self.pack_start(gtk.Label(name), expand=False)
        self.pack_start(self.combo, expand=False)
Exemplo n.º 3
0
    def init_save_dialog(self):
        dialog = gtk.FileChooserDialog(_("Save..."), self.app.drawWindow,
                                       gtk.FILE_CHOOSER_ACTION_SAVE,
                                       (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                        gtk.STOCK_SAVE, gtk.RESPONSE_OK))
        self.save_dialog = dialog
        dialog.set_default_response(gtk.RESPONSE_OK)
        dialog.set_do_overwrite_confirmation(True)
        add_filters_to_dialog(self.file_filters, dialog)

        # Add widget for selecting save format
        box = gtk.HBox()
        label = gtk.Label(_('Format to save as:'))
        label.set_alignment(0.0, 0.0)
        combo = self.saveformat_combo = gtk.ComboBoxText()
        for name, ext, opt in self.saveformats:
            combo.append_text(name)
        combo.set_active(0)
        combo.connect('changed', self.selected_save_format_changed_cb)
        box.pack_start(label)
        box.pack_start(combo, expand=False)
        dialog.set_extra_widget(box)
        dialog.show_all()
Exemplo n.º 4
0
    def get_toolbar(self):
        toolbar = gtk.Toolbar()
        toolbar.set_style({
                'default': False,
                'both': gtk.TOOLBAR_BOTH,
                'text': gtk.TOOLBAR_TEXT,
                'icons': gtk.TOOLBAR_ICONS}[CONFIG['client.toolbar']])

        self.widget.pack_start(toolbar, expand=False, fill=True)

        for icon in ['bold', 'italic', 'underline']:
            button = gtk.ToggleToolButton('gtk-%s' % icon)
            button.connect('toggled', self.toggle_props, icon)
            toolbar.insert(button, -1)
            self.tag_widgets[icon] = button

        toolbar.insert(gtk.SeparatorToolItem(), -1)

        for name, options, active in [
                ('family', FAMILIES, FAMILIES.index('normal')),
                ('size', SIZES, SIZES.index('4')),
                ]:
            try:
                combobox = gtk.ComboBoxText()
            except AttributeError:
                combobox = gtk.combo_box_new_text()
            for option in options:
                combobox.append_text(option)
            combobox.set_active(active)
            combobox.set_focus_on_click(False)
            combobox.connect('changed', self.change_props, name)
            tool = gtk.ToolItem()
            tool.add(combobox)
            toolbar.insert(tool, -1)
            self.tag_widgets[name] = combobox

        toolbar.insert(gtk.SeparatorToolItem(), -1)

        button = None
        for icon in ['left', 'center', 'right', 'fill']:
            name = icon
            if icon == 'fill':
                name = 'justify'
            stock_id = 'gtk-justify-%s' % icon
            if hasattr(gtk.RadioToolButton, 'new_with_stock_from_widget'):
                button = gtk.RadioToolButton.new_with_stock_from_widget(
                    button, stock_id)
            else:
                button = gtk.RadioToolButton(button, stock_id)
            button.set_active(icon == 'left')
            button.connect('toggled', self.toggle_justification, name)
            toolbar.insert(button, -1)
            self.tag_widgets[name] = button

        toolbar.insert(gtk.SeparatorToolItem(), -1)

        for icon, label in [
                ('foreground', _('Foreground')),
                # TODO ('background', _('Background')),
                ]:
            button = gtk.ToolButton('tryton-text-%s' % icon)
            button.set_label(label)
            button.connect('clicked', self.toggle_color, icon)
            toolbar.insert(button, -1)
            self.tag_widgets[icon] = button

        return toolbar
Exemplo n.º 5
0
    def __init__(
        self,
        parent,
        deputies,
        groups,
        initial_cmd="",
        initial_cmd_id="",
        initial_deputy="",
        initial_group="",
        initial_auto_respawn=False,
        initial_stop_signal=DEFAULT_STOP_SIGNAL,
        initial_stop_time_allowed=DEFAULT_STOP_TIME_ALLOWED,
        is_add=True,
    ):
        # add command dialog
        gtk.Dialog.__init__(
            self,
            "Add/Modify Command",
            parent,
            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
            (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT, gtk.STOCK_CANCEL,
             gtk.RESPONSE_REJECT),
        )
        table = gtk.Table(7, 2)

        # deputy
        table.attach(gtk.Label("Deputy"), 0, 1, 0, 1, 0, 0)
        self.deputy_cb = gtk.combo_box_new_text()

        dep_ind = 0
        deputies.sort()
        for deputy in deputies:
            self.deputy_cb.append_text(deputy)
            if deputy == initial_deputy:
                self.deputy_cb.set_active(dep_ind)
            dep_ind += 1
        if self.deputy_cb.get_active() < 0 and len(deputies) > 0:
            self.deputy_cb.set_active(0)

        table.attach(self.deputy_cb, 1, 2, 0, 1)
        if not is_add:
            self.deputy_cb.set_sensitive(False)
        self.deputies = deputies

        # command id
        table.attach(gtk.Label("Id"), 0, 1, 1, 2, 0, 0)
        self.cmd_id_te = gtk.Entry()
        self.cmd_id_te.set_text(initial_cmd_id)
        self.cmd_id_te.set_width_chars(60)
        table.attach(self.cmd_id_te, 1, 2, 1, 2)
        self.cmd_id_te.connect("activate",
                               lambda e: self.response(gtk.RESPONSE_ACCEPT))
        if not is_add:
            self.cmd_id_te.set_sensitive(False)

        # command name
        table.attach(gtk.Label("Command"), 0, 1, 2, 3, 0, 0)
        self.name_te = gtk.Entry()
        self.name_te.set_text(initial_cmd)
        self.name_te.set_width_chars(60)
        table.attach(self.name_te, 1, 2, 2, 3)
        self.name_te.connect("activate",
                             lambda e: self.response(gtk.RESPONSE_ACCEPT))
        self.name_te.grab_focus()

        # group
        table.attach(gtk.Label("Group"), 0, 1, 3, 4, 0, 0)
        self.group_cbe = gtk.combo_box_entry_new_text()
        #        groups = groups[:]
        groups.sort()
        for group_name in groups:
            self.group_cbe.append_text(group_name)
        table.attach(self.group_cbe, 1, 2, 3, 4)
        self.group_cbe.child.set_text(initial_group)
        self.group_cbe.child.connect(
            "activate", lambda e: self.response(gtk.RESPONSE_ACCEPT))

        # auto respawn
        auto_restart_tt = "If the command terminates while running, should the deputy automatically restart it?"
        auto_restart_label = gtk.Label("Auto-restart")
        auto_restart_label.set_tooltip_text(auto_restart_tt)
        table.attach(auto_restart_label, 0, 1, 4, 5, 0, 0)
        self.auto_respawn_cb = gtk.CheckButton()
        self.auto_respawn_cb.set_active(initial_auto_respawn)
        if initial_auto_respawn < 0:
            self.auto_respawn_cb.set_inconsistent(True)
        self.auto_respawn_cb.connect("toggled", self.auto_respawn_cb_callback)
        self.auto_respawn_cb.set_tooltip_text(auto_restart_tt)
        table.attach(self.auto_respawn_cb, 1, 2, 4, 5)

        # stop signal
        stop_signal_tt = "When stopping a signal, what OS signal to initially send to request a clean exit"
        stop_signal_label = gtk.Label("Stop signal")
        stop_signal_label.set_tooltip_text(stop_signal_tt)
        table.attach(stop_signal_label, 0, 1, 5, 6, 0, 0)
        try:
            self.stop_signal_c = gtk.ComboBoxText()
        except AttributeError:
            self.stop_signal_c = gtk.combo_box_new_text()
        self.stop_signal_entries = [
            (signal.SIGINT, "SIGINT"),
            (signal.SIGTERM, "SIGTERM"),
            (signal.SIGKILL, "SIGKILL"),
        ]
        for i, entry in enumerate(self.stop_signal_entries):
            signum, signame = entry
            self.stop_signal_c.append_text(signame)
            if signum == initial_stop_signal:
                self.stop_signal_c.set_active(i)
        self.stop_signal_c.set_tooltip_text(stop_signal_tt)
        table.attach(self.stop_signal_c, 1, 2, 5, 6)

        # stop time allowed
        stop_time_allowed_tt = "When stopping a running command, how long to wait between sending the stop signal and a SIGKILL if the command doesn't stop."
        stop_time_allowed_label = gtk.Label("Time allowed when stopping")
        stop_time_allowed_label.set_tooltip_text(stop_time_allowed_tt)
        table.attach(stop_time_allowed_label, 0, 1, 6, 7, 0, 0)
        self.stop_time_allowed_sb = gtk.SpinButton()
        self.stop_time_allowed_sb.set_increments(1, 5)
        self.stop_time_allowed_sb.set_range(1, 999999)
        self.stop_time_allowed_sb.set_value(int(initial_stop_time_allowed))
        self.stop_time_allowed_sb.set_tooltip_text(stop_time_allowed_tt)
        table.attach(self.stop_time_allowed_sb, 1, 2, 6, 7)

        self.vbox.pack_start(table, False, False, 0)
        table.show_all()
Exemplo n.º 6
0
    def search_box(self, widget):
        def window_hide(window, *args):
            window.hide()
            self.search_entry.grab_focus()

        def key_press(widget, event):
            if event.keyval == gtk.keysyms.Escape:
                window_hide(widget)
                return True
            return False

        def search():
            self.search_window.hide()
            text = ''
            for label, entry in self.search_table.fields:
                if isinstance(entry, gtk.ComboBox):
                    value = quote(entry.get_active_text()) or None
                elif isinstance(entry, (Dates, Selection)):
                    value = entry.get_value()
                else:
                    value = quote(entry.get_text()) or None
                if value is not None:
                    text += quote(label) + ': ' + value + ' '
            self.set_text(text)
            self.do_search()
            # Store text after doing the search
            # because domain parser could simplify the text
            self.last_search_text = self.get_text()

        if not self.search_window:
            self.search_window = gtk.Window()
            self.search_window.set_transient_for(widget.get_toplevel())
            self.search_window.set_type_hint(
                gtk.gdk.WINDOW_TYPE_HINT_POPUP_MENU)
            self.search_window.set_destroy_with_parent(True)
            self.search_window.set_decorated(False)
            self.search_window.set_deletable(False)
            self.search_window.connect('delete-event', window_hide)
            self.search_window.connect('key-press-event', key_press)
            self.search_window.connect('focus-out-event', window_hide)

            def toggle_window_hide(combobox, shown):
                if combobox.props.popup_shown:
                    self.search_window.handler_block_by_func(window_hide)
                else:
                    self.search_window.handler_unblock_by_func(window_hide)

            vbox = gtk.VBox()
            fields = [
                f for f in self.screen.domain_parser.fields.itervalues()
                if f.get('searchable', True)
            ]
            self.search_table = gtk.Table(rows=len(fields), columns=2)
            self.search_table.set_homogeneous(False)
            self.search_table.set_border_width(5)
            self.search_table.set_row_spacings(2)
            self.search_table.set_col_spacings(2)

            # Fill table with fields
            self.search_table.fields = []
            for i, field in enumerate(fields):
                label = gtk.Label(field['string'])
                label.set_alignment(0.0, 0.0)
                self.search_table.attach(label,
                                         0,
                                         1,
                                         i,
                                         i + 1,
                                         yoptions=gtk.FILL)
                yoptions = False
                if field['type'] == 'boolean':
                    if hasattr(gtk, 'ComboBoxText'):
                        entry = gtk.ComboBoxText()
                    else:
                        entry = gtk.combo_box_new_text()
                    entry.connect('notify::popup-shown', toggle_window_hide)
                    entry.append_text('')
                    selections = (_('True'), _('False'))
                    for selection in selections:
                        entry.append_text(selection)
                elif field['type'] == 'selection':
                    selections = tuple(x[1] for x in field['selection'])
                    entry = Selection(selections)
                    yoptions = gtk.FILL | gtk.EXPAND
                elif field['type'] in ('date', 'datetime', 'time'):
                    date_format = self.screen.context.get('date_format', '%x')
                    if field['type'] == 'date':
                        entry = Dates(date_format)
                    elif field['type'] in ('datetime', 'time'):
                        time_format = PYSONDecoder({}).decode(field['format'])
                        if field['type'] == 'time':
                            entry = Times(time_format)
                        elif field['type'] == 'datetime':
                            entry = DateTimes(date_format, time_format)
                    entry.connect_activate(lambda *a: search())
                else:
                    entry = gtk.Entry()
                    entry.connect('activate', lambda *a: search())
                label.set_mnemonic_widget(entry)
                self.search_table.attach(entry,
                                         1,
                                         2,
                                         i,
                                         i + 1,
                                         yoptions=yoptions)
                self.search_table.fields.append((field['string'], entry))

            scrolled = gtk.ScrolledWindow()
            scrolled.add_with_viewport(self.search_table)
            scrolled.set_shadow_type(gtk.SHADOW_NONE)
            scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
            vbox.pack_start(scrolled, expand=True, fill=True)
            find_button = gtk.Button(_('Find'))
            find_button.connect('clicked', lambda *a: search())
            find_img = gtk.Image()
            find_img.set_from_stock('tryton-find', gtk.ICON_SIZE_SMALL_TOOLBAR)
            find_button.set_image(find_img)
            hbuttonbox = gtk.HButtonBox()
            hbuttonbox.set_spacing(5)
            hbuttonbox.pack_start(find_button)
            hbuttonbox.set_layout(gtk.BUTTONBOX_END)
            vbox.pack_start(hbuttonbox, expand=False, fill=True)
            self.search_window.add(vbox)
            vbox.show_all()

            new_size = map(
                sum,
                zip(self.search_table.size_request(), scrolled.size_request()))
            self.search_window.set_default_size(*new_size)

        parent = widget.get_toplevel()
        widget_x, widget_y = widget.translate_coordinates(parent, 0, 0)
        widget_allocation = widget.get_allocation()

        # Resize the window to not be out of the parent
        width, height = self.search_window.get_default_size()
        allocation = parent.get_allocation()
        delta_width = allocation.width - (widget_x + width)
        delta_height = allocation.height - (widget_y +
                                            widget_allocation.height + height)
        if delta_width < 0:
            width += delta_width
        if delta_height < 0:
            height += delta_height
        self.search_window.resize(width, height)

        # Move the window under the button
        if hasattr(widget.window, 'get_root_coords'):
            x, y = widget.window.get_root_coords(widget_allocation.x,
                                                 widget_allocation.y)
        else:
            x, y = widget.window.get_origin()
        self.search_window.move(x, y + widget_allocation.height)
        self.search_window.show()
        self.search_window.grab_focus()

        if self.last_search_text.strip() != self.get_text().strip():
            for label, entry in self.search_table.fields:
                if isinstance(entry, gtk.ComboBox):
                    entry.set_active(-1)
                elif isinstance(entry, Dates):
                    entry.set_values(None, None)
                elif isinstance(entry, Selection):
                    entry.treeview.get_selection().unselect_all()
                else:
                    entry.set_text('')
            if self.search_table.fields:
                self.search_table.fields[0][1].grab_focus()
Exemplo n.º 7
0
    def __init__(self, view, attrs):
        super(RichTextBox, self).__init__(view, attrs)
        self.text_buffer = gtk.TextBuffer()
        setup_tags(self.text_buffer)
        self.text_buffer.register_serialize_format(MIME, serialize, None)
        self.text_buffer.register_deserialize_format(MIME, deserialize, None)
        self.text_buffer.connect_after('insert-text', self.insert_text_style)
        self.textview.set_buffer(self.text_buffer)
        self.textview.connect_after('move-cursor', self.detect_style)
        self.textview.connect('button-release-event', self.detect_style)

        self.toolbar = gtk.Toolbar()
        self.toolbar.set_style({
            'default': False,
            'both': gtk.TOOLBAR_BOTH,
            'text': gtk.TOOLBAR_TEXT,
            'icons': gtk.TOOLBAR_ICONS
        }[CONFIG['client.toolbar']])

        self.widget.pack_start(self.toolbar, expand=False, fill=True)
        self.tag_widgets = {}
        self.tags = {}

        for icon in ['bold', 'italic', 'underline']:
            button = gtk.ToggleToolButton('gtk-%s' % icon)
            button.connect('toggled', self.toggle_props, icon)
            self.toolbar.insert(button, -1)
            self.tag_widgets[icon] = button

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        for name, options, active in [
            ('family', FAMILIES, FAMILIES.index('normal')),
            ('size', SIZES, SIZES.index('4')),
        ]:
            try:
                combobox = gtk.ComboBoxText()
            except AttributeError:
                combobox = gtk.combo_box_new_text()
            for option in options:
                combobox.append_text(option)
            combobox.set_active(active)
            combobox.set_focus_on_click(False)
            combobox.connect('changed', self.change_props, name)
            tool = gtk.ToolItem()
            tool.add(combobox)
            self.toolbar.insert(tool, -1)
            self.tag_widgets[name] = combobox

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        button = None
        for icon in ['left', 'center', 'right', 'fill']:
            name = icon
            if icon == 'fill':
                name = 'justify'
            button = gtk.RadioToolButton(button, 'gtk-justify-%s' % icon)
            button.set_active(icon == 'left')
            button.connect('toggled', self.toggle_justification, name)
            self.toolbar.insert(button, -1)
            self.tag_widgets[name] = button

        self.toolbar.insert(gtk.SeparatorToolItem(), -1)

        self.colors = {}
        for icon, label in [
            ('foreground', _('Foreground')),
                # TODO ('background', _('Background')),
        ]:
            button = gtk.ToolButton('tryton-text-%s' % icon)
            button.set_label(label)
            button.connect('clicked', self.toggle_color, icon)
            self.toolbar.insert(button, -1)
            self.tag_widgets[icon] = button
Exemplo n.º 8
0
    def __init__(self, *args, **kwargs):
        super(WinCSV, self).__init__(*args, **kwargs)

        self.dialog = gtk.Dialog(parent=self.parent,
                                 flags=gtk.DIALOG_DESTROY_WITH_PARENT)
        Main().add_window(self.dialog)
        self.dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        self.dialog.set_icon(TRYTON_ICON)
        self.dialog.connect('response', self.response)

        dialog_vbox = gtk.VBox()

        hbox_mapping = gtk.HBox(True)
        dialog_vbox.pack_start(hbox_mapping, True, True, 0)

        frame_fields = gtk.Frame()
        frame_fields.set_shadow_type(gtk.SHADOW_NONE)
        viewport_fields = gtk.Viewport()
        scrolledwindow_fields = gtk.ScrolledWindow()
        scrolledwindow_fields.set_policy(gtk.POLICY_AUTOMATIC,
                                         gtk.POLICY_AUTOMATIC)
        viewport_fields.add(scrolledwindow_fields)
        frame_fields.add(viewport_fields)
        label_all_fields = gtk.Label(_('<b>All fields</b>'))
        label_all_fields.set_use_markup(True)
        frame_fields.set_label_widget(label_all_fields)
        hbox_mapping.pack_start(frame_fields, True, True, 0)

        vbox_buttons = gtk.VBox(False, 10)
        vbox_buttons.set_border_width(5)
        hbox_mapping.pack_start(vbox_buttons, False, True, 0)

        button_add = gtk.Button(_('_Add'), stock=None, use_underline=True)
        button_add.set_alignment(0.0, 0.0)
        img_button = gtk.Image()
        img_button.set_from_stock('tryton-list-add', gtk.ICON_SIZE_BUTTON)
        button_add.set_image(img_button)
        button_add.set_always_show_image(True)
        button_add.connect_after('clicked', self.sig_sel)
        vbox_buttons.pack_start(button_add, False, False, 0)

        button_remove = gtk.Button(_('_Remove'),
                                   stock=None,
                                   use_underline=True)
        button_remove.set_alignment(0.0, 0.0)
        img_button = gtk.Image()
        img_button.set_from_stock('tryton-list-remove', gtk.ICON_SIZE_BUTTON)
        button_remove.set_image(img_button)
        button_remove.set_always_show_image(True)
        button_remove.connect_after('clicked', self.sig_unsel)
        vbox_buttons.pack_start(button_remove, False, False, 0)

        button_remove_all = gtk.Button(_('_Clear'),
                                       stock=None,
                                       use_underline=True)
        button_remove_all.set_alignment(0.0, 0.0)
        img_button = gtk.Image()
        img_button.set_from_stock('tryton-clear', gtk.ICON_SIZE_BUTTON)
        button_remove_all.set_image(img_button)
        button_remove_all.set_always_show_image(True)
        button_remove_all.connect_after('clicked', self.sig_unsel_all)
        vbox_buttons.pack_start(button_remove_all, False, False, 0)

        hseparator_buttons = gtk.HSeparator()
        vbox_buttons.pack_start(hseparator_buttons, False, False, 3)

        self.add_buttons(vbox_buttons)

        frame_fields_selected = gtk.Frame()
        frame_fields_selected.set_shadow_type(gtk.SHADOW_NONE)
        viewport_fields_selected = gtk.Viewport()
        scrolledwindow_fields_selected = gtk.ScrolledWindow()
        scrolledwindow_fields_selected.set_policy(gtk.POLICY_AUTOMATIC,
                                                  gtk.POLICY_AUTOMATIC)
        viewport_fields_selected.add(scrolledwindow_fields_selected)
        frame_fields_selected.add(viewport_fields_selected)
        label_fields_selected = gtk.Label(_('<b>Fields selected</b>'))
        label_fields_selected.set_use_markup(True)
        frame_fields_selected.set_label_widget(label_fields_selected)
        hbox_mapping.pack_start(frame_fields_selected, True, True, 0)

        frame_csv_param = gtk.Frame()
        frame_csv_param.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
        dialog_vbox.pack_start(frame_csv_param, False, True, 0)
        alignment_csv_param = gtk.Alignment(0.5, 0.5, 1, 1)
        alignment_csv_param.set_padding(7, 7, 7, 7)
        frame_csv_param.add(alignment_csv_param)

        vbox_csv_param = gtk.VBox()
        alignment_csv_param.add(vbox_csv_param)

        self.add_chooser(vbox_csv_param)

        expander_csv = gtk.Expander()
        vbox_csv_param.pack_start(expander_csv, False, True, 0)
        label_csv_param = gtk.Label(_('CSV Parameters'))
        expander_csv.set_label_widget(label_csv_param)
        table = gtk.Table(2, 4, False)
        table.set_border_width(8)
        table.set_row_spacings(9)
        table.set_col_spacings(8)
        expander_csv.add(table)

        label_csv_delimiter = gtk.Label(_('Delimiter:'))
        label_csv_delimiter.set_alignment(1, 0.5)
        table.attach(label_csv_delimiter, 0, 1, 0, 1)
        self.csv_delimiter = gtk.Entry()
        self.csv_delimiter.set_max_length(1)
        if os.name == 'nt' and ',' == locale.localeconv()['decimal_point']:
            delimiter = ';'
        else:
            delimiter = ','
        self.csv_delimiter.set_text(delimiter)
        self.csv_delimiter.set_width_chars(1)
        label_csv_delimiter.set_mnemonic_widget(self.csv_delimiter)
        table.attach(self.csv_delimiter, 1, 2, 0, 1)

        label_csv_quotechar = gtk.Label(_("Quote char:"))
        label_csv_quotechar.set_alignment(1, 0.5)
        table.attach(label_csv_quotechar, 2, 3, 0, 1)
        self.csv_quotechar = gtk.Entry()
        self.csv_quotechar.set_text("\"")
        self.csv_quotechar.set_width_chars(1)
        label_csv_quotechar.set_mnemonic_widget(self.csv_quotechar)
        table.attach(self.csv_quotechar, 3, 4, 0, 1)

        label_csv_enc = gtk.Label(_("Encoding:"))
        label_csv_enc.set_alignment(1, 0.5)
        table.attach(label_csv_enc, 0, 1, 1, 2)
        if hasattr(gtk, 'ComboBoxText'):
            self.csv_enc = gtk.ComboBoxText()
        else:
            self.csv_enc = gtk.combo_box_new_text()
        for i, encoding in enumerate(encodings):
            self.csv_enc.append_text(encoding)
            if ((os.name == 'nt' and encoding == 'cp1252')
                    or (os.name != 'nt' and encoding == 'utf_8')):
                self.csv_enc.set_active(i)
        label_csv_enc.set_mnemonic_widget(self.csv_enc)
        table.attach(self.csv_enc, 1, 2, 1, 2)

        self.add_csv_header_param(table)

        button_cancel = gtk.Button("gtk-cancel", stock="gtk-cancel")
        self.dialog.add_action_widget(button_cancel, gtk.RESPONSE_CANCEL)

        button_ok = gtk.Button("gtk-ok", stock="gtk-ok")
        self.dialog.add_action_widget(button_ok, gtk.RESPONSE_OK)

        self.dialog.vbox.pack_start(dialog_vbox)

        self.view1 = gtk.TreeView()
        self.view1.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
        self.view1.connect('row-expanded', self.on_row_expanded)
        scrolledwindow_fields.add(self.view1)
        self.view2 = gtk.TreeView()
        self.view2.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
        scrolledwindow_fields_selected.add(self.view2)
        self.view1.set_headers_visible(False)
        self.view2.set_headers_visible(False)

        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_('Field name'), cell, text=0)
        self.view1.append_column(column)

        cell = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_('Field name'), cell, text=0)
        self.view2.append_column(column)

        self.model1 = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
        self.model2 = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)

        self.model_populate(self._get_fields(self.model))

        self.view1.set_model(self.model1)
        self.view1.connect('row-activated', self.sig_sel)
        self.view2.set_model(self.model2)
        self.view2.connect('row-activated', self.sig_unsel)

        self.dialog.show_all()
        self.show()

        self.register()

        if sys.platform != 'darwin':
            self.view2.drag_source_set(
                gtk.gdk.BUTTON1_MASK | gtk.gdk.BUTTON3_MASK, [
                    gtk.TargetEntry.new('EXPORT_TREE', gtk.TARGET_SAME_WIDGET,
                                        0)
                ], gtk.gdk.ACTION_MOVE)
            self.view2.drag_dest_set(gtk.DEST_DEFAULT_ALL, [
                gtk.TargetEntry.new('EXPORT_TREE', gtk.TARGET_SAME_WIDGET, 0)
            ], gtk.gdk.ACTION_MOVE)
            self.view2.connect('drag-begin', self.drag_begin)
            self.view2.connect('drag-motion', self.drag_motion)
            self.view2.connect('drag-drop', self.drag_drop)
            self.view2.connect("drag-data-get", self.drag_data_get)
            self.view2.connect('drag-data-received', self.drag_data_received)
            self.view2.connect('drag-data-delete', self.drag_data_delete)
Exemplo n.º 9
0
    def __init__(self, modpicker, key, args, validators={}):
        gtk.HBox.__init__(self, spacing=8)

        val = args[key]

        self.modpicker = modpicker
        self.key = key
        self.val = val
        self.lastval = val
        self.default = val

        self.validator = None
        if key in validators:
            self.validator = validators[key]

        self.label = gtk.Label(key)
        self.label.set_size_request(100, -1)
        self.label.set_alignment(1.0, 0.5)

        self.editor = None
        self.type = type(val)
        if self.validator is not None:
            if self.validator == os.path.isfile:
                self.file = gtk.FileChooserButton(key)
                self.file.set_filename(val)
                self.file.connect('file-set', self.file_set_cb)
                self.editor = self.file
            elif is_iter(self.validator):
                self.combo = gtk.ComboBoxText()
                self.combo.connect('changed', self.combo_changed_cb)
                index = 0
                for i in self.validator:
                    self.combo.append_text(i)
                    if i == val:
                        self.combodefault = index
                        self.combo.set_active(index)
                    index += 1
                self.editor = self.combo

        if self.editor is not None:
            # if we added it from the validator, do nothing here
            # otherwise, add an appropriate widget for the variable type.
            pass
        elif self.type == bool:
            self.check = gtk.ToggleButton(label=str(val))
            self.check.set_active(val)
            self.check.connect('clicked', self.check_clicked_cb)
            self.editor = self.check
        elif self.type == int:
            self.spin = gtk.SpinButton()
            self.spin.set_numeric(True)
            self.spin.set_range(-maxint, maxint)
            self.spin.set_increments(1, 10)
            self.spin.set_value(val)
            self.spin.connect('value-changed', self.spin_changed_cb)
            self.editor = self.spin
        else:
            self.entry = gtk.Entry()
            self.entry.set_text(str(val))
            self.entry.connect('changed', self.entry_changed_cb)
            self.editor = self.entry

        self.reset = gtk.Button('x')
        self.reset.connect('clicked', self.reset_cb)

        self.pack_start(self.label, expand=False)
        self.pack_start(self.editor, expand=True)
        self.pack_start(self.reset, expand=False)
Exemplo n.º 10
0
    def _init_ui(self):
        # Dialog for editing dimensions (width, height, DPI)
        app = self.app
        buttons = (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
        self._size_dialog = windowing.Dialog(app,
                                             _("Frame Size"),
                                             app.drawWindow,
                                             buttons=buttons)
        unit = _('px')

        height_label = gtk.Label(_('Height:'))
        height_label.set_alignment(0.0, 0.5)
        width_label = gtk.Label(_('Width:'))
        width_label.set_alignment(0.0, 0.5)
        dpi_label = gtk.Label(_('Resolution:'))
        dpi_label.set_alignment(0.0, 0.5)
        color_label = gtk.Label(_('Color:'))
        color_label.set_alignment(0.0, 0.5)

        height_entry = gtk.SpinButton(adjustment=self.height_adj,
                                      climb_rate=0.25,
                                      digits=0)
        self.height_adj.set_spin_button(height_entry)

        width_entry = gtk.SpinButton(adjustment=self.width_adj,
                                     climb_rate=0.25,
                                     digits=0)
        self.width_adj.set_spin_button(width_entry)
        dpi_entry = gtk.SpinButton(adjustment=self.dpi_adj,
                                   climb_rate=0.0,
                                   digits=0)

        color_button = gtk.ColorButton()
        color_rgba = self.app.preferences.get("frame.color_rgba")
        color_rgba = [min(max(c, 0), 1) for c in color_rgba]
        color_gdk = RGBColor(*color_rgba[0:3]).to_gdk_color()
        color_alpha = int(65535 * color_rgba[3])
        color_button.set_color(color_gdk)
        color_button.set_use_alpha(True)
        color_button.set_alpha(color_alpha)
        color_button.set_title(_("Frame Color"))
        color_button.connect("color-set", self._color_set_cb)
        color_align = gtk.Alignment(0, 0.5, 0, 0)
        color_align.add(color_button)

        size_table = gtk.Table(6, 3)
        size_table.set_border_width(3)
        xopts = gtk.FILL | gtk.EXPAND
        yopts = gtk.FILL
        xpad = ypad = 3

        unit_combobox = gtk.ComboBoxText()
        for unit in UnitAdjustment.CONVERT_UNITS.keys():
            unit_combobox.append_text(unit)
        for i, key in enumerate(UnitAdjustment.CONVERT_UNITS):
            if key == _('px'):
                unit_combobox.set_active(i)
        unit_combobox.connect('changed', self.on_unit_changed)
        self._unit_combobox = unit_combobox

        row = 0
        size_table.attach(width_label, 0, 1, row, row + 1, xopts, yopts, xpad,
                          ypad)
        size_table.attach(width_entry, 1, 2, row, row + 1, xopts, yopts, xpad,
                          ypad)
        size_table.attach(self.unit_label, 2, 3, row, row + 1, xopts, yopts,
                          xpad + 4, ypad)

        row += 1
        size_table.attach(height_label, 0, 1, row, row + 1, xopts, yopts, xpad,
                          ypad)
        size_table.attach(height_entry, 1, 2, row, row + 1, xopts, yopts, xpad,
                          ypad)
        size_table.attach(unit_combobox, 2, 3, row, row + 1, xopts, yopts,
                          xpad, ypad)

        row += 1
        size_table.attach(dpi_label, 0, 1, row, row + 1, xopts, yopts, xpad,
                          ypad)
        size_table.attach(dpi_entry, 1, 2, row, row + 1, xopts, yopts, xpad,
                          ypad)

        # Options panel UI
        opts_table = gtk.Table(3, 3)
        opts_table.set_border_width(3)

        row = 0
        size_button = gtk.Button("<size-summary>")
        self._size_button = size_button
        size_button.connect("clicked", self._size_button_clicked_cb)
        opts_table.attach(size_button, 0, 2, row, row + 1, xopts, yopts, xpad,
                          ypad)

        row += 1
        opts_table.attach(color_label, 0, 1, row, row + 1, xopts, yopts, xpad,
                          ypad)
        opts_table.attach(color_align, 1, 2, row, row + 1, xopts, yopts, xpad,
                          ypad)

        crop_layer_button = gtk.Button(_('Set Frame to Layer'))
        crop_layer_button.set_tooltip_text(
            _("Set frame to the extents of "
              "the current layer"))
        crop_document_button = gtk.Button(_('Set Frame to Document'))
        crop_document_button.set_tooltip_text(
            _("Set frame to the combination "
              "of all layers"))
        crop_layer_button.connect('clicked', self.crop_frame_cb,
                                  'CropFrameToLayer')
        crop_document_button.connect('clicked', self.crop_frame_cb,
                                     'CropFrameToDocument')

        trim_button = gtk.Button()
        trim_action = self.app.find_action("TrimLayer")
        trim_button.set_related_action(trim_action)
        trim_button.set_label(_('Trim Layer to Frame'))
        trim_button.set_tooltip_text(
            _("Trim parts of the current layer "
              "which lie outside the frame"))

        self.enable_button = gtk.CheckButton()
        frame_toggle_action = self.app.find_action("FrameToggle")
        self.enable_button.set_related_action(frame_toggle_action)
        self.enable_button.set_label(_('Enabled'))

        row += 1
        opts_table.attach(self.enable_button, 1, 2, row, row + 1, xopts, yopts,
                          xpad, ypad)

        row += 1
        opts_table.attach(crop_layer_button, 0, 2, row, row + 1, xopts, yopts,
                          xpad, ypad)

        row += 1
        opts_table.attach(crop_document_button, 0, 2, row, row + 1, xopts,
                          yopts, xpad, ypad)

        row += 1
        opts_table.attach(trim_button, 0, 2, row, row + 1, xopts, yopts, xpad,
                          ypad)

        content_area = self._size_dialog.get_content_area()
        content_area.pack_start(size_table, True, True)

        self._size_dialog.connect('response', self._size_dialog_response_cb)

        self.add(opts_table)
Exemplo n.º 11
0
    def get_toolbar(self, textview):
        toolbar = gtk.Toolbar()
        toolbar.set_style({
            'default': False,
            'both': gtk.TOOLBAR_BOTH,
            'text': gtk.TOOLBAR_TEXT,
            'icons': gtk.TOOLBAR_ICONS
        }[CONFIG['client.toolbar']])
        tag_widgets = self.tag_widgets[textview] = {}

        for icon in ['bold', 'italic', 'underline']:
            button = gtk.ToggleToolButton()
            button.set_icon_widget(
                IconFactory.get_image('tryton-format-%s' % icon,
                                      gtk.ICON_SIZE_SMALL_TOOLBAR))
            button.connect('toggled', self.toggle_props, icon, textview)
            toolbar.insert(button, -1)
            tag_widgets[icon] = button

        toolbar.insert(gtk.SeparatorToolItem(), -1)

        for name, options, active in [
            ('family', FAMILIES, FAMILIES.index('normal')),
            ('size', SIZES, SIZES.index('4')),
        ]:
            try:
                combobox = gtk.ComboBoxText()
            except AttributeError:
                combobox = gtk.combo_box_new_text()
            for option in options:
                combobox.append_text(option)
            combobox.set_active(active)
            combobox.set_focus_on_click(False)
            combobox.connect('changed', self.change_props, name, textview)
            tool = gtk.ToolItem()
            tool.add(combobox)
            toolbar.insert(tool, -1)
            tag_widgets[name] = combobox

        toolbar.insert(gtk.SeparatorToolItem(), -1)

        button = None
        for name in ['left', 'center', 'right', 'justify']:
            icon = 'tryton-format-align-%s' % name
            button = gtk.RadioToolButton.new_from_widget(button)
            button.set_icon_widget(
                IconFactory.get_image(icon, gtk.ICON_SIZE_SMALL_TOOLBAR))
            button.set_active(icon == 'left')
            button.connect('toggled', self.toggle_justification, name,
                           textview)
            toolbar.insert(button, -1)
            tag_widgets[name] = button

        toolbar.insert(gtk.SeparatorToolItem(), -1)

        for icon, label in [
            ('foreground', _('Foreground')),
                # TODO ('background', _('Background')),
        ]:
            button = gtk.ToolButton()
            if icon == 'foreground':
                button.set_icon_widget(
                    IconFactory.get_image('tryton-format-color-text',
                                          gtk.ICON_SIZE_SMALL_TOOLBAR))
            button.set_label(label)
            button.connect('clicked', self.toggle_color, icon, textview)
            toolbar.insert(button, -1)
            tag_widgets[icon] = button

        return toolbar