예제 #1
0
    def save(self):

        try:

            impl = xml.dom.getDOMImplementation()

            xml_data = impl.createDocument(constants.namespace,
                                           u"omnitux_highscores", None)

            root_node = xml_data.documentElement

            root_node.setAttribute(u"Version", constants.version)

            for score in self.scores:

                score_node = xml_data.createElement("highscore")

                score_node.setAttributeNode(xml_data.createAttribute("name"))
                score_node.setAttribute("name", score.get_name())

                score_node.setAttributeNode(
                    xml_data.createAttribute("datetime"))
                score_node.setAttribute("datetime", str(score.datetime))

                if (score.count_good == True):
                    score_node.setAttributeNode(
                        xml_data.createAttribute("good_answers"))
                    score_node.setAttribute(
                        "good_answers", str(score.get_good_answers_value()))

                if (score.count_wrong == True):
                    score_node.setAttributeNode(
                        xml_data.createAttribute("wrong_answers"))
                    score_node.setAttribute(
                        "wrong_answers", str(score.get_wrong_answers_value()))

                if (score.record_time == True):
                    score_node.setAttributeNode(
                        xml_data.createAttribute("time"))
                    score_node.setAttribute("time",
                                            str(score.timer.getValue()))

                root_node.appendChild(score_node)

            xml_funcs.save_xml_file(self.highscore_filename, xml_data)

        except Exception, e:

            common.error("Could not save highscore file")
            common.error(self.highscore_filename)
            common.error("Exception fired", e, traceback.format_exc())
예제 #2
0
	def save(self) :

		try :

			
			impl = xml.dom.getDOMImplementation()
	
			xml_data = impl.createDocument(constants.namespace, u"omnitux_highscores", None)

			root_node = xml_data.documentElement

			root_node.setAttribute(u"Version", constants.version)


			for score in self.scores :

				score_node = xml_data.createElement("highscore")

				score_node.setAttributeNode(xml_data.createAttribute("name"))
				score_node.setAttribute("name", score.get_name())

				score_node.setAttributeNode(xml_data.createAttribute("datetime"))
				score_node.setAttribute("datetime", str(score.datetime))

				if (score.count_good == True) :
					score_node.setAttributeNode(xml_data.createAttribute("good_answers"))
					score_node.setAttribute("good_answers", str(score.get_good_answers_value()))

				if (score.count_wrong == True) :
					score_node.setAttributeNode(xml_data.createAttribute("wrong_answers"))
					score_node.setAttribute("wrong_answers", str(score.get_wrong_answers_value()))

				if (score.record_time == True) :
					score_node.setAttributeNode(xml_data.createAttribute("time"))
					score_node.setAttribute("time", str(score.timer.getValue()))

				root_node.appendChild(score_node)

			xml_funcs.save_xml_file(self.highscore_filename, xml_data)


		except Exception, e :

			common.error("Could not save highscore file")
			common.error(self.highscore_filename)
			common.error("Exception fired", e, traceback.format_exc())	
