Exemple #1
0
    def __init__(self, parent, light):
        Gtk.Window.__init__(self, title="Light Settings")
        self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
        self.connect("delete-event", self.on_quit)
        self.set_border_width(10)
        self.set_default_size(250, 250)
        self.parent = parent
        self.light = light
        self.complete = False

        LightSettingsUI.open_lights.append(light)

        main_vertical_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                                    spacing=10)
        main_vertical_box.set_homogeneous(False)

        label = Gtk.Label("Light Settings")
        label.set_markup("<b>Light Settings</b>")
        main_vertical_box.pack_start(label, False, True, 0)

        #New Light Box

        new_light_vertical_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                                         spacing=10)

        label = Gtk.Label("Name")
        new_light_vertical_box.pack_start(label, False, True, 0)

        self.light_name = entry = Gtk.Entry()
        entry.set_text(light.light_name)
        entry.connect('changed', self.on_update)
        new_light_vertical_box.pack_start(entry, False, True, 0)

        label = Gtk.Label("Channel Index")
        new_light_vertical_box.pack_start(label, False, True, 0)

        self.channel_index = entry = Gtk.Entry()
        entry.connect('changed', self.on_update)
        entry.set_text(str(light.light_channel_index))
        new_light_vertical_box.pack_start(entry, False, True, 0)

        label = Gtk.Label("Size (px)")
        new_light_vertical_box.pack_start(label, False, True, 0)

        self.size_adjustment = size_adjustment = Gtk.Adjustment(
            50, 25, 250, 1, 10, 0)
        size_adjustment.connect('value-changed', self.on_update)
        self.scale = scale = Gtk.Scale(adjustment=size_adjustment)
        scale.set_digits(0)
        scale.set_value(light.light_size)
        scale.set_value_pos(Gtk.PositionType.BOTTOM)

        new_light_vertical_box.pack_start(scale, False, True, 0)

        label = Gtk.Label("Channel Size (3, 7, or 8)")
        new_light_vertical_box.pack_start(label, False, True, 0)

        self.channel_size = entry = Gtk.Entry()
        entry.connect('changed', self.on_update)
        entry.set_text("3")
        entry.root = self
        new_light_vertical_box.pack_start(entry, False, True, 0)

        location_box = Gtk.Box(spacing=10)

        label = Gtk.Label("X%:")
        location_box.pack_start(label, False, True, 0)

        self.x_adjustment = x_adjustment = Gtk.Adjustment(50, 0, 100, 1, 10, 0)
        x_adjustment.connect('value-changed', self.on_update)
        scale = Gtk.Scale(adjustment=x_adjustment)
        scale.set_digits(0)
        scale.set_value(light.light_x)
        scale.set_value_pos(Gtk.PositionType.BOTTOM)
        location_box.pack_start(scale, True, True, 0)

        label = Gtk.Label("Y%:")
        location_box.pack_start(label, False, True, 0)

        self.y_adjustment = y_adjustment = Gtk.Adjustment(50, 0, 100, 1, 10, 0)
        y_adjustment.connect('value-changed', self.on_update)
        scale = Gtk.Scale(adjustment=y_adjustment)
        scale.set_digits(0)
        scale.set_value(light.light_y)
        scale.set_value_pos(Gtk.PositionType.BOTTOM)
        location_box.pack_start(scale, True, True, 0)

        new_light_vertical_box.pack_start(location_box, False, True, 0)

        button = Gtk.Button.new_with_label("Remove Light")
        button.connect("clicked", self.on_remove_light)
        new_light_vertical_box.pack_start(button, False, True, 0)

        button = Gtk.Button.new_with_label("Single Capture Light")
        button.connect("clicked", self.on_update_light)
        new_light_vertical_box.pack_start(button, False, True, 0)

        self.cont_cap_btn = button = Gtk.Button.new_with_label(
            "Enable Continuous Capture")
        button.connect("clicked", self.on_cont_light)
        if light in self.parent.multi_capture_queue:
            button.set_sensitive(False)
        new_light_vertical_box.pack_start(button, False, True, 0)

        self.dis_cont_cap_btn = button = Gtk.Button.new_with_label(
            "Disable Continuous Capture")
        button.connect("clicked", self.on_dis_cont_light)
        if light not in self.parent.multi_capture_queue:
            button.set_sensitive(False)
        new_light_vertical_box.pack_start(button, False, True, 0)

        main_vertical_box.pack_start(new_light_vertical_box, False, True, 0)

        self.add(main_vertical_box)

        self.show_all()

        self.complete = True
Exemple #2
0
    def __init__(self, parent):
        Gtk.Dialog.__init__(self, "add new movement", parent, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        self.set_default_size(150, 100)

        box = self.get_content_area()
        grid = Gtk.Grid()

        # value field
        value_label = Gtk.Label("value")
        value_adjustment = Gtk.Adjustment(0, -99999, 99999, 0.1, 1, 0)
        self.value_button = Gtk.SpinButton()
        self.value_button.set_adjustment(value_adjustment)
        self.value_button.set_digits(2)
        self.value_button.set_numeric(True)

        grid.add(value_label)
        grid.attach_next_to(self.value_button, value_label,
                            Gtk.PositionType.RIGHT, 1, 1)

        cause_label = Gtk.Label("Cause")
        self.cause_entry = Gtk.Entry()
        self.cause_entry.set_placeholder_text("cause")

        grid.attach_next_to(cause_label, value_label, Gtk.PositionType.BOTTOM,
                            1, 1)

        grid.attach_next_to(self.cause_entry, cause_label,
                            Gtk.PositionType.RIGHT, 1, 1)

        #Date selection
        date = datetime.datetime.today().date()

        date_label = Gtk.Label("Date")

        grid.attach_next_to(date_label, cause_label, Gtk.PositionType.BOTTOM,
                            1, 1)

        year_label = Gtk.Label("Year")
        year_adjustment = Gtk.Adjustment(date.year, 1900, 2100, 1, 1, 0)
        self.year_spin = Gtk.SpinButton()
        self.year_spin.configure(year_adjustment, 1, 0)
        self.year_spin.connect("value-changed", self.update_day_adj)

        grid.attach_next_to(year_label, date_label, Gtk.PositionType.BOTTOM, 1,
                            1)
        grid.attach_next_to(self.year_spin, year_label, Gtk.PositionType.RIGHT,
                            1, 1)

        month_label = Gtk.Label("Month")
        month_adjustment = Gtk.Adjustment(date.month, 1, 12, 1, 1, 0)
        self.month_spin = Gtk.SpinButton()
        self.month_spin.configure(month_adjustment, 1, 0)
        self.month_spin.connect("value-changed", self.update_day_adj)

        grid.attach_next_to(month_label, year_label, Gtk.PositionType.BOTTOM,
                            1, 1)
        grid.attach_next_to(self.month_spin, month_label,
                            Gtk.PositionType.RIGHT, 1, 1)

        day_label = Gtk.Label("Day")
        day_adjustment = Gtk.Adjustment(date.day, 1,
                                        monthrange(date.year, date.month)[1],
                                        1, 1, 0)
        self.day_spin = Gtk.SpinButton()
        self.day_spin.configure(day_adjustment, 1, 0)

        grid.attach_next_to(day_label, month_label, Gtk.PositionType.BOTTOM, 1,
                            1)
        grid.attach_next_to(self.day_spin, day_label, Gtk.PositionType.RIGHT,
                            1, 1)

        box.add(grid)
        self.show_all()
Exemple #3
0
 def create_adj(self):
     return Gtk.Adjustment(1, 1, 65535, 1, 10, 0)
Exemple #4
0
def show_reverse_dialog(media_file, default_range_render, _response_callback):
    folder, file_name = os.path.split(media_file.path)
    if media_file.is_proxy_file:
        folder, file_name = os.path.split(media_file.second_file_path)

    name, ext = os.path.splitext(file_name)

    dialog = Gtk.Dialog(
        _("Render Reverse Motion Video File"), gui.editor_window.window,
        Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
        (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
         _("Render").encode('utf-8'), Gtk.ResponseType.ACCEPT))

    media_file_label = Gtk.Label(label=_("Source Media File: "))
    media_name = Gtk.Label(label="<b>" + media_file.name + "</b>")
    media_name.set_use_markup(True)
    SOURCE_PAD = 8
    SOURCE_HEIGHT = 20
    mf_row = guiutils.get_left_justified_box([
        media_file_label,
        guiutils.pad_label(SOURCE_PAD, SOURCE_HEIGHT), media_name
    ])

    mark_in = Gtk.Label(label=_("<b>not set</b>"))
    mark_out = Gtk.Label(label=_("<b>not set</b>"))
    if media_file.mark_in != -1:
        mark_in = Gtk.Label(label="<b>" +
                            utils.get_tc_string(media_file.mark_in) + "</b>")
    if media_file.mark_out != -1:
        mark_out = Gtk.Label(label="<b>" +
                             utils.get_tc_string(media_file.mark_out) + "</b>")
    mark_in.set_use_markup(True)
    mark_out.set_use_markup(True)

    fb_widgets = utils.EmptyClass()

    fb_widgets.file_name = Gtk.Entry()
    fb_widgets.file_name.set_text(name + "_REVERSE")

    fb_widgets.extension_label = Gtk.Label()
    fb_widgets.extension_label.set_size_request(45, 20)

    name_row = Gtk.HBox(False, 4)
    name_row.pack_start(fb_widgets.file_name, True, True, 0)
    name_row.pack_start(fb_widgets.extension_label, False, False, 4)

    fb_widgets.out_folder = Gtk.FileChooserButton(_("Select Target Folder"))
    fb_widgets.out_folder.set_action(Gtk.FileChooserAction.SELECT_FOLDER)
    fb_widgets.out_folder.set_current_folder(folder)

    label = Gtk.Label(label=_("Speed %:"))

    adjustment = Gtk.Adjustment(float(-100), float(-600), float(-1), float(1))
    fb_widgets.hslider = Gtk.HScale()
    fb_widgets.hslider.set_adjustment(adjustment)
    fb_widgets.hslider.set_draw_value(False)

    spin = Gtk.SpinButton()
    spin.set_numeric(True)
    spin.set_adjustment(adjustment)

    fb_widgets.hslider.set_digits(0)
    spin.set_digits(0)

    slider_hbox = Gtk.HBox(False, 4)
    slider_hbox.pack_start(fb_widgets.hslider, True, True, 0)
    slider_hbox.pack_start(spin, False, False, 4)
    slider_hbox.set_size_request(450, 35)

    hbox = Gtk.HBox(False, 2)
    hbox.pack_start(guiutils.pad_label(8, 8), False, False, 0)
    hbox.pack_start(slider_hbox, False, False, 0)

    profile_selector = ProfileSelector()
    profile_selector.fill_options()
    profile_selector.widget.set_sensitive(True)
    fb_widgets.out_profile_combo = profile_selector.widget

    quality_selector = RenderQualitySelector()
    fb_widgets.quality_cb = quality_selector.widget

    # Encoding
    encoding_selector = RenderEncodingSelector(quality_selector,
                                               fb_widgets.extension_label,
                                               None)
    encoding_selector.encoding_selection_changed()
    fb_widgets.encodings_cb = encoding_selector.widget

    objects_list = Gtk.TreeStore(str, bool)
    objects_list.append(None, [_("Full Source Length"), True])
    if media_file.mark_in != -1 and media_file.mark_out != -1:
        range_available = True
    else:
        range_available = False
    objects_list.append(None,
                        [_("Source Mark In to Mark Out"), range_available])

    fb_widgets.render_range = Gtk.ComboBox.new_with_model(objects_list)

    renderer_text = Gtk.CellRendererText()
    fb_widgets.render_range.pack_start(renderer_text, True)
    fb_widgets.render_range.add_attribute(renderer_text, "text", 0)
    fb_widgets.render_range.add_attribute(renderer_text, 'sensitive', 1)
    if default_range_render == False:
        fb_widgets.render_range.set_active(0)
    else:
        fb_widgets.render_range.set_active(1)
    fb_widgets.render_range.show()

    # To update rendered length display
    clip_length = _get_rendered_slomo_clip_length(media_file,
                                                  fb_widgets.render_range, 100)
    clip_length_label = Gtk.Label(label=utils.get_tc_string(clip_length))
    fb_widgets.hslider.connect("value-changed", _reverse_speed_changed,
                               media_file, fb_widgets.render_range,
                               clip_length_label)
    fb_widgets.render_range.connect("changed", _reverse_range_changed,
                                    media_file, fb_widgets.hslider,
                                    clip_length_label)

    # Build gui
    vbox = Gtk.VBox(False, 2)
    vbox.pack_start(mf_row, False, False, 0)
    vbox.pack_start(
        guiutils.get_left_justified_box([
            Gtk.Label(label=_("Source Mark In: ")),
            guiutils.pad_label(SOURCE_PAD, SOURCE_HEIGHT), mark_in
        ]), False, False, 0)
    vbox.pack_start(
        guiutils.get_left_justified_box([
            Gtk.Label(label=_("Source Mark Out: ")),
            guiutils.pad_label(SOURCE_PAD, SOURCE_HEIGHT), mark_out
        ]), False, False, 0)
    vbox.pack_start(guiutils.pad_label(18, 12), False, False, 0)
    vbox.pack_start(label, False, False, 0)
    vbox.pack_start(hbox, False, False, 0)
    vbox.pack_start(guiutils.pad_label(18, 12), False, False, 0)
    vbox.pack_start(
        guiutils.get_two_column_box(Gtk.Label(label=_("Target File:")),
                                    name_row, 120), False, False, 0)
    vbox.pack_start(
        guiutils.get_two_column_box(Gtk.Label(label=_("Target Folder:")),
                                    fb_widgets.out_folder, 120), False, False,
        0)
    vbox.pack_start(
        guiutils.get_two_column_box(Gtk.Label(label=_("Target Profile:")),
                                    fb_widgets.out_profile_combo, 200), False,
        False, 0)
    vbox.pack_start(
        guiutils.get_two_column_box(Gtk.Label(label=_("Target Encoding:")),
                                    fb_widgets.encodings_cb, 200), False,
        False, 0)
    vbox.pack_start(
        guiutils.get_two_column_box(Gtk.Label(label=_("Target Quality:")),
                                    fb_widgets.quality_cb, 200), False, False,
        0)
    vbox.pack_start(guiutils.pad_label(18, 12), False, False, 0)
    vbox.pack_start(
        guiutils.get_two_column_box(Gtk.Label(label=_("Render Range:")),
                                    fb_widgets.render_range, 180), False,
        False, 0)
    vbox.pack_start(
        guiutils.get_two_column_box(
            Gtk.Label(label=_("Rendered Clip Length:")), clip_length_label,
            180), False, False, 0)

    alignment = guiutils.set_margins(vbox, 6, 24, 24, 24)

    dialog.vbox.pack_start(alignment, True, True, 0)
    dialogutils.set_outer_margins(dialog.vbox)
    dialogutils.default_behaviour(dialog)
    dialog.connect('response', _response_callback, fb_widgets, media_file)
    dialog.show_all()
Exemple #5
0
#!/usr/bin/env python

from gi.repository import Gtk

window = Gtk.Window()
window.connect("destroy", lambda q: Gtk.main_quit())

adjustment = Gtk.Adjustment(value=5,
                            lower=0,
                            upper=10,
                            step_increment=1,
                            page_increment=1,
                            page_size=0)
spinbutton = Gtk.SpinButton(adjustment=adjustment)
window.add(spinbutton)

window.show_all()

Gtk.main()
Exemple #6
0
    def make_menu(self, initialize=True):
        """build the menu"""
        if initialize:
            self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
            self.window.connect("delete_event", self.close_application)

            self.window.set_title("Handymenu configuration")
            self.window.set_border_width(0)
        else:
            self.window.remove(self.mainbox)

        # Conteneur principal
        self.mainbox = Gtk.VBox(False, 10)
        self.mainbox.set_border_width(10)

        # configuration principale
        self.make_entrylist()

        # extra options
        extrabox = Gtk.HBox(False, 5)
        self.mainbox.pack_start(extrabox, False, False, 0)

        # coches pour modules
        modulesbox = Gtk.HBox(False, 5)
        modulesframe = Gtk.Frame(label=_("Modules"))
        modulesframe.add(modulesbox)
        extrabox.pack_start(modulesframe, False, False, 0)

        recents_files_check = Gtk.CheckButton(_("Show recent files"))
        recents_files_check.set_tooltip_text(_("Show recent files"))
        if "_recent_files_" in load_modules()[1]:
            recents_files_check.set_active(True)
        recents_files_check.connect("toggled", self.module_toggle,
                                    "_recent_files_")
        modulesbox.pack_start(recents_files_check, False, False, 0)

        # module firefox most viewed
        most_ffox_check = Gtk.CheckButton(_("Most visited"))
        most_ffox_check.set_tooltip_text(_("Show most visited uri"))
        if "_most_ffox_view_" in load_modules()[1]:
            most_ffox_check.set_active(True)
        most_ffox_check.connect("toggled", self.module_toggle,
                                "_most_ffox_view_")
        modulesbox.pack_start(most_ffox_check, False, False, 0)

        # position des modules
        self.modules_position = Gtk.SpinButton()
        #adjustment = Gtk.Adjustment(0, start, max, step, 10, 0)
        adjustment = Gtk.Adjustment(0, 1, len(self.config) + 1, 1, 10, 0)
        self.modules_position.set_adjustment(adjustment)
        self.modules_position.set_numeric(True)
        self.modules_position.set_value(load_modules()[0])
        self.modules_position.set_tooltip_text(
            _("Position of modules in menu"))
        self.modules_position.connect("value-changed", \
                lambda x: set_modules_position(self.modules_position.get_value_as_int()))
        modulesbox.pack_start(self.modules_position, False, False, 1)

        # conteneur pour les boutons
        btnbox = Gtk.HBox(True, 2)
        self.mainbox.pack_start(btnbox, False, False, 0)

        defaultbtn = Gtk.Button(label=_("Reset"))
        resetimg = Gtk.Image()
        resetimg.set_from_stock(Gtk.STOCK_REDO, Gtk.IconSize.BUTTON)
        defaultbtn.set_image(resetimg)
        defaultbtn.connect_object("clicked", self.back_to_default, self.window)
        btnbox.pack_start(defaultbtn, False, False, 0)

        viewbtn = Gtk.Button(label=_("View config"))
        viewbtn.connect("clicked", lambda x: self.view_config())
        btnbox.pack_start(viewbtn, False, False, 0)

        savebtn = Gtk.Button(label=_("Quit"), stock=Gtk.STOCK_CLOSE)
        savebtn.connect_object("clicked", self.close_application, self.window,
                               None)
        btnbox.pack_start(savebtn, False, False, 0)

        self.window.add(self.mainbox)
        self.window.set_default_size(620, 560)
        self.window.show_all()
Exemple #7
0
    def init_components(self) -> None:
        grid = Gtk.Grid(
            row_homogeneous=True,
            column_homogeneous=True,
            row_spacing=5,
            column_spacing=5,
        )

        # Simulate Switch ------------------------------------------------------
        top_box = Gtk.Box(spacing=2)

        self.simulating_label = Gtk.Label(label="Start Simulating")
        self.simulating_switch = Gtk.Switch()
        self.simulating_switch.set_active(False)
        self.simulating_switch.connect("notify::active",
                                       self.execute_simulation)
        self.executing_spinner = Gtk.Spinner()
        self.quantum_rat_spin_button = Gtk.SpinButton(
            adjustment=Gtk.Adjustment(value=750,
                                      lower=125,
                                      upper=10000,
                                      step_increment=125,
                                      page_increment=0,
                                      page_size=0),
            climb_rate=1,
            digits=0,
        )
        self.quantum_rat_spin_button.connect("value-changed",
                                             self.change_quantum_rat)

        # Inactive Processes List ----------------------------------------------
        self.inactive_processes_list_box = Gtk.ListBox()
        self.inactive_processes_list_box.set_selection_mode(
            Gtk.SelectionMode.NONE)
        inactive_processes_scrolled_window = Gtk.ScrolledWindow()
        inactive_processes_scrolled_window.add(
            self.inactive_processes_list_box)

        for i in self.process_manager.inactive_processes:
            process_button = Gtk.Button(label=i.name)
            process_button.connect("clicked", self.prepare_process_action)
            self.inactive_processes_list_box.add(process_button)

        add_process_button = Gtk.Button(label="Add Process")
        add_process_button.connect("clicked", self.add_process_action)

        # Prepared Processes List ----------------------------------------------
        self.prepared_processes_list_box = Gtk.ListBox()
        self.prepared_processes_list_box.set_selection_mode(
            Gtk.SelectionMode.NONE)
        prepared_processes_scrolled_window = Gtk.ScrolledWindow()
        prepared_processes_scrolled_window.add(
            self.prepared_processes_list_box)

        # Executed Process Progress Bar ----------------------------------------
        self.executed_process_list_box = Gtk.ListBox()
        self.executed_process_list_box.set_selection_mode(
            Gtk.SelectionMode.NONE)
        executed_process_scrolled_window = Gtk.ScrolledWindow()
        executed_process_scrolled_window.add(self.executed_process_list_box)

        # Suspended Processes List ---------------------------------------------
        self.suspended_processes_list_box = Gtk.ListBox()
        self.suspended_processes_list_box.set_selection_mode(
            Gtk.SelectionMode.NONE)
        suspended_processes_scrolled_window = Gtk.ScrolledWindow()
        suspended_processes_scrolled_window.add(
            self.suspended_processes_list_box)

        # Add Components -------------------------------------------------------
        top_box.add(Gtk.Label(label='Quantum Rat (ms):'))
        top_box.add(self.quantum_rat_spin_button)
        top_box.add(self.simulating_label)
        top_box.add(self.simulating_switch)
        top_box.add(self.executing_spinner)

        grid.attach(top_box, 0, 0, 3, 1)

        grid.attach(Gtk.Label(label="Inactive Processes"), 0, 1, 1, 1)
        grid.attach(inactive_processes_scrolled_window, 0, 2, 1, 15)
        grid.attach(add_process_button, 0, 17, 1, 1)

        grid.attach(Gtk.Label(label="Prepared Processes"), 1, 1, 3, 1)
        grid.attach(prepared_processes_scrolled_window, 1, 2, 3, 16)

        grid.attach(Gtk.Label(label="Executed Process"), 4, 1, 3, 1)
        grid.attach(executed_process_scrolled_window, 4, 2, 3, 1)

        grid.attach(Gtk.Label(label="Suspended Processes"), 4, 3, 3, 1)
        grid.attach(suspended_processes_scrolled_window, 4, 4, 3, 14)

        self.update_components()
        self.add(grid)
Exemple #8
0
    def __init__(self):

        Gtk.Window.__init__(self, title=_("Favorites Applet Settings"))

        window_icon = self.render_icon(Gtk.STOCK_PREFERENCES, 6)
        self.set_icon(window_icon)

        self.set_position(3)
        self.set_border_width(15)

        box_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
                                spacing=30)
        box_container.set_homogeneous(False)

        # Righ options column
        vbox_right = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
        vbox_right.set_homogeneous(False)

        # Columns options container box
        box_options = Gtk.HBox(spacing=15)
        box_options.set_homogeneous(False)
        box_options.pack_start(vbox_right, False, False, 0)

        # Bottom options box
        #box_extra = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
        #box_extra.set_homogeneous(False)

        # Buttons box
        box_buttons = Gtk.HBox(spacing=10)
        box_buttons.set_homogeneous(False)

        box_container.pack_start(box_options, True, True, 0)
        #box_container.pack_start(box_extra, True, True, 0)
        box_container.pack_start(box_buttons, True, True, 0)

        # Build options for right column
        if (config.has_key('SHOW_POPUPS')):
            switch_SHOW_POPUPS = switch_option()
            switch_SHOW_POPUPS.create(
                vbox_right, 'SHOW_POPUPS', config['SHOW_POPUPS'],
                _("Display pop-up confirmation windows for \"Quit...\" and \"Log Out...\"?"
                  ))

        vbox_right.pack_start(Gtk.HSeparator(), False, False, 0)

        # Icon size slider
        box_icon_size = Gtk.VBox(0)

        adjust_icon_size = Gtk.Adjustment(config['ICON_SIZE'], 16, 46, 6, 6, 0)
        adjust_icon_size.connect("value_changed", self.on_slider_change,
                                 'ICON_SIZE')
        slider_icon_size = Gtk.HScale()
        slider_icon_size.set_adjustment(adjust_icon_size)
        slider_icon_size.set_digits(0)

        box_icon_size.pack_start(Gtk.Label(_("Icon size")), False, False, 0)
        box_icon_size.pack_start(slider_icon_size, False, False, 0)

        vbox_right.pack_start(box_icon_size, False, False, 0)

        # Build extra options
        #self.restart = False
        #self.check_restart = Gtk.CheckButton("Restart Cinnamon on close")
        #self.check_restart.connect('toggled', self.change_restart_status)
        #self.check_restart.set_active(False)
        #box_extra.pack_start(self.check_restart, True, True, 0)

        # Build buttons
        #img_default = Gtk.Image()
        #img_default.set_from_stock(Gtk.STOCK_PROPERTIES, 3)
        #btn_default = Gtk.Button(_("Default settings"))
        #btn_default.set_property("image", img_default)
        #btn_default.connect('clicked', self.generate_config_file)
        #box_buttons.pack_start(btn_default, False, False, 0)

        btn_close = Gtk.Button(stock=Gtk.STOCK_CLOSE)
        btn_close.connect('clicked', self.exit_application)
        box_buttons.pack_end(btn_close, False, False, 0)

        img_restart = Gtk.Image()
        img_restart.set_from_stock(Gtk.STOCK_REFRESH, 3)
        btn_restart = Gtk.Button(_("Restart Cinnamon"))
        btn_restart.set_property("image", img_restart)
        btn_restart.connect('clicked', self.restart_shell)
        box_buttons.pack_end(btn_restart, False, False, 0)

        self.add(box_container)
