Пример #1
0
	def on_button_ok__clicked(self, *args):
		c_buffer = self.description.get_buffer()
		c_startpos = c_buffer.get_iter_at_offset(0)
		c_endpos = c_buffer.get_iter_at_offset(-1)
		description= c_buffer.get_text(c_startpos, c_endpos)

		start_dt = self.dateedit_start.dt
		end_dt = self.dateedit_end.dt

		if end_dt <= start_dt:
			dialogs.error('The event starts before it has begon. Please change the Start or End date/time.')
			return
		# FIXME: Check for valid date/time.

		# Any alarms that were previously in the list but not anymore have been
		# removed. Delete them from the event.
		for alarm in self.old_alarms:
			if alarm not in self.new_alarms:
				self.event.del_alarm(alarm)

		# Any alarms that weren't previously in the list, but are now, are new.
		# Add them to the event.
		for i in range(len(self.new_alarms)):
			alarm = self.new_alarms[i]
			if not alarm in self.old_alarms:
				self.event.add_alarm(alarm)
			
		self.event.set_summary(self.summary.get_text())
		self.event.set_location(self.location.get_text())
		self.event.set_description(description)
		self.event.set_start(start_dt)
		self.event.set_end(end_dt)

		self.quit()
Пример #2
0
    def validate_widget_names(self, project, show_error_dialogs=True):
        """Return True if all the widgets in project have valid names.

        A widget has a valid name if the name is not empty an unique.
        As soon as this function finds a widget with a non valid name it
        select it in the widget tree and returns False
        """

        widget_names = [widget.name for widget in project.get_widgets()]
        for widget in project.get_widgets():
            # skip internal children (they have None as the name)
            if widget.name is None:
                continue

            if widget.name == '':
                if show_error_dialogs:
                    error(_("There is a widget with an empty name"))
                project.selection.set(widget, True)
                return False

            widget_names.remove(widget.name)

            if widget.name in widget_names:
                if show_error_dialogs:
                    msg = _('The name "%s" is used in more than one widget')
                    error(msg % widget.name)
                project.selection.set(widget, True)
                return False

        return True
Пример #3
0
    def __init__(self, model):

        self.__model = model
        #self.__model.set_view(self)

        BaseView.__init__(self,
                               gladefile="virtlab",
                               delete_handler=self.quit_if_last)

  #      self.__col_pixbuf = gtk.TreeViewColumn("Image")
  #      cellrenderer_pixbuf = gtk.CellRendererPixbuf()
  #      cellrenderer_pixbuf.set_properties("pixbuf", )
  #      self.__col_pixbuf.pack_start(cellrenderer_pixbuf, False)
  #      self.__col_pixbuf.add_attribute(cellrenderer_pixbuf, "pixbuf", 1)

        tableColumns = [
                    Column("image", title=" ", width=30, data_type=gtk.gdk.Pixbuf, sorted=False),
                    Column("name", title='VM Name', width=130, sorted=True),
                    Column("state", title='State', width=70),
                    Column("order", title='Order (Delay/min)', width=145),
                    Column("ordinal", visible=False),
                    Column("delay", visible=False),
                    Column("desc", title='Description', width=200)
                    ]


        self.vmlist_widget = ObjectList(tableColumns)
        self.vmlist_widget.set_size_request(300, 400)
        self.vmlist_widget.set_selection_mode(gtk.SELECTION_SINGLE)
        self.hbox4.pack_start(self.vmlist_widget)

        store = gtk.ListStore(gobject.TYPE_STRING)

        self.vmlist_widget.show()

        self.__dialog = None
        self.__status_text = gtk.TextBuffer()

        try:
            self.populate_vmlist()
            self.populate_order_dropdown(store, len(self.__model.get_vms()))
        except VMLabException as exception:
            if exception.vme_id is c.EXCEPTION_LIBVIRT_001:
                error("Initialization error",
                      "No connection to Libvirtd.\n Exiting.")
                exit(1)

        self.ordercombo.set_model(store)
        cell = gtk.CellRendererText()
        self.ordercombo.pack_start(cell, True)
        self.ordercombo.add_attribute(cell, 'text', 0)

        self.virtlab.set_size_request(800, 460)

        self.change_title("")
        self.__statusbar_ctx = self.statusbar.get_context_id("virtlab")
        self.virtlab.set_icon(gtk.gdk.pixbuf_new_from_file("pixmaps/about-logo.png"))
