def load():
def save():
def _test(): class TimeZone(object):
	def __init__(self, code, utc, offset, longitude):
	def __str__(self):
	def __repr__(self):
def get(zone): class Filter(db.Object):
	"""Filters set and options."""
	
	__slots__ = ('_idx_', '_name', '_bg_color', '_ephe_type', '_ephe_path',
		'_hsys', '_sid_mode', '_sid_t0', '_sid_ayan_t0', '_true_pos',
		'_xcentric', '_calc_midp', '_draw_midp', '_comment',
		# sub-filters:
		'_planets', '_aspects', '_orbs', '_asprestr', '_orbrestr',
		'_midpoints')
	
	def _get_name(self):
		"""Get filter name.
		
		:rtype: str
		"""
		return self._name
	
	def _set_name(self, name):
		"""Set filter name.
		
		:type name: str
		"""
		self._name = name
	
	def _get_bg_color(self):
		"""Get background color.
		
		:rtype: str
		"""
		return self._bg_color
	
	def _set_bg_color(self, clr):
		"""Set background color ('black', 'white').
		
		:type clr: str
		:raise ValueError: invalid color
		"""
		if clr not in ('black', 'white'):
			raise ValueError('Invalid background color %s.' % clr)
		self._bg_color = clr
	
	def _get_ephe_type(self):
		"""Get ephemeris type.
		
		:rtype: str
		"""
		return self._ephe_type
	
	def _set_ephe_type(self, ephe='swiss'):
		"""Set ephemeris type ('swiss', 'jpl', 'moshier').
		
		:type ephe: str
		:raise ValueError: invalid ephemeris type
		"""
		if ephe not in ('swiss', 'jpl', 'moshier'):
			raise ValueError('Invalid ephemeris type %s.' % ephe)
		self._ephe_type = ephe
	
	def _get_ephe_path(self):
		"""Get ephemeris files directory (or file for jpl) path.
		
		:rtype: str
		"""
		return self._ephe_path
	
	def _set_ephe_path(self, path):
		"""Set ephemeris directory/file.
		
		:type path: str
		"""
		self._ephe_path = str(path) # str() till pyswisseph accepts unicode!
	
	def _get_hsys(self):
		"""Get house system.
		
		:rtype: str
		"""
		return self._hsys
	
	def _set_hsys(self, hsys='P'):
		"""Set house system.
		
		One in 'PKORCAEVXHTBG'. See swisseph docs.
		
		:type hsys: str
		"""
		if hsys not in 'PKRCBOAEHVXGU':
			raise ValueError('Invalid house system %s.' % hsys)
		self._hsys = str(hsys) ## till pyswisseph accepts unicode
	
	def _get_sid_mode(self):
		return self._sid_mode
	
	def _set_sid_mode(self, sidmode=-1):
		"""Set sidereal mode.
		
			- -1 -> western tropical zodiac
			- 0+ -> sidereal modes
			- 255 -> user-defined sidereal (see sid_t0 and sid_ayan_t0)
		
		:type sidmode: int
		:raise ValueError: invalid sidereal mode
		"""
		if sidmode < -1 or sidmode > 255:
			raise ValueError('Invalid sidereal mode %s.' % sidmode)
		self._sid_mode = sidmode
	
	def _get_sid_t0(self):
		"""Get sidereal time 0.
		
		:rtype: float
		"""
		return self._sid_t0
	
	def _set_sid_t0(self, sidt0):
		"""Set sidereal time 0.
		
		:type sidt0: numeric
		"""
		self._sid_t0 = float(sidt0)
	
	def _get_sid_ayan_t0(self):
		"""Get sidereal ayanamsa at t0.
		
		:rtype: float
		"""
		return self._sid_ayan_t0
	
	def _set_sid_ayan_t0(self, ayan_t0):
		"""Set sidereal ayanamsa at t0.
		
		:type ayan_t0: numeric
		"""
		self._sid_ayan_t0 = float(ayan_t0)
	
	def _get_true_pos(self):
		"""Get true positions flag.
		
		:rtype: bool
		"""
		return self._true_pos
	
	def _set_true_pos(self, boolean=False):
		"""Set true positions flag
		
		:type boolean: bool
		"""
		self._true_pos = bool(boolean)
	
	def _get_xcentric(self):
		"""Get observer mode.
		
		:rtype: str
		"""
		return self._xcentric
	
	def _set_xcentric(self, xcentric='geo'):
		"""Set geo/topo/helio/bary centric mode.
		
		:type xcentric: str
		:raise ValueError: invalid mode
		"""
		if xcentric not in ('geo', 'topo', 'helio', 'bary'):
			raise ValueError('Invalid xcentric mode %s.' % xcentric)
		self._xcentric = xcentric
	
	def _get_calc_midp(self):
		"""Calculate mid-points or not (boolean).
		
		:rtype: bool
		"""
		return self._calc_midp
	
	def _set_calc_midp(self, boolean):
		"""Set midpoints flag.
		
		:type boolean: bool
		"""
		if boolean in (True, 1, 'True', '1', 'yes'):
			self._calc_midp = True
		else:
			self._calc_midp = False
	
	def _get_draw_midp(self):
		"""Draw mid-points aspects or not (boolean).
		
		:rtype: bool
		"""
		return self._draw_midp
	
	def _set_draw_midp(self, boolean):
		"""Set mid-points drawing flag.
		
		:type boolean: bool
		"""
		if boolean in (True, 1, 'True', '1', 'yes'):
			self._draw_midp = True
		else:
			self._draw_midp = False
	
	def _get_comment(self):
		"""Get comment
		
		:rtype: str
		"""
		return self._comment
	
	def _set_comment(self, comment):
		"""Set comment.
		
		:type comment: str
		"""
		self._comment = comment
	
	# sub filters
	
	def _get_planets(self):
		"""Get planets filter.
		
		:rtype: PlanetsFilter
		"""
		return self._planets
	
	def _set_planets(self, filt):
		"""Set planets filter.
		
		:type filt: PlanetsFilter, str or int
		"""
		if not isinstance(filt, PlanetsFilter):
			self._planets = PlanetsFilter(filt)
		else:
			self._planets = filt
	
	def _get_aspects(self):
		"""Get aspects filter.
		
		:rtype: AspectsFilter
		"""
		return self._aspects
	
	def _set_aspects(self, filt):
		"""Set aspects filter.
		
		:type filt: AspectsFilter, str or int
		"""
		if not isinstance(filt, AspectsFilter):
			self._aspects = AspectsFilter(filt)
		else:
			self._aspects = filt
	
	def _get_orbs(self):
		"""Get orbs filter.
		
		:rtype: OrbsFilter
		"""
		return self._orbs
	
	def _set_orbs(self, filt):
		"""Set orbs filter.
		
		:type filt: OrbsFilter, str or int
		"""
		if not isinstance(filt, OrbsFilter):
			self._orbs = OrbsFilter(filt)
		else:
			self._orbs = filt
	
	def _get_asprestr(self):
		"""Get aspects restrictions.
		
		:rtype: AspectsRestrictions
		"""
		return self._asprestr
	
	def _set_asprestr(self, filt):
		"""Set aspects restrictions.
		
		:type filt: AspectsRestrictions, str or int
		"""
		if not isinstance(filt, AspectsRestrictions):
			self._asprestr = AspectsRestrictions(filt)
		else:
			self._asprestr = filt
	
	def _get_orbrestr(self):
		"""Get orbs restrictions.
		
		:rtype: OrbsRestrictions
		"""
		return self._orbrestr
	
	def _set_orbrestr(self, filt):
		"""Set orbs restrictions.
		
		:type filt: OrbsRestrictions, str or int
		"""
		if not isinstance(filt, OrbsRestrictions):
			self._orbrestr = OrbsRestrictions(filt)
		else:
			self._orbrestr = filt
	
	def _get_midpoints(self):
		"""Get midpoints filters.
		
		:rtype: MidPointsFilter
		"""
		return self._midpoints
	
	def _set_midpoints(self, filt):
		"""Set mid-points filters.
		
		:type filt: MidPointsFilter, str or int
		"""
		if not isinstance(filt, MidPointsFilter):
			self._midpoints = MidPointsFilter(filt)
		else:
			self._midpoints = filt
	
	_idx = property(db.Object._get_idx, db.Object._set_idx,
		doc='Filter db index value.')
	name = property(_get_name, _set_name,
		doc='Filter name.')
	bg_color = property(_get_bg_color, _set_bg_color,
		doc='Background color (black|white).')
	ephe_type = property(_get_ephe_type, _set_ephe_type,
		doc='Ephemeris type (swiss|jpl|moshier).')
	ephe_path = property(_get_ephe_path, _set_ephe_path,
		doc='Ephemeris directory/files path.')
	hsys = property(_get_hsys, _set_hsys,
		doc='House system (PKORCAEVXHTBG). See swisseph docs.')
	sid_mode = property(_get_sid_mode, _set_sid_mode,
		doc='Sidereal mode (-1=tropical). See swisseph docs.')
	sid_t0 = property(_get_sid_t0, _set_sid_t0,
		doc='Sidereal mode reference time.')
	sid_ayan_t0 = property(_get_sid_ayan_t0, _set_sid_ayan_t0,
		doc='Sidereal mode ayanmsa.')
	true_pos = property(_get_true_pos, _set_true_pos,
		doc='True positions mode (boolean).')
	xcentric = property(_get_xcentric, _set_xcentric,
		doc='geo/topo/helio/bary centric mode.')
	calc_midp = property(_get_calc_midp, _set_calc_midp,
		doc='Calculate mid-points.')
	draw_midp = property(_get_draw_midp, _set_draw_midp,
		doc='Draw mid-points.')
	planets = property(_get_planets, _set_planets,
		doc='Planets filter.')
	aspects = property(_get_aspects, _set_aspects,
		doc='Aspects filter.')
	orbs = property(_get_orbs, _set_orbs,
		doc='Orbs filter.')
	asprestr = property(_get_asprestr, _set_asprestr,
		doc='Aspects restrictions.')
	orbrestr = property(_get_orbrestr, _set_orbrestr,
		doc='Orbs restrictions.')
	midpoints = property(_get_midpoints, _set_midpoints,
		doc='Mid-points filter.')
	comment = property(_get_comment, _set_comment,
		doc='Filter comment.')
	
	def set(self, _idx=None, name=None, bg_color=None, ephe_type=None,
		ephe_path=None, hsys=None, sid_mode=None, sid_t0=None,
		sid_ayan_t0=None, true_pos=None, xcentric=None, calc_midp=None,
		draw_midp=None, planets=None, aspects=None, orbs=None, asprestr=None,
		orbrestr=None, midpoints=None, comment=None):
		"""Set filter properties."""
		if _idx != None:
			self._idx = _idx
		if name != None:
			self.name = name
		if bg_color != None:
			self.bg_color = bg_color
		if ephe_type != None:
			self.ephe_type = ephe_type
		if ephe_path != None:
			self.ephe_path = ephe_path
		if hsys != None:
			self.hsys = hsys
		if sid_mode != None:
			self.sid_mode = sid_mode
		if sid_t0 != None:
			self.sid_t0 = sid_t0
		if sid_ayan_t0 != None:
			self.sid_ayan_t0 = sid_ayan_t0
		if true_pos != None:
			self.true_pos = true_pos
		if xcentric != None:
			self.xcentric = xcentric
		if calc_midp != None:
			self.calc_midp = calc_midp
		if draw_midp != None:
			self.draw_midp = draw_midp
		if planets != None:
			self.planets = planets
		if aspects != None:
			self.aspects = aspects
		if orbs != None:
			self.orbs = orbs
		if asprestr != None:
			self.asprestr = asprestr
		if orbrestr != None:
			self.orbrestr = orbrestr
		if midpoints != None:
			self.midpoints = midpoints
		if comment != None:
			self.comment = comment
	
	def __init__(self, filt=None, set_default=True):
		"""Init filter.
		
		:type filt: str or int
		:type set_default: bool
		"""
		if filt != None:
			return self._select(filt)
		if set_default:
			self.set_default()
	
	def set_default(self):
		"""Set filter to default values."""
		sql = 'select dft_filter from Config;'
		idx = int(db.execute(sql).fetchone()[0])
		self._select_by_idx(idx)
	
	def reset(self):
		"""Reset filter when database is updated.
		
		Filter may have been deleted, then load the default one.
		
		"""
		try:
			self._select_by_idx(self._idx_)
		except ValueError: # filter deleted
			self.set_default()
	
	def _select(self, filt):
		"""Select filter in database.
		
		:raise TypeError: invalid filter
		"""
		if isinstance(filt, int):
			return self._select_by_idx(filt)
		elif isinstance(filt, basestring): ## not py3
			return self._select_by_name(filt)
		raise TypeError('Invalid filter %s.' % filt)
	
	def _select_by_idx(self, idx):
		"""Select filter in database, by idx.
		
		:type idx: int
		:raise ValueError: not found
		"""
		sql = "select * from Filters where _idx = ?;"
		res = db.execute(sql, (idx,)).fetchall()
		if len(res) == 0:
			raise ValueError('Invalid idx %s.' % idx)
		self.set(*res[0])
	
	def _select_by_name(self, filt):
		"""Select filter in database, by name.
		
		:type filt: str
		:raise ValueError: not found
		"""
		sql = "select * from Filters where name = ?;"
		res = db.execute(sql, (filt,)).fetchall()
		if len(res) == 0:
			raise ValueError('Invalid filter %s.' % filt)
		self.set(*res[0])
	
	def save(self, recursive=False):
		"""Save filter in database.
		
		If recursive is True, save all sub-filters.
		Else raise TypeError if a sub-filter is not saved.
		
		:type recursive: bool
		"""
		if self._idx_ == None:
			self._insert(recursive)
		else:
			self._update(recursive)
	
	def _insert(self, recursive=False):
		"""Insert filter in database.
		
		:type recursive: bool
		:raise ValueError: duplicate
		"""
		self._save_filters(recursive)
		sql1 = """insert into Filters (name, bg_color, ephe_type, ephe_path,
			hsys, sid_mode, sid_t0, sid_ayan_t0, true_pos, xcentric, calc_midp,
			draw_midp, planets, aspects, orbs, asprestr, orbrestr, midpoints,
			comment) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
			?, ?);"""
		var = (self._name, self._bg_color, self._ephe_type, self._ephe_path,
			self._hsys, self._sid_mode, self._sid_t0, self._sid_ayan_t0,
			self._true_pos, self._xcentric, self._calc_midp, self._draw_midp,
			self._planets._idx_, self._aspects._idx_, self._orbs._idx_,
			self._asprestr._idx_, self._orbrestr._idx_, self._midpoints._idx_,
			self._comment)
		sql2 = "select _idx from Filters where name = ?;"
		try:
			db.execute(sql1, var)
		except: # sqlite3.IntegrityError
			raise ValueError('Duplicate filter %s.' % self._name)
		self._idx = db.execute(sql2,(self._name,)).fetchone()[0]
	
	def _update(self, recursive=False):
		"""Update filter in database.
		
		:raise ValueError: duplicate
		"""
		self._save_filters(recursive)
		sql = """update Filters set name = ?, bg_color = ?, ephe_type = ?,
			ephe_path = ?, hsys = ?, sid_mode = ?, sid_t0 = ?, sid_ayan_t0 = ?,
			true_pos = ?, xcentric = ?, calc_midp = ?, draw_midp = ?,
			planets = ?, aspects = ?, orbs = ?, asprestr = ?, orbrestr = ?,
			midpoints = ?, comment = ? where _idx = ?;"""
		var = (self._name, self._bg_color, self._ephe_type, self._ephe_path,
			self._hsys, self._sid_mode, self._sid_t0, self._sid_ayan_t0,
			self._true_pos, self._xcentric, self._calc_midp, self._draw_midp,
			self._planets._idx_, self._aspects._idx_, self._orbs._idx_,
			self._asprestr._idx_, self._orbrestr._idx_, self._midpoints._idx_,
			self._comment, self._idx_)
		try:
			db.execute(sql, var)
		except: ## integrity error
			raise ValueError('Duplicate filter %s.' % self._name)
	
	def _save_filters(self, recursive):
		"""Save sub-filters if recursive is True, else check they are saved.
		
		Raise TypeError if recursive is False and sub-filter is not saved.
		
		:type recursive: bool
		"""
		for f in (self.planets, self.aspects, self.orbs, self.asprestr,
			self.orbrestr, self.midpoints):
			if recursive:
				f.save()
			else:
				if f._idx_ == None:
					raise TypeError('Sub filter %s is not saved.' % f._name)
	
	def delete(self):
		"""Delete filter in database.
		
		:raise TypeError: invalid index
		:raise ValueError: integrity error
		"""
		if self._idx_ == None:
			raise TypeError('Missing idx')
		sql = "delete from Filters where _idx = ?;"
		try:
			db.execute(sql, (self._idx_,))
		except: # sqlite3 integrity error
			raise ValueError('Cannot delete default filter.')
		self._idx_ = None
	
	def get_calcflag(self):
		"""Return swisseph calculation flag.
		
		:rtype: int
		"""
		flag = 0
		# speed
		flag += swe.FLG_SPEED
		# ephemeris type
		if self._ephe_type == 'swiss':
			flag += swe.FLG_SWIEPH
		elif self._ephe_type == 'jpl':
			flag += swe.FLG_JPLEPH
		elif self._ephe_type == 'moshier':
			flag += swe.FLG_MOSEPH
		# sidereal mode
		if self._sid_mode > -1:
			flag += swe.FLG_SIDEREAL
		# true positions
		if self._true_pos:
			flag += swe.FLG_TRUEPOS
		# xcentric
		if self._xcentric == 'topo':
			flag += swe.FLG_TOPOCTR
		elif self._xcentric == 'helio':
			flag += swe.FLG_HELCTR
		elif self._xcentric == 'bary':
			flag += swe.FLG_BARYCTR
		return flag
	
	def __iter__(self):
		"""Iterate over filter internals.
		
		:rtype: iterator
		"""
		return (x for x in (self._idx_, self._name, self._bg_color,
			self._ephe_type, self._ephe_path, self._hsys, self._sid_mode,
			self._sid_t0, self._sid_ayan_t0, self._true_pos, self._xcentric,
			self._calc_midp, self._draw_midp, self._planets, self._aspects,
			self._orbs, self._asprestr, self._orbrestr, self._midpoints,
			self._comment))
	
	def __str__(self):
		"""Show filter internals."""
		return str(tuple(self))
	
	def __repr__(self):
		if self._idx_ == None:
			return repr(tuple(repr(x) for x in self))
		return "Filter('''%s''')" % self._name
	
	def __getstate__(self):
		"""TODO."""
		pass
	
	def _to_xml(self, with_idx=False):
		"""TODO."""
		pass
	
	def _from_xml(self, elem, with_idx=False):
		"""TODO."""
		pass
	
	def __eq__(self, other):
		"""Return True if other is the same filter in database.
		
		:rtype: bool
		"""
		if other == None:
			return False
		if not isinstance(other, Filter):
			return False
		if other._idx_ == self._idx_:
			return True
		return False
	
	def __ne__(self, other):
		"""Return True if other is not the same filter in database.
		
		:rtype: bool
		"""
		if other == None:
			return True
		if not isinstance(other, Filter):
			return True
		if other._idx_ != self._idx_:
			return True
		return False def all_filters_names():
	"""Return a list of all filters names.
	
	:rtype: list
	"""
	ret = list()
	sql = 'select name from Filters order by name;'
	res = db.execute(sql).fetchall()
	for row in res:
		ret.append(row[0])
	return ret def load(lng, app): class LatitudeEdit(_CoordsWidget):
	
	def latitude(self):
		return _CoordsWidget.value(self)
	
	def setLatitude(self, lat):
		self._coords = lat
		self.reset() class LongitudeEdit(_CoordsWidget):
	
	def longitude(self):
		return _CoordsWidget.value(self)
	
	def setLongitude(self, lon):
		self._coords = lon
		self.reset() class AltitudeEdit(QSpinBox):
	
	def __init__(self, alt, parent):
		QSpinBox.__init__(self, parent)
		self._alt = alt
		self.setMaximum(10000)
		self.setMinimum(0)
		self.setSuffix(self.tr(' m.', 'meters'))
		self.setAccelerated(True)
		self.setButtonSymbols(QAbstractSpinBox.PlusMinus)
		self.reset()
	
	def reset(self):
		self.setValue(int(self._alt))
	
	def altitude(self):
		return QSpinBox.value(self)
	
	def setAltitude(self, alt):
		self._alt = alt
		self.reset() class FilterDialog(QDialog):
	
	def __init__(self, parent=None, filt=None):
		QDialog.__init__(self, parent)
		self._parent = parent
		tr = self.tr
		if isinstance(filt, Filter):
			self._filt = filt
			title = unicode(tr('Edit Filter \xab %(filter)s \xbb')) % {
				'filter': filt._name}
		else:
			self._filt = Filter(cfg.dft_filter._idx_)
			self._filt._idx_ = None # copy dft filter and set idx to None
			title = tr('New Filter')
		self.setWindowTitle(title)
		# size
		self.setMinimumWidth(300)
		self.setMinimumHeight(380)
		self.setSizeGripEnabled(True)
		# layout
		layout = QVBoxLayout(self)
		self.setLayout(layout)
		# tabs
		tabs = QTabWidget(self)
		layout.addWidget(tabs)
		
		# ### general settings ###
		generalWidget = QWidget()
		tabs.addTab(generalWidget, tr('Main', 'Main settings'))
		# layout
		grid = QGridLayout()
		generalWidget.setLayout(grid)
		# filter name
		grid.addWidget(QLabel(tr('Filter name')), 0, 0)
		self.nameEdit = QLineEdit(self)
		grid.addWidget(self.nameEdit, 0, 1)
		# bg color
		grid.addWidget(QLabel(tr('Background')), 1, 0)
		self.bgcolorEdit = QComboBox(self)
		self.bgcolorEdit.setEditable(False)
		self.bgcolorEdit.addItems([tr('Black'), tr('White')])
		grid.addWidget(self.bgcolorEdit, 1, 1)
		# ephe type
		grid.addWidget(QLabel(tr('Ephemeris')), 2, 0)
		self.ephetypeEdit = QComboBox(self)
		self.ephetypeEdit.setEditable(False)
		self.ephetypeEdit.addItems([tr('Swiss'), tr('JPL'), tr('Moshier')])
		grid.addWidget(self.ephetypeEdit, 2, 1)
		# ephe path
		grid.addWidget(QLabel(tr('Ephem. path')), 3, 0)
		ephLayout = QHBoxLayout()
		self.ephepathEdit = QLineEdit(self)
		self.ephepathEdit.setReadOnly(True)
		ephLayout.addWidget(self.ephepathEdit)
		selectButton = QToolButton(self)
		selectButton.setIcon(QIcon(os.path.join(_baseDir,
			'icons', 'gtk-directory.png')))
		selectButton.setToolTip(tr('Select ephemeris path'))
		self.connect(selectButton, SIGNAL('clicked()'), self.ephePathSelect)
		ephLayout.addWidget(selectButton)
		grid.addLayout(ephLayout, 3, 1)
		# house system
		grid.addWidget(QLabel(tr('Domification')), 4, 0)
		self.hsysEdit = QComboBox(self)
		self.hsysEdit.setEditable(False)
		self.hsysEdit.addItems([y for x, y in names.houseSystems])
		grid.addWidget(self.hsysEdit, 4, 1)
		# sidereal mode
		grid.addWidget(QLabel(tr('Sidereal mode')), 5, 0)
		self.sidmodeEdit = QComboBox(self)
		self.sidmodeEdit.setEditable(False)
		self.sidmodeEdit.addItems([y for x, y in names.sidModes])
		grid.addWidget(self.sidmodeEdit, 5, 1)
		# sidereal t0
		grid.addWidget(QLabel(tr('Sidereal T0')), 6, 0)
		self.sidt0Edit = QDoubleSpinBox(self)
		self.sidt0Edit.setDecimals(6)
		self.sidt0Edit.setMaximum(9999999)
		self.sidt0Edit.setSuffix(tr(' JD', 'Julian day suffix'))
		self.sidt0Edit.setButtonSymbols(QAbstractSpinBox.PlusMinus)
		grid.addWidget(self.sidt0Edit, 6, 1)
		# sidereal ayanamsa at t0
		grid.addWidget(QLabel(tr('Ayanamsa T0')), 7, 0)
		self.sidayant0Edit = QDoubleSpinBox(self)
		self.sidayant0Edit.setDecimals(6)
		self.sidayant0Edit.setMaximum(360)
		self.sidayant0Edit.setSuffix(tr('\xb0', 'Degrees'))
		self.sidayant0Edit.setButtonSymbols(QAbstractSpinBox.PlusMinus)
		grid.addWidget(self.sidayant0Edit, 7, 1)
		# true positions
		grid.addWidget(QLabel(tr('Calc. positions')), 8, 0)
		self.trueposEdit = QComboBox(self)
		self.trueposEdit.setEditable(False)
		self.trueposEdit.addItems(
			[tr('Apparent', 'Positions'), tr('True', 'Positions')])
		grid.addWidget(self.trueposEdit, 8, 1)
		# xcentric
		grid.addWidget(QLabel(tr('Situation')), 9, 0)
		self.xcentricEdit = QComboBox(self)
		self.xcentricEdit.setEditable(False)
		self.xcentricEdit.addItems(
			[tr('Geocentric'), tr('Topocentric'), tr('Heliocentric'),
			tr('Barycentric')])
		grid.addWidget(self.xcentricEdit, 9, 1)
		# comment
		grid.addWidget(QLabel(tr('Comment')), 10, 0, Qt.AlignTop)
		self.commentEdit = QTextEdit('', self)
		grid.addWidget(self.commentEdit, 10, 1)
		
		# ### filters settings ###
		filtersWidget = QWidget()
		tabs.addTab(filtersWidget, tr('Filters'))
		# layout
		grid = QGridLayout()
		filtersWidget.setLayout(grid)
		# planets filter
		grid.addWidget(QLabel(tr('Planets filter')), 0, 0)
		pfLayout = QHBoxLayout()
		self.planetsEdit = QComboBox(self)
		self.planetsEdit.setEditable(False)
		pfLayout.addWidget(self.planetsEdit)
		pfButton = QToolButton(self)
		pfButton.setIcon(QIcon(os.path.join(_baseDir, 'icons',
			'gtk-execute.png')))
		pfButton.setToolTip(tr('Edit planets filter'))
		self.connect(pfButton, SIGNAL('clicked()'), self.editPlanetsFilter)
		pfLayout.addWidget(pfButton)
		grid.addLayout(pfLayout, 0, 1)
		# aspects filter
		grid.addWidget(QLabel(tr('Aspects filter')), 1, 0)
		afLayout = QHBoxLayout()
		self.aspectsEdit = QComboBox(self)
		self.aspectsEdit.setEditable(False)
		afLayout.addWidget(self.aspectsEdit)
		afButton = QToolButton(self)
		afButton.setIcon(QIcon(os.path.join(_baseDir, 'icons',
			'gtk-execute.png')))
		afButton.setToolTip(tr('Edit aspects filter'))
		self.connect(afButton, SIGNAL('clicked()'), self.editAspectsFilter)
		afLayout.addWidget(afButton)
		grid.addLayout(afLayout, 1, 1)
		# orbs filter
		grid.addWidget(QLabel(tr('Orbs filter')), 2, 0)
		ofLayout = QHBoxLayout()
		self.orbsEdit = QComboBox(self)
		self.orbsEdit.setEditable(False)
		ofLayout.addWidget(self.orbsEdit)
		ofButton = QToolButton(self)
		ofButton.setIcon(QIcon(os.path.join(_baseDir, 'icons',
			'gtk-execute.png')))
		ofButton.setToolTip(tr('Edit orbs filter'))
		self.connect(ofButton, SIGNAL('clicked()'), self.editOrbsFilter)
		ofLayout.addWidget(ofButton)
		grid.addLayout(ofLayout, 2, 1)
		# aspects restrictions
		grid.addWidget(QLabel(tr('Aspects restrictions')), 3, 0)
		arLayout = QHBoxLayout()
		self.asprestrEdit = QComboBox(self)
		self.asprestrEdit.setEditable(False)
		arLayout.addWidget(self.asprestrEdit)
		arButton = QToolButton(self)
		arButton.setIcon(QIcon(os.path.join(_baseDir, 'icons',
			'gtk-execute.png')))
		arButton.setToolTip(tr('Edit aspects restrictions'))
		self.connect(arButton, SIGNAL('clicked()'), self.editAspectsRestrictions)
		arLayout.addWidget(arButton)
		grid.addLayout(arLayout, 3, 1)
		# orbs restrictions
		grid.addWidget(QLabel(tr('Orbs modifiers')), 4, 0)
		orLayout = QHBoxLayout()
		self.orbrestrEdit = QComboBox(self)
		self.orbrestrEdit.setEditable(False)
		orLayout.addWidget(self.orbrestrEdit)
		orButton = QToolButton(self)
		orButton.setIcon(QIcon(os.path.join(_baseDir, 'icons',
			'gtk-execute.png')))
		orButton.setToolTip(tr('Edit orbs restrictions'))
		self.connect(orButton, SIGNAL('clicked()'), self.editOrbsRestrictions)
		orLayout.addWidget(orButton)
		grid.addLayout(orLayout, 4, 1)
		# midpoints settings
		## calc midpoints
		self.calc_midpEdit = QCheckBox(tr('Calc. midpoints'), self)
		self.connect(self.calc_midpEdit, SIGNAL('stateChanged(int)'),
			self.calc_midpEditChanged)
		grid.addWidget(self.calc_midpEdit, 5, 0)
		## draw midpoints
		self.draw_midpEdit = QCheckBox(tr('Draw midpoints aspects'), self)
		self.connect(self.draw_midpEdit, SIGNAL('stateChanged(int)'),
			self.draw_midpEditChanged)
		grid.addWidget(self.draw_midpEdit, 5, 1)
		## filters
		grid.addWidget(QLabel(tr('MidPoints filter')), 6, 0)
		mpLayout = QHBoxLayout()
		self.midpointsEdit = QComboBox(self)
		self.midpointsEdit.setEditable(False)
		mpLayout.addWidget(self.midpointsEdit)
		mpButton = QToolButton(self)
		mpButton.setIcon(QIcon(os.path.join(_baseDir, 'icons',
			'gtk-execute.png')))
		mpButton.setToolTip(tr('Edit MidPoints filter'))
		self.connect(mpButton, SIGNAL('clicked()'), self.editMidPointsFilter)
		mpLayout.addWidget(mpButton)
		grid.addLayout(mpLayout, 6, 1)
		
		# ### buttons ###
		buttonsLayout = QHBoxLayout()
		resetButton = QPushButton(tr('Reset'), self)
		self.connect(resetButton, SIGNAL('clicked()'), self.reset)
		buttonsLayout.addWidget(resetButton)
		cancelButton = QPushButton(tr('Cancel'), self)
		self.connect(cancelButton, SIGNAL('clicked()'), self.reject)
		buttonsLayout.addWidget(cancelButton)
		okButton = QPushButton(tr('Ok'), self)
		okButton.setDefault(True)
		self.connect(okButton, SIGNAL('clicked()'), self.accept)
		buttonsLayout.addWidget(okButton)
		layout.addLayout(buttonsLayout)
		
		# load entries
		self.reset()
	
	def ephePathSelect(self):
		"""Select directory (for swisseph) or a file (for jpl)."""
		path = ''
		if self.ephetypeEdit.currentIndex() == 0: # swisseph
			path = unicode(QFileDialog.getExistingDirectory(self,
				self.tr('Set Swisseph directory'),
				os.path.expanduser('~')))
		elif self.ephetypeEdit.currentIndex() == 1: # jpl
			path = unicode(QFileDialog.getOpenFileName(self,
				self.tr('Set JPL file'),
				os.path.expanduser('~')))
		else: # moshier
			QMessageBox.information(self, self.tr('Moshier ephemeris'),
				self.tr('No ephemeris path needed for Moshier ephemeris.'))
		if path != '':
				self.ephepathEdit.setText(path)
	
	def calc_midpEditChanged(self, val):
		if not self.calc_midpEdit.isChecked():
			self.draw_midpEdit.setChecked(False)
	
	def draw_midpEditChanged(self, val):
		if self.draw_midpEdit.isChecked():
			self.calc_midpEdit.setChecked(True)
	
	# ### edit filters ###
	
	def editPlanetsFilter(self):
		"""Open planets filter edit dialog."""
		pf = PlanetsFilter(
			all_planets_filters_names()[self.planetsEdit.currentIndex()])
		edit = PlanetsFilterDialog(self, pf)
		ok = edit.exec_()
		if ok: ## reset our filters
			if pf == self._filt._planets:
				self._filt._planets.reset()
			self.resetPlanetsFilters()
	
	def editAspectsFilter(self):
		"""Open aspects filter edit dialog."""
		af = AspectsFilter(
			all_aspects_filters_names()[self.aspectsEdit.currentIndex()])
		edit = AspectsFilterDialog(self, af)
		ok = edit.exec_()
		if ok: ## reset our filters
			if af == self._filt._aspects:
				self._filt._aspects.reset()
			self.resetAspectsFilters()
	
	def editOrbsFilter(self):
		of = OrbsFilter(
			all_orbs_filters_names()[self.orbsEdit.currentIndex()])
		edit = OrbsFilterDialog(self, of)
		ok = edit.exec_()
		if ok: ## reset our filters
			if of == self._filt._orbs:
				self._filt._orbs.reset()
			self.resetOrbsFilters()
	
	def editAspectsRestrictions(self):
		ar = AspectsRestrictions(
			all_aspects_restrictions_names()[self.asprestrEdit.currentIndex()])
		edit = AspectsRestrictionsDialog(self, ar)
		ok = edit.exec_()
		if ok: ## reset our filters
			if ar == self._filt._asprestr:
				self._filt._asprestr.reset()
			self.resetAspectsRestrictions()
	
	def editOrbsRestrictions(self):
		orb = OrbsRestrictions(
			all_orbs_restrictions_names()[self.orbrestrEdit.currentIndex()])
		edit = OrbsRestrictionsDialog(self, orb)
		ok = edit.exec_()
		if ok: ## reset our filters
			if orb == self._filt._orbrestr:
				self._filt._orbrestr.reset()
			self.resetOrbsRestrictions()
	
	def editMidPointsFilter(self):
		mp = MidPointsFilter(
			all_midpoints_filters_names()[self.midpointsEdit.currentIndex()])
		edit = MidPointsFilterDialog(self, mp)
		ok = edit.exec_()
		if ok: ## reset our filters
			if mp == self._filt._midpoints:
				self._filt._midpoints.reset()
			self.resetMidPointsFilters()
	
	# ### reset filters boxes ###
	
	def resetPlanetsFilters(self):
		"""Reset planets filter box."""
		self.planetsEdit.clear()
		all = all_planets_filters_names()
		self.planetsEdit.addItems(all)
		i = all.index(self._filt._planets._name)
		self.planetsEdit.setCurrentIndex(i)
	
	def resetAspectsFilters(self):
		"""Reset aspects filters box."""
		self.aspectsEdit.clear()
		all = all_aspects_filters_names()
		self.aspectsEdit.addItems(all)
		i = all.index(self._filt._aspects._name)
		self.aspectsEdit.setCurrentIndex(i)
	
	def resetOrbsFilters(self):
		"""Reset orbs filters box."""
		self.orbsEdit.clear()
		all = all_orbs_filters_names()
		self.orbsEdit.addItems(all)
		i = all.index(self._filt._orbs._name)
		self.orbsEdit.setCurrentIndex(i)
	
	def resetAspectsRestrictions(self):
		"""Reset aspects restrictions box."""
		self.asprestrEdit.clear()
		all = all_aspects_restrictions_names()
		self.asprestrEdit.addItems(all)
		i = all.index(self._filt._asprestr._name)
	
	def resetOrbsRestrictions(self):
		"""Reset orbs restrictions box."""
		self.orbrestrEdit.clear()
		all = all_orbs_restrictions_names()
		self.orbrestrEdit.addItems(all)
		i = all.index(self._filt._orbrestr._name)
		self.orbrestrEdit.setCurrentIndex(i)
	
	def resetMidPointsFilters(self):
		"""Reset midpoints filters box."""
		self.midpointsEdit.clear()
		all = all_midpoints_filters_names()
		self.midpointsEdit.addItems(all)
		i = all.index(self._filt._midpoints._name)
		self.midpointsEdit.setCurrentIndex(i)
	
	def reset(self):
		"""Reset entries."""
		filt = self._filt
		# name
		self.nameEdit.setText(filt._name)
		# bg color
		self.bgcolorEdit.setCurrentIndex(0 if filt._bg_color == 'black' else 1)
		# ephe type
		t = filt._ephe_type
		if t == 'swiss':
			t = 0
		elif t == 'jpl':
			t = 1
		else:
			t = 2
		self.ephetypeEdit.setCurrentIndex(t)
		# ephe path
		self.ephepathEdit.setText(os.path.expanduser(filt._ephe_path))
		# domification
		hsys = filt._hsys
		for i, a in enumerate(names.houseSystems):
			if a[0] == hsys:
				self.hsysEdit.setCurrentIndex(i)
				break
		# sid mode
		sidm = filt._sid_mode
		for i, a in enumerate(names.sidModes):
			if a[0] == sidm:
				self.sidmodeEdit.setCurrentIndex(i)
				break
		# sid t0
		self.sidt0Edit.setValue(filt._sid_t0)
		# sid ayan t0
		self.sidayant0Edit.setValue(filt._sid_ayan_t0)
		# true pos
		self.trueposEdit.setCurrentIndex(0 if filt._true_pos == False else 1)
		# xcentric
		xcentric = filt._xcentric
		if xcentric == 'geo':
			i = 0
		elif xcentric == 'topo':
			i = 1
		elif xcentric == 'helio':
			i = 2
		else: # bary
			i = 3
		self.xcentricEdit.setCurrentIndex(i)
		# planets
		self.resetPlanetsFilters()
		# aspects
		self.resetAspectsFilters()
		# orbs
		self.resetOrbsFilters()
		# aspects restrictions
		self.resetAspectsRestrictions()
		# orbs modifiers
		self.resetOrbsRestrictions()
		# calc midp
		self.calc_midpEdit.setChecked(self._filt._calc_midp)
		# draw midp
		self.draw_midpEdit.setChecked(self._filt._draw_midp)
		# midpoints filter
		self.resetMidPointsFilters()
		# comment
		self.commentEdit.setPlainText(filt._comment)
	
	def accept(self):
		"""Set filter new values and save."""
		tr = self.tr
		# name
		name = unicode(self.nameEdit.text())
		if name == '':
			QMessageBox.critical(self, tr('Missing Name'),
				tr('Please set filter name.'))
			self.nameEdit.setFocus()
			return
		# bg color
		bg = self.bgcolorEdit.currentIndex()
		if bg == 0:
			bg = 'black'
		else:
			bg = 'white'
		# ephe type
		ephetype = self.ephetypeEdit.currentIndex()
		if ephetype == 0:
			ephetype = 'swiss'
		elif ephetype == 1:
			ephetype = 'jpl'
		else:
			ephetype = 'moshier'
		# ephe path
		ephepath = unicode(self.ephepathEdit.text())
		# hsys
		hsys = names.houseSystems[self.hsysEdit.currentIndex()][0]
		# sidereal mode
		sidm = names.sidModes[self.sidmodeEdit.currentIndex()][0]
		# sidereal t0
		sidt0 = self.sidt0Edit.value()
		# sidereal ayanamsa t0
		sidayant0 = self.sidayant0Edit.value()
		# true pos
		truepos = False if self.trueposEdit.currentIndex() == 0 else True
		# xcentric
		xcentric = self.xcentricEdit.currentIndex()
		if xcentric == 0:
			xcentric = 'geo'
		elif xcentric == 1:
			xcentric = 'topo'
		elif xcentric == 2:
			xcentric = 'helio'
		else:
			xcentric = 'bary'
		# planets filter
		planets = all_planets_filters_names()[self.planetsEdit.currentIndex()]
		# aspects filter
		aspects = all_aspects_filters_names()[self.aspectsEdit.currentIndex()]
		# orbs filter
		orbs = all_orbs_filters_names()[self.orbsEdit.currentIndex()]
		# aspects restrictions
		asprestr = all_aspects_restrictions_names()[self.asprestrEdit.currentIndex()]
		# orbs restrictions
		orbrestr = all_orbs_restrictions_names()[self.orbrestrEdit.currentIndex()]
		# midpoints settings
		calc_midp = self.calc_midpEdit.isChecked()
		draw_midp = self.draw_midpEdit.isChecked()
		# midpoints filter
		midpoints = all_midpoints_filters_names()[self.midpointsEdit.currentIndex()]
		# comment
		cmt = unicode(self.commentEdit.toPlainText())
		# ### set filter ###
		self._filt.set(name=name, bg_color=bg, ephe_type=ephetype,
			ephe_path=ephepath, hsys=hsys, sid_mode=sidm, sid_t0=sidt0,
			sid_ayan_t0=sidayant0, true_pos=truepos, xcentric=xcentric,
			calc_midp=calc_midp, draw_midp=draw_midp,
			planets=planets, aspects=aspects, orbs=orbs, asprestr=asprestr,
			orbrestr=orbrestr, midpoints=midpoints, comment=cmt)
		# save
		try:
			self._filt.save()
		except ValueError: # duplicate filter
			QMessageBox.critical(self, tr('Error'),
				unicode(tr('Duplicate filter name \xab %(filter)s \xbb.')) % {
					'filter': self._filt._name})
			self.nameEdit.setFocus()
			return
		# reload cfg in case filter is default,
		# and opened charts if using this filter
		if __name__ != '__main__':
			app.filterUpdatedEvent(self._filt._idx_)
		# done
		self.done(QDialog.Accepted) class GeoNamesQueryDialog(QDialog):
	
	def __init__(self, parent=None):
		QDialog.__init__(self, parent)
		tr = self.tr
		self._parent = parent
		self.setWindowTitle(tr('Query GeoNames.org'))
		self.setSizeGripEnabled(True)
		self.setMinimumWidth(400)
		self._results = list() # geonames results
		self._sel = None # selected result
		# layout
		grid = QGridLayout(self)
		self.setLayout(grid)
		# search
		grid.addWidget(QLabel(tr('Search for')), 0, 0)
		self.nameQuery = QLineEdit(self)
		grid.addWidget(self.nameQuery, 0, 1)
		# results
		grid.addWidget(QLabel(tr('Results')), 1, 0)
		self.resultsBox = QComboBox(self)
		self.resultsBox.setEditable(False)
		grid.addWidget(self.resultsBox, 1, 1)
		# buttons
		buttonsLayout = QHBoxLayout()
		grid.addLayout(buttonsLayout, 2, 0, 1, 2)
		searchButton = QPushButton(tr('Search'), self)
		searchButton.setDefault(True)
		self.connect(searchButton, SIGNAL('clicked()'), self.searchEvent)
		buttonsLayout.addWidget(searchButton)
		self.selectButton = QPushButton(tr('Select'), self)
		self.selectButton.setDisabled(True)
		self.connect(self.selectButton, SIGNAL('clicked()'), self.selectEvent)
		buttonsLayout.addWidget(self.selectButton)
		closeButton = QPushButton(tr('Close'), self)
		self.connect(closeButton, SIGNAL('clicked()'), SLOT('close()'))
		buttonsLayout.addWidget(closeButton)
	
	def searchEvent(self):
		tr = self.tr
		txt = unicode(self.nameQuery.text()).strip()
		if txt == '': # no input
			self.selectButton.setDisabled(True)
			self.nameQuery.setFocus()
			return
		# threading
		th = SearchThread(txt, self)
		progDialog = ProgressDialog(self)
		self.connect(th, SIGNAL('finished()'), progDialog, SLOT('accept()'))
		self.connect(th, SIGNAL('terminated()'), progDialog, SLOT('reject()'))
		self.connect(progDialog, SIGNAL('rejected()'), th, SLOT('quit()'))
		th.start()
		ok = progDialog.exec_()
		if not ok: # aborted or error
			return
		# display results
		fmt = unicode(
			tr('%(name)s, %(cty)s, %(lat)s, %(lon)s, %(alt)s %(m)s, %(tz)s'))
		all = [fmt % {
			'name': x[0], 
			'cty': x[1],
			'lat': str(x[2]),
			'lon': str(x[3]),
			'alt': str(x[4]),
			'm': tr('m.', 'Meters'),
			'tz': x[5]
			}	for x in self._results]
		self.resultsBox.clear()
		if len(all) != 0:
			self.resultsBox.addItems(all)
			self.selectButton.setEnabled(True)
		else:
			self.selectButton.setDisabled(True)
	
	def selectEvent(self):
		"""Set parent's geonames results."""
		try:
			self._sel = self._results[self.resultsBox.currentIndex()]
		except IndexError: # should not happen
			self.done(QDialog.Rejected)
		self.done(QDialog.Accepted)
	
	def exec_(self):
		ok = QDialog.exec_(self)
		if ok:
			return ok, self._sel
		else:
			return ok, None