Exemple #9
0
 def createOptionWidgets (self):
     n=0
     if self.option_label:
         n=1
         lab=Gtk.Label()
         lab.set_text('<span weight="bold"><u>%s</u></span>'%self.option_label)
         lab.set_use_markup(True)
         lab.set_alignment(0.0,0.5)
         lab.set_justify(Gtk.Justification.LEFT)
         self.attach(lab, 0, 1, 0, 1, xpadding=self.xpadding, ypadding=self.ypadding)
                     #xoptions=Gtk.AttachOptions.SHRINK, yoptions=Gtk.AttachOptions.SHRINK)
         lab.show()
     if self.value_label:
         n=1
         lab=Gtk.Label()
         lab.set_markup('<span weight="bold"><u>%s</u></span>'%self.value_label)
         lab.set_alignment(0,0.5)
         lab.set_justify(Gtk.Justification.CENTER)
         self.attach(lab, 1, 2, 0, 1, xpadding=self.xpadding, ypadding=self.ypadding,
                     xoptions=Gtk.AttachOptions.SHRINK, yoptions=Gtk.AttachOptions.SHRINK)
         lab.show()
     for l,v in self.options:
         if isinstance(v,CustomOption):
             w = v
             self.widgets.append([v,'get_value','set_value'])
             v.connect('changed',lambda * args: self.emit('changed'))
         elif isinstance(v, bool):
             w=Gtk.CheckButton()
             w.set_active(v)
             # widgets contains the widget, the get method and the set method
             self.widgets.append([w,'get_active','set_active'])
             w.connect('toggled',lambda *args: self.emit('changed'))
             if self.changedcb:
                 w.connect('toggled',self.changedcb)
         elif isinstance(v, str):
             w=Gtk.Entry()
             w.set_text(v)
             self.widgets.append([w, 'get_text', 'set_text'])
             w.connect('changed',lambda *args: self.emit('changed'))
             if self.changedcb:
                 w.connect('changed',self.changedcb)
         elif isinstance(v, (int, float)):
             adj = Gtk.Adjustment(value=0, lower=0, upper=100*(v or 1), step_incr=(v or 1)*0.1, page_incr=(v or 1)*0.5)
             if isinstance(v, int):
                 # if an integer...
                 w=Gtk.SpinButton(adj, digits=0)
                 self.widgets.append([w,'get_value_as_int','set_value'])
             else:
                 w=Gtk.SpinButton(adj, digits=2)
                 self.widgets.append([w,'get_value','set_value'])
             w.set_value(v)
             w.connect('changed',lambda *args: self.emit('changed'))
             if self.changedcb:
                 w.connect('changed',self.changedcb)
         elif isinstance(v, (list, tuple)):
             default,value_list = v
             w = Gtk.ComboBoxText()
             for itm in value_list:
                 w.append_text(itm)
             cb_extras.cb_set_active_text(w,default)
             cb_extras.setup_typeahead(w)
             self.widgets.append([w,'get_active_text',cb_extras.cb_set_active_text])
             w.connect('changed',lambda *args: self.emit('changed'))
             if self.changedcb: w.connect('changed',self.changedcb)
         else:
             raise Exception("I don't know what to do with a value of type %s (%s)" % (type(v),v))
         # attach out label and our widget
         lab = Gtk.Label()
         lab.set_text_with_mnemonic(l)
         lab.set_mnemonic_widget(w)
         lab.set_justify(Gtk.Justification.LEFT)
         lab.set_alignment(0,0)
         self.attach(lab, 0, 1, n, n+1, xpadding=self.xpadding, ypadding=self.ypadding,
                     xoptions=Gtk.AttachOptions.FILL,yoptions=Gtk.AttachOptions.SHRINK)
         lab.show()
         self.attach(w, 1, 2, n, n+1, xpadding=self.xpadding, ypadding=self.ypadding,
                     xoptions=Gtk.AttachOptions.FILL,yoptions=Gtk.AttachOptions.SHRINK)
         w.show()
         n += 1
Exemple #10
0
    def crop_page_dialog(self, widget):
        """Opens a dialog box to define margins for page cropping"""

        sides = ('L', 'R', 'T', 'B')
        side_names = {
            'L': _('Left'),
            'R': _('Right'),
            'T': _('Top'),
            'B': _('Bottom')
        }
        opposite_sides = {'L': 'R', 'R': 'L', 'T': 'B', 'B': 'T'}

        def set_crop_value(spinbutton, side):
            opp_side = opposite_sides[side]
            pos = sides.index(opp_side)
            adj = spin_list[pos].get_adjustment()
            adj.set_upper(99.0 - spinbutton.get_value())

        model = self.iconview.get_model()
        selection = self.iconview.get_selected_items()

        crop = [0., 0., 0., 0.]
        if selection:
            path = selection[0]
            pos = model.get_iter(path)
            crop = [model.get_value(pos, 7 + side) for side in range(4)]

        dialog = Gtk.Dialog(title=(_('Crop Selected Pages')),
                            parent=self.window,
                            flags=Gtk.DialogFlags.MODAL,
                            buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                     Gtk.STOCK_OK, Gtk.ResponseType.OK))
        dialog.set_size_request(340, 250)
        dialog.set_default_response(Gtk.ResponseType.OK)

        frame = Gtk.Frame(_('Crop Margins'))
        dialog.vbox.pack_start(frame, False, False, 20)

        vbox = Gtk.VBox(False, 0)
        frame.add(vbox)

        spin_list = []
        units = 2 * [_('% of width')] + 2 * [_('% of height')]
        for side in sides:
            hbox = Gtk.HBox(True, 0)
            vbox.pack_start(hbox, False, False, 5)

            label = Gtk.Label(label=side_names[side])
            label.set_alignment(0, 0.0)
            hbox.pack_start(label, True, True, 20)

            adj = Gtk.Adjustment(100. * crop.pop(0), 0.0, 99.0, 1.0, 5.0, 0.0)
            spin = Gtk.SpinButton(adj, 0, 1)
            spin.set_activates_default(True)
            spin.connect('value-changed', set_crop_value, side)
            spin_list.append(spin)
            hbox.pack_start(spin, False, False, 30)

            label = Gtk.Label(label=units.pop(0))
            label.set_alignment(0, 0.0)
            hbox.pack_start(label, True, True, 0)

        dialog.show_all()
        result = dialog.run()

        if result == Gtk.ResponseType.OK:
            modified = False
            crop = [spin.get_value() / 100. for spin in spin_list]
            for path in selection:
                pos = model.get_iter(path)
                for it in range(4):
                    old_val = model.get_value(pos, 7 + it)
                    model.set_value(pos, 7 + it, crop[it])
                    if crop[it] != old_val:
                        modified = True
                self.update_geometry(pos)
            if modified:
                self.set_unsaved(True)
            self.reset_iv_width()
        elif result == Gtk.ResponseType.CANCEL:
            print(_('Dialog closed'))
        dialog.destroy()