Пример #4
0
def load_catalogs(external=True):
    """
    @param external: If true, allow loading of external (eg, not base) catalogs
    """
    try:
        catalogs = _get_catalog_dirs()
    except EnvironmentError, e:
        dialogs.error("<b>There were errors while loading Gazpacho</b>", str(e))
        raise SystemExit
Пример #5
0
    def open_project(self, path):
        """
        Open the project at the specified path. If the project has
        already been loaded we ask if we should reload it (close and
        reopen) or just switch to the loaded project.

        @param path: the path to the project file
        @type path: str
        """
        # Check if the project is loaded and ask the user what to do.
        for project in self._projects:
            if project.path and project.path == path:
                if not self._confirm_open_project(project):
                    self._set_project(project)
                    return project

                self._close_project(project)
                break

        project = Project(self)
        try:
            project.load(path)
        except ParseError:
            submsg1 = _('The project could not be loaded')
            submsg2 = _('An error occurred while parsing the file "%s".') % \
                      os.path.abspath(path)
            msg = '<span weight="bold" size="larger">%s</span>\n\n%s\n' % \
                      (submsg1, submsg2)
            error(msg)
            self._update_palette_sensitivity()
        except IOError:
            if path in config.recent_projects:
                config.recent_projects.remove(path)
                #self._update_recent_items()

            submsg1 = _('The project could not be loaded')
            submsg2 = _('The file "%s" could not be opened') % \
                      os.path.abspath(path)
            msg = '<span weight="bold" size="larger">%s</span>\n\n%s\n' % \
                      (submsg1, submsg2)
            error(msg)
            self._update_palette_sensitivity()

        failures = project.get_unsupported_widgets()
        if failures:
            dialog = UnsupportedWidgetsDialog(self._window, failures)
            dialog.run()
            dialog.destroy()

        self._add_project(project)
        return project
Пример #6
0
 def add_source(self, filename, parent=None, name="",
                xcol=0, ycol=1, xexpr="x", yexpr="y",
                xexpren=False, yexpren=False,
                data=None):
     """Create a new source with (optional) data."""
     try:
         src=Source(id=self.src_id, datafile=filename, x_col=xcol, y_col=ycol,
                x_expr=xexpr, y_expr=yexpr,
                x_expr_enable=xexpren, y_expr_enable=yexpren,
                data=data)
         self.source_list.append(src,select=True)
         self.src_id+=1
         #self.name.set_active()
     except SourceError:
         dialogs.error("Plothole was not able to load the input.",
               filename+"\n\nIt expects text with numeric data in column format.")
Пример #7
0
	def load(self, cal_fname):
		self.log.debug('Loading iCal file \'%s\'.' % (cal_fname))

		cal_mtime = os.stat(cal_fname)[stat.ST_CTIME]
		f = file(cal_fname, 'r')
		contents = f.read()
		f.close()

		try:
			cal_model = CalendarModel(icalendar.Calendar.from_string(contents))

			self.cal_mtime = cal_mtime
			self.cal_model = cal_model
			self.cal_modified = False
			self.cal_fname = cal_fname
		except ValueError, e:
			dialogs.error('Error in calendar file', str(e))
Пример #8
0
 def on_open__activate(self, *args):
     filter = gtk.FileFilter()
     filter.add_pattern('*.crisk')
     selected_file = open_dialog(_('Open'), filter=filter)
     if selected_file is None:
         return None
     try:
         db_url = 'sqlite:///%s' % selected_file
         metadata.bind = db_url
         metadata.bind.echo = False
         metadata.bind.has_table('model_asset')
         setup_all()
         self.db_file = selected_file
         self.tree.select(self.first)
         return True
     except Exception, info:
         error(_('Error opening database'), str(info))
Пример #9
0
 def on_open__activate(self, *args):
     filter = gtk.FileFilter()
     filter.add_pattern('*.crisk')
     selected_file = open_dialog(_('Open'), filter = filter)
     if selected_file is None:
         return None
     try:
         db_url = 'sqlite:///%s' % selected_file
         metadata.bind = db_url
         metadata.bind.echo = False
         metadata.bind.has_table('model_asset')
         setup_all()
         self.db_file = selected_file
         self.tree.select(self.first)
         return True
     except Exception, info:
         error(_('Error opening database'), str(info))
