def unlink(self, uri): """Deletes the specified URI. @param uri: The URI to delete. @type uri: a gnomevfs.URI """ # Be sure the file exists then delete it if gnomevfs.exists(uri): file_info = gnomevfs.get_file_info(uri) # Double check the user wants to delete the file response = dialogs.choice_ok_cancel(fmt0001 % str(uri), True) if response == gtk.RESPONSE_OK: try: if files.is_dir(file_info): self.__remove_directory(uri) else: gnomevfs.unlink(uri) except Exception, e: dialogs.error(fmt0002 % e) self.refresh()
def cb_button(self, widget, *args): devtype = '' node = '' callval = None debug.debug('cb_button, widget', widget.get_name(), 'status', self.fsent.check()) if widget == self.button_okBtn: self.fsent.dev = self.dev self.fsent.devtype = self.devtype self.fsent.mountpoint = self.dir_mountpoint.get_filename() fstype = self.cb_fstype.get_active_text() if fstype == 'Other...': fstype = self.entry_otherfstype.get_text() debug.debug('Other fstype is {}'.format(fstype)) self.fsent.fstype = fstype self.fsent.fsfreq = self.sb_fsfreq.get_value_as_int() self.fsent.fspass = self.sb_fspass.get_value_as_int() self.fsent.fsopts = self.entry_fsopts.get_text() if self.fsent.fsopts == '': dialogs.message( _("No filesystem options selected, using 'defaults'"), parent=self.window) self.fsent.fsopts = 'defaults' status, errors = self.fsent.check() if not status: dialogs.error( _("Error(s): These field(s) need values:\n{}").format( ', '.join(errors))) return False callval = self.fsent else: callval = False if isinstance(self.callback, collections.Callable): self.callback(callval) self.window.close()
def _delete_cb(self, widget): """Properties dialog delete callback""" self._dialog.hide() name = brushmanager.translate_group_name(self._group) msg = C_( "brush group delete", u"Really delete group \u201C{group_name}\u201D?", ).format(group_name=name, ) bm = self._app.brushmanager if not dialogs.confirm(self, msg): return bm.delete_group(self._group) if self._group not in bm.groups: GLib.idle_add( self._remove_panel_idle_cb, self.__gtype_name__, (self._group, ), ) return # Special groups like "Deleted" cannot be deleted, # but the error message is very confusing in that case... msg = C_( "brush group delete", u"Could not delete group \u201C{group_name}\u201D.\n" u"Some special groups cannot be deleted.", ).format(group_name=name, ) dialogs.error(self, msg)
def _rename_cb(self, widget): """Properties dialog rename callback""" # XXX Because of the way this works, groups can only be renamed from # XXX the widget's properties dialog at present. Maybe that's OK. self._dialog.hide() old_group = self._group new_group = dialogs.ask_for_name( self, C_("brush group rename dialog: title", "Rename Group"), old_group, ) if not new_group: return if old_group not in self._app.brushmanager.groups: return if new_group not in self._app.brushmanager.groups: self._app.brushmanager.rename_group(old_group, new_group) self._group = new_group workspace = self._app.workspace gtype_name = self.__gtype_name__ workspace.update_tool_widget_params(gtype_name, (old_group, ), (new_group, )) self._update_brush_list() else: dialogs.error( self, C_( 'brush group rename', 'A group with this name already exists!', ))
def _rename_cb(self, widget): """Properties dialog rename callback""" # XXX Because of the way this works, groups can only be renamed from # XXX the widget's properties dialog at present. Maybe that's OK. self._dialog.hide() old_group = self._group new_group = dialogs.ask_for_name( self, C_("brush group rename dialog: title", "Rename Group"), old_group, ) if not new_group: return if old_group not in self._app.brushmanager.groups: return if new_group not in self._app.brushmanager.groups: self._app.brushmanager.rename_group(old_group, new_group) self._group = new_group workspace = self._app.workspace gtype_name = self.__gtype_name__ workspace.update_tool_widget_params(gtype_name, (old_group,), (new_group,)) self._update_brush_list() else: dialogs.error(self, C_( 'brush group rename', 'A group with this name already exists!', ))
def _delete_cb(self, widget): """Properties dialog delete callback""" self._dialog.hide() name = brushmanager.translate_group_name(self._group) msg = C_( "brush group delete", u"Really delete group \u201C{group_name}\u201D?", ).format( group_name = name, ) bm = self._app.brushmanager if not dialogs.confirm(self, msg): return bm.delete_group(self._group) if self._group not in bm.groups: GLib.idle_add( self._remove_panel_idle_cb, self.__gtype_name__, (self._group,), ) return # Special groups like "Deleted" cannot be deleted, # but the error message is very confusing in that case... msg = C_( "brush group delete", u"Could not delete group \u201C{group_name}\u201D.\n" u"Some special groups cannot be deleted.", ).format( group_name = name, ) dialogs.error(self, msg)
def update_settings_cb(self, window): b = self.bm.selected_brush if not b.name: dialogs.error(self, _('No brush selected, please use "Add As New" instead.')) return b.brushinfo = self.app.brush.clone() b.save()
def data_entry_store(self): """ Attempt to store data read from a textview packed in the data frame. """ new_data = self.data.get_buffer().get_text(*self.data.get_buffer().get_bounds()) if new_data == "": return True if self.node.data is None and not self.interacted: return True else: value_check = self.node.validity_check(self.node.datatype, new_data) if value_check is None: dialogs.error(None, "Invalid value entered") return False elif value_check != self.node.data: self.node.set_data(value_check) if (isinstance(self.node, mixedtree.MixedTree) and "shape" in self.node.child.attrs.keys() and self.node.child.attrs["shape"][0] is int and isinstance(self.node.datatype, plist.List) and self.node.datatype.cardinality == "+"): self.node.child.set_attr("shape", str(len(value_check.split(" ")))) self.emit("on-store") self.interacted = False return True
def rename_button_clicked_cb(self, button): """Rename the current brush; user is prompted for a new name""" bm = self.app.brushmanager src_brush = bm.selected_brush if not src_brush.name: dialogs.error(self, C_( 'brush settings editor: rename brush: error message', 'No brush selected!', )) return src_name_pp = src_brush.name.replace('_', ' ') dst_name = dialogs.ask_for_name( self, C_( "brush settings editor: rename brush: dialog title", "Rename Brush", ), src_name_pp, ) if not dst_name: return dst_name = dst_name.replace(' ', '_') # ensure we don't overwrite an existing brush by accident dst_deleted = None for group, brushes in bm.groups.iteritems(): for b2 in brushes: if b2.name == dst_name: if group == brushmanager.DELETED_BRUSH_GROUP: dst_deleted = b2 else: msg = C_( 'brush settings editor: ' 'rename brush: error message', 'A brush with this name already exists!', ) dialogs.error(self, msg) return logger.info("Renaming brush %r -> %r", src_brush.name, dst_name) if dst_deleted: deleted_group = brushmanager.DELETED_BRUSH_GROUP deleted_brushes = bm.get_group_brushes(deleted_group) deleted_brushes.remove(dst_deleted) bm.brushes_changed(deleted_brushes) # save src as dst src_name = src_brush.name src_brush.name = dst_name src_brush.save() src_brush.name = src_name # load dst dst_brush = brushmanager.ManagedBrush(bm, dst_name, persistent=True) dst_brush.load() # Replace src with dst, but keep src in the deleted list if it # is a stock brush self._delete_brush(src_brush, replacement=dst_brush) bm.select_brush(dst_brush)
def cb_button(self,widget,*args): devtype = '' node = '' callval = None debug.debug('cb_button, widget',widget.get_name(),'status',self.fsent.check()) if widget == self.button_okBtn: self.fsent.dev = self.dev self.fsent.devtype = self.devtype self.fsent.mountpoint = self.dir_mountpoint.get_filename() fstype = self.cb_fstype.get_active_text() if fstype == 'Other...': fstype = self.entry_otherfstype.get_text() debug.debug('Other fstype is {}'.format(fstype)) self.fsent.fstype = fstype self.fsent.fsfreq = self.sb_fsfreq.get_value_as_int() self.fsent.fspass = self.sb_fspass.get_value_as_int() self.fsent.fsopts = self.entry_fsopts.get_text() if self.fsent.fsopts == '': dialogs.message(_("No filesystem options selected, using 'defaults'"),parent=self.window) self.fsent.fsopts = 'defaults' status, errors = self.fsent.check() if not status: dialogs.error(_("Error(s): These field(s) need values:\n{}").format(', '.join(errors))) return False callval = self.fsent else: callval = False if isinstance(self.callback, collections.Callable): self.callback(callval) self.window.close()
def data_entry_store(self): """ Attempt to store data read from a textview packed in the data frame. """ new_data = self.data.get_buffer().get_text( *self.data.get_buffer().get_bounds()) if new_data == "": return True if self.node.data is None and not self.interacted: return True else: value_check = self.node.validity_check(self.node.datatype, new_data) if value_check is None: dialogs.error(None, "Invalid value entered") return False elif value_check != self.node.data: self.node.set_data(value_check) if (isinstance(self.node, mixedtree.MixedTree) and "shape" in self.node.child.attrs.keys() and self.node.child.attrs["shape"][0] is int and isinstance(self.node.datatype, plist.List) and self.node.datatype.cardinality == "+"): self.node.child.set_attr("shape", str(len(value_check.split(" ")))) self.emit("on-store") self.interacted = False return True
def rename_button_clicked_cb(self, button): """Rename the current brush; user is prompted for a new name""" bm = self.app.brushmanager src_brush = bm.selected_brush if not src_brush.name: dialogs.error(self, C_( 'brush settings editor: rename brush: error message', 'No brush selected!', )) return src_name_pp = src_brush.name.replace('_', ' ') dst_name = dialogs.ask_for_name( self, C_( "brush settings editor: rename brush: dialog title", "Rename Brush", ), src_name_pp, ) if not dst_name: return dst_name = dst_name.replace(' ', '_') # ensure we don't overwrite an existing brush by accident dst_deleted = None for group, brushes in bm.groups.iteritems(): for b2 in brushes: if b2.name == dst_name: if group == brushmanager.DELETED_BRUSH_GROUP: dst_deleted = b2 else: msg = C_( 'brush settings editor: rename brush: error message', 'A brush with this name already exists!', ) dialogs.error(self, msg) return logger.info("Renaming brush %r -> %r", src_brush.name, dst_name) if dst_deleted: deleted_group = brushmanager.DELETED_BRUSH_GROUP deleted_brushes = bm.get_group_brushes(deleted_group) deleted_brushes.remove(dst_deleted) bm.brushes_changed(deleted_brushes) # save src as dst src_name = src_brush.name src_brush.name = dst_name src_brush.save() src_brush.name = src_name # load dst dst_brush = brushmanager.ManagedBrush(bm, dst_name, persistent=True) dst_brush.load() # Replace src with dst, but keep src in the deleted list if it # is a stock brush self._delete_brush(src_brush, replacement=dst_brush) bm.select_brush(dst_brush)
def data_tensor_store(self): """ Attempt to store data read from tensor data entry widgets packed in the data frame. """ dim1, dim2 = self.node.tensor_shape(self.geometry_dim_tree) is_symmetric = self.node.is_symmetric_tensor(self.geometry_dim_tree) if True not in self.interacted: return True entry_values = [] for i in range(dim1): for j in range(dim2): if is_symmetric and i > j: entry_values.append( self.data.get_children()[i + j * dim1].get_text()) else: entry_values.append( self.data.get_children()[j + i * dim2].get_text()) changed = False for i in range(dim1): for j in range(dim2): if (self.interacted[j + i * dim2] and entry_values[j + i * dim2] != "" and (self.node.data is None or self.node.data.split(" ")[j + i * dim2] != entry_values[j + i * dim2])): changed = True if not changed: return True elif (self.node.data is None and False in self.interacted) or "" in entry_values: dialogs.error(None, "Invalid value entered") return False new_data = "" for i in range(dim1): for j in range(dim2): new_data += " " + entry_values[j + i * dim2] value_check = self.node.validity_check(self.node.datatype, new_data) if value_check is None: return False elif not value_check == self.node.data: self.node.set_data(value_check) dim1, dim2 = self.node.tensor_shape(self.geometry_dim_tree) if int(self.node.child.attrs["rank"][1]) == 1: self.node.child.set_attr("shape", str(dim1)) else: self.node.child.set_attr("shape", str(dim1) + " " + str(dim2)) self.emit("on-store") self.interacted = [False for i in range(dim1 * dim2)] return True
def rename_group_cb(self, w, old_group): new_group = dialogs.ask_for_name(self, _('Rename Group'), old_group) if not new_group: return if new_group not in self.bm.groups: self.bm.rename_group(old_group, new_group) else: dialogs.error(self, _('A group with this name already exists!'))
def delete_brush_cb(self, window): b = self.bm.selected_brush if not b.name: dialogs.error(self, _('No brush selected!')) return if not dialogs.confirm(self, _("Really delete brush from disk?")): return self.bm.select_brush(None) self.delete_brush_internal(b)
def delete_group_cb(self, w, group): msg = _('Really delete group %s?') \ % brushmanager.translate_group_name(group) if dialogs.confirm(self, msg): self.bm.delete_group(group) if group in self.bm.groups: msg = _('This group can not be deleted ' '(try to empty it first).') dialogs.error(self, msg)
def data_tensor_store(self): """ Attempt to store data read from tensor data entry widgets packed in the data frame. """ dim1, dim2 = self.node.tensor_shape(self.geometry_dim_tree) is_symmetric = self.node.is_symmetric_tensor(self.geometry_dim_tree) if True not in self.interacted: return True entry_values = [] for i in range(dim1): for j in range(dim2): if is_symmetric and i > j: entry_values.append(self.data.get_children()[i + j * dim1].get_text()) else: entry_values.append(self.data.get_children()[j + i * dim2].get_text()) changed = False for i in range(dim1): for j in range(dim2): if (self.interacted[j + i * dim2] and entry_values[j + i * dim2] != "" and (self.node.data is None or self.node.data.split(" ")[j + i * dim2] != entry_values[j + i * dim2])): changed = True break if not changed: return True elif (self.node.data is None and False in self.interacted) or "" in entry_values: dialogs.error(None, "Invalid value entered") return False new_data = "" for i in range(dim1): for j in range(dim2): new_data += " " + entry_values[j + i * dim2] value_check = self.node.validity_check(self.node.datatype, new_data) if value_check is None: return False elif not value_check == self.node.data: self.node.set_data(value_check) dim1, dim2 = self.node.tensor_shape(self.geometry_dim_tree) if int(self.node.child.attrs["rank"][1]) == 1: self.node.child.set_attr("shape", str(dim1)) else: self.node.child.set_attr("shape", str(dim1) + " " + str(dim2)) self.emit("on-store") self.interacted = [False for i in range(dim1 * dim2)] return True
def save_button_clicked_cb(self, button): """Save the current brush settings (overwrites)""" bm = self.app.brushmanager b = bm.selected_brush if not b.name: msg = _('No brush selected, please use "Add As New" instead.') dialogs.error(self, msg) return b.brushinfo = self.app.brush.clone() b.save()
def delete_button_clicked_cb(self, button): """Deletes the current brush, with a confirmation dialog""" bm = self.app.brushmanager b = bm.selected_brush if not b.name: dialogs.error(self, _('No brush selected!')) return if not dialogs.confirm(self, _("Really delete brush from disk?")): return bm.select_brush(None) self._delete_brush(b, replacement=None)
def update_preview_cb(self, window): pixbuf = self.get_preview_pixbuf() b = self.bm.selected_brush if not b.name: dialogs.error(self, _('No brush selected, please use "Add As New" instead.')) return b.preview = pixbuf b.save() for brushes in self.bm.groups.itervalues(): if b in brushes: for f in self.bm.brushes_observers: f(brushes)
def _name_check(self, value): """ Check to see if the supplied data is a valid tree name. """ valid_chars = "_:[]1234567890qwertyuioplkjhgfdsazxcvbnmMNBVCXZASDFGHJKLPOIUYTREWQ" for char in value: if char not in valid_chars: dialogs.error(None, "Invalid value entered") return False return True
def on_remove_frames(self, button): ammount = anidialogs.ask_for(self, _("Remove frames"), _("Ammount of frames to remove:"), "1") try: ammount = int(ammount) except TypeError: return except ValueError: dialogs.error(self, _("Ammount of frames must be integer")) return if ammount < 1: dialogs.error(self, _("Ammount of frames must be bigger than one")) return self.ani.remove_frames(ammount)
def addButtonClicked(self, widget, liststore): dropdownlist = self.set.keys() for row in liststore: if row[1] in dropdownlist: dropdownlist.remove(row[1]) if len(dropdownlist) > 0: response, param = dialogs.dropdown(dropdownlist, '<b>Add</b>') if response == gtk.RESPONSE_OK: liststore.prepend((False, param, self.set[param])) self.window.set_title(str('! %s' % (self.setFile))) return else: dialogs.error('No more keywords to add.') return
def addButtonClicked(self, widget, liststore): dropdownlist=self.set.keys(); for row in liststore: if row[1] in dropdownlist: dropdownlist.remove(row[1]); if len(dropdownlist)>0: response,param=dialogs.dropdown(dropdownlist, '<b>Add</b>'); if response == gtk.RESPONSE_OK: liststore.prepend((False, param, self.set[param])) self.window.set_title(str('! %s' % ( self.setFile) )) return else: dialogs.error('No more keywords to add.') return
def save_button_clicked_cb(self, button): """Save the current brush settings (overwrites)""" bm = self.app.brushmanager b = bm.selected_brush if not b.name: msg = C_( 'brush settings editor: save brush: error message', 'No brush selected, please use “Add As New” instead.', ) dialogs.error(self, msg) return b.brushinfo = self.app.brush.clone() b.save() self._mark_all_settings_unmodified_in_treeview() self._update_brush_header(modified=False)
def _delete_cb(self, widget): """Properties dialog delete callback""" self._dialog.hide() name = brushmanager.translate_group_name(self._group) msg = _('Really delete group "%s"?') % (name,) bm = self._app.brushmanager if not dialogs.confirm(self, msg): return bm.delete_group(self._group) if self._group not in bm.groups: self._app.workspace.hide_tool_widget(self.__gtype_name__, (self._group,)) return msg = _('Group "%s" cannot be deleted. Try emptying it first.') dialogs.error(self, msg % (name,))
def _delete_cb(self, widget): """Properties dialog delete callback""" self._dialog.hide() name = brushmanager.translate_group_name(self._group) msg = _('Really delete group "%s"?') % (name, ) bm = self._app.brushmanager if not dialogs.confirm(self, msg): return bm.delete_group(self._group) if self._group not in bm.groups: self._app.workspace.hide_tool_widget(self.__gtype_name__, (self._group, )) return msg = _('Group "%s" cannot be deleted. Try emptying it first.') dialogs.error(self, msg % (name, ))
def on_validate_schematron(self, widget=None): """ Tools > Validate Schematron. This uses the etree.Schematron API, if it exists, to validate the document tree against a supplied schematron file. """ if self.schematron_file is None: dialogs.error(self.parent.main_window, "No schematron file supplied") return # Write the current version out to file. tmp = tempfile.NamedTemporaryFile() self.parent.tree.write(tmp.name) std_input, std_output, err_output = os.popen3( "xmllint --schematron %s %s --noout" % (self.schematron_file, tmp.name)) output = err_output.read() output = output.replace("%s fails to validate" % tmp.name, "") output = output.strip() if output == "%s validates" % tmp.name: self.destroy_error_list() dialogs.message_box( self.parent.main_window, "XML file validated successfully against %s" % self.schematron_file, "XML validation successful") # Clear the list, as there may still be errors from a previous schematron validation. self.model.clear() self.errlist_type = 0 # Add each line of output as a new row. lines = output.split("\n") for line in lines: if len(line) == 0: continue tokens = line.split(" ") self.model.append([tokens[0], " ".join(tokens[3:]), 0]) # Finish set up of list view widget. self.listview.set_property("visible", True) self.listwindow.set_property("visible", True) self.parent.statusbar.set_statusbar( "There are %u Schematron errors in the document" % len(lines))
def rename_brush_cb(self, window): src_brush = self.bm.selected_brush if not src_brush.name: dialogs.error(self, _('No brush selected!')) return dst_name = dialogs.ask_for_name(self, _("Rename Brush"), src_brush.name.replace('_', ' ')) if not dst_name: return dst_name = dst_name.replace(' ', '_') # ensure we don't overwrite an existing brush by accident dst_deleted = None for group, brushes in self.bm.groups.iteritems(): for b2 in brushes: if b2.name == dst_name: if group == brushmanager.DELETED_BRUSH_GROUP: dst_deleted = b2 else: dialogs.error(self, _('A brush with this name already exists!')) return print 'renaming brush', repr(src_brush.name), '-->', repr(dst_name) if dst_deleted: deleted_brushes = self.bm.get_group_brushes(brushmanager.DELETED_BRUSH_GROUP) deleted_brushes.remove(dst_deleted) for f in self.bm.brushes_observers: f(deleted_brushes) # save src as dst src_name = src_brush.name src_brush.name = dst_name src_brush.save() src_brush.name = src_name # load dst dst_brush = brushmanager.ManagedBrush(self.bm, dst_name, persistent=True) dst_brush.load() dst_brush.in_brushlist = True # replace src with dst (but keep src in the deleted list if it is a stock brush) self.delete_brush_internal(src_brush, replacement=dst_brush) self.bm.select_brush(dst_brush)
def on_validate_schematron(self, widget=None): """ Tools > Validate Schematron. This uses the etree.Schematron API, if it exists, to validate the document tree against a supplied schematron file. """ if self.schematron_file is None: dialogs.error(self.parent.main_window, "No schematron file supplied") return # Write the current version out to file. tmp = tempfile.NamedTemporaryFile() self.parent.tree.write(tmp.name) std_input, std_output, err_output = os.popen3("xmllint --schematron %s %s --noout" % (self.schematron_file, tmp.name)) output = err_output.read() output = output.replace("%s fails to validate" % tmp.name, "") output = output.strip() if output == "%s validates" % tmp.name: self.destroy_error_list() dialogs.message_box(self.parent.main_window, "XML file validated successfully against %s" % self.schematron_file, "XML validation successful") # Clear the list, as there may still be errors from a previous schematron validation. self.model.clear() self.errlist_type = 0 # Add each line of output as a new row. lines = output.split("\n") for line in lines: if len(line) == 0: continue tokens = line.split(" ") self.model.append([ tokens[0], " ".join(tokens[3:]), 0 ]) # Finish set up of list view widget. self.listview.set_property("visible", True) self.listwindow.set_property("visible", True) self.parent.statusbar.set_statusbar("There are %u Schematron errors in the document" % len(lines))
def error(self, parent, primary, secondary, details=None, alternative_action=None): from dialogs import error res = "ok" res = error(parent=parent, primary=primary, secondary=secondary, details=details, alternative_action=alternative_action) if res == Gtk.ResponseType.YES: res = "yes" return res
def delete_button_clicked_cb(self, button): """Deletes the current brush, with a confirmation dialog""" bm = self.app.brushmanager b = bm.selected_brush if not b.name: dialogs.error(self, C_( 'brush settings editor: delete brush: error message', 'No brush selected!', )) return b_name_pp = b.name.replace('_', ' ') msg = C_( "brush settings editor: delete brush: confirm dialog question", "Really delete brush “{brush_name}” from disk?", ).format( brush_name = b_name_pp, ) if not dialogs.confirm(self, msg): return bm.select_brush(None) self._delete_brush(b, replacement=None)
def open_file_browser(self, uri): """Opens a file browser at the specified location. @param uri: The local URI to open the file browser to. @type uri: a gnomevfs.URI """ message = None if not gnomevfs.exists(uri): message = fmt0003 % uri elif not uri.is_local: message = fmt0004 % uri if message is not None: dialogs.error(message) return local_path = uri.path app = gnomevfs.URI(self.get_settings().get_file_browser()).path args = self.get_settings().get_browser_arguments() os.spawnlp(os.P_NOWAIT, app, app, args % local_path)
def on_validate(self, widget=None): """ Tools > Validate XML. This writes out the XML to a temporary file, then calls xmllint on it. (I didn't use the Xvif validation capabilities because the error messages are worse than useless; xmllint actually gives line numbers and such). """ if self.schema_file is None: dialogs.error(self.parent.main_window, "No schema file open") return self.tmp = tempfile.NamedTemporaryFile() self.parent.tree.write(self.tmp.name) std_input, std_output, std_error = os.popen3( "xmllint --relaxng %s %s --noout --path \".\"" % (self.schema_file, self.tmp.name)) output = std_error.read() output = output.replace("%s fails to validate" % self.tmp.name, "") if output.strip() == "%s validates" % self.tmp.name: # No errors. Close the error list (if it is open) and display a congratulatory message box. self.destroy_error_list() dialogs.message_box(self.parent.main_window, "XML file validated successfully", "Validation successful") else: self.create_error_list() self.errlist_type = 1 self.model.clear() lines = output.split("\n") # Read the temporary output file, split it by lines and use it to convert # line numbers to xpaths for the column data. f = file(self.tmp.name) data = f.read() output_lines = data.split("\n") for line in lines: if len(line) == 0: continue tokens = line.split(" ") # Parse each line of the xmllint --relaxng output. # FORMAT: # ELEMENT:LINE: element NAME: Relax-NG validity error : ERROR MESSAGE # (Capitals denotes variable data). Update the following code if the output changes. sub_tokens = tokens[0].split(":") message = " ".join(tokens[7:]) line = sub_tokens[1] xpath = self.add_to_xpath(output_lines, "", long(line) - 1) self.model.append([xpath, message]) self.listview.set_property("visible", True) self.listwindow.set_property("visible", True) # Update the status bar. Inform the user of the number of errors. self.parent.statusbar.set_statusbar( "There are %u Relax-NG errors in the document" % len(lines)) return
def on_validate(self, widget=None): """ Tools > Validate XML. This writes out the XML to a temporary file, then calls xmllint on it. (I didn't use the Xvif validation capabilities because the error messages are worse than useless; xmllint actually gives line numbers and such). """ if self.schema_file is None: dialogs.error(self.parent.main_window, "No schema file open") return self.tmp = tempfile.NamedTemporaryFile() self.parent.tree.write(self.tmp.name) std_input, std_output, std_error = os.popen3("xmllint --relaxng %s %s --noout --path \".\"" % (self.schema_file, self.tmp.name)) output = std_error.read() output = output.replace("%s fails to validate" % self.tmp.name, "") if output.strip() == "%s validates" % self.tmp.name: # No errors. Close the error list (if it is open) and display a congratulatory message box. self.destroy_error_list() dialogs.message_box(self.parent.main_window, "XML file validated successfully", "Validation successful") else: self.create_error_list() self.errlist_type = 1 self.model.clear() lines = output.split("\n") # Read the temporary output file, split it by lines and use it to convert # line numbers to xpaths for the column data. f = file(self.tmp.name) data = f.read() output_lines = data.split("\n") for line in lines: if len(line) == 0: continue tokens = line.split(" ") # Parse each line of the xmllint --relaxng output. # FORMAT: # ELEMENT:LINE: element NAME: Relax-NG validity error : ERROR MESSAGE # (Capitals denotes variable data). Update the following code if the output changes. sub_tokens = tokens[0].split(":") message = " ".join(tokens[7:]) line = sub_tokens[1] xpath = self.add_to_xpath(output_lines, "", long(line)-1) self.model.append([ xpath, message ]) self.listview.set_property("visible", True) self.listwindow.set_property("visible", True) # Update the status bar. Inform the user of the number of errors. self.parent.statusbar.set_statusbar("There are %u Relax-NG errors in the document" % len(lines)) return
def menuAction(self, w): m = w.get_name() if m == "New": #self.runcmd("agooey &"); os.system('agooey &') elif m == "Open": chooser = gtk.FileChooserDialog( title=None, action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) response = chooser.run() if response == gtk.RESPONSE_OK: filename = chooser.get_filename() if os.path.splitext(filename)[-1] == ".set": self.runcmd("cd " + os.path.dirname(filename)) self.runcmd("settings load " + filename) else: dialogs.error( str('%s does not appear to be an ADORE settings file.' % filename)) chooser.destroy() return elif m == "Connect": response, param = dialogs.parameters( "<b>Connect</b>", labels=("URI", "Agooey Temporary File"), parameters=('*****@*****.**', self.setFile), titleString="Connect to remote server") if response == gtk.RESPONSE_OK: # self.runcmd(str('ssh -Y %s -t "bash -c adore -g %s"' % (param[0], param[1]))) self.setFile = param[1] self.runcmd( str('ssh -Y %s -t \'bash -i -c "adore -i -g %s"\' ' % (param[0], param[1]))) return elif m == "demLoad": chooser = gtk.FileChooserDialog( title=None, action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) response = chooser.run() if response == gtk.RESPONSE_OK: filename = chooser.get_filename() self.runcmd("dem load " + filename) # elif response == gtk.RESPONSE_CANCEL: chooser.destroy() return elif m == "demMake": response, param = dialogs.parameter( "<b>dem make</b>", "SRTM1/SRTM3 extraBufferPercentage name", "SRTM3 20 dem", "Enter parameters for...") if response == gtk.RESPONSE_OK: self.runcmd("dem make " + param) return elif m == "ShowAbout": #os.system("echo ADORE-GUI")#self.answer_label.set_label( "Created by Beda Kosata") self.readSet() about = gtk.AboutDialog() about.set_program_name("ADORE-GOOEY") about.set_version( open( self.set.get('adore', 'ADOREFOLDER').strip('\'"') + "/version", 'r').read()) about.set_copyright("(c) Batuhan Osmanoglu 2009-2012") about.set_license( open( self.set.get('adore', 'ADOREFOLDER').strip('\'"') + "/license.txt", 'r').read()) about.set_comments(""" Automated Doris Environment SHELL PID: {} """.format(self.vPid)) about.set_website("http://code.google.com/p/adore-doris/") about.set_logo( gtk.gdk.pixbuf_new_from_file( self.set.get('adore', 'ADOREFOLDER').strip('\'"') + "/gui/adore-doris-gui-icon-256px.png")) about.run() about.destroy() return elif m == "toolsPythonCmd": response, param = dialogs.parameter("<b>Python Command</b>", "Please enter your command", "", "") if response == gtk.RESPONSE_OK: self.v.feed(str(eval(param))) self.v.feed('\n') return
def menuAction(self, w): m=w.get_name() if m == "New": #self.runcmd("agooey &"); os.system('agooey &') elif m == "Open": chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) response = chooser.run() if response == gtk.RESPONSE_OK: filename=chooser.get_filename(); if os.path.splitext(filename)[-1]==".set": self.runcmd("cd " + os.path.dirname(filename)); self.runcmd("settings load " + filename); else: dialogs.error(str('%s does not appear to be an ADORE settings file.' %filename)) chooser.destroy() return elif m == "Connect": response,param=dialogs.parameters("<b>Connect</b>", labels=("URI", "Agooey Temporary File"), parameters=('*****@*****.**',self.setFile), titleString="Connect to remote server"); if response == gtk.RESPONSE_OK: # self.runcmd(str('ssh -Y %s -t "bash -c adore -g %s"' % (param[0], param[1]))) self.setFile=param[1] self.runcmd(str('ssh -Y %s -t \'bash -i -c "adore -i -g %s"\' '% (param[0],param[1]))) return elif m == "demLoad": chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) response = chooser.run() if response == gtk.RESPONSE_OK: filename=chooser.get_filename(); self.runcmd("dem load " + filename); # elif response == gtk.RESPONSE_CANCEL: chooser.destroy() return elif m == "demMake": response,param=dialogs.parameter("<b>dem make</b>", "SRTM1/SRTM3 extraBufferPercentage name", "SRTM3 20 dem", "Enter parameters for..."); if response == gtk.RESPONSE_OK: self.runcmd("dem make " + param); return elif m == "ShowAbout": #os.system("echo ADORE-GUI")#self.answer_label.set_label( "Created by Beda Kosata") self.readSet(); about = gtk.AboutDialog() about.set_program_name("ADORE-GOOEY") about.set_version(open(self.set.get('adore','ADOREFOLDER').strip('\'"')+"/version", 'r').read()) about.set_copyright("(c) Batuhan Osmanoglu 2009-2012") about.set_license(open(self.set.get('adore','ADOREFOLDER').strip('\'"')+"/license.txt", 'r').read()) about.set_comments(""" Automated Doris Environment SHELL PID: {} """.format(self.vPid)) about.set_website("http://code.google.com/p/adore-doris/") about.set_logo(gtk.gdk.pixbuf_new_from_file(self.set.get('adore','ADOREFOLDER').strip('\'"') +"/gui/adore-doris-gui-icon-256px.png")) about.run() about.destroy() return elif m =="toolsPythonCmd": response,param=dialogs.parameter("<b>Python Command</b>", "Please enter your command", "", ""); if response == gtk.RESPONSE_OK: self.v.feed(str(eval(param))); self.v.feed('\n'); return