Exemple #11
0
    def __init__(self, controls):
        self.controls = controls

        box = Gtk.VBox(False, 0)
        box.hide()

        download_frame = Gtk.Frame(label=_("File downloads"))
        df_vbox = Gtk.VBox(False, 5)
        df_vbox.set_border_width(4)
        """save to"""

        hbox = Gtk.HBox(False, 5)
        self.online_dir = Gtk.FileChooserButton("set place")
        self.online_dir.set_action(Gtk.FileChooserAction.SELECT_FOLDER)
        self.online_dir.connect("current-folder-changed",
                                self.on_change_folder)

        hbox.pack_start(Gtk.Label(_("Save online music to folder:")), False,
                        True, 0)
        hbox.pack_start(self.online_dir, True, True, 0)
        """automatic save"""
        self.automatic_save_checkbutton = Gtk.CheckButton(
            label=_("Automatic online music save"), use_underline=True)
        self.nosubfolder_checkbutton = Gtk.CheckButton(
            label=_("Save to one folder (no subfolders)"), use_underline=True)
        """download threads"""
        thbox = Gtk.HBox(False, 5)
        tab_label = Gtk.Label(_("Download in threads"))

        adjustment = Gtk.Adjustment(value=1,
                                    lower=1,
                                    upper=10,
                                    step_incr=1,
                                    page_incr=1,
                                    page_size=0)
        self.threads_count = Gtk.SpinButton(adjustment=adjustment)

        thbox.pack_start(tab_label, False, False, 0)
        thbox.pack_start(self.threads_count, False, True, 0)

        df_vbox.pack_start(hbox, False, False, 2)
        df_vbox.pack_start(self.automatic_save_checkbutton, False, False, 2)
        df_vbox.pack_start(self.nosubfolder_checkbutton, False, False, 2)
        df_vbox.pack_start(thbox, False, False, 2)
        download_frame.add(df_vbox)
        download_frame.show_all()
        """disc cover size"""
        dc_frame = Gtk.Frame(label=_("Disc cover settings"))

        cbox = Gtk.HBox(False, 5)
        cbox.set_border_width(4)

        tab_label = Gtk.Label(_("Disc cover size:"))

        adjustment = Gtk.Adjustment(value=1,
                                    lower=100,
                                    upper=350,
                                    step_incr=20,
                                    page_incr=50,
                                    page_size=0)
        self.image_size_spin = Gtk.SpinButton(adjustment=adjustment)

        cbox.pack_start(tab_label, False, False, 0)
        cbox.pack_start(self.image_size_spin, False, True, 0)

        dc_frame.add(cbox)
        dc_frame.show_all()
        """notification"""
        updates_frame = Gtk.Frame(label=_("Updates"))
        uhbox = Gtk.HBox(False, 5)
        uhbox.set_border_width(4)
        self.check_new_version = Gtk.CheckButton(
            label=_("Check for new foobnix release on start"),
            use_underline=True)

        demo = Gtk.Button(label=_("Check for update"))
        demo.connect(
            "clicked",
            lambda *a: info_dialog_with_link_and_donate("foobnix [version]"))
        uhbox.pack_start(self.check_new_version, True, True, 0)
        uhbox.pack_start(demo, False, False, 0)
        updates_frame.add(uhbox)
        updates_frame.show_all()
        """background image"""
        theme_frame = Gtk.Frame(label=_("Theming"))
        thvbox = Gtk.VBox(False, 1)
        thvbox.set_border_width(4)
        """menu position"""
        pbox = Gtk.HBox(False, 5)
        pbox.show()

        label = Gtk.Label(_("Menu type: "))

        self.old_style = Gtk.RadioButton(_("Old Style (Menu Bar)"))

        self.new_style = Gtk.RadioButton.new_with_label_from_widget(
            self.old_style, _("New Style (Button)"))

        pbox.pack_start(label, False, False, 0)
        pbox.pack_start(self.new_style, False, True, 0)
        pbox.pack_start(self.old_style, False, False, 0)

        o_r_box = Gtk.HBox(False, 5)
        o_r_box.show()

        o_r_label = Gtk.Label(_("Order-Repeat Switcher Style:"))

        self.buttons = Gtk.RadioButton(None, _("Toggle Buttons"))

        self.labels = Gtk.RadioButton.new_with_label_from_widget(
            self.buttons, _("Text Labels"))

        o_r_box.pack_start(o_r_label, False, False, 0)
        o_r_box.pack_start(self.buttons, False, True, 0)
        o_r_box.pack_start(self.labels, False, False, 0)
        """opacity"""
        obox = Gtk.HBox(False, 5)
        obox.show()

        tab_label = Gtk.Label(_("Opacity:"))
        tab_label.show()

        adjustment = Gtk.Adjustment(value=1,
                                    lower=20,
                                    upper=100,
                                    step_incr=1,
                                    page_incr=1,
                                    page_size=0)
        self.opacity_size = Gtk.SpinButton(adjustment=adjustment)
        self.opacity_size.connect("value-changed", self.on_chage_opacity)
        self.opacity_size.show()

        obox.pack_start(tab_label, False, False, 0)
        obox.pack_start(self.opacity_size, False, True, 0)

        self.fmgrs_combo = self.fmgr_combobox()
        hcombobox = Gtk.HBox(False, 5)
        hcombobox.pack_start(
            Gtk.Label(_('Choose your preferred file manager:')), False, False,
            0)
        hcombobox.pack_start(self.fmgrs_combo, False, False, 0)

        self.disable_screensaver = Gtk.CheckButton(
            label=_("Disable Xscreensaver"), use_underline=True)

        thvbox.pack_start(pbox, False, False, 1)
        thvbox.pack_start(o_r_box, False, False, 1)
        thvbox.pack_start(obox, False, False, 1)
        thvbox.pack_start(hcombobox, False, False, 1)
        thvbox.pack_start(self.disable_screensaver, False, False, 0)
        theme_frame.add(thvbox)
        theme_frame.show_all()
        """packaging"""
        box.pack_start(download_frame, False, True, 2)
        box.pack_start(dc_frame, False, True, 2)
        box.pack_start(theme_frame, False, False, 2)
        box.pack_start(updates_frame, False, True, 2)

        self.widget = box
Exemple #12
0
    def createTraceToolBar(self):
        toolbar = Gtk.Toolbar()
        #toolbar.set_orientation(Gtk.Orientation.VERTICAL)
        #toolbar.set_icon_size(Gtk.IconSize.MENU)
        toolbar.set_icon_size(Gtk.IconSize.LARGE_TOOLBAR)
        toolbar.set_style(Gtk.ToolbarStyle.ICONS)
        toolbar.set_show_arrow(False)

        # build the zoom controls
        self.zoomin_button = Gtk.ToolButton(Gtk.STOCK_ZOOM_IN)
        self.zoomin_button.set_homogeneous(False)
        self.zoomin_button.set_tooltip_text('Zoom in')
        self.zoomin_button.connect('clicked', self.zoomButtons, 1)
        toolbar.insert(self.zoomin_button, -1)

        self.zoomout_button = Gtk.ToolButton(Gtk.STOCK_ZOOM_OUT)
        self.zoomout_button.set_homogeneous(False)
        self.zoomout_button.set_tooltip_text('Zoom out')
        self.zoomout_button.connect('clicked', self.zoomButtons, -1)
        toolbar.insert(self.zoomout_button, -1)

        self.zoom_combo = Gtk.ComboBoxText()
        for zoom in self.zoom_levels:
            self.zoom_combo.append_text(str(zoom) + '%')
        self.zoom_combo.set_active(self.curr_zoom)
        self.zoom_combo.connect('changed', self.zoomComboBox)

        # Place the combo box in a VButtonBox to prevent it from expanding
        # vertically.
        vbox = Gtk.VButtonBox()
        vbox.pack_start(self.zoom_combo, False, True, 0)
        t_item = Gtk.ToolItem()
        t_item.add(vbox)
        t_item.set_tooltip_text('Adjust the zoom level')
        t_item.set_expand(False)
        toolbar.insert(t_item, -1)

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

        # build the y scale adjustment slider
        t_item = Gtk.ToolItem()
        t_item.add(Gtk.Label(label='Y:'))
        toolbar.insert(t_item, -1)

        self.vscale_adj = Gtk.Adjustment(0, 0, 0)
        hslider = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL,
                            adjustment=self.vscale_adj)
        hslider.set_draw_value(False)
        self.initYScaleSlider(self.selected_seqtv)

        sizereq = hslider.get_size_request()
        hslider.set_size_request(60, sizereq.height)

        self.y_slider = Gtk.ToolItem()
        self.y_slider.add(hslider)
        self.y_slider.set_tooltip_text('Adjust the Y scale of the trace view')
        toolbar.insert(self.y_slider, -1)

        self.vscale_adj.connect('value_changed', self.yScaleChanged)

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

        # build the toggle button for phred scores
        toggle = Gtk.CheckButton()
        toggle.set_label('conf. scores')
        toggle.set_active(True)
        toggle.connect('toggled', self.showConfToggled)

        # Place the toggle button in a VButtonBox to prevent it from expanding
        # vertically.
        vbox = Gtk.VButtonBox()
        vbox.pack_start(toggle, False, True, 0)
        t_item = Gtk.ToolItem()
        t_item.add(vbox)
        t_item.set_tooltip_text('Turn the display of phred scores on or off')
        t_item.set_expand(False)
        toolbar.insert(t_item, -1)

        # if we got two sequences, build a combo box to choose between them
        if len(self.seqt_viewers) == 2:
            trace_combo = Gtk.ComboBoxText()

            # see if the forward trace is first or second
            if self.seqt_viewers[0].getSequenceTrace().isReverseComplemented():
                trace_combo.append_text('Reverse:')
                trace_combo.append_text('Forward:')
            else:
                trace_combo.append_text('Forward:')
                trace_combo.append_text('Reverse:')
            trace_combo.append_text('Both:')
            trace_combo.set_active(0)
            trace_combo.connect('changed', self.traceComboBox)

            # Place the combo box in a VButtonBox to prevent it from expanding
            # vertically.
            vbox = Gtk.VButtonBox()
            vbox.pack_start(trace_combo, False, True, 0)
            t_item = Gtk.ToolItem()
            t_item.add(vbox)
            #t_item.set_tooltip_text('Adjust the zoom level')
            toolbar.insert(t_item, 0)

            trace_combo.set_active(2)

        return toolbar
    def __init__(self, abiword_canvas):
        Gtk.Toolbar.__init__(self)

        self._abiword_canvas = abiword_canvas
        self._zoom_percentage = 0

        self._zoom_out = ToolButton('zoom-out')
        self._zoom_out.set_tooltip(_('Zoom Out'))
        self._zoom_out_id = self._zoom_out.connect(
            'clicked', self._zoom_out_cb)
        self.insert(self._zoom_out, -1)
        self._zoom_out.show()

        self._zoom_in = ToolButton('zoom-in')
        self._zoom_in.set_tooltip(_('Zoom In'))
        self._zoom_in_id = self._zoom_in.connect('clicked', self._zoom_in_cb)
        self.insert(self._zoom_in, -1)
        self._zoom_in.show()

        # TODO: fix the initial value
        self._zoom_spin_adj = Gtk.Adjustment(0, 25, 400, 25, 50, 0)
        self._zoom_spin = Gtk.SpinButton.new(self._zoom_spin_adj, 0, 0)
        self._zoom_spin_id = self._zoom_spin.connect('value-changed',
                                                     self._zoom_spin_cb)
        self._zoom_spin.set_numeric(True)
        self._zoom_spin.show()
        tool_item_zoom = Gtk.ToolItem()
        tool_item_zoom.add(self._zoom_spin)
        self.insert(tool_item_zoom, -1)
        tool_item_zoom.show()

        zoom_perc_label = Gtk.Label(_("%"))
        zoom_perc_label.show()
        tool_item_zoom_perc_label = Gtk.ToolItem()
        tool_item_zoom_perc_label.add(zoom_perc_label)
        self.insert(tool_item_zoom_perc_label, -1)
        tool_item_zoom_perc_label.show()

        separator = Gtk.SeparatorToolItem()
        separator.set_draw(True)
        separator.show()
        self.insert(separator, -1)

        page_label = Gtk.Label(_("Page: "))
        page_label.show()
        tool_item_page_label = Gtk.ToolItem()
        tool_item_page_label.add(page_label)
        self.insert(tool_item_page_label, -1)
        tool_item_page_label.show()

        self._page_spin_adj = Gtk.Adjustment(0, 1, 0, -1, -1, 0)
        self._page_spin = Gtk.SpinButton.new(self._page_spin_adj, 0, 0)
        self._page_spin_id = self._page_spin.connect('value-changed',
                                                     self._page_spin_cb)
        self._page_spin.set_numeric(True)
        self._page_spin.show()
        tool_item_page = Gtk.ToolItem()
        tool_item_page.add(self._page_spin)
        self.insert(tool_item_page, -1)
        tool_item_page.show()

        self._total_page_label = Gtk.Label(" / 0")
        self._total_page_label.show()
        tool_item = Gtk.ToolItem()
        tool_item.add(self._total_page_label)
        self.insert(tool_item, -1)
        tool_item.show()

        self._abiword_canvas.connect("page-count", self._page_count_cb)
        self._abiword_canvas.connect("current-page", self._current_page_cb)
        self._abiword_canvas.connect("zoom", self._zoom_cb)
Exemple #14
0
    def __init__(self, songs):
        super().__init__()

        self.image_cache = []
        self.image_cache_size = 10
        self.search_lock = False

        self.set_title(_('Album Art Downloader'))
        self.set_icon_name(Icons.EDIT_FIND)
        self.set_default_size(800, 550)

        image = CoverArea(self, songs[0])

        self.liststore = Gtk.ListStore(object, object)
        self.treeview = treeview = AllTreeView(model=self.liststore)
        self.treeview.set_headers_visible(False)
        self.treeview.set_rules_hint(True)

        targets = [("text/uri-list", 0, 0)]
        targets = [Gtk.TargetEntry.new(*t) for t in targets]

        treeview.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, targets,
                                 Gdk.DragAction.COPY)

        treeselection = self.treeview.get_selection()
        treeselection.set_mode(Gtk.SelectionMode.SINGLE)
        treeselection.connect('changed', self.__select_callback, image)

        self.treeview.connect("drag-data-get", self.__drag_data_get,
                              treeselection)

        rend_pix = Gtk.CellRendererPixbuf()
        img_col = Gtk.TreeViewColumn('Thumb')
        img_col.pack_start(rend_pix, False)

        def cell_data_pb(column, cell, model, iter_, *args):
            surface = model[iter_][0]
            cell.set_property("surface", surface)

        img_col.set_cell_data_func(rend_pix, cell_data_pb, None)
        treeview.append_column(img_col)

        rend_pix.set_property('xpad', 2)
        rend_pix.set_property('ypad', 2)
        border_width = self.get_scale_factor() * 2
        rend_pix.set_property('width', self.THUMB_SIZE + 4 + border_width)
        rend_pix.set_property('height', self.THUMB_SIZE + 4 + border_width)

        def escape_data(data):
            for rep in ('\n', '\t', '\r', '\v'):
                data = data.replace(rep, ' ')
            return util.escape(' '.join(data.split()))

        def cell_data(column, cell, model, iter, data):
            cover = model[iter][1]

            esc = escape_data

            txt = '<b><i>%s</i></b>' % esc(cover['name'])
            txt += "\n<small>%s</small>" % (
                _('from %(source)s') % {
                    "source": util.italic(esc(cover['source']))
                })
            if 'resolution' in cover:
                txt += "\n" + _('Resolution: %s') % util.italic(
                    esc(cover['resolution']))
            if 'size' in cover:
                txt += "\n" + _('Size: %s') % util.italic(esc(cover['size']))

            cell.markup = txt
            cell.set_property('markup', cell.markup)

        rend = Gtk.CellRendererText()
        rend.set_property('ellipsize', Pango.EllipsizeMode.END)
        info_col = Gtk.TreeViewColumn('Info', rend)
        info_col.set_cell_data_func(rend, cell_data)

        treeview.append_column(info_col)

        sw_list = Gtk.ScrolledWindow()
        sw_list.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        sw_list.set_shadow_type(Gtk.ShadowType.IN)
        sw_list.add(treeview)

        search_labelraw = Gtk.Label('raw')
        search_labelraw.set_alignment(xalign=1.0, yalign=0.5)
        self.search_fieldraw = Gtk.Entry()
        self.search_fieldraw.connect('activate', self.start_search)
        self.search_fieldraw.connect('changed', self.__searchfieldchanged)
        search_labelclean = Gtk.Label('clean')
        search_labelclean.set_alignment(xalign=1.0, yalign=0.5)
        self.search_fieldclean = Gtk.Label()
        self.search_fieldclean.set_can_focus(False)
        self.search_fieldclean.set_alignment(xalign=0.0, yalign=0.5)

        self.search_radioraw = Gtk.RadioButton(group=None, label=None)
        self.search_radioraw.connect("toggled", self.__searchtypetoggled,
                                     "raw")
        self.search_radioclean = Gtk.RadioButton(group=self.search_radioraw,
                                                 label=None)
        self.search_radioclean.connect("toggled", self.__searchtypetoggled,
                                       "clean")
        #note: set_active(False) appears to have no effect
        #self.search_radioraw.set_active(
        #    self.config_get_bool('searchraw', False))
        if self.config_get_bool('searchraw', False):
            self.search_radioraw.set_active(True)
        else:
            self.search_radioclean.set_active(True)

        search_labelresultsmax = Gtk.Label('limit')
        search_labelresultsmax.set_alignment(xalign=1.0, yalign=0.5)
        search_labelresultsmax.set_tooltip_text(
            _("Per engine 'at best' results limit"))
        search_adjresultsmax = Gtk.Adjustment(value=int(
            self.config_get("resultsmax", 3)),
                                              lower=1,
                                              upper=REQUEST_LIMIT_MAX,
                                              step_incr=1,
                                              page_incr=0,
                                              page_size=0)
        self.search_spinresultsmax = Gtk.SpinButton(
            adjustment=search_adjresultsmax, climb_rate=0.2, digits=0)
        self.search_spinresultsmax.set_alignment(xalign=0.5)
        self.search_spinresultsmax.set_can_focus(False)

        self.search_button = Button(_("_Search"), Icons.EDIT_FIND)
        self.search_button.connect('clicked', self.start_search)
        search_button_box = Gtk.Alignment()
        search_button_box.set(1, 0, 0, 0)
        search_button_box.add(self.search_button)

        search_table = Gtk.Table(rows=3, columns=4, homogeneous=False)
        search_table.attach(search_labelraw,
                            0,
                            1,
                            0,
                            1,
                            xoptions=Gtk.AttachOptions.FILL,
                            xpadding=6)
        search_table.attach(self.search_radioraw,
                            1,
                            2,
                            0,
                            1,
                            xoptions=0,
                            xpadding=0)
        search_table.attach(self.search_fieldraw, 2, 4, 0, 1)
        search_table.attach(search_labelclean,
                            0,
                            1,
                            1,
                            2,
                            xoptions=Gtk.AttachOptions.FILL,
                            xpadding=6)
        search_table.attach(self.search_radioclean,
                            1,
                            2,
                            1,
                            2,
                            xoptions=0,
                            xpadding=0)
        search_table.attach(self.search_fieldclean, 2, 4, 1, 2, xpadding=4)
        search_table.attach(search_labelresultsmax,
                            0,
                            2,
                            2,
                            3,
                            xoptions=Gtk.AttachOptions.FILL,
                            xpadding=6)
        search_table.attach(self.search_spinresultsmax,
                            2,
                            3,
                            2,
                            3,
                            xoptions=Gtk.AttachOptions.FILL,
                            xpadding=0)
        search_table.attach(search_button_box, 3, 4, 2, 3)

        widget_space = 5

        self.progress = Gtk.ProgressBar()

        left_vbox = Gtk.VBox(spacing=widget_space)
        left_vbox.pack_start(search_table, False, True, 0)
        left_vbox.pack_start(sw_list, True, True, 0)

        hpaned = Paned()
        hpaned.set_border_width(widget_space)
        hpaned.pack1(left_vbox, shrink=False)
        hpaned.pack2(image, shrink=False)
        hpaned.set_position(275)

        self.add(hpaned)

        self.show_all()

        left_vbox.pack_start(self.progress, False, True, 0)

        self.connect('destroy', self.__save_config)

        song = songs[0]
        text = SEARCH_PATTERN.format(song)
        self.set_text(text)
        self.start_search()