Пример #10
0
    def on_new__activate(self, *args):
        new_file = save(_('Save'))
        if new_file is None:
            return None

        if not new_file.endswith('.crisk'):
            new_file = new_file + '.crisk'

        try:
            db_url = 'sqlite:///%s' % new_file
            metadata.bind = db_url
            metadata.bind.echo = False
            setup_all()
            create_all()
            tmp = Basic()
            session.commit()
            self.db_file = new_file
            self.tree.select(self.first)
            return True
        except Exception, info:
            res = error(_("An error has ocurred"), info.__str__())
Пример #11
0
    def on_new__activate(self, *args):
        new_file = save(_('Save'))        
        if new_file is None:
            return None

        if not new_file.endswith('.crisk'):
            new_file = new_file + '.crisk'
        
        try:
            db_url = 'sqlite:///%s' % new_file
            metadata.bind = db_url
            metadata.bind.echo = False
            setup_all()
            create_all()
            tmp = Basic()
            session.commit()
            self.db_file = new_file
            self.tree.select(self.first)
            return True
        except Exception, info:
            res = error(_("An error has ocurred"), info.__str__())
Пример #12
0
 def __init__(self, msg1, msg2):
     """
     
     """
     error(msg1, msg2)       
Пример #13
0
 def error(self, short, description):
     error(short, description, get_current_toplevel())
Пример #14
0
 def error(self, short, description):
     error(short, description, get_current_toplevel())
Пример #15
0
    def execute_clicked(self, widget):
        """ called when the user clicks on the execute button """
        if self.outputLabels != None:
            """ clears the output label widgets """
            for l in self.outputLabels:
                l.destroy()
        self.outputLabels = []
        """ clears the output plots """
        for op in self.outputPlots:
            op.clear()

        try:
            """ calibrates the rule base of the controller """
            self.currentFLC.rulebase.calibrate()
        except:
            error(
                "Incomplete rule base",
                "Please fill in the missing items in the Rule Base and try again."
            )
            return

        try:
            """ sets the input variable values from the text boxes """
            input_vars = [
                float(self.fssEntry.get_text()),
                float(self.bssEntry.get_text())
            ]
        except:
            error(
                "Incorrect sensor input values",
                "Please input correct integer or floating-point values and try again."
            )
            return
        """ sets the function pointer to the AND and implication operators, either
        to the python built-in function min() or the product() function
    """
        if (self.andCombo.get_active_text() == "Minimum"):
            andOp = min
        else:
            andOp = product

        if (self.implicationCombo.get_active_text() == "Minimum"):
            implOp = min
        else:
            implOp = product
        """ sets the number of discretization steps from the spin text box """
        disc_steps = self.discSpin.get_value_as_int()
        """ runs the controller """
        output = self.currentFLC.run(input_vars, andOp, implOp, disc_steps)
        """ refreshes the view from the model """
        self.rbList.refresh()
        """ sets the output label widgets to their values and puts them into the
        gtk box
    """
        for o in output:
            tmp = Label("<b>" + o[0] + "</b>" + "\t" + str(o[1]))
            tmp.set_use_markup(True)
            self.outputLabels.append(tmp)
        for w in self.outputLabels:
            self.rulesBox.pack_start(w, False, False, 5)
        """ clears the plotting widgets, creates the new plots of the outputs
        (adding the defuzzified outputs) and adds the widgets back with the
        new plots
    """
        for k, v in enumerate(self.currentFLC.outputs):
            self.outputPlots[k].add_var(v.get_defuz_var(implOp, disc_steps))
        self.outputsBox.foreach(self.outputsBox.remove)
        for k, i in enumerate(self.outputPlots):
            self.outputsBox.pack_start(self.outputPlots[k].get_canvas_widget())
        self.mainWindow.show_all()
Пример #16
0
                          "base.xml. Please remove it.", stacklevel=2)
            continue

        resources_path = environ.get_resource_paths('resource')
        try:
            catalog = Catalog(filename, resources_path)
            _catalogs.append(catalog)
        except IOError, e:
            problems.append(str(e))
        except BadCatalogSyntax, e:
            problems.append(str(e))
        except CatalogError, e:
            print 'Error while loading catalog %s: %s' % (name, e)

    if problems:
        dialogs.error('\n'.join(problems))

    _catalogs.sort(lambda c1, c2: cmp(c1.priority,
                                      c2.priority))

# Default name of the file that contains custom UI definitions
CUSTOM_UI_FILENAME = 'custom.ui'

def get_custom_ui_filename():
    """Return the name of the file with custom UI definitions if it exists

    First it look in the user home directory (in the .gazpacho subdirectory),
    then it looks in every directory where there are catalogs.
    """
    # First we look in the user home directory
    app_dir = get_app_data_dir('gazpacho')