def write_report(self): # Header with user details self.add_header() # Pagenumber and date #TODO: how to get pagenr and total pages at this point? # self.doc.start_paragraph("pagenr") # self.doc.write_text("") # self.doc.end_paragraph() # Actual results self.headermap = { "date": _("Date"), "point": _("Racepoint"), "ring": _("Band no."), "placestr": _("Placed"), "out": _("Out of"), "type": _("Type"), "wind": _("Wind"), "weather": _("Weather"), "coefstr": _("Coef."), "sector": _("Sector"), "category": _("Category"), "comment": _("Comment") } if config.get("interface.results-mode") == 0: self._do_report_classic() elif config.get("interface.results-mode") == 1: self._do_report_splitted()
def _cell_func(self, column, cell, model, rowiter): show = model.get_value(rowiter, 0).show color = "white" if config.get("interface.missing-pigeon-color"): if not show: color = config.get("interface.missing-pigeon-color-value") cell.set_property("cell-background", color)
def __init__(self): gtk.Window.__init__(self) builder.GtkBuilder.__init__(self, "MainWindow.ui") component.Component.__init__(self, "MainWindow") self.widgets.treeview = treeview.MainTreeView() self.widgets.treeview.connect("pigeons-changed", self.on_treeview_pigeons_changed) self.widgets.treeview.connect("key-press-event", self.on_treeview_key_press) self.widgets.treeview.connect("button-press-event", self.on_treeview_press) self.widgets.scrolledwindow.add(self.widgets.treeview) self.widgets.selection = self.widgets.treeview.get_selection() self.widgets.selection.connect("changed", self.on_selection_changed) self.pedigree = pedigree.DrawPedigree() self.detailsview = detailsview.DetailsView(self, True) self.widgets.aligndetails.add(self.detailsview.get_root_widget()) pedigreetab = tabs.PedigreeTab(self.pedigree) relativestab = tabs.RelativesTab() self.resultstab = tabs.ResultsTab() breedingtab = tabs.BreedingTab() mediatab = tabs.MediaTab() medicationtab = tabs.MedicationTab() self._loaded_tabs = [pedigreetab, relativestab, self.resultstab, breedingtab, mediatab, medicationtab] for tab in self._loaded_tabs: self.widgets.notebook.append_page(*tab.get_tab_widgets()) self._build_menubar() self.widgets.treeview.fill_treeview() self.current_pigeon = 0 self.pigeon_no = len(self.widgets.treeview.get_model()) self.widgets.removedialog.set_transient_for(self) self.widgets.rangedialog.set_transient_for(self) self.widgets.MenuShowAll.set_active(config.get("interface.show-all-pigeons")) self.widgets.MenuArrows.set_active(config.get("interface.arrows")) self.widgets.MenuStats.set_active(config.get("interface.stats")) self.widgets.MenuToolbar.set_active(config.get("interface.toolbar")) self.widgets.MenuStatusbar.set_active(config.get("interface.statusbar")) self.connect("delete-event", self.quit_program) self.set_title(const.NAME) self.set_icon_from_file(os.path.join(const.IMAGEDIR, "icon_logo.png")) self.add(self.widgets.mainvbox) self.resize(config.get("interface.window-w"), config.get("interface.window-h")) self.move(config.get("interface.window-x"), config.get("interface.window-y")) self.show() self.widgets.treeview.grab_focus() if gtkosx is not None: def osx_quit(*args): self.quit_program(bckp=False) return False gtkosx.connect("NSApplicationBlockTermination", osx_quit) gtkosx.ready()
def begin_report(self): name = "" colour = "" sex = "" if config.get("printing.pedigree-name") and self._pigeon is not None and\ self._pigeon.get_name(): name = "%s - " % self._pigeon.get_name() if config.get("printing.pedigree-colour") and self._pigeon is not None and\ self._pigeon.get_colour(): colour = "%s - " % self._pigeon.get_colour() if config.get("printing.pedigree-sex") and self._pigeon is not None: sex = self._pigeon.get_sex_string() self.pigeoninfo = name + colour + sex
def _do_report_classic(self): columns = ["ring", "date", "point", "placestr", "out"] if config.get("columns.result-coef"): columns.append("coefstr") if config.get("columns.result-sector"): columns.append("sector") if config.get("columns.result-type"): columns.append("type") if config.get("columns.result-category"): columns.append("category") if config.get("columns.result-weather"): columns.append("wind") if config.get("columns.result-wind"): columns.append("weather") if config.get("columns.result-comment"): columns.append("comment") self._add_table_style([columnsize[col] for col in columns]) self.doc.start_table("my_table", "table") if config.get("printing.result-colnames"): self.doc.start_row() for name in columns: self.add_cell(self.headermap[name], "headercell", "colheader") self.doc.end_row() # data = [{}] for item in self._data: self.doc.start_row() for name in columns: self.add_cell(str(item[name]), "cell", "celltext") self.doc.end_row() self.doc.end_table()
def set_columns(self): columnsdic = { self.COL_COEF: config.get("columns.result-coef"), self.COL_SPEED: config.get("columns.result-speed"), self.COL_SECTOR: config.get("columns.result-sector"), self.COL_TYPE: config.get("columns.result-type"), self.COL_CATEGORY: config.get("columns.result-category"), self.COL_WIND: config.get("columns.result-wind"), self.COL_WINDSPEED: config.get("columns.result-windspeed"), self.COL_WEATHER: config.get("columns.result-weather"), self.COL_TEMPERATURE: config.get("columns.result-temperature"), self.COL_COMMENT: config.get("columns.result-comment") } for key, value in columnsdic.items(): self.treeview.get_column(key).set_visible(value)
def _do_report_splitted(self): racecolumns = ["date", "point"] if config.get("columns.result-type"): racecolumns.append("type") if config.get("columns.result-weather"): racecolumns.append("wind") if config.get("columns.result-wind"): racecolumns.append("weather") resultcolumns = ["ring", "placestr", "out"] if config.get("columns.result-coef"): resultcolumns.append("coefstr") if config.get("columns.result-sector"): resultcolumns.append("sector") if config.get("columns.result-category"): resultcolumns.append("category") if config.get("columns.result-comment"): resultcolumns.append("comment") columns = racecolumns + resultcolumns dummyrace = { "date": "", "point": "", "type": "", "wind": "", "weather": "" } self._add_table_style([columnsize[col] for col in columns]) self.doc.start_table("my_table", "table") if config.get("printing.result-colnames"): self.doc.start_row() for name in columns: self.add_cell(self.headermap[name], "headercell", "colheader") self.doc.end_row() # data = [{"race": {}, "results": [{}, {}]}] for item in self._data: self.doc.start_row() for name in racecolumns: value = item["race"][name] self.add_cell(str(value), "cell", "celltext") for name in resultcolumns: value = item["results"][0][name] self.add_cell(str(value), "cell", "celltext") self.doc.end_row() for result in item["results"][1:]: self.doc.start_row() for name in racecolumns: value = dummyrace[name] self.add_cell(str(value), "cell", "celltext") for name in resultcolumns: value = result[name] self.add_cell(str(value), "cell", "celltext") self.doc.end_row() self.doc.end_table()
def get_pagesize_from_opts(): optvalue = config.get("printing.general-paper") if optvalue == 0: psize = "A4" elif optvalue == 1: psize = "Letter" return psize
def do_operation(self, print_action, save_path=None): userinfo = common.get_own_address() if not tools.check_user_info(self, userinfo["name"]): return # Show a message to the user if the original image is not found and # can't be shown on the pedigree if config.get("printing.pedigree-image") and self.pigeon.image is not None: if not os.path.exists(self.pigeon.image): msg = (_("Cannot find image '%s'"), _("You need to edit the pigeon and select the correct " "path or restore the original image on your computer."), "") # In some very old versions, an empty image was stored as an # empty string instead of None. Don't show this message in cases # like this ofcourse. if not self.pigeon.image == "": InfoDialog(msg, self, self.pigeon.image) PedigreeReport, PedigreeReportOptions = get_pedigree() psize = common.get_pagesize_from_opts() opts = PedigreeReportOptions(psize, print_action=print_action, filename=save_path, parent=self) try: report(PedigreeReport, opts, self.pigeon, userinfo) except ReportError as exc: ErrorDialog((exc.value.split("\n")[0], _("You probably don't have write permissions on this folder."), _("Error")) )
def add_header(self): """ Add a header with user info to the report. Note: this method assumes there is a self._userinfo """ self.doc.start_paragraph("header") if config.get("printing.user-name"): self.doc.write_text(self._userinfo["name"] + "\n") if config.get("printing.user-address"): self.doc.write_text(self._userinfo["street"] + "\n") self.doc.write_text("%s %s\n" % (self._userinfo["code"], self._userinfo["city"])) if config.get("printing.user-phone"): self.doc.write_text(self._userinfo["phone"] + "\n") if config.get("printing.user-email"): self.doc.write_text(self._userinfo["email"]) self.doc.end_paragraph()
def reset_result_mode(self): if self.widgets.resultview.ID != config.get("interface.results-mode"): self.widgets.resultview.destroy() view = get_view_for_current_config() self.widgets.resultview = view(self.widgets._root) if self.pigeon is not None: # The result mode is changed on an empty database and no pigeon # has been set before. self.widgets.resultview.set_pigeon(self.pigeon)
def setup_locale(self, gtk_ui): from pigeonplanner.core import config language = config.get("options.language") localedomain = const.DOMAIN localedir = const.LANGDIR if language in ("def", "Default"): if const.OSX: #TODO: get default language language = "C" else: language = "" try: language = os.environ["LANG"] except KeyError: language = locale.getlocale()[0] if not language: try: language = locale.getdefaultlocale()[0] + ".UTF-8" except (TypeError, ValueError): pass else: language = locale.normalize(language).split(".")[0] + ".UTF-8" os.environ["LANG"] = language os.environ["LANGUAGE"] = language gettext.bindtextdomain(localedomain, localedir) gettext.bind_textdomain_codeset(localedomain, "UTF-8") gettext.textdomain(localedomain) gettext.install(localedomain, localedir, unicode=True) try: locale.bindtextdomain(localedomain, localedir) except AttributeError: # locale has no bindtextdomain on Windows, fall back to intl.dll if const.WINDOWS: if gtk_ui and hasattr(sys, "frozen"): # There is a weird issue where cdll.intl throws an exception # when built with py2exe. Apparently GTK links some libraries # on import (details needed!). So this is a little workaround # to detect if we're running a py2exe'd package and the gtk # interface is requested. # Also shut up any code analysers... import gtk gtk from ctypes import cdll cdll.msvcrt._putenv("LANG=%s" % language) cdll.msvcrt._putenv("LANGUAGE=%s" % language) libintl = cdll.intl libintl.bindtextdomain(localedomain, localedir) libintl.bind_textdomain_codeset(localedomain, "UTF-8") libintl.textdomain(localedomain) del libintl
def get_pedigree(layout=None): if layout is None: layout = config.get("printing.pedigree-layout") if layout == 0: from .pedigrees.original import PedigreeReport, PedigreeReportOptions elif layout == 1: from .pedigrees.swapped_details import PedigreeReport, PedigreeReportOptions elif layout == 2: from .pedigrees.middle import PedigreeReport, PedigreeReportOptions return PedigreeReport, PedigreeReportOptions
def calculate_coefficient(place, out, as_string=False): """ Calculate the coefficient of a result @param place: The pigeons place @param out: The total number of pigeons @param as_string: Return a localized string """ coef = (float(place) / float(out)) * config.get("options.coef-multiplier") if as_string: return locale.format_string("%.4f", coef) return coef
def quit_program(self, widget=None, event=None, bckp=True): try: database.session.optimize_database() except Exception as exc: logger.error("Database optimizing failed: %s", exc) database.session.close() x, y = self.get_position() w, h = self.get_size() config.set("interface.window-x", x) config.set("interface.window-y", y) config.set("interface.window-w", w) config.set("interface.window-h", h) if config.get("backup.automatic-backup") and bckp: daysInSeconds = config.get("backup.interval") * 24 * 60 * 60 if time.time() - config.get("backup.last") >= daysInSeconds: if backup.make_backup(config.get("backup.location")): InfoDialog(messages.MSG_BACKUP_SUCCES, self) else: InfoDialog(messages.MSG_BACKUP_FAILED, self) config.set("backup.last", time.time()) config.save() gtk.main_quit()
def run_ui(dbcode): formatter = logging.Formatter(const.LOG_FORMAT) handler = GtkLogHandler() handler.setFormatter(formatter) handler.setLevel(logging.CRITICAL) logger.addHandler(handler) logger.debug("Python version: %s" % ".".join(map(str, sys.version_info[:3]))) logger.debug("GTK+ version: %s" % ".".join(map(str, gtk.gtk_version))) logger.debug("PyGTK version: %s" % ".".join(map(str, gtk.pygtk_version))) setup_icons() from pigeonplanner import database if dbcode == database.DATABASE_TOO_NEW: from pigeonplanner import messages from pigeonplanner.ui.messagedialog import ErrorDialog ErrorDialog(messages.MSG_NEW_DATABASE) sys.exit(0) elif dbcode == database.DATABASE_CHANGED: from pigeonplanner import messages from pigeonplanner.ui.messagedialog import InfoDialog InfoDialog(messages.MSG_UPDATED_DATABASE) elif dbcode == database.DATABASE_ERROR: from pigeonplanner import messages from pigeonplanner.ui.messagedialog import ErrorDialog ErrorDialog(messages.MSG_ERROR_DATABASE) sys.exit(0) # Import widgets that are used in GtkBuilder files from pigeonplanner.ui.widgets import statusbar from pigeonplanner.ui.widgets import checkbutton from pigeonplanner.ui.widgets import latlongentry from pigeonplanner.ui import mainwindow mainwindow.MainWindow() from pigeonplanner.core import config if config.get("options.check-for-updates"): updatethread = Thread(None, search_updates, None) updatethread.start() gtk.main()
def __init__(self): store = gtk.ListStore(str, float) gtk.ComboBox.__init__(self, store) units = ((_("Yard per Minute"), 0.01524), (_("Metres per Minute"), 0.0166666666), (_("Metres per Second"), 1.), (_("Kilometre per Hour"), 0.27777777777777777777777777777777), (_("Feet per Second"), 0.3048), (_("Feet per Minute"), 0.00508), (_("Mile per Hour"), 0.44704) ) for unit in units: store.append(unit) cell = gtk.CellRendererText() self.pack_start(cell, True) self.add_attribute(cell, "text", 0) self.set_active(config.get("options.speed-unit")) self.show()
def fill_treeview(self, path=0): self._liststore.clear() for pindex, pigeon in pigeonparser.parser.pigeons.items(): if not config.get( "interface.show-all-pigeons") and not pigeon.get_visible(): continue ring, year = pigeon.get_band() self._liststore.insert(0, [ pigeon, pindex, ring, year, pigeon.get_name(), pigeon.get_colour(), pigeon.get_sex_string(), pigeon.get_loft(), pigeon.get_strain(), pigeon.get_status(), utils.get_sex_image(pigeon.sex) ]) self._selection.select_path(path) self.emit("pigeons-changed")
def __init__(self): store = gtk.ListStore(str, float) gtk.ComboBox.__init__(self, store) units = ((_("Yards"), 0.9144), (_("Kilometres"), 1000.), (_("Metres"), 1.), (_("Centimetres"), 0.01), (_("Inches"), 0.025), (_("Feet"), 0.3048), (_("Miles"), 1609.344), (_("Nautical Miles"), 1852.) ) for unit in units: store.append(unit) cell = gtk.CellRendererText() self.pack_start(cell, True) self.add_attribute(cell, "text", 0) self.set_active(config.get("options.distance-unit")) self.show()
def set_columns(self): columnsdic = { 2: config.get("columns.pigeon-name"), 3: config.get("columns.pigeon-colour"), 4: config.get("columns.pigeon-sex"), 5: config.get("columns.pigeon-loft"), 6: config.get("columns.pigeon-strain"), 7: config.get("columns.pigeon-status") } for key, value in columnsdic.items(): self.get_column(key).set_visible(value) if key == 4 and value: sexcoltype = config.get("columns.pigeon-sex-type") for renderer in self.get_column(key).get_cell_renderers(): if isinstance(renderer, gtk.CellRendererText): text = renderer else: pixbuf = renderer text.set_visible(sexcoltype == 1 or sexcoltype == 3) pixbuf.set_visible(sexcoltype == 2 or sexcoltype == 3)
def write_report(self): # Header with user details self.add_header() # Pigeon table #TODO: column size with different columns columns = [(_("Band no."), "get_band_string")] if config.get("columns.pigeon-sex") or config.get( "printing.pigeon-sex"): columns.append((_("Sex"), "get_sex_string")) if config.get("columns.pigeon-name"): columns.append((_("Name"), "get_name")) if config.get("columns.pigeon-colour"): columns.append((_("Colour"), "get_colour")) if config.get("columns.pigeon-loft"): columns.append((_("Loft"), "get_loft")) if config.get("columns.pigeon-strain"): columns.append((_("Strain"), "get_strain")) if config.get("columns.pigeon-status"): columns.append((_("Status"), "get_status")) self.doc.start_table("my_table", "table") if config.get("printing.pigeon-colnames"): self.doc.start_row() for name, method in columns: self.add_cell(name, "headercell", "colheader") self.doc.end_row() for pigeon in self._pigeons: self.doc.start_row() for name, method in columns: self.add_cell(getattr(pigeon, method)(), "cell", "celltext") self.doc.end_row() self.doc.end_table()
def update(): local = os.path.join(const.TEMPDIR, "pigeonplanner_update") try: urllib.urlretrieve(const.UPDATEURL, local) with open(local, "r") as versionfile: versiondict = json.load(versionfile) except IOError as exc: logger.error(exc) raise UpdateError(messages.MSG_CONNECTION_ERROR) try: os.remove(local) except: pass # See what version we need to check for dev = versiontuple(versiondict["dev"]) stable = versiontuple(versiondict["stable"]) if config.get("options.check-for-dev-updates"): if stable > dev: version = stable else: version = dev else: version = stable new = False current = const.VERSION_TUPLE if current < version: msg = messages.MSG_UPDATE_AVAILABLE new = True elif current == version: msg = messages.MSG_NO_UPDATE elif current > version: msg = messages.MSG_UPDATE_DEVELOPMENT return new, msg
def get_view_for_current_config(): if config.get("interface.results-mode") == ClassicView.ID: return ClassicView else: return SplittedView
def write_report(self): self.doc.start_page() # Title line band = self._pigeon.get_band_string(True) if self._pigeon is not None else "" x_cm = self.get_right_align_x("Title", band) self.doc.draw_text("Title", _("Pedigree of:"), .1, 0) self.doc.draw_text("Title", band, x_cm, 0) self.doc.draw_line("Seperator", 0, .8, self.doc.get_usable_width(), .8) # Header ## User info header_x = .1 header_y = 1.2 header_y_offset = .4 if config.get("printing.user-name"): self.doc.draw_text("Header", self._userinfo["name"], header_x, header_y) header_y += header_y_offset if config.get("printing.user-address"): self.doc.draw_text("Header", self._userinfo["street"], header_x, header_y) header_y += header_y_offset self.doc.draw_text("Header", "%s %s" % (self._userinfo["code"], self._userinfo["city"]), header_x, header_y) header_y += header_y_offset if config.get("printing.user-phone"): self.doc.draw_text("Header", self._userinfo["phone"], header_x, header_y) header_y += header_y_offset if config.get("printing.user-email"): self.doc.draw_text("Header", self._userinfo["email"], header_x, header_y) ## Draw image if config.get("printing.pedigree-image") and self._pigeon is not None and\ self._pigeon.image: img_x = self.doc.get_usable_width() img_y = 1 img_w = 6 img_h = 3 self.doc.draw_image(self._pigeon.image, img_x, img_y, img_w, img_h, xalign="right", yalign="top") ## Seperator self.doc.draw_line("Seperator", 0, 4.2, self.doc.get_usable_width(), 4.2) # Pedigree lst = [None]*31 corepigeon.build_pedigree_tree(self._pigeon, 0, 1, lst) header_bottom = 3.0 h_sep = .2 w_sep = .2 w = (self.doc.get_usable_width() / 4) - w_sep h_total = self.doc.get_usable_height() - (header_bottom + .2) y_start = header_bottom + .2 y_div = (h_total / 16) + y_start if config.get("printing.pedigree-box-colour"): h0, h1, h2, h3, h4 = 3.4, 3.1, 3.1, 1.9, 0.9 else: h0, h1, h2, h3, h4 = 3.1, 2.8, 2.8, 1.6, 0.9 for index, pigeon in enumerate(lst): # Calculate box positions for each vertical row if index == 0: n_lines = 6 x = 0 h = h0 y_mid = y_div + ((h4 * 16 + h_sep * 15) / 2) y = y_mid - (h / 2) y_offset = (h4 * 8) + (h_sep * 8) left = False right = False first = True last = False elif index == 1: n_lines = 6 x = 0 h = h1 y_mid = y_div + ((h4 * 8 + h_sep * 7) / 2) y = y_mid - (h / 2) y_offset = (h4 * 8) + (h_sep * 8) left = False right = True first = False last = False elif index == 3: n_lines = 6 x += w + w_sep h = h2 y_mid = y_div + ((h4 * 4 + h_sep * 3) / 2) y = y_mid - (h / 2) y_offset = (h4 * 4) + (h_sep * 4) left = True right = True first = False last = False elif index == 7: n_lines = 3 x += w + w_sep h = h3 y_mid = y_div + ((h4 * 2 + h_sep) / 2) y = y_mid - (h / 2) y_offset = (h4 * 2) + (h_sep * 2) left = True right = True first = False last = False elif index == 15: n_lines = 1 x += w + w_sep h = h4 y_mid = y_div + h / 2 y = y_div y_offset = h + h_sep left = True right = False first = False last = True # Get the text if pigeon is not None: text = pigeon.get_band_string(True) ex1, ex2, ex3, ex4, ex5, ex6 = pigeon.get_extra() if first: text += "\n" + pigeon.get_sex_string() if not last and config.get("printing.pedigree-box-colour"): text += "\n" + pigeon.get_colour() else: text = "" ex1, ex2, ex3, ex4, ex5, ex6 = ("", "", "", "", "", "") if n_lines >= 1: text += "\n" + ex1 if n_lines >= 3: text += "\n" + ex2 text += "\n" + ex3 if n_lines == 6: text += "\n" + ex4 text += "\n" + ex5 text += "\n" + ex6 # Draw box with text self.doc.draw_box("Pedigree", text, x, y, w, h) # Draw pedigree lines if right: self.doc.draw_line("PedigreeLine", x + w, y_mid, x + w + (w_sep / 2), y_mid) if left: self.doc.draw_line("PedigreeLine", x, y_mid, x - (w_sep / 2), y_mid) if index % 2 == 1: self.doc.draw_line("PedigreeLine", x - (w_sep / 2), y_mid, x - (w_sep / 2), y_mid + y_offset) if first: self.doc.draw_line("PedigreeLine", x + w/2, y, x + w/2, y - 3) self.doc.draw_line("PedigreeLine", x + w/2, y + h, x + w/2, y + h + 3) # Increase y position for next box y += y_offset y_mid += y_offset self.doc.end_page()
def write_report(self): self.doc.start_page() w_center = self.doc.get_usable_width() / 2. h_center = self.doc.get_usable_height() / 2. # Header band = self._pigeon.get_band_string(True) if self._pigeon is not None else "" title = _("Pedigree of:") + (" %s" % band) self.doc.center_text("Title", title, w_center, 0) self.doc.draw_line("Seperator", 0, 1, self.doc.get_usable_width(), 1) # User info userinfo = [] if config.get("printing.user-name"): userinfo.append(self._userinfo["name"]) if config.get("printing.user-address"): userinfo.append(self._userinfo["street"]) userinfo.append("%s %s" % (self._userinfo["code"], self._userinfo["city"])) if config.get("printing.user-phone"): userinfo.append(self._userinfo["phone"]) if config.get("printing.user-email"): userinfo.append(self._userinfo["email"]) header_y = self.doc.get_usable_height() - 3 self.doc.center_text("User", "\n".join(userinfo), w_center, header_y) if config.get("printing.pedigree-image") and self._pigeon is not None and\ self._pigeon.image: img_x = w_center img_y = 2 img_w = 7 img_h = 4 self.doc.draw_image(self._pigeon.image, img_x, img_y, img_w, img_h, xalign="center", yalign="top") # Pedigree lst = [None]*31 corepigeon.build_pedigree_tree(self._pigeon, 0, 1, lst) h_sep = .2 w_sep = .2 w = (self.doc.get_usable_width() / 5) - (w_sep * 3) h = 3.1 x_0 = w_center - (w / 2.) x_left_1 = w_center - w - w / 2. - w_sep * 2 x_left_2 = w_center - w - w / 1.6 - w_sep * 2 x_left_3 = w_center - w * 2. - w / 1.6 - w_sep * 4 x_right_1 = w_center - (w / 2.) + w + w_sep * 2 x_right_2 = w_center + w / 1.6 + w_sep * 2 x_right_3 = w_center + w + w / 1.6 + w_sep * 4 y_1 = h_center - h * 2. - h_sep * 5 y_2 = h_center - h - h / 2. - h_sep * 4 y_3 = h_center - h - h_sep * 3 y_4 = h_center - (h / 2.) y_5 = h_center + h_sep * 3 y_6 = h_center + h / 2. + h_sep * 4 y_7 = h_center + h + h_sep * 5 posmap = {0: {"x": x_0, "y": y_4}, 1: {"x": x_left_1, "y": y_4}, 2: {"x": x_right_1, "y": y_4}, 3: {"x": x_left_2, "y": y_2}, 4: {"x": x_left_2, "y": y_6}, 5: {"x": x_right_2, "y": y_2}, 6: {"x": x_right_2, "y": y_6}, 7: {"x": x_left_3, "y": y_1}, 8: {"x": x_left_3, "y": y_3}, 9: {"x": x_left_3, "y": y_5}, 10: {"x": x_left_3, "y": y_7}, 11: {"x": x_right_3, "y": y_1}, 12: {"x": x_right_3, "y": y_3}, 13: {"x": x_right_3, "y": y_5}, 14: {"x": x_right_3, "y": y_7}, } for index, pigeon in enumerate(lst): try: x = posmap[index]["x"] y = posmap[index]["y"] except KeyError: break # Get the text if pigeon is not None: text = [pigeon.get_band_string(True)] ex1, ex2, ex3, ex4, ex5, ex6 = pigeon.get_extra() if config.get("printing.pedigree-box-colour"): text.append(pigeon.get_colour()) else: text = [""] ex1, ex2, ex3, ex4, ex5, ex6 = ("", "", "", "", "", "") for ex in ex1, ex2, ex3, ex4, ex5, ex6: text.append(ex) self.doc.draw_box("Pedigree", "\n".join(text), x, y, w, h) # Pedigree lines # Box 0 to 1 and 2 y = y_4 + h / 2. self.doc.draw_line("PedigreeLine", x_0, y, x_0 - w_sep * 2, y) self.doc.draw_line("PedigreeLine", x_0 + w, y, x_0 + w + w_sep * 2, y) # Box 1 to 3 and 4 x = x_left_1 + w / 2. self.doc.draw_line("PedigreeLine", x, y_4, x, y_2 + h) self.doc.draw_line("PedigreeLine", x, y_4 + h, x, y_6) # Box 2 to 5 and 6 x = x_right_1 + w / 2. self.doc.draw_line("PedigreeLine", x, y_4, x, y_2 + h) self.doc.draw_line("PedigreeLine", x, y_4 + h, x, y_6) # Box 3 to 7 and 8 y = y_2 + h / 2. self.doc.draw_line("PedigreeLine", x_left_2, y, x_left_2 - w_sep, y) x = x_left_3 + w y1 = y_1 + h / 2. self.doc.draw_line("PedigreeLine", x, y1, x + w_sep, y1) y2 = y_3 + h / 2. self.doc.draw_line("PedigreeLine", x, y2, x + w_sep, y2) self.doc.draw_line("PedigreeLine", x + w_sep, y1, x + w_sep, y2) # Box 4 to 9 and 10 y = y_6 + h / 2. self.doc.draw_line("PedigreeLine", x_left_2, y, x_left_2 - w_sep, y) x = x_left_3 + w y1 = y_5 + h / 2. self.doc.draw_line("PedigreeLine", x, y1, x + w_sep, y1) y2 = y_7 + h / 2. self.doc.draw_line("PedigreeLine", x, y2, x + w_sep, y2) self.doc.draw_line("PedigreeLine", x + w_sep, y1, x + w_sep, y2) # Box 5 to 11 and 12 y = y_2 + h / 2. self.doc.draw_line("PedigreeLine", x_right_2 + w, y, x_right_2 + w + w_sep, y) x = x_right_3 y1 = y_1 + h / 2. self.doc.draw_line("PedigreeLine", x, y1, x - w_sep, y1) y2 = y_3 + h / 2. self.doc.draw_line("PedigreeLine", x, y2, x - w_sep, y2) self.doc.draw_line("PedigreeLine", x - w_sep, y1, x - w_sep, y2) # Box 6 to 13 and 14 y = y_6 + h / 2. self.doc.draw_line("PedigreeLine", x_right_2 + w, y, x_right_2 + w + w_sep, y) x = x_right_3 y1 = y_5 + h / 2. self.doc.draw_line("PedigreeLine", x, y1, x - w_sep, y1) y2 = y_7 + h / 2. self.doc.draw_line("PedigreeLine", x, y2, x - w_sep, y2) self.doc.draw_line("PedigreeLine", x - w_sep, y1, x - w_sep, y2) self.doc.end_page()
def on_buttonok_clicked(self, widget): restart = self.widgets.combolangs.get_active_text() != config.get( "options.language") if self.widgets.radioSexText.get_active(): sexcoltype = 1 elif self.widgets.radioSexImage.get_active(): sexcoltype = 2 elif self.widgets.radioSexTextImage.get_active(): sexcoltype = 3 settings = [ ("options.check-for-updates", self.widgets.chkUpdate.get_active()), ("options.check-for-dev-updates", self.widgets.chkDevUpdate.get_active()), ("options.language", self.widgets.combolangs.get_active_text()), ("options.coef-multiplier", self.widgets.spincoef.get_value_as_int()), ("options.distance-unit", self.widgets.combodistance.get_active()), ("options.speed-unit", self.widgets.combospeed.get_active()), ##("options.format-date", self.entrydate.get_text()), ("interface.arrows", self.widgets.chkArrows.get_active()), ("interface.stats", self.widgets.chkStats.get_active()), ("interface.toolbar", self.widgets.chkToolbar.get_active()), ("interface.statusbar", self.widgets.chkStatusbar.get_active()), ("interface.results-mode", self.widgets.cbResultsMode.get_active()), ("interface.missing-pigeon-hide", self.widgets.chkShowHidden.get_active()), ("interface.missing-pigeon-color", self.widgets.chkColorHidden.get_active()), ("interface.missing-pigeon-color-value", self.widgets.chkColorHiddenValue.get_color().to_string()), ("backup.automatic-backup", self.widgets.checkbackup.get_active()), ("backup.interval", self.widgets.spinday.get_value_as_int()), ("backup.location", self.widgets.fcbutton.get_current_folder()), ("columns.pigeon-name", self.widgets.chkName.get_active()), ("columns.pigeon-colour", self.widgets.chkColour.get_active()), ("columns.pigeon-sex", self.widgets.chkSex.get_active()), ("columns.pigeon-sex-type", sexcoltype), ("columns.pigeon-strain", self.widgets.chkStrain.get_active()), ("columns.pigeon-status", self.widgets.chkStatus.get_active()), ("columns.pigeon-loft", self.widgets.chkLoft.get_active()), ("columns.result-coef", self.widgets.chkCoef.get_active()), ("columns.result-speed", self.widgets.chkSpeed.get_active()), ("columns.result-sector", self.widgets.chkSector.get_active()), ("columns.result-category", self.widgets.chkCategory.get_active()), ("columns.result-type", self.widgets.chkType.get_active()), ("columns.result-weather", self.widgets.chkWeather.get_active()), ("columns.result-temperature", self.widgets.chkTemperature.get_active()), ("columns.result-wind", self.widgets.chkWind.get_active()), ("columns.result-windspeed", self.widgets.chkWindspeed.get_active()), ("columns.result-comment", self.widgets.chkComment.get_active()), ("printing.general-paper", self.widgets.cbPaper.get_active()), ("printing.pedigree-layout", self.widgets.cbLayout.get_active()), ("printing.pedigree-box-colour", self.widgets.chkPigOptColour.get_active()), ("printing.pedigree-name", self.widgets.chkPigName.get_active()), ("printing.pedigree-colour", self.widgets.chkPigColour.get_active()), ("printing.pedigree-sex", self.widgets.chkPigSex.get_active()), ("printing.pedigree-extra", self.widgets.chkPigExtra.get_active()), ("printing.pedigree-image", self.widgets.chkPigImage.get_active()), ("printing.pigeon-colnames", self.widgets.chkPigColumnNames.get_active()), ("printing.pigeon-sex", self.widgets.chkPigOptSex.get_active()), ("printing.result-colnames", self.widgets.chkResColumnNames.get_active()), ("printing.result-date", self.widgets.chkResDate.get_active()), ("printing.user-name", self.widgets.chkPerName.get_active()), ("printing.user-address", self.widgets.chkPerAddress.get_active()), ("printing.user-phone", self.widgets.chkPerPhone.get_active()), ("printing.user-email", self.widgets.chkPerEmail.get_active()), ] for option, value in settings: config.set(option, value) config.save() self._finish_options(restart)
def _set_options(self): # General self.widgets.chkUpdate.set_active( config.get("options.check-for-updates")) self.widgets.chkDevUpdate.set_active( config.get("options.check-for-dev-updates")) for index, lang in enumerate(self.languages): if config.get("options.language") == lang: self.widgets.combolangs.set_active(index) break self.widgets.checkbackup.set_active( config.get("backup.automatic-backup")) self.widgets.spinday.set_value(config.get("backup.interval")) self.widgets.fcbutton.set_current_folder(config.get("backup.location")) self.widgets.combodistance.set_active( config.get("options.distance-unit")) self.widgets.combospeed.set_active(config.get("options.speed-unit")) self.widgets.spincoef.set_value(config.get("options.coef-multiplier")) ##self.widgets.entrydate.set_text(config.get("options.format-date")) # Appearance self.widgets.chkName.set_active(config.get("columns.pigeon-name")) self.widgets.chkColour.set_active(config.get("columns.pigeon-colour")) self.widgets.chkSex.set_active(config.get("columns.pigeon-sex")) self.widgets.chkLoft.set_active(config.get("columns.pigeon-loft")) self.widgets.chkStrain.set_active(config.get("columns.pigeon-strain")) self.widgets.chkStatus.set_active(config.get("columns.pigeon-status")) self.widgets.chkCoef.set_active(config.get("columns.result-coef")) self.widgets.chkSpeed.set_active(config.get("columns.result-speed")) self.widgets.chkSector.set_active(config.get("columns.result-sector")) self.widgets.chkCategory.set_active( config.get("columns.result-category")) self.widgets.chkType.set_active(config.get("columns.result-type")) self.widgets.chkWeather.set_active( config.get("columns.result-weather")) self.widgets.chkTemperature.set_active( config.get("columns.result-temperature")) self.widgets.chkWind.set_active(config.get("columns.result-wind")) self.widgets.chkWindspeed.set_active( config.get("columns.result-windspeed")) self.widgets.chkComment.set_active( config.get("columns.result-comment")) sexcoltype = config.get("columns.pigeon-sex-type") if sexcoltype == 1: self.widgets.radioSexText.set_active(True) elif sexcoltype == 2: self.widgets.radioSexImage.set_active(True) elif sexcoltype == 3: self.widgets.radioSexTextImage.set_active(True) self.widgets.chkArrows.set_active(config.get("interface.arrows")) self.widgets.chkStats.set_active(config.get("interface.stats")) self.widgets.chkToolbar.set_active(config.get("interface.toolbar")) self.widgets.chkStatusbar.set_active(config.get("interface.statusbar")) self.widgets.cbResultsMode.set_active( config.get("interface.results-mode")) self.widgets.chkShowHidden.set_active( config.get("interface.missing-pigeon-hide")) self.widgets.chkColorHidden.set_active( config.get("interface.missing-pigeon-color")) self.widgets.chkColorHiddenValue.set_color( gtk.gdk.color_parse( config.get("interface.missing-pigeon-color-value"))) # Printing self.widgets.cbPaper.set_active(config.get("printing.general-paper")) self.widgets.cbLayout.set_active( config.get("printing.pedigree-layout")) self.widgets.chkPigOptColour.set_active( config.get("printing.pedigree-box-colour")) self.widgets.chkPerName.set_active(config.get("printing.user-name")) self.widgets.chkPerAddress.set_active( config.get("printing.user-address")) self.widgets.chkPerPhone.set_active(config.get("printing.user-phone")) self.widgets.chkPerEmail.set_active(config.get("printing.user-email")) self.widgets.chkPigName.set_active( config.get("printing.pedigree-name")) self.widgets.chkPigColour.set_active( config.get("printing.pedigree-colour")) self.widgets.chkPigSex.set_active(config.get("printing.pedigree-sex")) self.widgets.chkPigExtra.set_active( config.get("printing.pedigree-extra")) self.widgets.chkPigImage.set_active( config.get("printing.pedigree-image")) self.widgets.chkPigColumnNames.set_active( config.get("printing.pigeon-colnames")) self.widgets.chkPigOptSex.set_active(config.get("printing.pigeon-sex")) self.widgets.chkResColumnNames.set_active( config.get("printing.result-colnames")) self.widgets.chkResDate.set_active(config.get("printing.result-date"))
def write_report(self): self.doc.start_page() # Title line band = self._pigeon.get_band_string( True) if self._pigeon is not None else "" x_cm = self.get_right_align_x("Title", band) self.doc.draw_text("Title", _("Pedigree of:"), .1, 0) self.doc.draw_text("Title", band, x_cm, 0) self.doc.draw_line("Seperator", 0, 1, self.doc.get_usable_width(), 1) # Header header_bottom = 0 ## User info header_x = .1 header_y = 1.2 header_y_offset = .4 if config.get("printing.user-name"): self.doc.draw_text("Header", self._userinfo["name"], header_x, header_y) header_y += header_y_offset if config.get("printing.user-address"): self.doc.draw_text("Header", self._userinfo["street"], header_x, header_y) header_y += header_y_offset self.doc.draw_text( "Header", "%s %s" % (self._userinfo["code"], self._userinfo["city"]), header_x, header_y) header_y += header_y_offset if config.get("printing.user-phone"): self.doc.draw_text("Header", self._userinfo["phone"], header_x, header_y) header_y += header_y_offset if config.get("printing.user-email"): self.doc.draw_text("Header", self._userinfo["email"], header_x, header_y) header_y += header_y_offset header_bottom = header_y ## Pigeon details header_y = 1.2 header_y_offset = .4 x_cm = self.get_right_align_x("Header", self.pigeoninfo) self.doc.draw_text("Header", self.pigeoninfo, x_cm, header_y) header_y += header_y_offset if config.get("printing.pedigree-extra"): ex1, ex2, ex3, ex4, ex5, ex6 = self._pigeon.get_extra() if\ self._pigeon is not None else ("", "", "", "", "", "") if ex1: x_cm = self.get_right_align_x("Header", ex1) self.doc.draw_text("Header", ex1, x_cm, header_y) header_y += header_y_offset if ex2: x_cm = self.get_right_align_x("Header", ex2) self.doc.draw_text("Header", ex2, x_cm, header_y) header_y += header_y_offset if ex3: x_cm = self.get_right_align_x("Header", ex3) self.doc.draw_text("Header", ex3, x_cm, header_y) header_y += header_y_offset if ex4: x_cm = self.get_right_align_x("Header", ex4) self.doc.draw_text("Header", ex4, x_cm, header_y) header_y += header_y_offset if ex5: x_cm = self.get_right_align_x("Header", ex5) self.doc.draw_text("Header", ex5, x_cm, header_y) header_y += header_y_offset if ex6: x_cm = self.get_right_align_x("Header", ex6) self.doc.draw_text("Header", ex6, x_cm, header_y) header_y += header_y_offset if header_y > header_bottom: header_bottom = header_y ## Seperator header_bottom += .2 self.doc.draw_line("Seperator", 0, header_bottom, self.doc.get_usable_width(), header_bottom) # Pedigree lst = [None] * 31 corepigeon.build_pedigree_tree(self._pigeon, 0, 1, lst) h_sep = .2 w_sep = .2 w = (self.doc.get_usable_width() / 4) - w_sep h_total = self.doc.get_usable_height() - (header_bottom + .2) y_start = header_bottom + .2 y_div = (h_total / 16) + y_start if config.get("printing.pedigree-box-colour"): h1, h2, h3, h4 = 3.1, 3.1, 1.9, 0.9 else: h1, h2, h3, h4 = 2.8, 2.8, 1.6, 0.9 for index, pigeon in enumerate(lst): # Skip first item, it's the selected pigeon if index == 0: continue # Calculate box positions for each vertical row if index == 1: n_lines = 6 x = 0 h = h1 y_mid = y_div + ((h4 * 8 + h_sep * 7) / 2) y = y_mid - (h / 2) y_offset = (h4 * 8) + (h_sep * 8) left = False right = True last = False elif index == 3: n_lines = 6 x += w + w_sep h = h2 y_mid = y_div + ((h4 * 4 + h_sep * 3) / 2) y = y_mid - (h / 2) y_offset = (h4 * 4) + (h_sep * 4) left = True right = True last = False elif index == 7: n_lines = 3 x += w + w_sep h = h3 y_mid = y_div + ((h4 * 2 + h_sep) / 2) y = y_mid - (h / 2) y_offset = (h4 * 2) + (h_sep * 2) left = True right = True last = False elif index == 15: n_lines = 1 x += w + w_sep h = h4 y_mid = y_div + h / 2 y = y_div y_offset = h + h_sep left = True right = False last = True # Get the text if pigeon is not None: text = pigeon.get_band_string(True) ex1, ex2, ex3, ex4, ex5, ex6 = pigeon.get_extra() if not last and config.get("printing.pedigree-box-colour"): text += "\n" + pigeon.get_colour() else: text = "" ex1, ex2, ex3, ex4, ex5, ex6 = ("", "", "", "", "", "") if n_lines >= 1: text += "\n" + ex1 if n_lines >= 3: text += "\n" + ex2 text += "\n" + ex3 if n_lines == 6: text += "\n" + ex4 text += "\n" + ex5 text += "\n" + ex6 # Draw box with text self.doc.draw_box("Pedigree", text, x, y, w, h) # Draw pedigree lines if right: self.doc.draw_line("PedigreeLine", x + w, y_mid, x + w + (w_sep / 2), y_mid) if left: self.doc.draw_line("PedigreeLine", x, y_mid, x - (w_sep / 2), y_mid) if index % 2 == 1: self.doc.draw_line("PedigreeLine", x - (w_sep / 2), y_mid, x - (w_sep / 2), y_mid + y_offset) # Draw image if index == 22 and config.get("printing.pedigree-image") and\ self._pigeon is not None and\ self._pigeon.image: # index 22 is last box of first part img_y = y + y_offset - (h_sep / 2) img_w = w - .2 img_h = 5 self.doc.draw_image(self._pigeon.image, w / 2, img_y, img_w, img_h, xalign="center", yalign="center") # Increase y position for next box y += y_offset y_mid += y_offset self.doc.end_page()
def _visible_func(self, model, rowiter): show = model.get_value(rowiter, 0).show if not show: return not config.get("interface.missing-pigeon-hide") return True