Exemple #15
0
    def UCI_options(self):
        self.check_running()
        options = self.get_options()
        # option
        # [name, otype, default, minimum, maximum, uvars, userval]
        wdgts = []
        opt_i = -1
        for option in options:
            opt_i += 1
            name = option[0]
            otype = option[1]
            default = option[2]
            minimum = option[3]
            maximum = option[4]
            uvars = option[5]
            userval = option[6]
            # if in common engine settings then skip
            if name in ("Hash", "Ponder"):
                continue
            wdgts.append((
                opt_i, name, otype, default, minimum, maximum, uvars, userval))

        diagtitle = self.get_engine()
        dialog = Gtk.Dialog(
            diagtitle, gv.gui.get_window(), 0,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        sw = Gtk.ScrolledWindow.new(None, None)
        dialog.vbox.pack_start(sw, True, True, 0)

        vb=Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        sw.add(vb)

        sw.show()
        vb.show()

        wlist = []
        for w in wdgts:
            opt_i, name, otype, default, minimum, maximum, uvars, userval = w
            #print(name)
            if otype == "spin":
                if minimum == "":
                    minimum = 0
                if maximum == "":
                    maximum = 10
                if default == "":
                    default = minimum
                if userval != "":
                    default = userval
                adj = Gtk.Adjustment(
                    value=float(default), lower=float(minimum), upper=float(maximum),
                    step_increment=1, page_increment=5, page_size=0)
                spinner = Gtk.SpinButton.new(adj, 1.0, 0)
                # spinner.set_width_chars(14)
                al = Gtk.Alignment.new(
                    xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
                al.add(spinner)

                lbl = Gtk.Label(label=name + ":")

                hb = Gtk.HBox(False, 0)
                hb.pack_start(lbl, False, False, 0)
                hb.pack_start(al, True, True, 10)

                vb.pack_start(hb, False, True, 0)

                v = (opt_i, adj, name, otype)
                wlist.append(v)

                lbl.show()
                spinner.show()
                al.show()
                hb.show()
            elif otype == "string":
                ent = Gtk.Entry()
                if userval != "":
                    default = userval
                ent.set_text(default)

                al = Gtk.Alignment.new(
                    xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
                al.add(ent)

                lbl = Gtk.Label(label=name + ":")

                hb = Gtk.HBox(False, 0)
                hb.pack_start(lbl, False, False, 0)
                hb.pack_start(al, True, True, 10)

                vb.pack_start(hb, False, True, 0)

                v = (opt_i, ent, name, otype)
                wlist.append(v)

                lbl.show()
                ent.show()
                al.show()
                hb.show()
            elif otype == "check":
                cb = Gtk.CheckButton(label=None)
                if userval != "":
                    default = userval
                if default == "true":
                    cb.set_active(True)
                else:
                    cb.set_active(False)
                al = Gtk.Alignment.new(
                    xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
                al.add(cb)

                lbl = Gtk.Label(label=name + ":")
                hb = Gtk.HBox(False, 0)
                hb.pack_start(lbl, False, False, 0)
                hb.pack_start(al, True, True, 10)

                vb.pack_start(hb, False, True, 0)

                v = (opt_i, cb, name, otype)
                wlist.append(v)

                lbl.show()
                cb.show()
                al.show()
                hb.show()
            elif otype == "combo":
                if userval != "":
                    default = userval
                combobox = Gtk.ComboBoxText()
                i = 0
                for v in uvars:
                    combobox.append_text(v)
                    if v == default:
                        combobox.set_active(i)
                    i += 1

                al = Gtk.Alignment.new(
                    xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
                al.add(combobox)
                al.show()
                combobox.show()

                lbl = Gtk.Label(label=name + ":")
                hb = Gtk.HBox(False, 0)
                hb.pack_start(lbl, False, False, 0)
                hb.pack_start(al, True, True, 10)

                vb.pack_start(hb, False, True, 0)

                v = (opt_i, combobox, name, otype)
                wlist.append(v)

                lbl.show()
                hb.show()
            elif otype == "button":
                b = Gtk.Button(label=name)
                al = Gtk.Alignment.new(
                    xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
                al.add(b)

                b.connect(
                    "clicked",
                    lambda widget: self.command(
                        "setoption name " +
                        widget.get_label() + "\n"))

                lbl = Gtk.Label(label=name + ":")
                hb = Gtk.HBox(False, 0)
                hb.pack_start(lbl, False, False, 0)
                hb.pack_start(al, True, True, 10)
                vb.pack_start(hb, False, True, 0)
                lbl.show()
                b.show()
                al.show()
                hb.show()
            else:
                if gv.verbose:
                    print("type ignored - ", otype)
                  
        # set size of scrollwindow to size of child            
        minsize, naturalsize = vb.get_preferred_size()
        sw.set_size_request(minsize.width+20, min(minsize.height, 500))

        dialog.set_default_response(Gtk.ResponseType.OK)
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            for w in wlist:
                opt_i, widge, name, otype = w
                if otype == "spin":
                    av = int(widge.get_value())
                elif otype == "string":
                    av = widge.get_text()
                elif otype == "check":
                    if widge.get_active():
                        av = "true"
                    else:
                        av = "false"
                elif otype == "combo":
                    av = widge.get_active_text()
                else:
                    if gv.verbose:
                        print("unknown type", otype)
                # setoption name <id> [value <x>]
                # uci.set_option(
                #   "option name LimitDepth type spin default 10 min 4 max 10")
                a = "setoption name " + name + " value " + str(av)
                self.set_option(a)
                # update user value
                options[opt_i][6] = str(av)
            self.set_options(options)
            gv.engine_manager.set_uservalues(self.engine, options)
        dialog.destroy()
        self.stop_engine()
Exemple #16
0
 def set_widget_formats(self):
     for widget in (self.cost, self.price):
         widget.set_adjustment(
             Gtk.Adjustment(lower=0, upper=MAX_INT, step_incr=1))
     self.requires_weighing_label.set_size("small")
     self.requires_weighing_label.set_text("")
    def __init__(self):
        Gtk.Settings.get_default().set_long_property('gtk-tooltip-timeout', 0,
                                                     '')
        ##################################
        # init GUI
        self.builder = Gtk.Builder()
        self.builder.add_from_file(os.path.join(WORK_DIR, 'GameConqueror.xml'))

        self.main_window = self.builder.get_object('MainWindow')
        self.main_window.set_title('GameConqueror %s' % (VERSION, ))
        self.about_dialog = self.builder.get_object('AboutDialog')
        # set version
        self.about_dialog.set_version(VERSION)

        self.process_list_dialog = self.builder.get_object('ProcessListDialog')
        self.addcheat_dialog = self.builder.get_object('AddCheatDialog')

        # init memory editor
        self.memoryeditor_window = self.builder.get_object(
            'MemoryEditor_Window')
        self.memoryeditor_hexview = HexView()
        self.memoryeditor_window.get_child().pack_start(
            self.memoryeditor_hexview, True, True, 0)
        self.memoryeditor_hexview.show_all()
        self.memoryeditor_address_entry = self.builder.get_object(
            'MemoryEditor_Address_Entry')
        self.memoryeditor_hexview.connect(
            'char-changed', self.memoryeditor_hexview_char_changed_cb)

        self.found_count_label = self.builder.get_object('FoundCount_Label')
        self.process_label = self.builder.get_object('Process_Label')
        self.value_input = self.builder.get_object('Value_Input')

        self.scanoption_frame = self.builder.get_object('ScanOption_Frame')
        self.scanprogress_progressbar = self.builder.get_object(
            'ScanProgress_ProgressBar')

        self.scan_button = self.builder.get_object('Scan_Button')
        self.reset_button = self.builder.get_object('Reset_Button')
        self.is_first_scan = True

        ###
        # Set scan data type
        self.scan_data_type_combobox = self.builder.get_object(
            'ScanDataType_ComboBox')
        misc.build_combobox(self.scan_data_type_combobox, SCAN_VALUE_TYPES)
        # apply setting
        misc.combobox_set_active_item(self.scan_data_type_combobox,
                                      SETTINGS['scan_data_type'])

        ###
        # set search scope
        self.search_scope_scale = self.builder.get_object('SearchScope_Scale')
        self.search_scope_scale_adjustment = Gtk.Adjustment(lower=0,
                                                            upper=2,
                                                            step_incr=1,
                                                            page_incr=1,
                                                            page_size=0)
        self.search_scope_scale.set_adjustment(
            self.search_scope_scale_adjustment)
        # apply setting
        self.search_scope_scale.set_value(SETTINGS['search_scope'])

        # init scanresult treeview
        # we may need a cell data func here
        # create model
        self.scanresult_tv = self.builder.get_object('ScanResult_TreeView')
        self.scanresult_liststore = Gtk.ListStore(
            str, str, str, bool)  #addr, value, type, valid
        self.scanresult_tv.set_model(self.scanresult_liststore)
        # init columns
        misc.treeview_append_column(self.scanresult_tv,
                                    'Address',
                                    attributes=(('text', 0), ),
                                    properties=(('family', 'monospace'), ))
        misc.treeview_append_column(self.scanresult_tv,
                                    'Value',
                                    attributes=(('text', 1), ),
                                    properties=(('family', 'monospace'), ))

        # init CheatList TreeView
        self.cheatlist_tv = self.builder.get_object('CheatList_TreeView')
        self.cheatlist_liststore = Gtk.ListStore(
            str, bool, str, str, str, str,
            bool)  #lockflag, locked, description, addr, type, value, valid
        self.cheatlist_tv.set_model(self.cheatlist_liststore)
        self.cheatlist_tv.set_reorderable(True)
        self.cheatlist_updates = []
        self.cheatlist_editing = False
        self.cheatlist_tv.connect('key-press-event', self.cheatlist_keypressed)
        # Lock Flag
        misc.treeview_append_column(
            self.cheatlist_tv,
            '',
            renderer_class=Gtk.CellRendererCombo,
            attributes=(('text', 0), ),
            properties=(('editable', True), ('has-entry', False),
                        ('model', LOCK_FLAG_TYPES), ('text-column', 0)),
            signals=(
                ('edited', self.cheatlist_toggle_lock_flag_cb),
                ('editing-started', self.cheatlist_edit_start),
                ('editing-canceled', self.cheatlist_edit_cancel),
            ))
        # Lock
        misc.treeview_append_column(
            self.cheatlist_tv,
            'Lock',
            renderer_class=Gtk.CellRendererToggle,
            attributes=(('active', 1), ),
            properties=(('activatable', True), ('radio', False),
                        ('inconsistent', False)),
            signals=(('toggled', self.cheatlist_toggle_lock_cb), ))
        # Description
        misc.treeview_append_column(
            self.cheatlist_tv,
            'Description',
            attributes=(('text', 2), ),
            properties=(('editable', True), ),
            signals=(
                ('edited', self.cheatlist_edit_description_cb),
                ('editing-started', self.cheatlist_edit_start),
                ('editing-canceled', self.cheatlist_edit_cancel),
            ))
        # Address
        misc.treeview_append_column(self.cheatlist_tv,
                                    'Address',
                                    attributes=(('text', 3), ),
                                    properties=(('family', 'monospace'), ))
        # Type
        misc.treeview_append_column(
            self.cheatlist_tv,
            'Type',
            renderer_class=Gtk.CellRendererCombo,
            attributes=(('text', 4), ),
            properties=(('editable', True), ('has-entry', False),
                        ('model', LOCK_VALUE_TYPES), ('text-column', 0)),
            signals=(
                ('edited', self.cheatlist_edit_type_cb),
                ('editing-started', self.cheatlist_edit_start),
                ('editing-canceled', self.cheatlist_edit_cancel),
            ))
        # Value
        misc.treeview_append_column(
            self.cheatlist_tv,
            'Value',
            attributes=(('text', 5), ),
            properties=(('editable', True), ('family', 'monospace')),
            signals=(
                ('edited', self.cheatlist_edit_value_cb),
                ('editing-started', self.cheatlist_edit_start),
                ('editing-canceled', self.cheatlist_edit_cancel),
            ))

        # init ProcessList
        self.processfilter_input = self.builder.get_object(
            'ProcessFilter_Input')
        self.userfilter_input = self.builder.get_object('UserFilter_Input')
        # init ProcessList_TreeView
        self.processlist_tv = self.builder.get_object('ProcessList_TreeView')
        self.processlist_tv.get_selection().set_mode(Gtk.SelectionMode.SINGLE)
        self.processlist_liststore = Gtk.ListStore(str, str, str)
        self.processlist_filter = self.processlist_liststore.filter_new(
            root=None)
        self.processlist_filter.set_visible_func(self.processlist_filter_func,
                                                 data=None)
        self.processlist_tv.set_model(self.processlist_filter)
        self.processlist_tv.set_enable_search(True)
        self.processlist_tv.set_search_column(1)
        # first col
        misc.treeview_append_column(self.processlist_tv,
                                    'PID',
                                    attributes=(('text', 0), ))
        # second col
        misc.treeview_append_column(self.processlist_tv,
                                    'User',
                                    attributes=(('text', 1), ))

        # third col
        misc.treeview_append_column(self.processlist_tv,
                                    'Process',
                                    attributes=(('text', 2), ))
        # init AddCheatDialog
        self.addcheat_address_input = self.builder.get_object('Address_Input')
        self.addcheat_description_input = self.builder.get_object(
            'Description_Input')
        self.addcheat_type_combobox = self.builder.get_object('Type_ComboBox')
        misc.build_combobox(self.addcheat_type_combobox, LOCK_VALUE_TYPES)
        misc.combobox_set_active_item(self.addcheat_type_combobox,
                                      SETTINGS['lock_data_type'])

        # init popup menu for scanresult
        self.scanresult_popup = Gtk.Menu()
        misc.menu_append_item(self.scanresult_popup, 'Add to cheat list',
                              self.scanresult_popup_cb, 'add_to_cheat_list')
        misc.menu_append_item(self.scanresult_popup, 'Browse this address',
                              self.scanresult_popup_cb, 'browse_this_address')
        misc.menu_append_item(self.scanresult_popup, 'Scan for this address',
                              self.scanresult_popup_cb,
                              'scan_for_this_address')
        self.scanresult_popup.show_all()

        # init popup menu for cheatlist
        self.cheatlist_popup = Gtk.Menu()
        misc.menu_append_item(self.cheatlist_popup, 'Browse this address',
                              self.cheatlist_popup_cb, 'browse_this_address')
        misc.menu_append_item(self.cheatlist_popup, 'Copy address',
                              self.cheatlist_popup_cb, 'copy_address')
        misc.menu_append_item(self.cheatlist_popup, 'Remove this entry',
                              self.cheatlist_popup_cb, 'remove_entry')
        self.cheatlist_popup.show_all()

        self.builder.connect_signals(self)
        self.main_window.connect('destroy', self.exit)

        ###########################
        # init others (backend, flag...)
        self.pid = 0  # target pid
        self.maps = []
        self.last_hexedit_address = (0, 0)  # used for hexview
        self.is_scanning = False
        self.exit_flag = False  # currently for data_worker only, other 'threads' may also use this flag
        self.is_data_worker_working = False

        self.backend = GameConquerorBackend()
        self.check_backend_version()
        self.search_count = 0
        GObject.timeout_add(DATA_WORKER_INTERVAL, self.data_worker)
        self.command_lock = threading.RLock()
Exemple #18
0
    def build_gui(self):
        self.win = win = Gtk.Window(title='GnomeCast')
        win.set_border_width(0)
        win.set_icon(self.get_logo_pixbuf(color='#000000'))
        self.cast_store = cast_store = Gtk.ListStore(object, str)
        cast_store.append([None, "Searching local network - please wait..."])

        vbox_outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=16)

        self.thumbnail_image = Gtk.Image()
        self.thumbnail_image.set_from_pixbuf(self.get_logo_pixbuf())
        vbox_outer.pack_start(self.thumbnail_image, True, False, 0)
        alignment = Gtk.Alignment(xscale=1, yscale=1)
        alignment.add(vbox)
        alignment.set_padding(16, 20, 16, 16)
        vbox_outer.pack_start(alignment, False, False, 0)

        self.cast_combo = cast_combo = Gtk.ComboBox.new_with_model(cast_store)
        cast_combo.set_entry_text_column(1)
        renderer_text = Gtk.CellRendererText()
        cast_combo.pack_start(renderer_text, True)
        cast_combo.add_attribute(renderer_text, "text", 1)
        cast_combo.set_active(0)

        vbox.pack_start(cast_combo, False, False, 0)
        win.add(vbox_outer)

        self.file_button = button1 = Gtk.Button(
            "Choose an audio or video file...")
        button1.connect("clicked", self.on_file_clicked)
        vbox.pack_start(button1, False, False, 0)

        self.subtitle_store = subtitle_store = Gtk.ListStore(str, int, str)
        subtitle_store.append(["No subtitles.", -1, None])
        subtitle_store.append(["Add subtitle file...", -2, None])
        self.subtitle_combo = Gtk.ComboBox.new_with_model(subtitle_store)
        self.subtitle_combo.connect("changed", self.on_subtitle_combo_changed)
        self.subtitle_combo.set_entry_text_column(0)
        renderer_text = Gtk.CellRendererText()
        self.subtitle_combo.pack_start(renderer_text, True)
        self.subtitle_combo.add_attribute(renderer_text, "text", 0)
        self.subtitle_combo.set_active(0)
        vbox.pack_start(self.subtitle_combo, False, False, 0)

        self.scrubber_adj = Gtk.Adjustment(0, 0, 100, 15, 60, 0)
        self.scrubber = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL,
                                  adjustment=self.scrubber_adj)
        self.scrubber.set_digits(0)

        def f(scale, s):
            notes = [self.humanize_seconds(s)]
            if self.cast and self.cast.media_controller.status.player_state == 'BUFFERING':
                notes.append('...')
            return ''.join(notes)

        self.scrubber.connect("format-value", f)
        self.scrubber.connect("change-value", self.scrubber_move_started)
        self.scrubber.connect("change-value", self.scrubber_moved)
        self.scrubber.set_sensitive(False)
        vbox.pack_start(self.scrubber, False, False, 0)

        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=16)
        self.rewind_button = Gtk.Button(
            None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_REWIND))
        self.rewind_button.connect("clicked", self.rewind_clicked)
        self.rewind_button.set_sensitive(False)
        hbox.pack_start(self.rewind_button, True, False, 0)
        self.play_button = Gtk.Button(
            None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_PLAY))
        self.play_button.connect("clicked", self.play_clicked)
        self.play_button.set_sensitive(False)
        hbox.pack_start(self.play_button, True, False, 0)
        self.forward_button = Gtk.Button(
            None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_FORWARD))
        self.forward_button.connect("clicked", self.forward_clicked)
        self.forward_button.set_sensitive(False)
        hbox.pack_start(self.forward_button, True, False, 0)
        self.stop_button = Gtk.Button(
            None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_STOP))
        self.stop_button.connect("clicked", self.stop_clicked)
        self.stop_button.set_sensitive(False)
        hbox.pack_start(self.stop_button, True, False, 0)
        vbox.pack_start(hbox, False, False, 0)

        cast_combo.connect("changed", self.on_cast_combo_changed)

        win.connect("delete-event", self.quit)
        win.connect("key_press_event", self.on_key_press)
        win.show_all()

        GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.quit)
