2007-09-08 Don Allingham <don@gramps-project.org>

* src/ViewManager.py: code cleanup
	* src/FontScale.py: code cleanup
	* src/GrampsWidgets.py: code cleanup
	* src/ExportOptions.py: code cleanup
	* src/GrampsDisplay.py: code cleanup
	* src/DateEdit.py: code cleanup
	* src/DbLoader.py: code cleanup



svn: r8951
This commit is contained in:
Don Allingham 2007-09-09 05:24:15 +00:00
parent 651e29ead4
commit 6d9dbfee49
8 changed files with 593 additions and 501 deletions

View File

@ -1,3 +1,12 @@
2007-09-08 Don Allingham <don@gramps-project.org>
* src/ViewManager.py: code cleanup
* src/FontScale.py: code cleanup
* src/GrampsWidgets.py: code cleanup
* src/ExportOptions.py: code cleanup
* src/GrampsDisplay.py: code cleanup
* src/DateEdit.py: code cleanup
* src/DbLoader.py: code cleanup
2007-09-08 Benny Malengier <benny.malengier@gramps-project.org>
* src/DataViews/_RelationView.py : expand/collapse, edit button on/off bug fix
* src/GrampsWidgets.py : Expand widget, changes link labels

View File

@ -264,7 +264,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
if response == gtk.RESPONSE_HELP:
GrampsDisplay.help('adv-dates')
elif response == gtk.RESPONSE_DELETE_EVENT:
return
break
else:
if response == gtk.RESPONSE_OK:
(the_quality, the_modifier, the_calendar,
@ -277,9 +277,11 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
value=the_value,
text=the_text)
self.close()
return
def build_menu_names(self, obj):
"""
Define the menu entry for the ManagedWindows
"""
return (_("Date selection"), None)
def build_date_from_ui(self):

View File