예제 #3
0
	def save_user_options(self) :

		try :
			user_options_file = os.path.join(constants.home_dir, constants.user_options_filename)

			impl = xml.dom.getDOMImplementation()
	
			xml_data = impl.createDocument(constants.namespace, u"omnitux_user_options", None)

			root_node = xml_data.documentElement

			root_node.setAttribute(u"Version", constants.version)


			# save screen resolution

			resolution_node = xml_data.createElement("screen_resolution")

			width_node = xml_data.createElement("width") 

			width_node.appendChild(xml_data.createTextNode(str(self.screen_width)))

			resolution_node.appendChild(width_node)

			height_node = xml_data.createElement("height") 

			height_node.appendChild(xml_data.createTextNode(str(self.screen_height)))

			resolution_node.appendChild(height_node)

			root_node.appendChild(resolution_node)


			# save music volume

			music_volume_node = xml_data.createElement("music_volume")

			music_volume_node.appendChild(xml_data.createTextNode(str(self.music_volume)))

			root_node.appendChild(music_volume_node)


			# save congratulation sounds mode

			congrat_sounds_node = xml_data.createElement("congrats_sounds")

			congrat_sounds_node.setAttributeNode(xml_data.createAttribute("active"))

			congrat_sounds_node.setAttribute("active", str(self.congrats_sounds_active))

			root_node.appendChild(congrat_sounds_node)


			# save congratulation voices mode

			congrat_voices_node = xml_data.createElement("congrats_voices")

			congrat_voices_node.setAttributeNode(xml_data.createAttribute("active"))

			congrat_voices_node.setAttribute("active", str(self.congrats_voices_active))

			root_node.appendChild(congrat_voices_node)


			# save igloo display mode

			igloo_node = xml_data.createElement("igloo")

			igloo_node.setAttributeNode(xml_data.createAttribute("display"))

			igloo_node.setAttribute("display", str(self.display_igloo))

			root_node.appendChild(igloo_node)


			# save arcade mode

			arcade_node = xml_data.createElement("arcade")

			arcade_node.setAttributeNode(xml_data.createAttribute("enabled"))

			arcade_node.setAttribute("enabled", str(self.arcade_mode))

			root_node.appendChild(arcade_node)


			# save default language

			language_node = xml_data.createElement("language")
				
			language_node.setAttributeNode(xml_data.createAttribute("default"))

			if (cmp(self.main_language_mode, "system") == 0) :
				default_language = "system"

			else :
				default_language = self.main_language

			language_node.setAttribute("default", default_language)


			root_node.appendChild(language_node)



			# write the file

			xml_funcs.save_xml_file(user_options_file, xml_data)

		except Exception, e :
			error("Could not save user options file ", e, traceback.format_exc())
예제 #4
0
파일: common.py 프로젝트: edupals/omnitux
    def save_user_options(self):

        try:
            user_options_file = os.path.join(constants.home_dir,
                                             constants.user_options_filename)

            impl = xml.dom.getDOMImplementation()

            xml_data = impl.createDocument(constants.namespace,
                                           u"omnitux_user_options", None)

            root_node = xml_data.documentElement

            root_node.setAttribute(u"Version", constants.version)

            # save screen resolution

            resolution_node = xml_data.createElement("screen_resolution")

            width_node = xml_data.createElement("width")

            width_node.appendChild(
                xml_data.createTextNode(str(self.screen_width)))

            resolution_node.appendChild(width_node)

            height_node = xml_data.createElement("height")

            height_node.appendChild(
                xml_data.createTextNode(str(self.screen_height)))

            resolution_node.appendChild(height_node)

            root_node.appendChild(resolution_node)

            # save music volume

            music_volume_node = xml_data.createElement("music_volume")

            music_volume_node.appendChild(
                xml_data.createTextNode(str(self.music_volume)))

            root_node.appendChild(music_volume_node)

            # save congratulation sounds mode

            congrat_sounds_node = xml_data.createElement("congrats_sounds")

            congrat_sounds_node.setAttributeNode(
                xml_data.createAttribute("active"))

            congrat_sounds_node.setAttribute("active",
                                             str(self.congrats_sounds_active))

            root_node.appendChild(congrat_sounds_node)

            # save congratulation voices mode

            congrat_voices_node = xml_data.createElement("congrats_voices")

            congrat_voices_node.setAttributeNode(
                xml_data.createAttribute("active"))

            congrat_voices_node.setAttribute("active",
                                             str(self.congrats_voices_active))

            root_node.appendChild(congrat_voices_node)

            # save igloo display mode

            igloo_node = xml_data.createElement("igloo")

            igloo_node.setAttributeNode(xml_data.createAttribute("display"))

            igloo_node.setAttribute("display", str(self.display_igloo))

            root_node.appendChild(igloo_node)

            # save arcade mode

            arcade_node = xml_data.createElement("arcade")

            arcade_node.setAttributeNode(xml_data.createAttribute("enabled"))

            arcade_node.setAttribute("enabled", str(self.arcade_mode))

            root_node.appendChild(arcade_node)

            # save default language

            language_node = xml_data.createElement("language")

            language_node.setAttributeNode(xml_data.createAttribute("default"))

            if (cmp(self.main_language_mode, "system") == 0):
                default_language = "system"

            else:
                default_language = self.main_language

            language_node.setAttribute("default", default_language)

            root_node.appendChild(language_node)

            # write the file

            xml_funcs.save_xml_file(user_options_file, xml_data)

        except Exception, e:
            error("Could not save user options file ", e,
                  traceback.format_exc())