Exemple #19
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle, True)

        self.max_participants = 1
        self.dic = {}

        # Canvas
        self._canvas = Gtk.VBox()

        hbox = Gtk.HBox()
        self._liststore = Gtk.ListStore(str)
        self.combo1 = Gtk.ComboBox.new_with_model_and_entry(self._liststore)
        cell = Gtk.CellRendererText()
        self.combo1.pack_start(cell, True)
        self.combo1.set_entry_text_column(0)
        self.combo1.connect('changed', self._call)

        flip_btn = Gtk.Button()
        flip_btn.connect('clicked', self._flip)
        flip_btn.add(Gtk.Image.new_from_file('icons/flip.svg'))

        self.combo2 = Gtk.ComboBox.new_with_model_and_entry(self._liststore)
        cell = Gtk.CellRendererText()
        self.combo2.pack_start(cell, True)
        self.combo2.set_entry_text_column(0)
        self.combo2.connect('changed', self._call)

        self.label_box = Gtk.HBox()

        self.adjustment = Gtk.Adjustment(1.0, 0, 10.00**10.00, 1.0, 1.0, 0)
        self.spin = Gtk.SpinButton()
        self.spin.set_adjustment(self.adjustment)
        self.spin.set_numeric(True)

        self.label = Gtk.Label()
        self.label._size = 12
        self.label.set_selectable(True)
        self.label.connect('draw', self.resize_label)

        self.convert_btn = Gtk.Button(_('Convert'))
        self.convert_btn.connect('clicked', self._call)

        self._canvas.pack_start(hbox, False, False, 20)
        hbox.pack_start(self.combo1, False, True, 20)
        hbox.pack_start(flip_btn, True, False, 20)
        hbox.pack_end(self.combo2, False, True, 20)
        spin_box = Gtk.HBox()
        convert_box = Gtk.HBox()
        convert_box.pack_start(spin_box, True, False, 0)
        spin_box.pack_start(self.spin, False, False, 0)
        self._canvas.pack_start(convert_box, False, False, 5)
        self._canvas.pack_start(self.label_box, True, False, 0)
        self.label_box.add(self.label)
        spin_box.pack_start(self.convert_btn, False, False, 20)

        self.set_canvas(self._canvas)

        # Toolbar
        toolbarbox = ToolbarBox()

        activity_button = ActivityToolbarButton(self)

        toolbarbox.toolbar.insert(activity_button, 0)

        separator = Gtk.SeparatorToolItem()
        separator.set_expand(False)
        separator.set_draw(True)
        toolbarbox.toolbar.insert(separator, -1)

        self._edit_toolbar = EditToolbar()
        self._edit_toolbar.undo.props.visible = False
        self._edit_toolbar.redo.props.visible = False
        self._edit_toolbar.separator.props.visible = False
        self._edit_toolbar.copy.set_sensitive = False
        self._edit_toolbar.copy.connect('clicked', self._edit_copy_cb)

        edit_toolbar_button = ToolbarButton(page=self._edit_toolbar,
                                            icon_name='toolbar-edit')
        edit_toolbar_button.props.label = _('Edit')

        self._edit_toolbar.show()
        edit_toolbar_button.show()
        toolbarbox.toolbar.insert(edit_toolbar_button, -1)

        # RadioToolButton
        self._length_btn = RadioToolButton()
        self._length_btn.connect('clicked',
                                 lambda w: self._update_combo(convert.length))
        # TRANS: https://en.wikipedia.org/wiki/Length
        self._length_btn.set_tooltip(_('Length'))
        self._length_btn.props.icon_name = 'length'

        self._volume_btn = RadioToolButton()
        self._volume_btn.connect('clicked',
                                 lambda w: self._update_combo(convert.volume))
        # TRANS: https://en.wikipedia.org/wiki/Volume
        self._volume_btn.set_tooltip(_('Volume'))
        self._volume_btn.props.icon_name = 'volume'
        self._volume_btn.props.group = self._length_btn

        self._area_btn = RadioToolButton()
        self._area_btn.connect('clicked',
                               lambda w: self._update_combo(convert.area))
        # TRANS: https://en.wikipedia.org/wiki/Area
        self._area_btn.set_tooltip(_('Area'))
        self._area_btn.props.icon_name = 'area'
        self._area_btn.props.group = self._length_btn

        self._weight_btn = RadioToolButton()
        self._weight_btn.connect('clicked',
                                 lambda w: self._update_combo(convert.weight))
        # TRANS: https://en.wikipedia.org/wiki/Weight
        self._weight_btn.set_tooltip(_('Weight'))
        self._weight_btn.props.icon_name = 'weight'
        self._weight_btn.props.group = self._length_btn

        self._speed_btn = RadioToolButton()
        self._speed_btn.connect('clicked',
                                lambda w: self._update_combo(convert.speed))
        # TRANS: https://en.wikipedia.org/wiki/Speed
        self._speed_btn.set_tooltip(_('Speed'))
        self._speed_btn.props.icon_name = 'speed'
        self._speed_btn.props.group = self._length_btn

        self._time_btn = RadioToolButton()
        self._time_btn.connect('clicked',
                               lambda w: self._update_combo(convert.time))
        # TRANS: https://en.wikipedia.org/wiki/Time
        self._time_btn.set_tooltip(_('Time'))
        self._time_btn.props.icon_name = 'time'
        self._time_btn.props.group = self._length_btn

        self._temp_btn = RadioToolButton()
        self._temp_btn.connect('clicked',
                               lambda w: self._update_combo(convert.temp))
        # TRANS: https://en.wikipedia.org/wiki/Temperature
        self._temp_btn.set_tooltip(_('Temperature'))
        self._temp_btn.props.icon_name = 'temp'
        self._temp_btn.props.group = self._length_btn

        toolbarbox.toolbar.insert(self._length_btn, -1)
        toolbarbox.toolbar.insert(self._volume_btn, -1)
        toolbarbox.toolbar.insert(self._area_btn, -1)
        toolbarbox.toolbar.insert(self._weight_btn, -1)
        toolbarbox.toolbar.insert(self._speed_btn, -1)
        toolbarbox.toolbar.insert(self._time_btn, -1)
        toolbarbox.toolbar.insert(self._temp_btn, -1)

        separator = Gtk.SeparatorToolItem()
        separator.set_expand(True)
        separator.set_draw(False)
        toolbarbox.toolbar.insert(separator, -1)

        stopbtn = StopButton(self)
        toolbarbox.toolbar.insert(stopbtn, -1)

        self.set_toolbar_box(toolbarbox)
        self._update_combo(convert.length)
        self.show_all()
Exemple #20
0
col = Gtk.ColorSelection(has_palette=True) #Color Pallete

button1 = Gtk.Button(label="Width++")   #Width of brush
button2= Gtk.Button(label="Width--")

button3=Gtk.ComboBoxText()
button3.append("1","Rectangle")
button3.append("2","Ellipse")
button3.append("3","Circle")
button4=Gtk.Button(label="Ok")
button5=Gtk.Entry()
button6=Gtk.Button(label="Save")
button5.set_text("Enter file name with extn")

range=Gtk.Adjustment(lower=1,upper=1000,step_increment=1)
range2=Gtk.Adjustment(lower=1,upper=1000,step_increment=1)
range3=Gtk.Adjustment(lower=1,upper=750,step_increment=1)

shape_length=Gtk.SpinButton(adjustment=range)
shape_width=Gtk.SpinButton(adjustment=range2)
shape_radius=Gtk.SpinButton(adjustment=range3)

listb=Gtk.ListBox()
listb.set_selection_mode(Gtk.SelectionMode.NONE)

row = Gtk.ListBoxRow()
row2= Gtk.ListBoxRow()
row3= Gtk.ListBoxRow()

label1 = Gtk.Label(label="Length ")
Exemple #21
0
    def __init__(self, keys=None):

        """Initialize and display a keyboard
        
        keys is an optional array of frequency indexes
        
        """

        # I18n
        ######
        # Using local path
        local_path = os.path.abspath(os.path.dirname(sys.argv[0])) + "/locale"
        gettext.install("tuner", local_path)
        
        # Create empty if no key specified
        self._default_keys = keys or []

        # Variables
        ###########

        # Buttons and handlers
        self._buttons = []

        # Beep process
        self._beep_process = 0

        # Beep queue
        self._beep_queue = deque([])

        # Note playing token
        self._note_playing  = False

        # Keys modified flag
        self._keys_modified_flag = False

        # Settings
        self._beep_length = 1
        self._notestyle = _Note.INDEX_FR_NAME
        self._backend = self._SOX_PLUCK

        # Create window
        ###############
        self._dialog = Gtk.Dialog()
        self._dialog.connect("destroy", self._close_request)
        self._dialog.set_title(_("Tuner"))
        self._dialog.set_border_width(10)

        # Create vertical box and horizontal sub-boxes
        vbox = Gtk.Box(homogeneous=False, spacing=10, 
                       orientation=Gtk.Orientation.VERTICAL)
        hbox_controls = Gtk.ButtonBox()
        self._hbox_keys = Gtk.Box(homogeneous=True)
        hbox_settings = Gtk.Box(homogeneous=False, spacing=10)

        # Control horizontal box
        ########################

        hbox_controls.set_layout(Gtk.ButtonBoxStyle.START)

        # Reset keys modifications
        self._reset_button = Gtk.Button(stock=Gtk.STOCK_CANCEL)
        self._reset_button.set_sensitive(False)
        hbox_controls.add(self._reset_button)
        self._reset_button.connect("clicked", self._reset_keys)
        self._reset_button.show()

        # Remove key
        self._button_rem = Gtk.Button(stock=Gtk.STOCK_REMOVE)
        hbox_controls.add(self._button_rem)
        self._button_rem.connect("clicked", self._rem_key)
        self._button_rem.show()
        
        # Add key
        self._button_add = Gtk.Button(stock=Gtk.STOCK_ADD)
        hbox_controls.add(self._button_add)
        self._button_add.connect("clicked", self._add_key)
        self._button_add.show()
        
        # Stop playback
        self._stop_playback_button = Gtk.Button(stock=Gtk.STOCK_MEDIA_STOP)
        self._stop_playback_button.set_sensitive(False)
        hbox_controls.add(self._stop_playback_button)
        hbox_controls.set_child_secondary(self._stop_playback_button, True)
        self._stop_playback_button.connect("clicked", 
                                           self._stop_playback_request)
        self._stop_playback_button.show()

        # Play all keys
        self._play_all_button = Gtk.Button(stock=Gtk.STOCK_MEDIA_PLAY)
        hbox_controls.add(self._play_all_button)
        hbox_controls.set_child_secondary(self._play_all_button, True)
        self._play_all_button.connect("clicked", self._play_all)
        self._play_all_button.show()

        # Keys horizontal box
        #####################

        # Add global incrementor / decrementor buttons
        vbox_inc_dec = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)

        # Octave decrement
        hbox_arrow = Gtk.Box()
        arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.DOWN, 
                          shadow_type=Gtk.ShadowType.OUT)
        hbox_arrow.pack_start(arrow, True, True, 0)
        arrow.show()
        label = Gtk.Label(label="8")
        hbox_arrow.pack_start(label, True, True, 0)
        label.show()
        self._button_oct_down = Gtk.Button()
        self._button_oct_down.add(hbox_arrow)
        vbox_inc_dec.pack_end(self._button_oct_down, False, True, 0)
        hbox_arrow.show()
        self._button_oct_down.show()
        
        # Semitone decrement
        hbox_arrow = Gtk.Box()
        arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.DOWN, 
                          shadow_type=Gtk.ShadowType.OUT)
        hbox_arrow.pack_start(arrow, True, True, 0)
        arrow.show()
        label = Gtk.Label(label=u"\u266D")
        hbox_arrow.pack_start(label, True, True, 0)
        label.show()
        self._button_down = Gtk.Button()
        self._button_down.add(hbox_arrow)
        vbox_inc_dec.pack_end(self._button_down, False, True, 0)
        hbox_arrow.show()
        self._button_down.show()

        # Semitone increment
        hbox_arrow = Gtk.Box()
        arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.UP, 
                          shadow_type=Gtk.ShadowType.OUT)
        hbox_arrow.pack_start(arrow, True, True, 0)
        arrow.show()
        label = Gtk.Label(label=u"\u266F")
        hbox_arrow.pack_start(label, True, True, 0)
        label.show()
        self._button_up = Gtk.Button()
        self._button_up.add(hbox_arrow)
        vbox_inc_dec.pack_end(self._button_up, False, True, 0)
        hbox_arrow.show()
        self._button_up.show()
        
        # Octave increment
        hbox_arrow = Gtk.Box()
        arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.UP, 
                          shadow_type=Gtk.ShadowType.OUT)
        hbox_arrow.pack_start(arrow, True, True, 0)
        arrow.show()
        label = Gtk.Label(label="8")
        hbox_arrow.pack_start(label, True, True, 0)
        label.show()
        self._button_oct_up = Gtk.Button()
        self._button_oct_up.add(hbox_arrow)
        vbox_inc_dec.pack_end(self._button_oct_up, False, True, 0)
        hbox_arrow.show()
        self._button_oct_up.show()
        
        vbox_inc_dec.show()
        self._hbox_keys.pack_start(vbox_inc_dec, True, True, 0)

        self._button_up.connect("clicked", self._adjust_freq, 1)
        self._button_down.connect("clicked", self._adjust_freq, -1)
        self._button_oct_up.connect("clicked", self._adjust_freq, 12)
        self._button_oct_down.connect("clicked", self._adjust_freq, -12)

        # Set default keys
        self._reset_keys()
 
        # Settings horizontal box
        #########################

        # Note style selector
        vbox_notestyle = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        label = Gtk.Label(label=_("Notestyle"))
        label.set_alignment(0, 1)
        vbox_notestyle.pack_start(label, False, True, 0)
        label.show()
        button = Gtk.RadioButton.new_with_label_from_widget(None, _("French"))
        button.connect("clicked", self._set_notestyle, _Note.INDEX_FR_NAME)
        vbox_notestyle.pack_start(button, False, True, 0)
        button.show()
        button = Gtk.RadioButton.new_with_label_from_widget(button, _("English"))
        button.connect("clicked", self._set_notestyle, _Note.INDEX_EN_NAME)
        button.emit('clicked')
        vbox_notestyle.pack_start(button, False, True, 0)
        button.show()
        hbox_settings.pack_start(vbox_notestyle, False, True, 0)
        vbox_notestyle.show()

        # Separator
        separator = Gtk.VSeparator()
        hbox_settings.pack_start(separator, False, True, 0)
        separator.show()

        # Beep length
        vbox_beep_length = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        label = Gtk.Label(label=_("Length (s)"))
        label.set_alignment(0, 1)
        vbox_beep_length.pack_start(label, False, True, 0)
        label.show()
        beep_length_adj = Gtk.Adjustment(value=self._beep_length, \
                                         lower=1, \
                                         upper=10, \
                                         step_increment=1, \
                                         page_increment=1, \
                                         page_size=0)
        beep_length_spin = Gtk.SpinButton(adjustment=beep_length_adj, 
                                          climb_rate=0, 
                                          digits=1)
        beep_length_adj.connect("value_changed", 
                                self._set_beep_length, 
                                beep_length_spin)
        vbox_beep_length.pack_start(beep_length_spin, False, True, 0)
        beep_length_spin.show()
        hbox_settings.pack_start(vbox_beep_length, False, True, 0)
        vbox_beep_length.show()

        # Separator
        separator = Gtk.VSeparator()
        hbox_settings.pack_start(separator, False, True, 0)
        separator.show()

        # Backend selector
        vbox_backend = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        label = Gtk.Label(label=_("Output"))
        label.set_alignment(0, 1)
        vbox_backend.pack_start(label, False, True, 0)
        label.show()
        button = Gtk.RadioButton.new_with_label_from_widget(None, 
                                                            "Sox (pluck)")
        button.connect("clicked", self._set_backend, self._SOX_PLUCK)
        vbox_backend.pack_start(button, False, True, 0)
        button.show()
        button = Gtk.RadioButton.new_with_label_from_widget(button,
                                                            "Sox (sine)")
        button.connect("clicked", self._set_backend, self._SOX_SINE)
        vbox_backend.pack_start(button, False, True, 0)
        button.show()
        button = Gtk.RadioButton.new_with_label_from_widget(button, 
                                                            "Beep")
        button.connect("clicked", self._set_backend, self._BEEP)
        vbox_backend.pack_start(button, False, True, 0)
        button.show()
        hbox_settings.pack_start(vbox_backend, False, True, 0)
        vbox_backend.show()

        # Show everything
        #################
        vbox.pack_start(hbox_controls, True, True, 0)
        vbox.pack_start(self._hbox_keys, True, True, 0)
        vbox.pack_start(hbox_settings, True, True, 0)
        hbox_controls.show()
        self._hbox_keys.show()
        hbox_settings.show()
        vbox.show()
        self._dialog.vbox.add(vbox)
        self._dialog.show()

        # Poll note queue
        GObject.idle_add(self._play_note_from_queue)
