Python gi.repository.GObject.TYPE_STRING Examples
The following are 24
code examples of gi.repository.GObject.TYPE_STRING().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gi.repository.GObject
, or try the search function
.
Example #1
Source File: DenominoViso.py From addons-source with GNU General Public License v2.0 | 6 votes |
def create_lstore(self,list_of_lists): lstore_args = [] for cell in list_of_lists[0]: if type(cell) == type("string"): lstore_args.append(GObject.TYPE_STRING) elif type(cell) == type(1): lstore_args.append(GObject.TYPE_UINT) elif type(cell) == type(False): lstore_args.append(GObject.TYPE_BOOLEAN) else: raise TypeError("%s" % type(cell)) lstore = Gtk.ListStore(*lstore_args) for row in list_of_lists: iter = lstore.append() index_values = [] for i,v in enumerate(row): index_values.append(i) index_values.append(v) lstore.set(iter,*index_values) return lstore
Example #2
Source File: execution_history.py From RAFCON with Eclipse Public License 1.0 | 6 votes |
def __init__(self, model=None, view=None): assert isinstance(model, StateMachineManagerModel) assert isinstance(view, ExecutionHistoryView) super(ExecutionHistoryTreeController, self).__init__(model, view) self.history_tree_store = Gtk.TreeStore(GObject.TYPE_STRING, GObject.TYPE_PYOBJECT, GObject.TYPE_STRING) # a TreeView self.history_tree = view['history_tree'] self.history_tree.set_model(self.history_tree_store) view['history_tree'].set_tooltip_column(self.TOOL_TIP_STORAGE_ID) self.observe_model(state_machine_execution_model) self._expansion_state = {} self._update_lock = RLock() self.update()
Example #3
Source File: preferences_window.py From RAFCON with Eclipse Public License 1.0 | 6 votes |
def __init__(self, core_config_model, view, gui_config_model): assert isinstance(view, PreferencesWindowView) assert isinstance(core_config_model, ConfigModel) assert isinstance(gui_config_model, ConfigModel) ExtendedController.__init__(self, core_config_model, view) self.core_config_model = core_config_model self.gui_config_model = gui_config_model self.observe_model(gui_config_model) # (config_key, config_value, text_visible, toggle_activatable, toggle_visible, text_editable, toggle_value) self.core_list_store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, bool, bool, bool, bool, bool) self.library_list_store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING) self.gui_list_store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, bool, bool, bool, bool, bool) self.shortcut_list_store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING) self._lib_counter = 0 self._gui_checkbox = Gtk.CheckButton(label="GUI Config") self._core_checkbox = Gtk.CheckButton(label="Core Config") self._last_path = self.core_config_model.config.path
Example #4
Source File: outcomes.py From RAFCON with Eclipse Public License 1.0 | 6 votes |
def __init__(self, model, view): assert isinstance(model, AbstractStateModel) # initiate data base and tree # id, name, to-state, to-outcome, name-color, to-state-color, outcome, state, outcome_model list_store = Gtk.ListStore(int, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT) super(StateOutcomesListController, self).__init__(model, view, view['tree_view'], list_store, logger) self.to_state_combo_list = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING) self.to_outcome_combo_list = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING) # key-outcome_id -> label, to_state_id, transition_id self.dict_to_other_state = {} # key-outcome_id -> label, to_outcome_id, transition_id self.dict_to_other_outcome = {} # not used at the moment key-outcome_id -> label, from_state_id, transition_id self.dict_from_other_state = {} # if widget gets extended # TODO check why the can happen should not be handed always the LibraryStateModel if not (model.state.is_root_state or model.state.is_root_state_of_library): self.observe_model(model.parent) if self.model.get_state_machine_m() is not None: self.observe_model(self.model.get_state_machine_m()) else: logger.warning("State model has no state machine model -> state model: {0}".format(self.model))
Example #5
Source File: state_machine_tree.py From RAFCON with Eclipse Public License 1.0 | 6 votes |
def __init__(self, model, view): assert isinstance(model, StateMachineManagerModel) tree_store = Gtk.TreeStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_PYOBJECT, GObject.TYPE_STRING) super(StateMachineTreeController, self).__init__(model, view, view, tree_store) self.add_controller("state_right_click_ctrl", StateMachineTreeRightClickMenuController(model, view)) self.view_is_registered = False # view.set_hover_expand(True) self.state_row_iter_dict_by_state_path = {} self.__my_selected_sm_id = None self._selected_sm_model = None self.__expansion_state = {} self._ongoing_complex_actions = [] self._state_which_is_updated = None self.register()
Example #6
Source File: semantic_data_editor.py From RAFCON with Eclipse Public License 1.0 | 6 votes |
def __init__(self, model, view): """Constructor """ assert isinstance(model, AbstractStateModel) assert isinstance(view, SemanticDataEditorView) if isinstance(model.state, LibraryState): model_to_observe = model.state_copy else: model_to_observe = model # define tree store with the values in [key, value Is Dict] tree_store = Gtk.TreeStore(GObject.TYPE_STRING, GObject.TYPE_STRING, bool, GObject.TYPE_PYOBJECT) # unfortunately this cannot be down with super, as gtkmvc3 does not use super() consistently TreeViewController.__init__(self, model_to_observe, view, view["semantic_data_tree_view"], tree_store, logger) AbstractExternalEditor.__init__(self) self.semantic_data_counter = 0
Example #7
Source File: data_flows.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def __init__(self, model, view): """Constructor """ # ListStore for: id, from-state, from-key, to-state, to-key, is_external, # name-color, to-state-color, data-flow-object, state-object, is_editable, data-flow-model list_store = Gtk.ListStore(int, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, bool, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT, bool, GObject.TYPE_PYOBJECT) self.view_dict = {'data_flows_internal': True, 'data_flows_external': True} self.tree_dict_combos = {'internal': {}, 'external': {}} self.data_flow_dict = {'internal': {}, 'external': {}} self.debug_log = False super(StateDataFlowsListController, self).__init__(model, view, view.get_top_widget(), list_store, logger)
Example #8
Source File: exports.py From rednotebook with GNU General Public License v2.0 | 5 votes |
def refresh_categories_list(self): model_available = Gtk.ListStore(GObject.TYPE_STRING) for category in self.journal.categories: model_available.append([category]) self.available_categories.set_model(model_available) model_selected = Gtk.ListStore(GObject.TYPE_STRING) self.selected_categories.set_model(model_selected)
Example #9
Source File: customwidgets.py From rednotebook with GNU General Public License v2.0 | 5 votes |
def __init__(self, combo_box): self.combo_box = combo_box self.liststore = Gtk.ListStore(GObject.TYPE_STRING) self.entries = set() self.combo_box.set_model(self.liststore) self.combo_box.set_entry_text_column(0) self.entry = self.combo_box.get_child() # Autocompletion entry_completion = Gtk.EntryCompletion() entry_completion.set_model(self.liststore) entry_completion.set_minimum_key_length(1) entry_completion.set_text_column(0) self.entry.set_completion(entry_completion)
Example #10
Source File: builder.py From pympress with GNU General Public License v2.0 | 5 votes |
def __translate_widget_strings(a_widget): """ Calls gettext on all strings we can find in a_widgets. Args: a_widget (:class:`~GObject.Object`): an object built by the builder, usually a widget """ for str_prop in (prop.name for prop in a_widget.props if prop.value_type == GObject.TYPE_STRING): try: str_val = getattr(a_widget.props, str_prop) if str_val: setattr(a_widget.props, str_prop, _(str_val)) except TypeError: # Thrown when a string property is not readable pass
Example #11
Source File: modification_history.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def __init__(self, model, view): """Constructor :param model StateMachineModel should be exchangeable """ assert isinstance(model, StateMachineManagerModel) ExtendedController.__init__(self, model, view) self.view_is_registered = False self._mode = 'branch' self.with_tree = True self.tree_folded = False assert self._mode in ['trail', 'branch'] self.history_tree_store = Gtk.TreeStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_PYOBJECT, GObject.TYPE_STRING, GObject.TYPE_STRING) if view is not None: view['history_tree'].set_model(self.history_tree_store) view['history_tree'].set_tooltip_column(8) # view.set_hover_expand(True) self.__my_selected_sm_id = None self._selected_sm_model = None self.doing_update = False self.no_cursor_observation = False self.next_activity_focus_self = True self.on_toggle_mode_check_gaphas_view_is_meta_data_consistent = True self.register()
Example #12
Source File: transitions.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def __init__(self, model, view): # ListStore for: id, from-state, from-outcome, to-state, to-outcome, is_external, # name-color, to-state-color, transition-object, state-object, is_editable, transition-model list_store = Gtk.ListStore(int, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, bool, GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT, bool, GObject.TYPE_PYOBJECT) self.view_dict = {'transitions_internal': True, 'transitions_external': True} self.combo = {} self.debug_log = False super(StateTransitionsListController, self).__init__(model, view, view.get_top_widget(), list_store, logger)
Example #13
Source File: io_data_port_list.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def _get_new_list_store(): return Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, int, bool, GObject.TYPE_STRING, GObject.TYPE_PYOBJECT)
Example #14
Source File: global_variable_manager.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def __init__(self, model, view): # list store order -> gv_name, data_type, data_value, is_locked super(GlobalVariableManagerController, self).__init__(model, view, view['global_variable_tree_view'], Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING), logger) self.global_variable_counter = 0 self.list_store_iterators = {}
Example #15
Source File: library_tree.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def __init__(self, model, view): assert isinstance(model, LibraryManagerModel) assert isinstance(view, Gtk.TreeView) ExtendedController.__init__(self, model, view) self.tree_store = Gtk.TreeStore(GObject.TYPE_STRING, GObject.TYPE_PYOBJECT, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING) view.set_model(self.tree_store) view.set_tooltip_column(3) # Gtk TODO: solve via Gtk.TargetList? https://python-gtk-3-tutorial.readthedocs.io/en/latest/drag_and_drop.html view.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [Gtk.TargetEntry.new('STRING', 0, 0)], Gdk.DragAction.COPY) self.library_row_iter_dict_by_library_path = {} self.__expansion_state = None self.update()
Example #16
Source File: state_icons.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def __init__(self): View.__init__(self) Gtk.IconView.__init__(self) self.props.item_orientation = Gtk.Orientation.HORIZONTAL self.set_columns(len(self.states)) self.set_margin(0) self.set_item_width(23) self.set_spacing(0) self.set_row_spacing(0) self.set_column_spacing(0) liststore = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING) self.set_model(liststore) self.set_markup_column(0) self.set_tooltip_column(1) for shorthand, state_class, icon in self.states: liststore.append(['<span font_desc="{font} {size}" color="{color}">{icon}</span> {text}'.format( font=constants.ICON_FONT_FONTAWESOME, size=constants.FONT_SIZE_BIG, color=global_gui_config.colors['BUTTON_TEXT_COLOR'], icon=icon, text=shorthand ), "Add/Drag and Drop " + state_class.__name__]) self['state_icon_view'] = self self.top = 'state_icon_view'
Example #17
Source File: combobox_enhanced.py From gtg with GNU General Public License v3.0 | 5 votes |
def listStoreFromList(list_obj): list_store = Gtk.ListStore(GObject.TYPE_STRING) for elem in list_obj: iter = list_store.append() list_store.set(iter, 0, elem) return list_store
Example #18
Source File: backend_gtk3.py From Computable with MIT License | 4 votes |
def __init__ (self, title = 'Save file', parent = None, action = Gtk.FileChooserAction.SAVE, buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK), path = None, filetypes = [], default_filetype = None ): super (FileChooserDialog, self).__init__ (title, parent, action, buttons) self.set_default_response (Gtk.ResponseType.OK) if not path: path = os.getcwd() + os.sep # create an extra widget to list supported image formats self.set_current_folder (path) self.set_current_name ('image.' + default_filetype) hbox = Gtk.Box(spacing=10) hbox.pack_start(Gtk.Label(label="File Format:"), False, False, 0) liststore = Gtk.ListStore(GObject.TYPE_STRING) cbox = Gtk.ComboBox() #liststore) cbox.set_model(liststore) cell = Gtk.CellRendererText() cbox.pack_start(cell, True) cbox.add_attribute(cell, 'text', 0) hbox.pack_start(cbox, False, False, 0) self.filetypes = filetypes self.sorted_filetypes = filetypes.items() self.sorted_filetypes.sort() default = 0 for i, (ext, name) in enumerate(self.sorted_filetypes): liststore.append(["%s (*.%s)" % (name, ext)]) if ext == default_filetype: default = i cbox.set_active(default) self.ext = default_filetype def cb_cbox_changed (cbox, data=None): """File extension changed""" head, filename = os.path.split(self.get_filename()) root, ext = os.path.splitext(filename) ext = ext[1:] new_ext = self.sorted_filetypes[cbox.get_active()][0] self.ext = new_ext if ext in self.filetypes: filename = root + '.' + new_ext elif ext == '': filename = filename.rstrip('.') + '.' + new_ext self.set_current_name (filename) cbox.connect ("changed", cb_cbox_changed) hbox.show_all() self.set_extra_widget(hbox)
Example #19
Source File: export.py From gtg with GNU General Public License v3.0 | 4 votes |
def _init_gtk(self): """ Initialize all the GTK widgets """ self.menu_entry = False self.menu_item = Gtk.ModelButton() self.menu_item.set_label(_("Export the tasks currently listed")) self.menu_item.connect('clicked', self.show_dialog) self.menu_item.show() builder = Gtk.Builder() cur_dir = os.path.dirname(os.path.abspath(__file__)) builder_file = os.path.join(cur_dir, "export.ui") builder.add_from_file(builder_file) self.combo = builder.get_object("export_combo_templ") templates_list = Gtk.ListStore( GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING) self.combo.set_model(templates_list) cell = Gtk.CellRendererText() self.combo.pack_start(cell, True) self.combo.add_attribute(cell, 'text', 1) self.export_dialog = builder.get_object("export_dialog") self.export_image = builder.get_object("export_image") self.preferences_dialog = builder.get_object("preferences_dialog") self.pref_menu = builder.get_object("pref_chbox_menu") self.description_label = builder.get_object("label_description") self.save_button = builder.get_object("export_btn_save") self.open_button = builder.get_object("export_btn_open") self.export_all_active = builder.get_object( "export_all_active_rb") self.export_all_active.set_active(True) self.export_finished_last_week = builder.get_object( "export_finished_last_week_rb") self.export_all_finished = builder.get_object( "export_all_finished_rb") builder.connect_signals({ "on_export_btn_open_clicked": lambda widget: self.on_export_start(False), "on_export_btn_save_clicked": lambda widget: self.on_export_start(True), "on_export_dialog_delete_event": self._hide_dialog, "on_export_combo_templ_changed": self.on_combo_changed, "on_preferences_dialog_delete_event": self.on_preferences_cancel, "on_btn_preferences_cancel_clicked": self.on_preferences_cancel, "on_btn_preferences_ok_clicked": self.on_preferences_ok, })
Example #20
Source File: backend_gtk3.py From neural-network-animation with MIT License | 4 votes |
def __init__ (self, title = 'Save file', parent = None, action = Gtk.FileChooserAction.SAVE, buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK), path = None, filetypes = [], default_filetype = None ): super (FileChooserDialog, self).__init__ (title, parent, action, buttons) self.set_default_response (Gtk.ResponseType.OK) if not path: path = os.getcwd() + os.sep # create an extra widget to list supported image formats self.set_current_folder (path) self.set_current_name ('image.' + default_filetype) hbox = Gtk.Box(spacing=10) hbox.pack_start(Gtk.Label(label="File Format:"), False, False, 0) liststore = Gtk.ListStore(GObject.TYPE_STRING) cbox = Gtk.ComboBox() #liststore) cbox.set_model(liststore) cell = Gtk.CellRendererText() cbox.pack_start(cell, True) cbox.add_attribute(cell, 'text', 0) hbox.pack_start(cbox, False, False, 0) self.filetypes = filetypes self.sorted_filetypes = list(six.iteritems(filetypes)) self.sorted_filetypes.sort() default = 0 for i, (ext, name) in enumerate(self.sorted_filetypes): liststore.append(["%s (*.%s)" % (name, ext)]) if ext == default_filetype: default = i cbox.set_active(default) self.ext = default_filetype def cb_cbox_changed (cbox, data=None): """File extension changed""" head, filename = os.path.split(self.get_filename()) root, ext = os.path.splitext(filename) ext = ext[1:] new_ext = self.sorted_filetypes[cbox.get_active()][0] self.ext = new_ext if ext in self.filetypes: filename = root + '.' + new_ext elif ext == '': filename = filename.rstrip('.') + '.' + new_ext self.set_current_name (filename) cbox.connect ("changed", cb_cbox_changed) hbox.show_all() self.set_extra_widget(hbox)
Example #21
Source File: backend_gtk3.py From ImageFusion with MIT License | 4 votes |
def __init__ (self, title = 'Save file', parent = None, action = Gtk.FileChooserAction.SAVE, buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK), path = None, filetypes = [], default_filetype = None ): super (FileChooserDialog, self).__init__ (title, parent, action, buttons) self.set_default_response (Gtk.ResponseType.OK) if not path: path = os.getcwd() + os.sep # create an extra widget to list supported image formats self.set_current_folder (path) self.set_current_name ('image.' + default_filetype) hbox = Gtk.Box(spacing=10) hbox.pack_start(Gtk.Label(label="File Format:"), False, False, 0) liststore = Gtk.ListStore(GObject.TYPE_STRING) cbox = Gtk.ComboBox() #liststore) cbox.set_model(liststore) cell = Gtk.CellRendererText() cbox.pack_start(cell, True) cbox.add_attribute(cell, 'text', 0) hbox.pack_start(cbox, False, False, 0) self.filetypes = filetypes self.sorted_filetypes = list(six.iteritems(filetypes)) self.sorted_filetypes.sort() default = 0 for i, (ext, name) in enumerate(self.sorted_filetypes): liststore.append(["%s (*.%s)" % (name, ext)]) if ext == default_filetype: default = i cbox.set_active(default) self.ext = default_filetype def cb_cbox_changed (cbox, data=None): """File extension changed""" head, filename = os.path.split(self.get_filename()) root, ext = os.path.splitext(filename) ext = ext[1:] new_ext = self.sorted_filetypes[cbox.get_active()][0] self.ext = new_ext if ext in self.filetypes: filename = root + '.' + new_ext elif ext == '': filename = filename.rstrip('.') + '.' + new_ext self.set_current_name (filename) cbox.connect ("changed", cb_cbox_changed) hbox.show_all() self.set_extra_widget(hbox)
Example #22
Source File: backend_gtk3.py From CogAlg with MIT License | 4 votes |
def __init__(self, title = 'Save file', parent = None, action = Gtk.FileChooserAction.SAVE, buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK), path = None, filetypes = [], default_filetype = None ): super().__init__(title, parent, action, buttons) self.set_default_response(Gtk.ResponseType.OK) self.set_do_overwrite_confirmation(True) if not path: path = os.getcwd() # create an extra widget to list supported image formats self.set_current_folder(path) self.set_current_name('image.' + default_filetype) hbox = Gtk.Box(spacing=10) hbox.pack_start(Gtk.Label(label="File Format:"), False, False, 0) liststore = Gtk.ListStore(GObject.TYPE_STRING) cbox = Gtk.ComboBox() cbox.set_model(liststore) cell = Gtk.CellRendererText() cbox.pack_start(cell, True) cbox.add_attribute(cell, 'text', 0) hbox.pack_start(cbox, False, False, 0) self.filetypes = filetypes sorted_filetypes = sorted(filetypes.items()) default = 0 for i, (ext, name) in enumerate(sorted_filetypes): liststore.append(["%s (*.%s)" % (name, ext)]) if ext == default_filetype: default = i cbox.set_active(default) self.ext = default_filetype def cb_cbox_changed(cbox, data=None): """File extension changed""" head, filename = os.path.split(self.get_filename()) root, ext = os.path.splitext(filename) ext = ext[1:] new_ext = sorted_filetypes[cbox.get_active()][0] self.ext = new_ext if ext in self.filetypes: filename = root + '.' + new_ext elif ext == '': filename = filename.rstrip('.') + '.' + new_ext self.set_current_name(filename) cbox.connect("changed", cb_cbox_changed) hbox.show_all() self.set_extra_widget(hbox)
Example #23
Source File: backend_gtk3.py From matplotlib-4-abaqus with MIT License | 4 votes |
def __init__ (self, title = 'Save file', parent = None, action = Gtk.FileChooserAction.SAVE, buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK), path = None, filetypes = [], default_filetype = None ): super (FileChooserDialog, self).__init__ (title, parent, action, buttons) self.set_default_response (Gtk.ResponseType.OK) if not path: path = os.getcwd() + os.sep # create an extra widget to list supported image formats self.set_current_folder (path) self.set_current_name ('image.' + default_filetype) hbox = Gtk.Box(spacing=10) hbox.pack_start(Gtk.Label(label="File Format:"), False, False, 0) liststore = Gtk.ListStore(GObject.TYPE_STRING) cbox = Gtk.ComboBox() #liststore) cbox.set_model(liststore) cell = Gtk.CellRendererText() cbox.pack_start(cell, True) cbox.add_attribute(cell, 'text', 0) hbox.pack_start(cbox, False, False, 0) self.filetypes = filetypes self.sorted_filetypes = filetypes.items() self.sorted_filetypes.sort() default = 0 for i, (ext, name) in enumerate(self.sorted_filetypes): liststore.append(["%s (*.%s)" % (name, ext)]) if ext == default_filetype: default = i cbox.set_active(default) self.ext = default_filetype def cb_cbox_changed (cbox, data=None): """File extension changed""" head, filename = os.path.split(self.get_filename()) root, ext = os.path.splitext(filename) ext = ext[1:] new_ext = self.sorted_filetypes[cbox.get_active()][0] self.ext = new_ext if ext in self.filetypes: filename = root + '.' + new_ext elif ext == '': filename = filename.rstrip('.') + '.' + new_ext self.set_current_name (filename) cbox.connect ("changed", cb_cbox_changed) hbox.show_all() self.set_extra_widget(hbox)
Example #24
Source File: backend_gtk3.py From Mastering-Elasticsearch-7.0 with MIT License | 4 votes |
def __init__(self, title = 'Save file', parent = None, action = Gtk.FileChooserAction.SAVE, buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK), path = None, filetypes = [], default_filetype = None ): super().__init__(title, parent, action, buttons) self.set_default_response(Gtk.ResponseType.OK) self.set_do_overwrite_confirmation(True) if not path: path = os.getcwd() # create an extra widget to list supported image formats self.set_current_folder(path) self.set_current_name('image.' + default_filetype) hbox = Gtk.Box(spacing=10) hbox.pack_start(Gtk.Label(label="File Format:"), False, False, 0) liststore = Gtk.ListStore(GObject.TYPE_STRING) cbox = Gtk.ComboBox() cbox.set_model(liststore) cell = Gtk.CellRendererText() cbox.pack_start(cell, True) cbox.add_attribute(cell, 'text', 0) hbox.pack_start(cbox, False, False, 0) self.filetypes = filetypes sorted_filetypes = sorted(filetypes.items()) default = 0 for i, (ext, name) in enumerate(sorted_filetypes): liststore.append(["%s (*.%s)" % (name, ext)]) if ext == default_filetype: default = i cbox.set_active(default) self.ext = default_filetype def cb_cbox_changed(cbox, data=None): """File extension changed""" head, filename = os.path.split(self.get_filename()) root, ext = os.path.splitext(filename) ext = ext[1:] new_ext = sorted_filetypes[cbox.get_active()][0] self.ext = new_ext if ext in self.filetypes: filename = root + '.' + new_ext elif ext == '': filename = filename.rstrip('.') + '.' + new_ext self.set_current_name(filename) cbox.connect("changed", cb_cbox_changed) hbox.show_all() self.set_extra_widget(hbox)