@ -87,6 +87,9 @@ class DbLoader:
self.uistate = uistate
def open_file(self):
"""
Presents a file open dialog and opens the corresponding exsting file
"""
choose = gtk.FileChooserDialog(
_('GRAMPS: Open database'),
self.uistate.window,
@ -140,63 +143,6 @@ class DbLoader:
choose.destroy()
return ('', '')
def new_file(self):
choose = gtk.FileChooserDialog(
_('GRAMPS: Create GRAMPS database'),
self.uistate.window,
gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_NEW, gtk.RESPONSE_OK))
# Always add automatic (macth all files) filter
add_all_files_filter(choose)
add_grdb_filter(choose)
default_dir = get_default_dir()
new_filename = Utils.get_new_filename('grdb', default_dir)
choose.set_current_folder(default_dir)
choose.set_current_name(os.path.split(new_filename)[1])
while (True):
response = choose.run()
if response == gtk.RESPONSE_OK:
filename = unicode(choose.get_filename(),
sys.getfilesystemencoding())
if self.check_errors(filename):
return ('','')
ext = os.path.splitext(filename)[1].lower()
if ext == ".ged":
filetype = const.APP_GEDCOM
elif ext == ".gramps":
filetype = const.APP_GRAMPS_XML
elif ext == ".grdb":
filetype = const.APP_GRAMPS
else:
filename = filename + ".grdb"
filetype = const.APP_GRAMPS
choose.destroy()
try:
self.dbstate.db.close()
except:
pass
self.read_file(filename, filetype)
try:
os.chdir(os.path.dirname(filename))
except:
return ('', '')
self.dbstate.db.db_is_open = True
return (filename, filetype)
else:
choose.destroy()
return ('', '')
choose.destroy()
return ('', '')
def save_as(self):
choose = gtk.FileChooserDialog(
_('GRAMPS: Create GRAMPS database'),
@ -343,8 +289,8 @@ class DbLoader:
# Then we try all the known plugins
(the_path, the_file) = os.path.split(filename)
Config.set(Config.RECENT_IMPORT_DIR, the_path)
for (importData, mime_filter, mime_type, native_format, format_name) \
in import_list:
for (importData, mime_filter, mime_type, native_format,
format_name) in import_list:
if filetype == mime_type or the_file == mime_type:
self.do_import(choose, importData, filename)
return True

View File

@ -17,10 +17,24 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
Provides the common export options for Exporters
"""
#-------------------------------------------------------------------------
#
# python modules
#
#-------------------------------------------------------------------------
import gtk
from gettext import gettext as _
import RelLib
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
import Config
from BasicUtils import name_displayer
@ -28,7 +42,7 @@ from Filters import GenericFilter, Rules
#-------------------------------------------------------------------------
#
#
# WriterOptionBox
#
#-------------------------------------------------------------------------
class WriterOptionBox:
@ -38,13 +52,24 @@ class WriterOptionBox:
"""
def __init__(self, person):
self.person = person
self.private = 0
self.restrict = 0
self.cfilter = None
self.restrict_check = None
self.private_check = None
self.filter_obj = None
def get_option_box(self):
"""
Builds up a gtk.Table that contains the standard options
"""
table = gtk.Table(3, 2)
label = gtk.Label('Filter')
self.filter_obj = gtk.ComboBox()
self.private_check = gtk.CheckButton(_('Do not include records marked private'))
self.restrict_check = gtk.CheckButton(_('Restrict data on living people'))
self.private_check = gtk.CheckButton(
_('Do not include records marked private'))
self.restrict_check = gtk.CheckButton(
_('Restrict data on living people'))
self.private_check.set_active(Config.get(Config.EXPORT_NO_PRIVATE))
self.restrict_check.set_active(Config.get(Config.EXPORT_RESTRICT))
@ -57,40 +82,19 @@ class WriterOptionBox:
table.attach(self.private_check, 1, 2, 1, 2, yoptions=0)
table.attach(self.restrict_check, 1, 2, 2, 3, yoptions=0)
#filter_obj = self.topDialog.get_widget("filter")
all = GenericFilter()
all.set_name(_("Entire Database"))
the_filters = [all]
entire_db = GenericFilter()
entire_db.set_name(_("Entire Database"))
the_filters = [entire_db]
if self.person:
des = GenericFilter()
des.set_name(_("Descendants of %s") %
name_displayer.display(self.person))
des.add_rule(Rules.Person.IsDescendantOf(
[self.person.get_gramps_id(), 1]))
ans = GenericFilter()
ans.set_name(_("Ancestors of %s")
% name_displayer.display(self.person))
ans.add_rule(Rules.Person.IsAncestorOf(
[self.person.get_gramps_id(), 1]))
com = GenericFilter()
com.set_name(_("People with common ancestor with %s") %
name_displayer.display(self.person))
com.add_rule(Rules.Person.HasCommonAncestorWith(
[self.person.get_gramps_id()]))
the_filters += [des, ans, com]
the_filters += self.__define_person_filters()
from Filters import CustomFilters
the_filters.extend(CustomFilters.get_filters('Person'))
model = gtk.ListStore(str, object)
for f in the_filters:
model.append(row=[f.get_name(), f])
for item in the_filters:
model.append(row=[item.get_name(), item])
cell = gtk.CellRendererText()
self.filter_obj.pack_start(cell, True)
@ -101,8 +105,40 @@ class WriterOptionBox:
table.show()
return table
def parse_options(self):
def __define_person_filters(self):
"""
Add person filters if the active person is defined
"""
des = GenericFilter()
des.set_name(_("Descendants of %s") %
name_displayer.display(self.person))
des.add_rule(Rules.Person.IsDescendantOf(
[self.person.get_gramps_id(), 1]))
ans = GenericFilter()
ans.set_name(_("Ancestors of %s")
% name_displayer.display(self.person))
ans.add_rule(Rules.Person.IsAncestorOf(
[self.person.get_gramps_id(), 1]))
com = GenericFilter()
com.set_name(_("People with common ancestor with %s") %
name_displayer.display(self.person))
com.add_rule(Rules.Person.HasCommonAncestorWith(
[self.person.get_gramps_id()]))
return [des, ans, com]
def parse_options(self):
"""
Extract the common values from the GTK widgets. After this function
is called, the following variables are defined:
private = privacy requested
restrict = restrict information on living peoplel
cfitler = return the GenericFilter selected
"""
self.restrict = self.restrict_check.get_active()
self.private = self.private_check.get_active()

View File

@ -17,7 +17,12 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
_swiss = [
"""
Provides a rough estimate of the width of a text string.
"""
SWISS = [
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
@ -45,7 +50,7 @@ _swiss = [
0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.584, 0.611, 0.556,
0.556, 0.556, 0.556, 0.500, 0.556, 0.500]
_swiss_b = [
SWISS_B = [
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
@ -73,7 +78,7 @@ _swiss_b = [
0.611, 0.611, 0.611, 0.611, 0.611, 0.611, 0.611, 0.584, 0.611, 0.611,
0.611, 0.611, 0.611, 0.556, 0.611, 0.556]
_swiss_i = [
SWISS_I = [
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
@ -101,7 +106,7 @@ _swiss_i = [
0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.556, 0.584, 0.611, 0.556,
0.556, 0.556, 0.556, 0.500, 0.556, 0.500]
_swiss_bi = [
SWISS_BI = [
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
@ -129,7 +134,7 @@ _swiss_bi = [
0.611, 0.611, 0.611, 0.611, 0.611, 0.611, 0.611, 0.584, 0.611, 0.611,
0.611, 0.611, 0.611, 0.556, 0.611, 0.556]
_roman = [
ROMAN = [
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
@ -157,7 +162,7 @@ _roman = [
0.500, 0.500, 0.500, 0.500, 0.500, 0.500, 0.500, 0.564, 0.500, 0.500,
0.500, 0.500, 0.500, 0.500, 0.500, 0.500]
_roman_b = [
ROMAN_B = [
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
@ -185,7 +190,7 @@ _roman_b = [
0.500, 0.556, 0.500, 0.500, 0.500, 0.500, 0.500, 0.570, 0.500, 0.556,
0.556, 0.556, 0.556, 0.500, 0.556, 0.500]
_roman_i = [
ROMAN_I = [
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
@ -213,7 +218,7 @@ _roman_i = [
0.500, 0.500, 0.500, 0.500, 0.500, 0.500, 0.500, 0.675, 0.500, 0.500,
0.500, 0.500, 0.500, 0.444, 0.500, 0.444]
_roman_bi = [
ROMAN_BI = [
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
@ -241,19 +246,22 @@ _roman_bi = [
0.500, 0.556, 0.500, 0.500, 0.500, 0.500, 0.500, 0.570, 0.500, 0.556,
0.556, 0.556, 0.556, 0.444, 0.500, 0.444]
_font_array = [ [_swiss, _swiss_b, _swiss_i, _swiss_bi ],
[_roman, _roman_b, _roman_i, _roman_bi ] ]
FONT_ARRAY = [ [SWISS, SWISS_B, SWISS_I, SWISS_BI ],
[ROMAN, ROMAN_B, ROMAN_I, ROMAN_BI ] ]
#-------------------------------------------------------------------------
#
#
# string_width
#
#-------------------------------------------------------------------------
def string_width(font,text):
def string_width(font, text):
"""
returns with width of a string in the specified font
"""
i = font.get_type_face()
j = font.get_bold() + font.get_italic()*2
s = font.get_size()
l = _font_array[i][j]
l = FONT_ARRAY[i][j]
r = 0
for c in text:
try:
@ -270,7 +278,7 @@ def string_trim(font, text, width, ellipses = "..."):
i = font.get_type_face()
j = font.get_bold() + font.get_italic()*2
s = font.get_size()
l = _font_array[i][j]
l = FONT_ARRAY[i][j]
ellipses_length = 0
# get length of each letter
for c in ellipses:

View File

@ -23,15 +23,21 @@
import const
def help(target):
"""
Display the specified target in a help window. If this fails,
open the manual on the web site.
"""
try:
import gnome
gnome.help_display('gramps',target)
except:
# FIXME: as manual translations appear online, this needs to
# become more complex to directo to the correct language
url(const.url_manual+'en/')
def url(target):
"""
Open the specified URL in a browser. Attempt using the GNOME system if
available, if not, try to find a browser.
"""
try:
import gnome
gnome.url_show(target)
@ -40,6 +46,10 @@ def url(target):
def run_browser(url):
"""
Attempt of find a browswer, and launch with the browser with the
specified URL
"""
import os
search = os.environ['PATH'].split(':')

View File

@ -8,7 +8,7 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@ -75,7 +75,7 @@ except:
INFO_ICON = gtk.STOCK_DIALOG_INFO
# Enabling custom widgets to be included in Glade
def get_custom_handler(glade, function_name, widget_name,
def get_custom_handler(glade, function_name, widget_name,
str1, str2, int1, int2):
if function_name == 'ValidatableMaskedEntry':
return ValidatableMaskedEntry()
@ -164,7 +164,7 @@ class LinkLabel(gtk.EventBox):
class IconButton(gtk.Button):
def __init__(self, func, handle, icon=gtk.STOCK_EDIT,
def __init__(self, func, handle, icon=gtk.STOCK_EDIT,
size=gtk.ICON_SIZE_MENU):
gtk.Button.__init__(self)
image = gtk.Image()
@ -366,7 +366,7 @@ class MonitoredCheckbox:
class MonitoredEntry:
def __init__(self, obj, set_val, get_val, read_only=False,
def __init__(self, obj, set_val, get_val, read_only=False,
autolist=None, changed=None):
self.obj = obj
self.set_val = set_val
@ -379,7 +379,7 @@ class MonitoredEntry:
self.obj.set_editable(not read_only)
if autolist:
AutoComp.fill_entry(obj,autolist)
AutoComp.fill_entry(obj, autolist)
def reinit(self, set_val, get_val):
self.set_val = set_val
@ -432,7 +432,7 @@ class MonitoredText:
class MonitoredType:
def __init__(self, obj, set_val, get_val, mapping, custom, readonly=False,
def __init__(self, obj, set_val, get_val, mapping, custom, readonly=False,
custom_values=None):
self.set_val = set_val
self.get_val = get_val
@ -467,7 +467,7 @@ class MonitoredType:
class MonitoredDataType:
def __init__(self, obj, set_val, get_val, readonly=False,
def __init__(self, obj, set_val, get_val, readonly=False,
custom_values=None, ignore_values=None):
"""
Constructor for the MonitoredDataType class.
@ -509,13 +509,13 @@ class MonitoredDataType:
del map[key]
self.sel = AutoComp.StandardCustomSelector(
map,
obj,
get_val().get_custom(),
default,
map,
obj,
get_val().get_custom(),
default,
additional=custom_values)
self.sel.set_values((int(get_val()),str(get_val())))
self.sel.set_values((int(get_val()), str(get_val())))
self.obj.set_sensitive(not readonly)
self.obj.connect('changed', self.on_change)
@ -528,14 +528,14 @@ class MonitoredDataType:
if value[0] == self.get_val().get_custom():
return value
else:
return (value[0],'')
return (value[0], '')
def update(self):
val = self.get_val()
if type(val) == tuple :
self.sel.set_values(val)
else:
self.sel.set_values((int(val),str(val)))
self.sel.set_values((int(val), str(val)))
def on_change(self, obj):
value = self.fix_value(self.sel.get_values())
@ -543,7 +543,7 @@ class MonitoredDataType:
class MonitoredMenu:
def __init__(self, obj, set_val, get_val, mapping,
def __init__(self, obj, set_val, get_val, mapping,
readonly=False, changed=None):
self.set_val = set_val
self.get_val = get_val
@ -567,7 +567,7 @@ class MonitoredMenu:
self.data[v] = index
index += 1
self.obj.set_model(self.model)
self.obj.set_active(self.data.get(self.get_val(),0))
self.obj.set_active(self.data.get(self.get_val(), 0))
def on_change(self, obj):
self.set_val(self.model.get_value(obj.get_active_iter(), 1))
@ -622,7 +622,7 @@ class PlaceEntry:
Handles the selection of a existing or new Place. Supports Drag and Drop
to select a place.
"""
def __init__(self, dbstate, uistate, track, obj, set_val,
def __init__(self, dbstate, uistate, track, obj, set_val,
get_val, add_del, share):
self.obj = obj
@ -643,7 +643,7 @@ class PlaceEntry:
if get_val():
self.set_button(True)
p = self.db.get_place_from_handle(self.get_val())
name = "%s [%s]" % (p.get_title(),p.gramps_id)
name = "%s [%s]" % (p.get_title(), p.gramps_id)
else:
name = u""
self.set_button(False)
@ -665,7 +665,7 @@ class PlaceEntry:
obj.set_text(name)
def after_edit(self, place):
name = "%s [%s]" % (place.get_title(),place.gramps_id)
name = "%s [%s]" % (place.get_title(), place.gramps_id)
self.obj.set_text(name)
def add_del_clicked(self, obj):
@ -679,7 +679,7 @@ class PlaceEntry:
place = Place()
try:
EditPlace(self.dbstate, self.uistate, self.track,
EditPlace(self.dbstate, self.uistate, self.track,
place, self.place_added)
except WindowActiveError:
pass
@ -692,7 +692,7 @@ class PlaceEntry:
def place_added(self, data):
self.set_val(data.handle)
self.obj.set_text("%s [%s]" % (data.get_title(),data.gramps_id))
self.obj.set_text("%s [%s]" % (data.get_title(), data.gramps_id))
self.set_button(True)
def share_clicked(self, obj):
@ -701,7 +701,7 @@ class PlaceEntry:
place = self.db.get_place_from_handle(self.get_val())
try:
EditPlace(self.dbstate, self.uistate, self.track, place,
EditPlace(self.dbstate, self.uistate, self.track, place,
self.after_edit)
except WindowActiveError:
pass
@ -721,22 +721,22 @@ class PlaceEntry:
if use_add:
image = gtk.Image()
image.set_from_stock(gtk.STOCK_REMOVE,gtk.ICON_SIZE_BUTTON)
image.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_BUTTON)
image.show()
self.add_del.add(image)
image = gtk.Image()
image.set_from_stock(gtk.STOCK_EDIT,gtk.ICON_SIZE_BUTTON)
image.set_from_stock(gtk.STOCK_EDIT, gtk.ICON_SIZE_BUTTON)
image.show()
self.share.add(image)
self.tooltips.set_tip(self.share, _('Edit place'))
self.tooltips.set_tip(self.add_del, _('Remove place'))
else:
image = gtk.Image()
image.set_from_stock(gtk.STOCK_ADD,gtk.ICON_SIZE_BUTTON)
image.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON)
image.show()
self.add_del.add(image)
image = gtk.Image()
image.set_from_stock(gtk.STOCK_INDEX,gtk.ICON_SIZE_BUTTON)
image.set_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
image.show()
self.share.add(image)
self.tooltips.set_tip(self.share, _('Select an existing place'))
@ -747,7 +747,7 @@ class Statusbar(gtk.HBox):
Statusbar can have any number of fields included, each identified
by it's own bar id. It has by default one field with id = 0. This
defult field is used when no bar id is given in the relevant (push, pop,
defult field is used when no bar id is given in the relevant (push, pop,
etc.) methods, thus Statusbar behaves as a single gtk.Statusbar.
To add a new field use the "insert" method. Using the received bar id
@ -757,16 +757,16 @@ class Statusbar(gtk.HBox):
__gtype_name__ = 'Statusbar'
##__gsignals__ = {
##'text-popped': ,
##'text-pushed': ,
##'text-popped': ,
##'text-pushed': ,
##}
__gproperties__ = {
'has-resize-grip': (gobject.TYPE_BOOLEAN,
'Resize grip',
'Whether resize grip is visible',
True,
gobject.PARAM_READWRITE),
'has-resize-grip': (gobject.TYPE_BOOLEAN,
'Resize grip',
'Whether resize grip is visible',
True,
gobject.PARAM_READWRITE),
}
def __init__(self, min_width=30):
@ -812,7 +812,7 @@ class Statusbar(gtk.HBox):
def _set_resize_grip(self):
"""Set the resize grip for the statusbar.
Resize grip is disabled for all statusbars except the last one,
Resize grip is disabled for all statusbars except the last one,
which is set according to the "has-resize-grip" propery.
"""
@ -824,7 +824,7 @@ class Statusbar(gtk.HBox):
def _set_packing(self):
"""Set packing style of the statusbars.
All bars are packed with "expand"=True, "fill"=True parameters,
All bars are packed with "expand"=True, "fill"=True parameters,
except the last one, which is packed with "expand"=False, "fill"=False.
"""
@ -937,12 +937,12 @@ class FadeOut(gobject.GObject):
Call my methods start() and stop() to control the fading.
"""
__gsignals__ = {
'done': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
()),
'color-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
(gtk.gdk.Color,)),
'done': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
()),
'color-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
(gtk.gdk.Color, )),
}
# How long time it'll take before we start (in ms)
@ -975,8 +975,8 @@ class FadeOut(gobject.GObject):
rs += rinc
gs += ginc
bs += binc
col = gtk.gdk.color_parse("#%02X%02X%02X" % (int(rs) >> 8,
int(gs) >> 8,
col = gtk.gdk.color_parse("#%02X%02X%02X" % (int(rs) >> 8,
int(gs) >> 8,
int(bs) >> 8))
self.emit('color-changed', col)
yield True
@ -993,7 +993,7 @@ class FadeOut(gobject.GObject):
return
##log.debug('_start_merging: Starting')
func = self._merge_colors(self._start_color,
func = self._merge_colors(self._start_color,
gtk.gdk.color_parse(self.ERROR_COLOR)).next
self._background_timeout_id = (
gobject.timeout_add(FadeOut.MERGE_COLORS_DELAY, func))
@ -1034,7 +1034,7 @@ class FadeOut(gobject.GObject):
self._widget.update_background(self._start_color)
self._done = False
if gtk.pygtk_version < (2,8,0):
if gtk.pygtk_version < (2, 8, 0):
gobject.type_register(FadeOut)
class Tooltip(gtk.Window):
@ -1095,9 +1095,9 @@ class Tooltip(gtk.Window):
# from gtktooltips.c:gtk_tooltips_paint_window
def _on__expose_event(self, window, event):
w, h = window.size_request()
window.style.paint_flat_box(window.window,
gtk.STATE_NORMAL, gtk.SHADOW_OUT,
None, window, "tooltip",
window.style.paint_flat_box(window.window,
gtk.STATE_NORMAL, gtk.SHADOW_OUT,
None, window, "tooltip",
0, 0, w, h)
return False
@ -1124,17 +1124,17 @@ class Tooltip(gtk.Window):
if self._show_timeout_id != -1:
return
self._show_timeout_id = gobject.timeout_add(Tooltip.DEFAULT_DELAY,
self._real_display,
self._show_timeout_id = gobject.timeout_add(Tooltip.DEFAULT_DELAY,
self._real_display,
widget)
# This is tricky and contains quite a few hacks:
# An entry contains 2 GdkWindows, one for the background and one for
# the text area. The normal one, on which the (normally white) background
# is drawn can be accessed through entry.window (after realization)
# The other window is the one where the cursor and the text is drawn upon,
# The other window is the one where the cursor and the text is drawn upon,
# it's refered to as "text area" inside the GtkEntry code and it is called
# the same here. It can only be accessed through window.get_children()[0],
# the same here. It can only be accessed through window.get_children()[0],
# since it's considered private to the entry.
#
# +-------------------------------------+
@ -1149,7 +1149,7 @@ class Tooltip(gtk.Window):
# +-------------------------------------|
#
# So, now we want to put an icon in the edge:
# An earlier approached by Lorzeno drew the icon directly on the text area,
# An earlier approached by Lorzeno drew the icon directly on the text area,
# which is not desired since if the text is using the whole width of the
# entry the icon will be drawn on top of the text.
# Now what we want to do is to resize the text area and create a
@ -1168,7 +1168,7 @@ class Tooltip(gtk.Window):
#
# When resizing the text area the cursor and text is not moved into the
# correct position, it'll still be off by the width of the icon window
# To fix this we need to call a private function, gtk_entry_recompute,
# To fix this we need to call a private function, gtk_entry_recompute,
# a workaround is to call set_visiblity() which calls recompute()
# internally.
#
@ -1191,11 +1191,11 @@ class IconEntry(object):
self._entry = entry
self._tooltip = Tooltip(self)
self._locked = False
entry.connect('enter-notify-event',
entry.connect('enter-notify-event',
self._on_entry__enter_notify_event)
entry.connect('leave-notify-event',
entry.connect('leave-notify-event',
self._on_entry__leave_notify_event)
entry.connect('notify::xalign',
entry.connect('notify::xalign',
self._on_entry__notify_xalign)
self._update_position()
@ -1278,17 +1278,17 @@ class IconEntry(object):
self._text_area_pos = self._text_area.get_position()
# PyGTK should allow default values for most of the values here.
win = gtk.gdk.Window(entry.window,
self._pixw, self._pixh,
gtk.gdk.WINDOW_CHILD,
win = gtk.gdk.Window(entry.window,
self._pixw, self._pixh,
gtk.gdk.WINDOW_CHILD,
(gtk.gdk.ENTER_NOTIFY_MASK |
gtk.gdk.LEAVE_NOTIFY_MASK),
gtk.gdk.INPUT_OUTPUT,
'icon window',
0, 0,
entry.get_visual(),
entry.get_colormap(),
gtk.gdk.Cursor(entry.get_display(), gtk.gdk.LEFT_PTR),
gtk.gdk.LEAVE_NOTIFY_MASK),
gtk.gdk.INPUT_OUTPUT,
'icon window',
0, 0,
entry.get_visual(),
entry.get_colormap(),
gtk.gdk.Cursor(entry.get_display(), gtk.gdk.LEFT_PTR),
'', '', True)
self._icon_win = win
win.set_user_data(entry)
@ -1365,13 +1365,13 @@ class IconEntry(object):
# Draw background first
color = self._entry.style.base_gc[self._entry.state]
win.draw_rectangle(color, True,
win.draw_rectangle(color, True,
0, 0, self._pixw, self._pixh)
# If sensitive draw the icon, regardless of the window emitting the
# event since makes it a bit smoother on resize
if self._entry.flags() & gtk.SENSITIVE:
win.draw_pixbuf(None, self._pixbuf, 0, 0, 0, 0,
win.draw_pixbuf(None, self._pixbuf, 0, 0, 0, 0,
self._pixw, self._pixh)
def _update_position(self):
@ -1403,17 +1403,17 @@ HAVE_2_6 = gtk.pygtk_version[:2] == (2, 6)
(DIRECTION_LEFT, DIRECTION_RIGHT) = (1, -1)
(INPUT_ASCII_LETTER,
INPUT_ALPHA,
INPUT_ALPHANUMERIC,
(INPUT_ASCII_LETTER,
INPUT_ALPHA,
INPUT_ALPHANUMERIC,
INPUT_DIGIT) = range(4)
INPUT_FORMATS = {
'0': INPUT_DIGIT,
'L': INPUT_ASCII_LETTER,
'A': INPUT_ALPHANUMERIC,
'a': INPUT_ALPHANUMERIC,
'&': INPUT_ALPHA,
'0': INPUT_DIGIT,
'L': INPUT_ASCII_LETTER,
'A': INPUT_ALPHANUMERIC,
'a': INPUT_ALPHANUMERIC,
'&': INPUT_ALPHA,
}
# Todo list: Other usefull Masks
@ -1422,13 +1422,13 @@ INPUT_FORMATS = {
# C - Alpha, optional
INPUT_CHAR_MAP = {
INPUT_ASCII_LETTER: lambda text: text in string.ascii_letters,
INPUT_ALPHA: unicode.isalpha,
INPUT_ALPHANUMERIC: unicode.isalnum,
INPUT_DIGIT: unicode.isdigit,
INPUT_ASCII_LETTER: lambda text: text in string.ascii_letters,
INPUT_ALPHA: unicode.isalpha,
INPUT_ALPHANUMERIC: unicode.isalnum,
INPUT_DIGIT: unicode.isdigit,
}
(COL_TEXT,
(COL_TEXT,
COL_OBJECT) = range(2)
class MaskedEntry(gtk.Entry):
@ -1455,7 +1455,7 @@ class MaskedEntry(gtk.Entry):
self.connect('focus-out-event', self._on_focus_out_event)
self.connect('move-cursor', self._on_move_cursor)
self.connect('button-press-event', self._on_button_press_event)
self.connect('notify::cursor-position',
self.connect('notify::cursor-position',
self._on_notify_cursor_position)
self._completion = None
@ -1482,7 +1482,7 @@ class MaskedEntry(gtk.Entry):
# Virtual methods
# PyGTK 2.6 does not support the virtual method do_size_allocate so
# we have to use the signal instead
# PyGTK 2.9.0 and later (bug #327715) does not work using the old code,
# PyGTK 2.9.0 and later (bug #327715) does not work using the old code,
# so we have to make this conditionally
if HAVE_2_6:
gsignal('size-allocate', 'override')
@ -1675,7 +1675,7 @@ class MaskedEntry(gtk.Entry):
start, end = self._mask_fields[field]
return end - start
def _shift_text(self, start, end, direction=DIRECTION_LEFT,
def _shift_text(self, start, end, direction=DIRECTION_LEFT,
positions=1):
"""
Shift the text, to the right or left, n positions. Note that this
@ -1705,11 +1705,11 @@ class MaskedEntry(gtk.Entry):
# Non-static char shoud be here. Get the next one (depending
# on the direction, and the number of positions to skip.)
#
# When shifting left, the next char will be on the right,
# When shifting left, the next char will be on the right,
# so, it will be appended, to the new text.
# Otherwise, when shifting right, the char will be
# prepended.
next_pos = self._get_next_non_static_char_pos(i, direction,
next_pos = self._get_next_non_static_char_pos(i, direction,
positions-1)
# If its outside the bounds of the region, ignore it.
@ -1737,7 +1737,7 @@ class MaskedEntry(gtk.Entry):
return new_text
def _get_next_non_static_char_pos(self, pos, direction=DIRECTION_LEFT,
def _get_next_non_static_char_pos(self, pos, direction=DIRECTION_LEFT,
skip=0):
"""
Get next non-static char position, skiping some chars, if necessary.
@ -1827,7 +1827,7 @@ class MaskedEntry(gtk.Entry):
def _get_completion(self):
# Check so we have completion enabled, not this does not
# depend on the property, the user can manually override it,
# depend on the property, the user can manually override it,
# as long as there is a completion object set
completion = self.get_completion()
if completion:
@ -1846,7 +1846,7 @@ class MaskedEntry(gtk.Entry):
#completion.set_model(gtk.ListStore(str, object))
completion.set_model(gtk.ListStore(str))
completion.set_text_column(0)
#completion.connect("match-selected",
#completion.connect("match-selected",
#self._on_completion__match_selected)
self._completion = gtk.Entry.get_completion(self)
@ -1920,7 +1920,7 @@ class MaskedEntry(gtk.Entry):
@param new: The char that wants to be inserted.
@param pos: The position where it wants to be inserted.
@return: Returns None if it can be inserted. If it cannot be,
@return: Returns None if it can be inserted. If it cannot be,
return the next position where it can be successfuly
inserted.
"""
@ -1954,7 +1954,7 @@ class MaskedEntry(gtk.Entry):
return None
# When inserting new text, supose, the entry, at some time is like this,
# When inserting new text, supose, the entry, at some time is like this,
# ahd the user presses '0', for instance:
# --------------------------------
# | ( 1 2 ) 3 4 5 - 6 7 8 9 |
@ -2105,7 +2105,7 @@ class MaskedEntry(gtk.Entry):
# Shift Left
new_text = (text[:start] +
self._shift_text(start, _end, DIRECTION_LEFT,
self._shift_text(start, _end, DIRECTION_LEFT,
end-start) +
text[_end:])
@ -2271,9 +2271,9 @@ class MaskedEntry(gtk.Entry):
else:
values[item] = None
model.append((item,))
model.append((item, ))
if gtk.pygtk_version < (2,8,0):
if gtk.pygtk_version < (2, 8, 0):
gobject.type_register(MaskedEntry)
#number = (int, float, long)
@ -2293,32 +2293,32 @@ class ValidatableMaskedEntry(MaskedEntry):
__gtype_name__ = 'ValidatableMaskedEntry'
__gsignals__ = {
'content-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
()),
'validation-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
(gobject.TYPE_BOOLEAN,)),
'validate': (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_PYOBJECT,
(gobject.TYPE_PYOBJECT,)),
'changed': 'override',
'content-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
()),
'validation-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
(gobject.TYPE_BOOLEAN, )),
'validate': (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_PYOBJECT,
(gobject.TYPE_PYOBJECT, )),
'changed': 'override',
}
__gproperties__ = {
'data-type': (gobject.TYPE_PYOBJECT,
'Data Type of the widget',
'Type object',
gobject.PARAM_READWRITE),
'mandatory': (gobject.TYPE_BOOLEAN,
'Mandatory',
'Mandatory',
False,
gobject.PARAM_READWRITE),
'data-type': (gobject.TYPE_PYOBJECT,
'Data Type of the widget',
'Type object',
gobject.PARAM_READWRITE),
'mandatory': (gobject.TYPE_BOOLEAN,
'Mandatory',
'Mandatory',
False,
gobject.PARAM_READWRITE),
}
# FIXME put the data type support back
#allowed_data_types = (basestring, datetime.date, datetime.time,
#allowed_data_types = (basestring, datetime.date, datetime.time,
#datetime.datetime, object) + number
def __init__(self, data_type=None, err_color = "#ffd5d5", error_icon=ERROR_ICON):
@ -2367,8 +2367,8 @@ class ValidatableMaskedEntry(MaskedEntry):
#if not issubclass(value, self.allowed_data_types):
#raise TypeError(
#"%s only accept %s types, not %r"
#% (self,
#' or '.join([t.__name__ for t in self.allowed_data_types]),
#% (self,
#' or '.join([t.__name__ for t in self.allowed_data_types]),
#value))
self.data_type = value
elif prop.name == 'mandatory':
@ -2565,10 +2565,9 @@ class ValidatableMaskedEntry(MaskedEntry):
def _on_fadeout__color_changed(self, fadeout, color):
self.update_background(color)
if gtk.pygtk_version < (2,8,0):
if gtk.pygtk_version < (2, 8, 0):
gobject.type_register(ValidatableMaskedEntry)
def main(args):
from DateHandler import parser
@ -2621,7 +2620,7 @@ def main(args):
statusbar.push(1, "A short one", yet_another_statusbar)
last_statusbar = statusbar.insert(min_width=41, ralign=True)
statusbar.push(1, "The last statusbar has always fixed width",
statusbar.push(1, "The last statusbar has always fixed width",
last_statusbar)
# =========================================================================

File diff suppressed because it is too large Load Diff