Exemple #22
0
    def PluginPreferences(self, win):
        vb = Gtk.VBox(spacing=6)
        if not self.player_has_eq:
            l = Gtk.Label()
            l.set_markup(
                _('The current backend does not support equalization.'))
            vb.pack_start(l, False, True, 0)
            return vb

        def format_hertz(band):
            if band >= 1000:
                return _('%.1f kHz') % (band / 1000.)
            return _('%d Hz') % band

        bands = [format_hertz(band) for band in app.player.eq_bands]
        levels = get_config() + [0.] * len(bands)

        table = Gtk.Table(rows=len(bands), columns=3)
        table.set_col_spacings(6)

        def set_band(adj, idx):
            levels[idx] = adj.get_value()
            config.set('plugins', 'equalizer_levels',
                       ','.join(map(str, levels)))
            self.apply()

        adjustments = []

        for i, band in enumerate(bands):
            # align numbers and suffixes in separate rows for great justice
            lbl = Gtk.Label(label=band.split()[0])
            lbl.set_alignment(1, 0.5)
            lbl.set_padding(0, 4)
            table.attach(lbl, 0, 1, i, i + 1, xoptions=Gtk.AttachOptions.FILL)
            lbl = Gtk.Label(label=band.split()[1])
            lbl.set_alignment(1, 0.5)
            table.attach(lbl, 1, 2, i, i + 1, xoptions=Gtk.AttachOptions.FILL)
            adj = Gtk.Adjustment(levels[i], -24., 12., 0.1)
            adj.connect('value-changed', set_band, i)
            adjustments.append(adj)
            hs = Gtk.HScale(adjustment=adj)
            hs.set_draw_value(True)
            hs.set_value_pos(Gtk.PositionType.RIGHT)
            hs.connect('format-value', lambda s, v: _('%.1f dB') % v)
            table.attach(hs, 2, 3, i, i + 1)
        vb.pack_start(table, True, True, 0)

        def clicked_cb(button):
            [adj.set_value(0) for adj in adjustments]

        sorted_presets = sorted(PRESETS.iteritems())

        def combo_changed(combo):
            # custom, skip
            if not combo.get_active():
                return
            gain = sorted_presets[combo.get_active() - 1][1][1]
            gain = interp_bands(PRESET_BANDS, app.player.eq_bands, gain)
            for (g, a) in zip(gain, adjustments):
                a.set_value(g)

        combo = Gtk.ComboBoxText()
        combo.append_text(_("Custom"))
        combo.set_active(0)
        for key, (name, gain) in sorted_presets:
            combo.append_text(name)
        combo.connect("changed", combo_changed)

        bbox = Gtk.HButtonBox()
        clear = Button(_("_Clear"), Icons.EDIT_CLEAR)
        clear.connect('clicked', clicked_cb)
        bbox.pack_start(combo, True, True, 0)
        bbox.pack_start(clear, True, True, 0)
        vb.pack_start(bbox, True, True, 0)
        return vb
Exemple #23
0
    def _fill(self, main):
        label = Gtk.Label(label="Ligne d'influence:")
        label.set_alignment(0., 0.5)
        label.set_padding(5, 0)
        self.vbox.pack_start(label, False, False, 0)
        button = Gtk.RadioButton.new_with_label_from_widget(
            None, "Effort tranchant")
        button.set_name("1")
        self.vbox.pack_start(button, False, False, 0)

        button = Gtk.RadioButton.new_with_label_from_widget(
            button, "Moment fléchissant")
        button.set_name("2")
        self.vbox.pack_start(button, False, False, 0)
        button = Gtk.RadioButton.new_with_label_from_widget(button, "Flèche")
        button.set_name("3")
        self.vbox.pack_start(button, False, False, 0)
        button = Gtk.RadioButton.new_with_label_from_widget(
            button, "Réaction d'appui")
        button.set_name("4")
        self.vbox.pack_start(button, False, False, 0)
        self.group = button.get_group()

        self.combobox1 = Gtk.ComboBoxText()
        hbox = Gtk.HBox()  # permet de controler la largeur du combo
        label = Gtk.Label(label="Elément: ")
        hbox.pack_start(label, False, False, 0)
        self.combobox1.set_size_request(80, -1)
        hbox.pack_start(self.combobox1, False, False, 0)
        self.vbox.pack_start(hbox, False, False, 0)
        #self.handler1 = self.combobox.connect("changed", main._get_one_value_influ)

        hbox = Gtk.HBox()
        label = self.spin_label1 = Gtk.Label(label="Position en %: ")
        hbox.pack_start(label, False, False, 0)
        adjust = Gtk.Adjustment(0., 0., 100., 1., 5.)
        spin = self.spin1 = Gtk.SpinButton.new(adjust, 5, 0)
        spin.connect("event", self._update)
        hbox.pack_start(spin, False, False, 0)
        self.vbox.pack_start(hbox, False, False, 0)

        #hbox = Gtk.HBox()
        b = self.check1 = Gtk.CheckButton("Longueur en m")
        b.connect('clicked', self._set_length_unit)
        #hbox.pack_start(b, False, False, 0)
        self.vbox.pack_start(b, False, False, 0)

        toolbar = Gtk.Toolbar()
        b = Gtk.ToolButton(Gtk.STOCK_EXECUTE)
        b.set_label("Calculer")
        b.set_tooltip_text("Calculer la ligne d'influence")
        b.connect("clicked", main.area_expose_influ)
        toolbar.insert(b, -1)
        b = Gtk.ToolButton(Gtk.STOCK_ADD)
        b.set_label("Superposer")
        b.set_tooltip_text("Superposer une nouvelle ligne d'influence")
        b.connect("clicked", main.area_expose_influ, False)
        toolbar.insert(b, -1)
        b = Gtk.ToolButton(Gtk.STOCK_CLEAR)
        b.set_label("Effacer")
        b.set_tooltip_text("Effacer les lignes d'influence")
        b.connect("clicked", main.on_del_influs)
        toolbar.insert(b, -1)
        self.vbox.pack_start(toolbar, False, False, 0)

        self.vbox.show_all()
Exemple #24
0
    def __init__(self, activity):
        GObject.GObject.__init__(self)

        self.playing = False
        self.playingbackwards = False
        self.toplevel = activity
        self.stickselected = 'RIGHT SHOULDER'
        self.surface = None
        self._emit_move_handle = None

        self.setplayspeed(50)

        self.keys_overlap_stack = []
        for i in range(len(model.keys)):
            self.keys_overlap_stack.append(i)

        self.key = screenflip.ScreenFrame()

        self.kfselected = 0
        self.jointpressed = None
        self.kfpressed = -1
        self.middlepressed = False
        self.rotatepressed = False
        self.iconsdir = os.path.join(get_bundle_path(), 'icons')

        # screen

        self.mfdraw = Gtk.DrawingArea()
        self.mfdraw.connect('draw', self.__draw_cb)
        self.mfdraw.connect('configure_event', self.configure_event)
        self.mfdraw.connect('motion_notify_event', self.motion_notify_event)
        self.mfdraw.connect('button_press_event', self.button_press_event)
        self.mfdraw.connect('button_release_event', self.button_release_event)
        self.mfdraw.set_events(Gdk.EventMask.EXPOSURE_MASK
                               | Gdk.EventMask.LEAVE_NOTIFY_MASK
                               | Gdk.EventMask.BUTTON_PRESS_MASK
                               | Gdk.EventMask.BUTTON_RELEASE_MASK
                               | Gdk.EventMask.POINTER_MOTION_MASK
                               | Gdk.EventMask.POINTER_MOTION_HINT_MASK)
        self.mfdraw.set_size_request(DRAWWIDTH, DRAWHEIGHT)

        screen_box = Gtk.EventBox()
        screen_box.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(BACKGROUND))
        screen_box.set_border_width(PAD / 2)
        screen_box.add(self.mfdraw)

        screen_pink = Gtk.EventBox()
        screen_pink.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(PINK))
        screen_pink.set_border_width(PAD)
        screen_pink.add(screen_box)

        # keyframes

        self.kfdraw = Gtk.DrawingArea()
        self.kfdraw.set_size_request(KEYFRAMEWIDTH, KEYFRAMEHEIGHT)
        self.kfdraw.connect('draw', self.__kf_draw_cb)
        self.kfdraw.connect('configure_event', self.kf_configure_event)
        self.kfdraw.connect('motion_notify_event', self.kf_motion_notify_event)
        self.kfdraw.connect('button_press_event', self.kf_button_press_event)
        self.kfdraw.connect('button_release_event',
                            self.kf_button_release_event)
        self.kfdraw.set_events(Gdk.EventMask.EXPOSURE_MASK
                               | Gdk.EventMask.LEAVE_NOTIFY_MASK
                               | Gdk.EventMask.BUTTON_PRESS_MASK
                               | Gdk.EventMask.BUTTON_RELEASE_MASK
                               | Gdk.EventMask.POINTER_MOTION_MASK
                               | Gdk.EventMask.POINTER_MOTION_HINT_MASK)

        kfdraw_box = Gtk.EventBox()
        kfdraw_box.set_border_width(PAD)
        kfdraw_box.add(self.kfdraw)

        # control box

        angle_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        anglelabel = Gtk.Label(label=_('Angle:'))
        anglelabel.modify_fg(Gtk.StateType.NORMAL,
                             Gdk.color_parse(BUTTON_BACKGROUND))
        anglelabel.set_size_request(60, -1)
        angle_box.pack_start(anglelabel, False, False, 5)
        self.angleentry = Gtk.Entry()
        self.angleentry.set_max_length(3)
        self.angleentry.set_width_chars(3)
        self.angleentry.connect('activate', self.enterangle_callback,
                                self.angleentry)
        self.angleentry.modify_bg(Gtk.StateType.INSENSITIVE,
                                  Gdk.color_parse(BUTTON_FOREGROUND))
        angle_box.pack_start(self.angleentry, False, False, 0)
        self.anglel_adj = Gtk.Adjustment(0, 0, 360, 1, 60, 0)
        self.anglel_adj.connect('value_changed', self._anglel_adj_cb)
        self.anglel_slider = Gtk.Scale.new(0, self.anglel_adj)
        self.anglel_slider.set_draw_value(False)
        for state, color in COLOR_BG_BUTTONS:
            self.anglel_slider.modify_bg(state, Gdk.color_parse(color))
        angle_box.pack_start(self.anglel_slider, True, True, 0)

        size_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        sizelabel = Gtk.Label(label=_('Size:'))
        sizelabel.modify_fg(Gtk.StateType.NORMAL,
                            Gdk.color_parse(BUTTON_BACKGROUND))
        sizelabel.set_size_request(60, -1)
        size_box.pack_start(sizelabel, False, False, 5)
        self.sizeentry = Gtk.Entry()
        self.sizeentry.set_max_length(3)
        self.sizeentry.set_width_chars(3)
        self.sizeentry.connect('activate', self.enterlen_callback,
                               self.sizeentry)
        self.sizeentry.modify_bg(Gtk.StateType.INSENSITIVE,
                                 Gdk.color_parse(BUTTON_FOREGROUND))
        size_box.pack_start(self.sizeentry, False, False, 0)
        self.size_adj = Gtk.Adjustment(0, 0, 200, 1, 30, 0)
        self.size_adj.connect('value_changed', self._size_adj_cb)
        size_slider = Gtk.Scale.new(0, self.size_adj)
        size_slider.set_draw_value(False)
        for state, color in COLOR_BG_BUTTONS:
            size_slider.modify_bg(state, Gdk.color_parse(color))
        size_box.pack_start(size_slider, True, True, 0)

        control_head_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        control_head_box.pack_start(angle_box, True, True, 0)
        control_head_box.pack_start(size_box, True, True, 0)

        control_head = Gtk.EventBox()
        control_head.modify_bg(Gtk.StateType.NORMAL,
                               Gdk.color_parse(BUTTON_FOREGROUND))
        control_head.add(control_head_box)

        control_options = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.stickbuttons = {}
        self.sticklabels = {}
        for stickpartname in LABELLIST:
            label = Gtk.Label(label=STRINGS[stickpartname])
            label.modify_fg(Gtk.StateType.NORMAL,
                            Gdk.color_parse(BUTTON_FOREGROUND))
            self.sticklabels[stickpartname] = label
            ebox = Gtk.EventBox()
            ebox.modify_bg(Gtk.StateType.NORMAL,
                           Gdk.color_parse(BUTTON_BACKGROUND))
            ebox.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)
            ebox.connect('button_press_event', self.selectstick, stickpartname)
            ebox.add(label)
            self.stickbuttons[stickpartname] = ebox
            control_options.pack_start(ebox, False, False, 0)
        self.selectstickebox()

        control_scroll = Gtk.ScrolledWindow()
        control_scroll.set_policy(Gtk.PolicyType.NEVER,
                                  Gtk.PolicyType.AUTOMATIC)
        control_scroll.add_with_viewport(control_options)
        control_options.get_parent().modify_bg(
            Gtk.StateType.NORMAL, Gdk.color_parse(BUTTON_BACKGROUND))

        control_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        control_box.pack_start(control_head, False, False, 0)
        control_box.pack_start(control_scroll, True, True, 0)

        control_bg = Gtk.EventBox()
        control_bg.modify_bg(Gtk.StateType.NORMAL,
                             Gdk.color_parse(BUTTON_BACKGROUND))
        control_bg.set_border_width(PAD / 2)
        control_bg.add(control_box)

        control_pink = Gtk.EventBox()
        control_pink.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(PINK))
        control_pink.set_border_width(PAD)
        control_pink.add(control_bg)

        # left control box

        logo = Gtk.Image()
        logo.set_from_file(os.path.join(self.iconsdir, 'logo.png'))

        leftbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        leftbox.pack_start(logo, False, False, 0)
        leftbox.pack_start(control_pink, True, True, 0)

        # desktop

        hdesktop = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        hdesktop.pack_start(leftbox, False, False, 0)
        hdesktop.pack_start(screen_pink, False, False, 0)

        desktop = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        desktop.pack_start(hdesktop, True, True, 0)
        desktop.pack_start(kfdraw_box, False, False, 0)

        greenbox = Gtk.EventBox()
        greenbox.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(BACKGROUND))
        greenbox.set_border_width(PAD / 2)
        greenbox.add(desktop)

        self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(YELLOW))
        self.add(greenbox)
        self.show_all()
