# HG changeset patch # User Miguel Ángel Bárcena Rodríguez # Date 1412090210 -7200 # Node ID 7bd4ca56607d31eeea645d2e9971ceff220aac82 # Parent f7e0cc58737fcdaac040e1fe5f7671a7970a37d0 bug fix: Mutable default arguments diff -r f7e0cc58737f -r 7bd4ca56607d Generic/base.py --- a/Generic/base.py Sun Sep 14 17:23:02 2014 +0200 +++ b/Generic/base.py Tue Sep 30 17:16:50 2014 +0200 @@ -3,7 +3,7 @@ ## File base.py ## This file is part of pyArq-Presupuestos. ## -## Copyright (C) 2010-2013 Miguel Ángel Bárcena Rodríguez +## Copyright (C) 2010-2014 Miguel Ángel Bárcena Rodríguez ## ## ## pyArq-Presupuestos is free software: you can redistribute it and/or modify @@ -259,8 +259,8 @@ Description: Record object Constructor: - base.Record(code, synonyms, hierarchy, unit, summary, prices, type, - subtype, text="") + base.Record(decimals, code, synonyms, hierarchy, unit, summary, + prices, type_, subtype, parents=None, text=None) Ancestry: +-- object +-- Record @@ -333,15 +333,19 @@ self.__labels = tuple[11] def __init__(self, decimals, code, synonyms, hierarchy, unit, summary, - prices, type_, subtype, parents=[], text=""): + prices, type_, subtype, parents=None, text=None): self.code = code self.synonyms = synonyms self.recordType = (hierarchy, type_, subtype) self.unit = unit self.summary = summary self.setPrices(prices, decimals) + if parents is None: + parents = [] self.parents = parents self.children = [] + if text is None: + text = "" self.text = text self.sheet = Sheet() self.files = [] @@ -543,9 +547,9 @@ self.__children = children def appendChild(self, child_code, decimals, factor=0.0, yield_=0.0, - measure=0.0, measure_list=[], type_ ="", label=""): + measure=0.0, measure_list=None, type_=None, label=None): """appendChildren(self, child_code, factor=0.0, yield_=0.0, - measure=0.0, measure_list=[], type_ ="", label="")) + measure=0.0, measure_list=None, type_=None, label=None)) position: child_code: @@ -558,6 +562,12 @@ Append a child to the list of children """ + if measure_list is None: + measure_list = [] + if type_ is None: + type_ = "" + if label is None: + label = "" _measure = Measure(decimals, self.recordType, measure, [], label, factor, yield_) if len(measure_list) > 0: @@ -719,8 +729,8 @@ Description: Parametric Record object Constructor: - base.ParametricRecord(code, synonyms, hierarchy, unit, summary, prices, - type_, subtype, text="") + base.ParametricRecord(budget, code, synonyms, hierarchy, unit, summary, + prices, type_, subtype, parents=None, text=None) Ancestry: +-- object +-- Record @@ -776,9 +786,13 @@ self.__parametric_text = tuple[19] def __init__(self, budget, code, synonyms, hierarchy, unit, summary, - prices, type_, subtype, parents=[], text=""): + prices, type_, subtype, parents=None, text=None): + if parents is None: + parents = [] + if text is None: + text = "" Record.__init__(self, budget, code, synonyms, hierarchy, unit, summary, - prices, type_, subtype, parents=[], text="") + prices, type_, subtype, parents, text) self.__parameters = {} self.__select_comment = "" self.__vars = {} @@ -1105,7 +1119,7 @@ """) def buildMeasure(self, list_lines, type_, decimals, recordType): - """setMeasure(self, list_lines, type_, decimals) + """setMeasure(list_lines, type_, decimals, recordType) list_lines: list of measure lines [ [linetype, comment, units, length, width, height, formula], ... ] @@ -1950,14 +1964,18 @@ def iter(self): for record in self.__records: yield record - def iterPreOrder(self, recordCode, codes=[]): + def iterPreOrder(self, recordCode, codes=None): + if codes is None: + codes = [] _children = self.getchildren(recordCode) for _child in _children: if not _child in codes: codes.append(_child) self.iterPreOrder(_child, codes) return codes - def iterPostOrder(self, recordCode, codes=[]): + def iterPostOrder(self, recordCode, codes=None): + if codes is None: + codes = [] _children = self.getchildren(recordCode) for _child in _children: if not _child in codes: @@ -2133,7 +2151,7 @@ dictionary["DIRC"], dictionary["DCD"], dictionary["DIVISA"]) self.__decimals[N] = decimals - def getDecimals(self, decimal="All", N=None): + def getDecimals(self, decimal=None, N=None): """getDecimals(self,decimal="All",N=None) decimal: @@ -2143,6 +2161,7 @@ N: the price group None,1,2,.. None: Return the active price group """ + if decimal is None: decimal = "All" if N is None: N = self.getActiveTitle() if decimal == "All": return self.__decimals[N+1] @@ -2172,14 +2191,16 @@ "IVA" : dictionary["IVA"]} self.__percentages = _percentages - def getPercentages(self, key="All"): - """getPercentages(self, percentage="All") + def getPercentages(self, key=None): + """getPercentages(self, key=None) key: "All": Return the Percentages dictionary "keys": Return the keys of a Percentages object key: Return a Percentages value for the key """ + if Key is None: + key = "All" if key == "All": return self.__percentages elif key == "keys": diff -r f7e0cc58737f -r 7bd4ca56607d Generic/globalVars.py --- a/Generic/globalVars.py Sun Sep 14 17:23:02 2014 +0200 +++ b/Generic/globalVars.py Tue Sep 30 17:16:50 2014 +0200 @@ -24,7 +24,7 @@ import sys version = "pyArq Presupuestos v0.0.0" -changeset = 21 +changeset = 22 baseversion = 0 # path: Paths where find the program files needed diff -r f7e0cc58737f -r 7bd4ca56607d Gtk/gui.py --- a/Gtk/gui.py Sun Sep 14 17:23:02 2014 +0200 +++ b/Gtk/gui.py Tue Sep 30 17:16:50 2014 +0200 @@ -2,7 +2,7 @@ ## File gui.py ## This file is part of pyArq-Presupuestos. ## -## Copyright (C) 2010 Miguel Ángel Bárcena Rodríguez +## Copyright (C) 2010-2014 Miguel Ángel Bárcena Rodríguez ## ## ## pyArq-Presupuestos is free software: you can redistribute it and/or modify @@ -914,8 +914,8 @@ # TODO: * pane types # TODO: * General budget properties (is better a dialog?) - def __init__(self, mainWindow, budget, path_record=(0,)): - """__init__(mainWindow, budget, path_record=(0,)) + def __init__(self, mainWindow, budget, path_record=None): + """__init__(mainWindow, budget, path_record=None) mainWindow: MainWindow object budget: "base.Budget" object @@ -931,6 +931,8 @@ self.__back_menu: a gtk.Menu self.__forward_menu: a gtk.Menu """ + if path_record is None: + path_record = (0,) #TODO: __panes_list should come from config file... self.__mainWindow = mainWindow self.__widget = gtk.VBox() @@ -1090,8 +1092,8 @@ # Thre is only one item in the page, it can not be closed pass - def _itemsFactory(self, list_paned, pane_path=(0,)): - """_itemsFactory(list_paned, pane_path(0,)) + def _itemsFactory(self, list_paned, pane_path=None): + """_itemsFactory(list_paned, pane_path=None) list_paned: list in "__panes_list" format [ "v" or "h", panel1_type, panel2_type] @@ -1107,6 +1109,8 @@ Creates the items and widgets and returns the main item """ + if pane_path is None: + pane_path = (0,) if not isinstance(list_paned , list): raise ValueError, _("The value must be a list") if list_paned[0] == "v" or list_paned[0] == "h": @@ -2195,8 +2199,8 @@ runMessage """ - def __init__(self, budget, page, pane_path, path_record=(0,)): - """__init__(budget, page, pane_path, path_record=(0,)) + def __init__(self, budget, page, pane_path, path_record=None): + """__init__(budget, page, pane_path, path_record=None) budget: budget showed ("base.Budget" object) page: weak reference from Page instance which creates this class @@ -2246,6 +2250,8 @@ """ # TODO: to group all columns in a dicctionary # Budget + if path_record is None: + parh_record = (0,) if not isinstance(budget, base.Budget): raise ValueError, _("Argument must be a Budget object") self.__budget = budget @@ -2823,8 +2829,8 @@ runMessage """ - def __init__(self, budget, page, pane_path, path_record=(0,)): - """__init__(budget, page, pane_path, path_record=(0,)) + def __init__(self, budget, page, pane_path, path_record=None): + """__init__(budget, page, pane_path, path_record=None) budget: budget: budget showed ("base.Budget" object) page: weak reference from Page instance which creates this class @@ -2873,6 +2879,8 @@ * Connects the events """ # Seting init args + if path_record is None: + path_record = (0,) if not isinstance(budget, base.Budget): raise ValueError, _("Argument must be a Budget object") self.__budget = budget @@ -3411,8 +3419,8 @@ """ # TODO: make standar: "DecompositonList and Description" - def __init__(self, budget, page, pane_path, path_record=(0,)): - """__init__(budget, page, pane_path, path_record=(0,)) + def __init__(self, budget, page, pane_path, path_record=None): + """__init__(budget, page, pane_path, path_record=None) budget: the budget (base.obra object) page: weak reference from Page instance which creates this class @@ -3432,6 +3440,8 @@ Creates an shows the scroledwindow that contain the description text of the record to be showed in a pane. """ + if path_record is None: + path_record = (0,) self.__budget = budget self.__page = page self.__pane_path = pane_path @@ -3592,8 +3602,8 @@ runMessage """ - def __init__(self, budget, page, pane_path, path_record=(0,)): - """__init__(budget, page, pane_path, path_record=(0,)) + def __init__(self, budget, page, pane_path, path_record=None): + """__init__(budget, page, pane_path, path_record=None) budget: the budget (base.obra object) page: weak reference from Page instance which creates this class @@ -3618,6 +3628,8 @@ Creates an shows the scroledwindow that contain the description text of the record to be showed in a pane. """ + if path_record is None: + path_record = (0,) self.__budget = budget self.__page = page self.__pane_path = pane_path @@ -3939,8 +3951,8 @@ runMessage """ - def __init__(self, budget, page, pane_path, path_record=(0,)): - """__init__(budget, page, pane_path, path_record=(0,)) + def __init__(self, budget, page, pane_path, path_record=None): + """__init__(budget, page, pane_path, path_record=None) budget: the budget (base.obra object) page: weak reference from Page instance which creates this class @@ -3958,6 +3970,8 @@ Creates an shows the scroledwindow that contain icon files of the record to be showed in a pane. """ + if path_record is None: + path_record = (0,) self.__budget = budget self.__page = page self.__pane_path = pane_path @@ -4182,8 +4196,8 @@ runMessage """ - def __init__(self, budget, page, pane_path, path_record=(0,)): - """__init__(budget, page, pane_path, path_record=(0,)) + def __init__(self, budget, page, pane_path, path_record=None): + """__init__(budget, page, pane_path, path_record=None) budget: budget: budget showed ("base.Budget" object) page: weak reference from Page instance which creates this class @@ -4201,6 +4215,8 @@ Creates an shows the scroledwindow that contain the company data. """ + if path_record is None: + path_record = (0,) self.__selection = None # Seting init args if not isinstance(budget, base.Budget): diff -r f7e0cc58737f -r 7bd4ca56607d Gtk/importFiebdc.py --- a/Gtk/importFiebdc.py Sun Sep 14 17:23:02 2014 +0200 +++ b/Gtk/importFiebdc.py Tue Sep 30 17:16:50 2014 +0200 @@ -3,7 +3,7 @@ ## File importFiebdc.py ## This file is part of pyArq-Presupuestos. ## -## Copyright (C) 2010 Miguel Ángel Bárcena Rodríguez +## Copyright (C) 2010-2014 Miguel Ángel Bárcena Rodríguez ## ## ## pyArq-Presupuestos is free software: you can redistribute it and/or modify @@ -387,10 +387,10 @@ isCanceled(self) """ - def __init__(self, page, mainWindow, - readFileMethod, budget, filename, cancelMethod, filetype): - """def __init__(self, page, mainWindow, - readFileMethod, budget, filename, cancelMethod) + def __init__(self, page, mainWindow, readFileMethod, budget, + filename, cancelMethod, filetype): + """def __init__(page, mainWindow, readFileMethod, budget, + filename, cancelMethod, filetype) page: The page instance that launch the thread mainWindow: gui.Mainwindow object