import sys
import os.path
import pytz
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from oroboros.core import cfg
from oroboros.core import timezone
from oroboros.core.filters import Filter, all_filters_names
from oroboros.gui import translations
from oroboros.gui.coordswidget import LatitudeEdit, LongitudeEdit, AltitudeEdit
from oroboros.gui.filterdialog import FilterDialog
from oroboros.gui.geonames import GeoNamesQueryDialog
		filtLayout.addWidget(self.filterEdit)
		filtButton = QToolButton(self)
		filtButton.setIcon(QIcon(os.path.join(_baseDir, 'icons',
			'gtk-execute.png')))
		filtButton.setToolTip(tr('Edit filter'))
		self.connect(filtButton, SIGNAL('clicked()'), self.editFilter)
		filtLayout.addWidget(filtButton)
		dftChartGrid.addLayout(filtLayout, 7, 1)
		
		# ### mercurial settings ###
		hgWidget = QWidget()
		tabs.addTab(hgWidget, tr('Mercurial'))
		hgGrid = QGridLayout()
		hgWidget.setLayout(hgGrid)
		# use hg
		self.useHgBox = QCheckBox(tr('Use Mercurial'), self)
		self.useHgBox.setToolTip(
			tr('Pull changes on startup and push changes on shutdown'))
		hgGrid.addWidget(self.useHgBox, 0, 0, 1, 2)
		# hg repo
		lbl = QLabel(tr('Hg repo'))
		lbl.setToolTip(tr('Distant repository address'))
		hgGrid.addWidget(lbl, 1, 0)
		self.hgRepoEdit = QLineEdit(self)
		hgGrid.addWidget(self.hgRepoEdit, 1, 1)
		# hg user
		hgGrid.addWidget(QLabel(tr('Username')), 2, 0)
		self.hgUserEdit = QLineEdit(self)
		hgGrid.addWidget(self.hgUserEdit, 2, 1)
		# hg pswd
		hgGrid.addWidget(QLabel(tr('Password')), 3, 0)
		self.hgPswdEdit = QLineEdit(self)
		self.hgPswdEdit.setEchoMode(QLineEdit.Password)
		hgGrid.addWidget(self.hgPswdEdit, 3, 1)
		
		# ### buttons ###
		buttonsLayout = QHBoxLayout()
		resetButton = QPushButton(tr('Reset'), self)
		self.connect(resetButton, SIGNAL('clicked()'), self.reset)
		buttonsLayout.addWidget(resetButton)
		cancelButton = QPushButton(tr('Cancel'), self)
		self.connect(cancelButton, SIGNAL('clicked()'), self.reject)
		buttonsLayout.addWidget(cancelButton)
		okButton = QPushButton(tr('Ok'), self)
		okButton.setDefault(True)
		self.connect(okButton, SIGNAL('clicked()'), self.accept)
		buttonsLayout.addWidget(okButton)
		grid.addLayout(buttonsLayout, 1, 0)
		# fill entries
		self.reset()
	
	def chartsDirSelect(self):
		"""Select charts directory."""
		path = unicode(QFileDialog.getExistingDirectory(self,
			self.tr('Set charts directory'),
			os.path.expanduser('~')))
		if path != '':
			self.chartsdirEdit.setText(path)
	
	def queryGeoNames(self):
		"""Query GeoNames.org database."""
		ok, res = GeoNamesQueryDialog(self).exec_()
		if ok:
			self.locationEdit.setText(res[0])
			self.countryEdit.setText(res[1])
			self.latitudeEdit.setLatitude(res[2])
			self.longitudeEdit.setLongitude(res[3])
			self.altitudeEdit.setAltitude(res[4])
			self.zoneinfoEdit.setCurrentIndex(
				pytz.all_timezones.index(res[5]) + 1)
	
	def editFilter(self):
		"""Open filter editor."""
		filt = Filter(all_filters_names()[self.filterEdit.currentIndex()])
		edit = FilterDialog(self, filt)
		ok = edit.exec_()
		if ok: # reload filter box
			# cfg is already updated by filter dialog
			self.resetFilters()
	
	def resetFilters(self):
		"""Reset filter box."""
		self.filterEdit.clear()
		all = all_filters_names()
		self.filterEdit.addItems(all)
		self.filterEdit.setCurrentIndex(all.index(cfg.dft_filter._name))
	
	def reset(self):
		"""Set entries with original values."""
		# ### main ###
		# user name
		self.usernameEdit.setText(cfg.username)
		# user email
		self.usermailEdit.setText(cfg.usermail)
		# language
		if cfg.language != '':
			self.languageEdit.setCurrentIndex(
				translations.languages.index(cfg.language))
		else:
			self.languageEdit.setCurrentIndex(0)
		# charts dir
		self.chartsdirEdit.setText(os.path.expanduser(cfg.charts_dir))
		# use docutils
		self.useDocutilsBox.setChecked(cfg.use_docutils)
		# ### default chart ###
		# default location
		self.locationEdit.setText(cfg.dft_location)
		# default country
		self.countryEdit.setText(cfg.dft_country)
		# zoneinfo
		if cfg.dft_zoneinfo in ('', None):
			self.zoneinfoEdit.setCurrentIndex(0)
		else:
			self.zoneinfoEdit.setCurrentIndex(
				pytz.all_timezones.index(cfg.dft_zoneinfo) + 1)
		# timezone
		if cfg.dft_timezone == None:
			self.timezoneEdit.setCurrentIndex(0)
		else:
			self.timezoneEdit.setCurrentIndex(

				timezone.all_timezones.index(cfg.dft_timezone) + 1)