Exemple #25
0
  def build_gui(self):
    self.win = win = Gtk.ApplicationWindow(title='Gnomecast v%s' % __version__)
    win.set_border_width(0)
    win.set_icon(self.get_logo_pixbuf(color='#000000'))
    self.cast_store = cast_store = Gtk.ListStore(object, str)

    vbox_outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
    vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=16)
    
    self.thumbnail_image = Gtk.Image()
    self.thumbnail_image.set_from_pixbuf(self.get_logo_pixbuf())
    vbox_outer.pack_start(self.thumbnail_image, True, False, 0)
    alignment = Gtk.Alignment(xscale=1, yscale=1)
    alignment.add(vbox)
    alignment.set_padding(16, 20, 16, 16)
    vbox_outer.pack_start(alignment, False, False, 0)

    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
    vbox.pack_start(hbox, False, False, 0)
    self.cast_combo = cast_combo = Gtk.ComboBox.new_with_model(cast_store)
    cast_combo.set_entry_text_column(1)
    renderer_text = Gtk.CellRendererText()
    cast_combo.pack_start(renderer_text, True)
    cast_combo.add_attribute(renderer_text, "text", 1)
    hbox.pack_start(cast_combo, True, True, 0)
    refresh_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_REFRESH))
    refresh_button.connect("clicked", self.init_casts)
    hbox.pack_start(refresh_button, False, False, 0)

    win.add(vbox_outer)
    
    # list of queued files
    self.files_store = Gtk.ListStore(str, str, int, str, str, int, str, object) # name, path, duration, duration_str, thumbnail_fn, transcode_progress, status_icon, transcoder
    self.files_store.connect("row-inserted", self.update_button_visible)
    self.files_store.connect("row-deleted", self.update_button_visible)
    self.files_view = Gtk.TreeView(self.files_store)
    self.files_view.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
    self.files_view.set_headers_visible(False)
    self.files_view.set_rules_hint(True)
    column = Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=0)
    column.set_expand(True)
    self.files_view.append_column(column)
    self.file_view_column_renderer = r = Gtk.CellRendererText()
    r.props.xalign = 1.0
    self.files_view.append_column(Gtk.TreeViewColumn("Duration", r, text=3))
    self.files_view_progress_column = column_progress = Gtk.TreeViewColumn("Progress", Gtk.CellRendererProgress(), value=5)
    self.files_view.append_column(column_progress)

    column_pixbuf = Gtk.TreeViewColumn("Playing", Gtk.CellRendererPixbuf(), icon_name=6)
    self.files_view.append_column(column_pixbuf)

    select = self.files_view.get_selection()
    select.connect("changed", self.on_files_view_selection_changed)
    self.files_view.connect("row-activated", self.on_files_view_row_activated)
    

    # contains the files list and the buttons to add/del
    self.hbox = hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
    vbox.pack_start(hbox, False, False, 0)

    self.scrolled_window = Gtk.ScrolledWindow()
    self.scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
    self.scrolled_window.add(self.files_view)
    hbox.pack_start(self.scrolled_window, True, True, 0)

    self.btn_vbox = btn_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
    hbox.pack_start(btn_vbox, True, True, 0)
    self.file_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_ADD))
    self.file_button.set_tooltip_text('Add one or more audio or video files...')
    self.file_button.set_always_show_image(True)
    self.file_button.connect("clicked", self.on_file_clicked)
    btn_vbox.pack_start(self.file_button, True, True, 0)
    self.remove_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_REMOVE))
    self.remove_button.set_tooltip_text('Overwrite original file with transcoded version.')
    self.remove_button.connect("clicked", self.remove_files)
    self.remove_button.set_sensitive(False)
    btn_vbox.pack_start(self.remove_button, False, False, 0)

    self.file_detail_row = hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
    vbox.pack_start(hbox, False, False, 0)
    self.subtitle_store = subtitle_store = Gtk.ListStore(str, int, str)
    subtitle_store.append(["No subtitles.", -1, None])
    subtitle_store.append(["Add subtitle file...", -2, None])
    self.subtitle_combo = Gtk.ComboBox.new_with_model(subtitle_store)
    self.subtitle_combo.connect("changed", self.on_subtitle_combo_changed)
    self.subtitle_combo.set_entry_text_column(0)
    renderer_text = Gtk.CellRendererText()
    self.subtitle_combo.pack_start(renderer_text, True)
    self.subtitle_combo.add_attribute(renderer_text, "text", 0)
    self.subtitle_combo.set_active(0)
    hbox.pack_start(self.subtitle_combo, True, True, 0)
    self.save_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_SAVE))
    self.save_button.set_tooltip_text('Overwrite original file with transcoded version.')
    self.save_button.connect("clicked", self.save_transcoded_file)
    hbox.pack_start(self.save_button, False, False, 0)

    # force transcode button
    self.transcode_button = Gtk.MenuButton()
    self.transcode_button.set_tooltip_text("Force transcode (if your Chromecast won't play a file)...")
    menumodel = Gio.Menu()
    menumodel.append("Transcode Audio Only (fast)", 'win.transcode-audio')
    menumodel.append("Transcode Audio and Video (slow)", "win.transcode-all")
    self.transcode_button.set_menu_model(menumodel)
    self.transcode_button.set_image(Gtk.Image(stock=Gtk.STOCK_CONVERT))
    action = Gio.SimpleAction.new("transcode-audio", None)
    action.connect("activate", lambda a,b: self.force_transcode(audio=True, video=False))
    self.win.add_action(action)
    action = Gio.SimpleAction.new("transcode-all", None)
    action.connect("activate", lambda a,b: self.force_transcode(audio=True, video=True))
    self.win.add_action(action)
    hbox.pack_start(self.transcode_button, False, False, 0)
    
    self.scrubber_adj = Gtk.Adjustment(0, 0, 100, 15, 60, 0)
    self.scrubber = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=self.scrubber_adj)
    self.scrubber.set_digits(0)
    def f(scale, s):
      notes = [self.humanize_seconds(s)]
      return ''.join(notes)
    self.scrubber.connect("format-value", f)
    self.scrubber.connect("change-value", self.scrubber_move_started)
    self.scrubber.connect("change-value", self.scrubber_moved)
    self.scrubber.set_sensitive(False)
    vbox.pack_start(self.scrubber, False, False, 0)

    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=16)
    self.rewind_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_REWIND))
    self.rewind_button.connect("clicked", self.rewind_clicked)
    self.rewind_button.set_sensitive(False)
    self.rewind_button.set_relief(Gtk.ReliefStyle.NONE)
    hbox.pack_start(self.rewind_button, True, False, 0)
    self.play_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_PLAY))
    self.play_button.connect("clicked", self.play_clicked)
    self.play_button.set_sensitive(False)
    self.play_button.set_relief(Gtk.ReliefStyle.NONE)
    hbox.pack_start(self.play_button, True, False, 0)
    self.forward_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_FORWARD))
    self.forward_button.connect("clicked", self.forward_clicked)
    self.forward_button.set_sensitive(False)
    self.forward_button.set_relief(Gtk.ReliefStyle.NONE)
    hbox.pack_start(self.forward_button, True, False, 0)
    self.stop_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_STOP))
    self.stop_button.connect("clicked", self.stop_clicked)
    self.stop_button.set_sensitive(False)
    self.stop_button.set_relief(Gtk.ReliefStyle.NONE)
    hbox.pack_start(self.stop_button, True, False, 0)
    self.volume_button = Gtk.VolumeButton()
    self.volume_button.set_value(1)
    self.volume_button.connect("value-changed", self.volume_moved)
    self.volume_button.set_sensitive(False)
    hbox.pack_start(self.volume_button, True, False, 0)
    vbox.pack_start(hbox, False, False, 0)
    
    cast_combo.connect("changed", self.on_cast_combo_changed)

    win.connect("delete-event", self.quit)
    win.connect("key_press_event", self.on_key_press)
    win.show_all()

    self.update_button_visible()

    win.resize(1,1)

    GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.quit)
Exemple #26
0
    def create_ui(self):
        screen = self.get_screen()
        w = screen.get_width() - 10
        h = screen.get_height() - 65
        self.set_default_size(w, h)

        hbox = Gtk.HBox()
        self.add(hbox)

        da = Gtk.DrawingArea()
        da.set_size_request(1280, 720)
        da.modify_bg(Gtk.StateType.NORMAL, Gdk.Color(0, 0, 0))
        hbox.pack_start(da, False, False, 2)

        vbox = Gtk.VBox()
        hbox.pack_end(vbox, True, True, 2)

        lblLeft = Gtk.Label("Left :")
        lblLeft.set_halign(Gtk.Align.START)
        vbox.pack_start(lblLeft, False, False, 0)

        adjLeft = Gtk.Adjustment(0, 0, 200, 10, 20, 0)
        adjLeft.connect('value-changed', self.on_left_changed)
        sclLeft = Gtk.HScale(adjustment=adjLeft)
        vbox.pack_start(sclLeft, False, True, 0)

        vbox.pack_start(Gtk.Label(""), False, False, 2)

        lblTop = Gtk.Label("Top :")
        lblTop.set_halign(Gtk.Align.START)
        vbox.pack_start(lblTop, False, False, 0)

        adjTop = Gtk.Adjustment(0, 0, 200, 10, 20, 0)
        adjTop.connect('value-changed', self.on_top_changed)
        sclTop = Gtk.HScale(adjustment=adjTop)
        vbox.pack_start(sclTop, False, True, 0)

        vbox.pack_start(Gtk.Label(""), False, False, 2)

        lblRight = Gtk.Label("Right :")
        lblRight.set_halign(Gtk.Align.START)
        vbox.pack_start(lblRight, False, False, 0)

        adjRight = Gtk.Adjustment(0, 0, 400, 10, 20, 0)
        adjRight.connect('value-changed', self.on_right_changed)
        sclRight = Gtk.HScale(adjustment=adjRight)
        vbox.pack_start(sclRight, False, True, 0)

        vbox.pack_start(Gtk.Label(""), False, False, 2)

        lblBottom = Gtk.Label("Bottom :")
        lblBottom.set_halign(Gtk.Align.START)
        vbox.pack_start(lblBottom, False, False, 0)

        adjBottom = Gtk.Adjustment(0, 0, 200, 10, 20, 0)
        adjBottom.connect('value-changed', self.on_bottom_changed)
        sclBottom = Gtk.HScale(adjustment=adjBottom)
        vbox.pack_start(sclBottom, False, True, 0)

        hbox2 = Gtk.HBox()
        vbox.pack_end(hbox2, True, False, 2)

        startBtn = Gtk.Button(label='Start')
        startBtn.connect('clicked', self.run)
        hbox2.pack_start(startBtn, True, True, 2)

        exitBtn = Gtk.Button(label='Exit')
        exitBtn.connect('clicked', self.on_quit)
        hbox2.pack_start(exitBtn, True, True, 2)
Exemple #27
0
 def __init__(self, min, max):
     Gtk.SpinButton.__init__(self)
     self.set_adjustment(
         Gtk.Adjustment(value=min, lower=min, upper=max, step_increment=1))
     self.show()
Exemple #28
0
    def __init__(self, controls):
        self.controls = controls

        box = VBox(self, Gtk.Orientation.VERTICAL, 0)
        box.hide()
        """LAST.FM"""
        l_layout = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        l_frame = FrameDecorator(_("Last.FM"), l_layout, border_width=0)
        """LOGIN"""
        lbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        lbox.show()

        login = Gtk.Label.new(_("Login"))
        login.set_size_request(150, -1)
        login.show()

        self.login_text = Gtk.Entry()
        self.login_text.show()

        lbox.pack_start(login, False, False, 0)
        lbox.pack_start(self.login_text, False, True, 0)
        """PASSWORD"""
        pbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        pbox.show()

        password = Gtk.Label.new(_("Password"))
        password.set_size_request(150, -1)
        password.show()

        self.password_text = Gtk.Entry()
        self.password_text.set_visibility(False)
        self.password_text.set_invisible_char("*")
        self.password_text.show()

        limit_text = Gtk.Label.new(_("Limit search results:  "))
        limit_text.show()

        self.adjustment = Gtk.Adjustment(value=50,
                                         lower=10,
                                         upper=200,
                                         step_incr=10)
        limit = Gtk.SpinButton.new(self.adjustment, 0.0, 0)
        limit.show()

        limitbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        limitbox.pack_start(limit_text, False, False, 0)
        limitbox.pack_start(limit, False, False, 0)

        self.music_scrobbler = Gtk.CheckButton.new_with_label(
            _("Enable Music Scrobbler"))
        self.music_scrobbler.show()

        self.radio_scrobbler = Gtk.CheckButton.new_with_label(
            _("Enable Radio Scrobbler"))
        self.radio_scrobbler.show()

        pbox.pack_start(password, False, False, 0)
        pbox.pack_start(self.password_text, False, True, 0)

        l_layout.pack_start(lbox, False, True, 0)
        l_layout.pack_start(pbox, False, True, 0)
        l_layout.pack_start(limitbox, False, True, 10)
        l_layout.pack_start(self.music_scrobbler, False, True, 0)
        l_layout.pack_start(self.radio_scrobbler, False, True, 0)
        """VK"""
        vk_layout = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        vk_frame = FrameDecorator(_("VKontakte"), vk_layout, border_width=0)

        self.default_label_value = _("Not connected")

        self.frase_begin = _("You vk account is:")
        self.vk_account_label = Gtk.Label.new(self.frase_begin +
                                              " %s" % self.default_label_value)
        self.reset_vk_auth_button = Gtk.Button.new_with_label(
            _("Reset vk authorization"))
        self.reset_vk_auth_button.connect("button-release-event",
                                          self.on_reset_vk_click)
        self.vk_autocomplete = Gtk.CheckButton.new_with_label(
            _("Enable VK autocomplete"))
        self.vk_autocomplete.show()
        vk_layout.pack_start(self.vk_account_label, False, False, 0)
        vk_layout.pack_start(self.reset_vk_auth_button, False, False, 0)
        vk_layout.pack_start(self.vk_autocomplete, False, False, 0)
        """all"""
        box.pack_start(l_frame, False, True, 0)
        box.pack_start(vk_frame, False, True, 0)

        self.widget = box
Exemple #29
0
    def time_control(self, b):
        dialog = Gtk.Dialog("Time Control", gv.gui.get_window(), 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        dialog.set_title("Time Control")
        dialog.vbox.set_spacing(20)

        # list of time control types
        combobox = Gtk.ComboBoxText()
        combobox.append_text("Byoyomi")
        combobox.append_text("Classical")
        combobox.append_text("Incremental")
        combobox.append_text("Fixed Time Per Move")
        combobox.append_text("Fixed Search Depth")
        combobox.append_text("Infinite Search")
        combobox.append_text("Nodes")
        combobox.set_active(self.type)

        al = Gtk.Alignment.new(xalign=0.0, yalign=1.0, xscale=0.0, yscale=0.5)
        # top, bottom, left, right
        al.set_padding(9, 0, 9, 9)
        al.add(combobox)
        dialog.vbox.pack_start(al, False, True, 5)
        self.combobox = combobox

        dialog.connect("draw", self.dialog_expose_event)

        #
        # settings for the byoyomi time control type
        #
        #   byoyomi
        #       e.g. 60 mins available time plus 10 seconds byoyomi
        #       go btime 3600000 wtime 3600000 byoyomi 10000
        #

        # list of time control vboxes. 1 per time control type
        self.tcvb = [Gtk.VBox(False, 0) for x in range(8)]

        byo_frame1 = Gtk.Frame.new("Available Time")
        vb = Gtk.VBox(False, 0)
        byo_frame1.add(vb)

        # available time - hours
        minimum = 0
        maximum = 10
        default = self.byo_hours
        byo_adj_hours = Gtk.Adjustment(value=default,
                                       lower=minimum,
                                       upper=maximum,
                                       step_increment=1,
                                       page_increment=5,
                                       page_size=0)
        spinner = Gtk.SpinButton.new(byo_adj_hours, 1.0, 0)
        al = Gtk.Alignment.new(xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
        al.add(spinner)
        hb = Gtk.HBox(False, 0)
        hb.pack_start(Gtk.Label("Hours:"), False, False, 0)
        hb.pack_start(al, True, True, 10)
        vb.pack_start(hb, False, True, 0)

        # available time - minutes
        minimum = 0
        maximum = 59
        default = self.byo_minutes
        byo_adj_mins = Gtk.Adjustment(value=default,
                                      lower=minimum,
                                      upper=maximum,
                                      step_increment=1,
                                      page_increment=5,
                                      page_size=0)
        spinner = Gtk.SpinButton.new(byo_adj_mins, 1.0, 0)
        al = Gtk.Alignment.new(xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
        al.add(spinner)
        lbl = Gtk.Label(label="Minutes :")
        hb = Gtk.HBox(False, 0)
        hb.pack_start(lbl, False, False, 0)
        hb.pack_start(al, True, True, 10)
        vb.pack_start(hb, False, True, 0)

        # byoyomi - seconds
        byo_frame2 = Gtk.Frame.new("Byoyomi")
        minimum = 0
        maximum = 60
        default = self.byo_byoyomi
        byo_adj_byoyomi = Gtk.Adjustment(value=default,
                                         lower=minimum,
                                         upper=maximum,
                                         step_increment=1,
                                         page_increment=5,
                                         page_size=0)
        spinner = Gtk.SpinButton.new(byo_adj_byoyomi, 1.0, 0)
        al = Gtk.Alignment.new(xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
        al.add(spinner)
        hb = Gtk.HBox(False, 0)
        hb.pack_start(Gtk.Label("Seconds:"), False, False, 0)
        hb.pack_start(al, True, True, 10)
        byo_frame2.add(hb)

        self.tcvb[0].pack_start(byo_frame1, False, False, 0)
        self.tcvb[0].pack_start(byo_frame2, False, False, 0)
        self.tcvb[0].set_spacing(20)

        #
        # settings for the classical time control type
        #
        #   classical
        #       e.g. 40 moves in 5 minutes
        #       go wtime 300000 btime 300000 movestogo 40
        #

        cls_frame1 = Gtk.Frame()
        vb = Gtk.VBox(False, 0)
        cls_frame1.add(vb)

        adj_cls_settings = []

        for i in range(0, self.cls_max_sessions):

            (moves_to_go, minutes, repeat_times) = self.cls_settings[i]

            # session
            hb = Gtk.HBox(False, 0)
            if i != 0:
                vb.pack_start(Gtk.HSeparator(), False, True, 0)
            hb.pack_start(Gtk.Label("#" + str(i + 1)), False, False, 0)
            # if i != 0:
            #   hb.pack_start(Gtk.CheckButton(, True, True, 0), True, True, 10)
            vb.pack_start(hb, False, True, 0)

            # moves
            minimum = 1
            maximum = 200
            default = moves_to_go
            # default = 40
            # if i == 0:
            #    default = 40
            # else:
            #    default = 0
            adj_moves_to_go = Gtk.Adjustment(value=default,
                                             lower=minimum,
                                             upper=maximum,
                                             step_increment=1,
                                             page_increment=5,
                                             page_size=0)
            spinner = Gtk.SpinButton.new(adj_moves_to_go, 1.0, 0)
            al = Gtk.Alignment.new(xalign=1.0,
                                   yalign=0.0,
                                   xscale=0.0,
                                   yscale=0.0)
            al.add(spinner)
            hb = Gtk.HBox(False, 0)
            hb.pack_start(Gtk.Label("Moves:"), False, False, 0)
            hb.pack_start(al, True, True, 10)
            vb.pack_start(hb, False, True, 0)

            # minutes
            minimum = 0
            maximum = 500
            # default = 5
            default = minutes
            # if i == 0:
            #    default = 5
            # else:
            #    default = 0
            adj_cls_mins = Gtk.Adjustment(value=default,
                                          lower=minimum,
                                          upper=maximum,
                                          step_increment=1,
                                          page_increment=5,
                                          page_size=0)
            spinner = Gtk.SpinButton.new(adj_cls_mins, 1.0, 0)
            al = Gtk.Alignment.new(xalign=1.0,
                                   yalign=0.0,
                                   xscale=0.0,
                                   yscale=0.0)
            al.add(spinner)
            lbl = Gtk.Label(label="Minutes :")
            hb = Gtk.HBox(False, 0)
            hb.pack_start(lbl, False, False, 0)
            hb.pack_start(al, True, True, 10)
            vb.pack_start(hb, False, True, 0)

            # repeating
            minimum = 0
            maximum = 9
            default = repeat_times
            # if i == 0:
            #    default = 1
            # else:
            #    default = 0
            adj_cls_repeat = Gtk.Adjustment(value=default,
                                            lower=minimum,
                                            upper=maximum,
                                            step_increment=1,
                                            page_increment=5,
                                            page_size=0)
            spinner = Gtk.SpinButton.new(adj_cls_repeat, 1.0, 0)
            al = Gtk.Alignment.new(xalign=1.0,
                                   yalign=0.0,
                                   xscale=0.0,
                                   yscale=0.0)
            al.add(spinner)
            lbl = Gtk.Label(label="Count :")
            hb = Gtk.HBox(False, 0)
            hb.pack_start(lbl, False, False, 0)
            hb.pack_start(al, True, True, 10)
            vb.pack_start(hb, False, True, 0)

            # enabled
            # lbl = Gtk.Label(label="Enabled :")
            # hb = Gtk.HBox(False, 0)
            # hb.pack_start(lbl, False, False, 0)
            # hb.pack_start(Gtk.CheckButton(, True, True, 0), True, True, 10)
            # vb.pack_start(hb, False, True, 0)

            adj_cls_settings.append(
                (adj_moves_to_go, adj_cls_mins, adj_cls_repeat))

        self.tcvb[1].pack_start(cls_frame1, False, False, 0)

        # Blitz (incremental)
        # e.g. 2 mins 0 seconds for whole game, 6 seconds 0 milliseconds bonus
        # per move
        # base is for whole game, bonus will be given for every move made
        # go wtime 126000 btime 120000 winc 6000 binc 6000
        # go wtime 130591 btime 118314 winc 6000 binc 6000
        # go wtime 135329 btime 118947 winc 6000 binc 6000

        inc_frame1 = Gtk.Frame.new("Time")
        vb = Gtk.VBox(False, 0)
        inc_frame1.add(vb)

        # available time - hours
        minimum = 0
        maximum = 10
        default = self.inc_hours
        inc_adj_hours = Gtk.Adjustment(value=default,
                                       lower=minimum,
                                       upper=maximum,
                                       step_increment=1,
                                       page_increment=5,
                                       page_size=0)
        spinner = Gtk.SpinButton.new(inc_adj_hours, 1.0, 0)
        al = Gtk.Alignment.new(xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
        al.add(spinner)
        hb = Gtk.HBox(False, 0)
        hb.pack_start(Gtk.Label("Hours:"), False, False, 0)
        hb.pack_start(al, True, True, 10)
        vb.pack_start(hb, False, True, 0)

        # available time - minutes
        minimum = 0
        maximum = 59
        default = self.inc_minutes
        inc_adj_mins = Gtk.Adjustment(value=default,
                                      lower=minimum,
                                      upper=maximum,
                                      step_increment=1,
                                      page_increment=5,
                                      page_size=0)
        spinner = Gtk.SpinButton.new(inc_adj_mins, 1.0, 0)
        al = Gtk.Alignment.new(xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
        al.add(spinner)
        lbl = Gtk.Label(label="Minutes :")
        hb = Gtk.HBox(False, 0)
        hb.pack_start(lbl, False, False, 0)
        hb.pack_start(al, True, True, 10)
        vb.pack_start(hb, False, True, 0)

        # bonus time per move - seconds
        inc_frame2 = Gtk.Frame.new("Bonus Time per Move")
        minimum = 0
        maximum = 60
        default = self.inc_bonus
        inc_adj_bonus = Gtk.Adjustment(value=default,
                                       lower=minimum,
                                       upper=maximum,
                                       step_increment=1,
                                       page_increment=5,
                                       page_size=0)
        spinner = Gtk.SpinButton.new(inc_adj_bonus, 1.0, 0)
        al = Gtk.Alignment.new(xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
        al.add(spinner)
        hb = Gtk.HBox(False, 0)
        hb.pack_start(Gtk.Label("Seconds:"), False, False, 0)
        hb.pack_start(al, True, True, 10)
        inc_frame2.add(hb)

        self.tcvb[2].pack_start(inc_frame1, False, False, 0)
        self.tcvb[2].pack_start(inc_frame2, False, False, 0)
        self.tcvb[2].set_spacing(20)

        #
        # settings for the fixed time per move time control type
        #
        #   fixed time per move
        #       e.g. 6 seconds per move
        #       go movetime 6000

        # ftpm_frame1 = Gtk.Frame("Fixed Time Per Move")
        ftpm_frame1 = Gtk.Frame()
        ftpm_frame1.set_shadow_type(Gtk.ShadowType.NONE)
        vb = Gtk.VBox(False, 0)
        ftpm_frame1.add(vb)

        # seconds per move
        minimum = 0
        maximum = 10000
        default = self.ftpm_seconds
        adj_ftpm_secs = Gtk.Adjustment(value=default,
                                       lower=minimum,
                                       upper=maximum,
                                       step_increment=1,
                                       page_increment=5,
                                       page_size=0)
        spinner = Gtk.SpinButton.new(adj_ftpm_secs, 1.0, 0)
        al = Gtk.Alignment.new(xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
        al.add(spinner)
        lbl = Gtk.Label(label="Seconds :")
        hb = Gtk.HBox(False, 0)
        hb.pack_start(lbl, False, False, 0)
        hb.pack_start(al, True, True, 10)
        vb.pack_start(hb, False, True, 0)

        self.tcvb[3].pack_start(ftpm_frame1, False, False, 0)

        #
        # settings for the fixed search depth time control type
        #
        #   fixed search depth
        #       e.g.
        #       go depth 8
        dpth_frame1 = Gtk.Frame()
        dpth_frame1.set_shadow_type(Gtk.ShadowType.NONE)
        vb = Gtk.VBox(False, 0)
        dpth_frame1.add(vb)

        # depth
        minimum = 0
        maximum = 999
        default = self.dpth_depth
        adj_dpth_depth = Gtk.Adjustment(value=default,
                                        lower=minimum,
                                        upper=maximum,
                                        step_increment=1,
                                        page_increment=5,
                                        page_size=0)
        spinner = Gtk.SpinButton.new(adj_dpth_depth, 1.0, 0)
        al = Gtk.Alignment.new(xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
        al.add(spinner)
        lbl = Gtk.Label(label="Search Depth :")
        hb = Gtk.HBox(False, 0)
        hb.pack_start(lbl, False, False, 0)
        hb.pack_start(al, True, True, 10)
        vb.pack_start(hb, False, True, 0)

        self.tcvb[4].pack_start(dpth_frame1, False, False, 0)

        # calculate to engines maximum search depth
        # (sends back bestmove if it gets the stop command)
        # go infinite

        # there are no cutomisable options for go infinite
        self.tcvb[5].pack_start(Gtk.Label("No customisable options"), True,
                                True, 0)

        #
        # settings for the fixed no. of nodes time control type
        #
        #   fixed no. of nodes
        #       e.g. search for 1 million nodes
        #       go nodes 1000000
        nodes_frame1 = Gtk.Frame()
        nodes_frame1.set_shadow_type(Gtk.ShadowType.NONE)
        vb = Gtk.VBox(False, 0)
        nodes_frame1.add(vb)

        # nodes
        minimum = 1
        maximum = 2000000000
        default = self.nodes_nodes
        adj_nodes_nodes = Gtk.Adjustment(value=default,
                                         lower=minimum,
                                         upper=maximum,
                                         step_increment=1,
                                         page_increment=5,
                                         page_size=0)
        spinner = Gtk.SpinButton.new(adj_nodes_nodes, 1.0, 0)
        al = Gtk.Alignment.new(xalign=1.0, yalign=0.0, xscale=0.0, yscale=0.0)
        al.add(spinner)
        lbl = Gtk.Label(label="No. of Nodes to Search :")
        hb = Gtk.HBox(False, 0)
        hb.pack_start(lbl, False, False, 0)
        hb.pack_start(al, True, True, 10)
        vb.pack_start(hb, False, True, 0)

        self.tcvb[6].pack_start(nodes_frame1, False, False, 0)

        # mate search
        # e.g. look for mate in 5 moves
        # go mate 5

        self.al = Gtk.Alignment.new(xalign=0.5,
                                    yalign=0.5,
                                    xscale=1.0,
                                    yscale=0.0)
        # top, bottom, left, right
        self.al.set_padding(0, 0, 9, 9)
        self.al.add(self.tcvb[self.type])
        dialog.vbox.pack_start(self.al, False, True, 0)

        combobox.connect("changed", self.tc_method_changed, dialog)

        dialog.set_default_response(Gtk.ResponseType.OK)
        dialog.show_all()

        self.set_frame_visibility(self.type)

        while True:
            response = dialog.run()
            if response != Gtk.ResponseType.OK:
                # cancelled - exit loop
                break
            # OK pressed - validate input"
            # print "ok pressed"

            self.type = combobox.get_active()
            # byoyomi
            if self.type == 0:
                byo_hours = int(byo_adj_hours.get_value())
                byo_minutes = int(byo_adj_mins.get_value())
                byo_byoyomi = int(byo_adj_byoyomi.get_value())
                if byo_hours == 0 and byo_minutes == 0 and byo_byoyomi == 0:
                    gv.gui.info_box("Time fields cannot all be zero!")
                else:
                    # input ok - exit loop
                    self.byo_hours = byo_hours
                    self.byo_minutes = byo_minutes
                    self.byo_byoyomi = byo_byoyomi

                    self.reset_clock()

                    self.set_toolbar_time_control(self.type, 0, WHITE)
                    self.set_toolbar_time_control(self.type, 0, BLACK)
                    break
            # classical
            elif self.type == 1:
                self.cls_settings = []
                rep_zero = True
                for i in range(0, self.cls_max_sessions):
                    moves_to_go, mins, rep = adj_cls_settings[i]
                    if rep.get_value() != 0:
                        rep_zero = False
                if rep_zero:
                    gv.gui.info_box("Count fields cannot all be zero!")
                else:
                    for i in range(0, self.cls_max_sessions):
                        moves_to_go, mins, rep = adj_cls_settings[i]
                        self.cls_settings.append(
                            (moves_to_go.get_value(), mins.get_value(),
                             rep.get_value()))

                    # fields for go command
                    self.reset_clock()

                    self.set_toolbar_time_control(self.type, 0, WHITE)
                    self.set_toolbar_time_control(self.type, 0, BLACK)
                    break
            # incremental
            if self.type == 2:
                inc_hours = int(inc_adj_hours.get_value())
                inc_minutes = int(inc_adj_mins.get_value())
                inc_bonus = int(inc_adj_bonus.get_value())
                if inc_hours == 0 and inc_minutes == 0 and inc_bonus == 0:
                    gv.gui.info_box(
                        "Incremental Time fields cannot all be zero!")
                else:
                    # input ok - exit loop
                    self.inc_hours = inc_hours
                    self.inc_minutes = inc_minutes
                    self.inc_bonus = inc_bonus

                    self.reset_clock()

                    self.set_toolbar_time_control(self.type, 0, WHITE)
                    self.set_toolbar_time_control(self.type, 0, BLACK)
                    break
            # fixed time per move
            elif self.type == 3:
                self.ftpm_seconds = int(adj_ftpm_secs.get_value())

                # fields for go command
                self.reset_clock()

                self.set_toolbar_time_control(self.type, 0, WHITE)
                self.set_toolbar_time_control(self.type, 0, BLACK)
                break
            # fixed search depth
            elif self.type == 4:
                self.dpth_depth = int(adj_dpth_depth.get_value())

                # fields for go command
                self.reset_clock()

                self.set_toolbar_time_control(self.type, 0, WHITE)
                self.set_toolbar_time_control(self.type, 0, BLACK)
                break
            # infinite search
            elif self.type == 5:
                break
            # fixed number of nodes search
            elif self.type == 6:
                self.nodes_nodes = int(adj_nodes_nodes.get_value())

                # fields for go command
                self.reset_clock()

                self.set_toolbar_time_control(self.type, 0, WHITE)
                self.set_toolbar_time_control(self.type, 0, BLACK)
                break

        dialog.destroy()
    def __init__(self, *args, **kwargs):
        Operation.__init__(self, *args, **kwargs)
        self._grid = Gtk.Grid(border_width=5,
                              row_spacing=5,
                              column_spacing=5,
                              halign=Gtk.Align.FILL,
                              valign=Gtk.Align.CENTER,
                              hexpand=True,
                              vexpand=False)
        self.add(self._grid)

        # we need boxes for at least
        # hostname
        # port
        # username
        # password
        # auto add new host keys
        # remote directory
        # create remote directory if necessary

        # Hostname
        tempgrid = Gtk.Grid(row_spacing=5,
                            column_spacing=5,
                            halign=Gtk.Align.FILL,
                            valign=Gtk.Align.CENTER,
                            hexpand=True,
                            vexpand=False)
        self._grid.attach(tempgrid, 0, 0, 1, 1)
        tempgrid.attach(
            Gtk.Label(
                label='Hostname',
                halign=Gtk.Align.START,
                valign=Gtk.Align.CENTER,
                hexpand=False,
                vexpand=False,
            ), 0, 0, 1, 1)
        widget = self.register_widget(
            Gtk.Entry(
                halign=Gtk.Align.FILL,
                valign=Gtk.Align.CENTER,
                hexpand=True,
                vexpand=False,
            ), 'hostname')
        tempgrid.attach(widget, 1, 0, 1, 1)

        # Port
        tempgrid.attach(
            Gtk.Label(
                label='Port',
                halign=Gtk.Align.CENTER,
                valign=Gtk.Align.CENTER,
                hexpand=False,
                vexpand=False,
            ), 2, 0, 1, 1)
        widget = self.register_widget(
            Gtk.SpinButton(adjustment=Gtk.Adjustment(lower=1,
                                                     upper=10000,
                                                     value=5,
                                                     page_size=0,
                                                     step_increment=1),
                           value=22,
                           update_policy=Gtk.SpinButtonUpdatePolicy.IF_VALID,
                           numeric=True,
                           climb_rate=5,
                           halign=Gtk.Align.CENTER,
                           valign=Gtk.Align.CENTER,
                           hexpand=False,
                           vexpand=False), 'port')
        tempgrid.attach(widget, 3, 0, 1, 1)

        # Username
        tempgrid = Gtk.Grid(
            row_spacing=5,
            column_spacing=5,
            halign=Gtk.Align.FILL,
            valign=Gtk.Align.CENTER,
            hexpand=True,
            vexpand=False,
        )
        self._grid.attach(tempgrid, 0, 1, 1, 1)
        tempgrid.attach(
            Gtk.Label(
                label='Username',
                halign=Gtk.Align.CENTER,
                valign=Gtk.Align.CENTER,
                hexpand=False,
                vexpand=False,
            ), 0, 0, 1, 1)
        widget = self.register_widget(
            Gtk.Entry(
                halign=Gtk.Align.FILL,
                valign=Gtk.Align.CENTER,
                hexpand=True,
                vexpand=False,
            ), 'username')
        tempgrid.attach(widget, 1, 0, 1, 1)

        # Password
        tempgrid.attach(
            Gtk.Label(
                label='Password',
                halign=Gtk.Align.CENTER,
                valign=Gtk.Align.CENTER,
                hexpand=False,
                vexpand=False,
            ), 2, 0, 1, 1)
        widget = self.register_widget(Gtk.Entry(
            visibility=False,
            halign=Gtk.Align.FILL,
            valign=Gtk.Align.CENTER,
            hexpand=True,
            vexpand=False,
        ),
                                      'password',
                                      exportable=False)
        tempgrid.attach(widget, 3, 0, 1, 1)

        # Remote directory
        tempgrid = Gtk.Grid(
            row_spacing=5,
            column_spacing=5,
            halign=Gtk.Align.FILL,
            valign=Gtk.Align.CENTER,
            hexpand=True,
            vexpand=False,
        )
        self._grid.attach(tempgrid, 0, 2, 1, 1)
        tempgrid.attach(
            Gtk.Label(
                label='Destination folder',
                halign=Gtk.Align.CENTER,
                valign=Gtk.Align.CENTER,
                hexpand=False,
                vexpand=False,
            ), 0, 0, 1, 1)
        widget = self.register_widget(
            Gtk.Entry(
                halign=Gtk.Align.FILL,
                valign=Gtk.Align.CENTER,
                hexpand=True,
                vexpand=False,
            ), 'destination')
        tempgrid.attach(widget, 1, 0, 1, 1)

        # Create directory
        widget = self.register_widget(
            Gtk.CheckButton(
                active=True,
                label="Create destination folder if necessary",
                halign=Gtk.Align.END,
                valign=Gtk.Align.CENTER,
                hexpand=False,
                vexpand=False,
            ), 'force_folder_creation')
        tempgrid.attach(widget, 2, 0, 1, 1)

        # Automatically accept new host keys
        tempgrid = Gtk.Grid(
            row_spacing=5,
            column_spacing=5,
            halign=Gtk.Align.FILL,
            valign=Gtk.Align.CENTER,
            hexpand=True,
            vexpand=False,
        )
        self._grid.attach(tempgrid, 0, 3, 1, 1)
        widget = self.register_widget(
            Gtk.CheckButton(
                active=False,
                label="Automatically accept new host keys (dangerous!!)",
                halign=Gtk.Align.END,
                valign=Gtk.Align.CENTER,
                hexpand=False,
                vexpand=False,
            ), 'auto_add_keys')
        tempgrid.attach(widget, 0, 0, 1, 1)