コード例 #1
0
def get_sorptionproperties(system, step):
    """Get some basic parameters for each layer."""

    root = CapSimWindow(master=None, buttons=1)
    root.make_window(SorptionProperties(root, system))
    root.mainloop()

    if root.main.get() == 1: system = None
    else:
        if root.step.get() == 1:
            system.get_sorptionproperties(root.window)
            for component in system.components:
                component.remove_sorptionwidgets()
            for chemical in system.chemicals:
                if chemical.soluable == 1:
                    chemical.remove_sorptionwidgets()
            for component in system.components:
                for chemical in system.chemicals:
                    if chemical.soluable == 1:
                        system.sorptions[component.name][
                            chemical.name].remove_propertieswidgets()
        else:
            system.sorptions = None

    root.destroy()

    return system, step + root.step.get()
コード例 #2
0
def get_solidlayerconditions(system, step):

    root_step = 0

    solid_check = 0
    for chemical in system.chemicals:
        for component in system.components:
            if system.sorptions[component.name][
                    chemical.name].kinetic == 'Transient':
                solid_check = 1

    if solid_check == 1:
        root = CapSimWindow(buttons=1)
        root.make_window(SolidLayerConditions(root, system))
        root.okbutton.focus_set()
        root.mainloop()

        if root.main.get() == 1: system = None
        else:
            root_step = root.step.get()
            if root.step.get() == 1:
                system.get_solidlayerconditions(root.window)
                for layer in system.layers:
                    layer.remove_SolidICwidgets()
                    for component in system.matrices[
                            layer.type_index].components:
                        component.remove_SolidICswidgets()
                        for chemical in system.chemicals:
                            system.SolidICs[layer.name][component.name][
                                chemical.name].remove_widgets()

                for chemical in system.chemicals:
                    try:
                        chemical.remove_ICwidgets()
                    except:
                        pass
            else:
                system.SolidICs = None

        root.destroy()

    else:
        if system.SolidICs == None:
            root_step = 1
            system.SolidICs = {}
            for layer in system.layers:
                system.SolidICs[layer.name] = {}
                for component in system.matrices[layer.type_index].components:
                    system.SolidICs[layer.name][component.name] = {}
                    for chemical in system.chemicals:
                        system.SolidICs[layer.name][component.name][
                            chemical.name] = SolidIC(layer.name,
                                                     component.name,
                                                     chemical.name)

        else:
            system.SolidICs = None
            root_step = -1

    return system, step + root_step
コード例 #3
0
def get_systemproperties(system, step):
    """Get flow and system parameters."""

    root = CapSimWindow(buttons=1)
    root.make_window(SystemProperties(root, system))
    root.mainloop()

    if root.main.get() == 1: system = None
    else:
        if root.step.get() == 1:
            system.get_systemproperties(root.window)
        else:
            system.adv = 'None'
            system.bio = 'None'
            system.con = 'None'

            system.Vdar = 0
            system.Vtidal = 0
            system.ptidal = 1
            system.sigma = 10
            system.hbio = 10
            system.Dbiop = 1
            system.Dbiopw = 100
            system.hcon = 0
            system.t90 = 1

    root.destroy()

    return system, step + root.step.get()
コード例 #4
0
def get_reactioncoefficients(system, step):
    """Get some basic parameters for each layer."""

    root_step = 0

    if len(system.reactions) > 0:
        root = CapSimWindow(master=None, buttons=1)
        root.make_window(ReactionCoefficients(root, system, editflag=0))
        root.mainloop()

        if root.main.get() == 1: system = None
        else:
            root_step = root.step.get()
            if root.step.get() == 1:
                system.get_reactioncoefficients(root.window)
                for layer in system.layers:
                    layer.remove_reactionwidgets()
                    for reaction in system.reactions:
                        system.coefficients[layer.name][
                            reaction.name].remove_propertieswidgets()
            else:
                system.coefficients = None
        root.destroy()

    else:
        if system.coefficients == None:
            root_step = 1
            system.coefficients = {}
            for layer in system.layers:
                system.coefficients[layer.name] = {}
        else:
            system.coefficients = None
            root_step = -1

    return system, step + root_step
コード例 #5
0
def get_layerconditions(system, step):
    """Get specific parameters for the layers."""

    root = CapSimWindow(buttons=1)
    root.make_window(LayerConditions(root, system))
    root.okbutton.focus_set()
    root.mainloop()

    if root.main.get() == 1: system = None
    else:
        if root.step.get() == 1:
            system.get_layerconditions(root.window)
            for layer in system.layers:
                layer.get_layerconditions()
                layer.remove_ICwidgets()
                for chemical in system.chemicals:
                    if chemical.soluable == 1:
                        system.ICs[layer.name][chemical.name].remove_widgets()

            for chemical in system.chemicals:
                if chemical.soluable == 1:
                    chemical.remove_ICwidgets()
                    system.BCs[chemical.name].remove_widgets()
        else:
            system.ICs = None
            system.BCs = None
            for layer in system.layers:
                layer.ICtype = 'Uniform'
                layer.remove_ICwidgets()

    root.destroy()

    return system, step + root.step.get()
コード例 #6
0
def edit_soliddatabase(soliddatabase, system):
    """Makes the GUI that is used to edit the chemical database."""

    root = CapSimWindow(master=None, buttons=None)
    root.make_window(Database(root, system, soliddatabase))
    root.mainloop()

    database = root.window.database
    flag = root.window.exitflag
    root.destroy()
    return database, flag
コード例 #7
0
ファイル: help.py プロジェクト: EnvironmentalSoftware/CapSim
def show_help(system):
    """Shows the main menu."""

    root = CapSimWindow(buttons = 2)
    root.make_window(Help(root, system))
    root.mainloop()

    flag = root.main.get()
        
    root.destroy()

    return flag
コード例 #8
0
def solve_batch(systems, type):

    root = CapSimWindow(buttons=2)
    root.make_window(BatchSolver(root, systems, type))
    root.window.solve_system()

    outputs = root.window.outputs
    main = root.main.get()

    root.destroy()

    return outputs, main
コード例 #9
0
def show_mainmenu(system):
    """Shows the main menu."""

    root = CapSimWindow(master=None, buttons=None)
    root.make_window(MainMenu(root, system))
    root.mainloop()

    option = root.window.option.get()
    filename = root.window.filename.get()

    root.destroy()

    return option, filename
コード例 #10
0
def solve_system(system):
    """Makes the GUI that shows the status of the simulation and runs the
    simulation."""

    root = CapSimWindow(buttons=2)
    root.make_window(Solver(root, system))
    root.mainloop()

    output = root.window.output
    main = root.main.get()

    root.destroy()

    return output, main
コード例 #11
0
def get_systemunits(system, step):
    """Get flow and system parameters."""

    root = CapSimWindow(buttons=1)
    root.make_window(UnitProperties(root, system))
    root.mainloop()
    if root.main.get() == 0 and root.step.get() == 1:
        system.get_systemunits(root.window)
    else:
        system = None

    root.destroy()

    return system, step + root.step.get()
コード例 #12
0
def get_reactionproperties(system, step):
    """Get some basic parameters for each layer."""

    root = CapSimWindow(master = None, buttons = 1)
    root.make_window(ReactionProperties(root, system))
    root.mainloop()

    if root.main.get() == 1: system = None
    else:
        if root.step.get() == 1:
            system.get_reactionproperties(root.window)
            for reaction in system.reactions: reaction.remove_propertieswidgets()
        else:
            system.reactions = None
        
    root.destroy()

    return system, step + root.step.get()
コード例 #13
0
def get_chemicalproperties(system, database, step):
    """Get some basic parameters for each layer."""

    root = CapSimWindow(master=None, buttons=1)
    root.make_window(ChemicalProperties(root, system, database))
    root.mainloop()

    if root.main.get() == 1: system = None
    else:
        if root.step.get() == 1:
            system.get_chemicalproperties(root.window)
            for chemical in system.chemicals:
                chemical.remove_chemicalwidgets()
        else:
            system.chemicals = None
            system.nchemical = 0

    root.destroy()

    return system, step + root.step.get()
コード例 #14
0
def get_layerproperties(system, step):
    """Get some basic parameters for each layer."""

    root = CapSimWindow(master = None, buttons = 1)
    root.make_window(LayerProperties(root, system))
    root.mainloop()

    if root.main.get() == 1: system = None
    else:
        if root.step.get() == 1:
            system.get_layerproperties(root.window)
            for layer in system.layers: layer.remove_propertywidgets()
        else:
            system.layers = None
            system.nlayers  = 0
            system.dep  = 0
            system.Vdep = 0

    root.destroy()

    return system, step + root.step.get()
コード例 #15
0
def get_matrixproperties(system, materials, step):
    """Get some basic parameters for each layer."""

    root = CapSimWindow(master = None, buttons = 1)
    root.make_window(MatrixProperties(root, system, materials))
    root.mainloop()
    
    if root.main.get() == 1: system = None
    else:
        if root.step.get() == 1:
            system.get_matricesproperties(root.window)
            for matrix in system.matrices: matrix.remove_propertieswidgets()
        else:
            system.matrices   = None
            system.nmatrices  = 0
            system.component_list      = []
            system.components          = []

    root.destroy()

    return system, step + root.step.get()
コード例 #16
0
class ChemicalProperties:
    """Gets the contaminant properties."""
    def __init__(self, master, system, database):
        """Constructor method. Defines the parameters to be obtained in this window."""

        self.master = master
        self.fonttype = system.fonttype
        self.version = system.version
        self.superfont = get_superfont(self.fonttype)  #superscript font
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)
        self.top = None  #flag for existence of toplevel#

        self.system = system
        self.database = database
        self.diffunit = system.diffunit
        self.concunit = system.concunit
        self.concunits = system.concunits

        if system.chemicals is None:
            self.chemicals = []
            self.nchemicals = 0
        else:
            self.chemicals = system.chemicals
            self.nchemicals = system.nchemicals

    def make_widgets(self):
        """Make the widgets for the window."""

        self.bgcolor = self.frame.cget('bg')

        # Construct all label widgets used in the problem
        self.instructions = Label(
            self.tframe,
            text=
            ' Please provide the following chemical properties:                    '
        )

        self.blankcolumn = Label(self.tframe, text='', width=1)
        self.editcolumn = Label(self.tframe, text='', width=6)
        self.delcolumn = Label(self.tframe, text='', width=6)
        self.numbercolumn = Label(self.tframe, text='', width=6)
        self.namecolumn = Label(self.tframe, text='', width=18)
        self.MWcolumn = Label(self.tframe, text='', width=8)
        self.tempcolumn = Label(self.tframe, text='', width=10)
        self.Dwcolumn = Label(self.tframe, text='', width=16)
        self.Koccolumn = Label(self.tframe, text='', width=16)
        self.Kdoccolumn = Label(self.tframe, text='', width=18)
        self.Refcolumn = Label(self.tframe, text='', width=17)
        self.endcolumn = Label(self.tframe, text='', width=1)

        self.botblankcolumn = Label(self.frame, text='', width=1)
        self.boteditcolumn = Label(self.frame, text='', width=6)
        self.botdelcolumn = Label(self.frame, text='', width=6)
        self.botnumbercolumn = Label(self.frame, text='', width=6)
        self.botnamecolumn = Label(self.frame, text='', width=18)
        self.botMWcolumn = Label(self.frame, text='', width=8)
        self.bottempcolumn = Label(self.frame, text='', width=10)
        self.botDwcolumn = Label(self.frame, text='', width=16)
        self.botKoccolumn = Label(self.frame, text='', width=16)
        self.botKdoccolumn = Label(self.frame, text='', width=18)
        self.botRefcolumn = Label(self.frame, text='', width=17)
        self.botendcolumn = Label(self.frame, text='', width=1)

        self.numberlabel = Label(self.tframe, text='Number')
        self.namelabel = Label(self.tframe, text='Chemical name')
        self.MWlabel = Label(self.tframe, text='Molecular\n Weight')
        self.templabel = Label(self.tframe, text='Temperature')
        self.Dwlabel = Label(self.tframe,
                             text='Molecular diffusivity\n in water')
        self.Koclabel = Label(self.tframe,
                              text='Organic carbon\n partition coefficient')
        self.Kdoclabel = Label(
            self.tframe,
            text='Dissolved organic carbon\n partition coefficient')
        self.Reflabel = Label(self.tframe, text='Reference')

        self.tempunits = Label(self.tframe, text=unichr(176) + 'C')
        self.Dwunits = Label(self.tframe, text=self.diffunit)
        self.Kocunits = Label(self.tframe, text='log(L/kg)')
        self.Kdocunits = Label(self.tframe, text='log(L/kg)')

        self.blank1 = Label(self.frame, text=' ')
        self.blank2 = Label(self.bframe, text=' ')

        self.addwidget = Button(self.bframe,
                                text='Add chemicals',
                                command=self.addchemical,
                                width=20)

        #show the widgets on the grid
        self.instructions.grid(row=0,
                               column=0,
                               columnspan=9,
                               padx=1,
                               sticky='W')

        self.blankcolumn.grid(row=1, column=0, sticky='WE', padx=1, pady=1)
        self.editcolumn.grid(row=1, column=1, sticky='WE', padx=1, pady=1)
        self.delcolumn.grid(row=1, column=2, sticky='WE', padx=1, pady=1)
        self.numbercolumn.grid(row=1, column=3, sticky='WE', padx=1, pady=1)
        self.namecolumn.grid(row=1, column=4, sticky='WE', padx=1, pady=1)
        self.MWcolumn.grid(row=1, column=5, sticky='WE', padx=1, pady=1)
        self.tempcolumn.grid(row=1, column=6, sticky='WE', padx=1, pady=1)
        self.Dwcolumn.grid(row=1, column=7, sticky='WE', padx=1, pady=1)
        self.Koccolumn.grid(row=1, column=8, sticky='WE', padx=1, pady=1)
        self.Kdoccolumn.grid(row=1, column=9, sticky='WE', padx=1, pady=1)
        self.Refcolumn.grid(row=1, column=10, sticky='WE', padx=1, pady=1)
        self.endcolumn.grid(row=1, column=11, sticky='WE', padx=1, pady=1)

        self.numberlabel.grid(row=2, column=3, sticky='WE', padx=1, pady=1)
        self.namelabel.grid(row=2, column=4, sticky='WE', padx=1, pady=1)
        self.MWlabel.grid(row=2, column=5, sticky='WE', padx=1, pady=1)
        self.templabel.grid(row=2, column=6, sticky='WE', padx=1, pady=1)
        self.Dwlabel.grid(row=2, column=7, sticky='WE', padx=1, pady=1)
        self.Koclabel.grid(row=2, column=8, sticky='WE', padx=1, pady=1)
        self.Kdoclabel.grid(row=2, column=9, sticky='WE', padx=1, pady=1)
        self.Reflabel.grid(row=2, column=10, sticky='WE', padx=1, pady=1)

        self.tempunits.grid(row=3, column=6, sticky='WE', padx=1, pady=1)
        self.Dwunits.grid(row=3, column=7, sticky='WE', padx=1, pady=1)
        self.Kocunits.grid(row=3, column=8, sticky='WE', padx=1, pady=1)
        self.Kdocunits.grid(row=3, column=9, sticky='WE', padx=1, pady=1)

        self.updatechemicals()

    def updatechemicals(self):

        try:
            self.botblankcolumn.grid_forget()
            self.boteditcolumn.grid_forget()
            self.botdelcolumn.grid_forget()
            self.botnumbercolumn.grid_forget()
            self.botnamecolumn.grid_forget()
            self.botMWcolumn.grid_forget()
            self.bottempcolumn.grid_forget()
            self.botDwcolumn.grid_forget()
            self.botKoccolumn.grid_forget()
            self.botKdoccolumn.grid_forget()
            self.botRefcolumn.grid_forget()
            self.botendcolumn.grid_forget()
        except:
            pass

        chemicals_list = self.database.keys()
        for chemical in self.chemicals:
            if chemical.soluable == 1:
                try:
                    chemicals_list.remove(chemical.name)
                except:
                    pass

        self.addwidget.grid_forget()

        namelabellength = 18
        reflabellength = 18

        row = 0

        for chemical in self.chemicals:
            try:
                chemical.remove_chemicalwidgets()
            except:
                pass
            chemical.number = self.chemicals.index(chemical) + 1
            chemical.chemicalwidgets(self.frame, row, self.master)
            row = row + 1

            if namelabellength < chemical.namelabel.winfo_reqwidth() / 8:
                namelabellength = int(
                    chemical.namelabel.winfo_reqwidth() / 8) + 1
            if reflabellength < chemical.Reflabel.winfo_reqwidth(
            ) / 8 * 1.1424219345:
                reflabellength = int(
                    chemical.Reflabel.winfo_reqwidth() / 8 * 1.1424219345) + 1

        self.namecolumn.config(width=namelabellength)
        self.Refcolumn.config(width=reflabellength)
        self.botnamecolumn.config(width=namelabellength)
        self.botRefcolumn.config(width=reflabellength)

        self.botblankcolumn.grid(row=row,
                                 column=0,
                                 sticky='WE',
                                 padx=1,
                                 pady=1)
        self.boteditcolumn.grid(row=row, column=1, sticky='WE', padx=1, pady=1)
        self.botdelcolumn.grid(row=row, column=2, sticky='WE', padx=1, pady=1)
        self.botnumbercolumn.grid(row=row,
                                  column=3,
                                  sticky='WE',
                                  padx=1,
                                  pady=1)
        self.botnamecolumn.grid(row=row, column=4, sticky='WE', padx=1, pady=1)
        self.botMWcolumn.grid(row=row, column=5, sticky='WE', padx=1, pady=1)
        self.bottempcolumn.grid(row=row, column=6, sticky='WE', padx=1, pady=1)
        self.botDwcolumn.grid(row=row, column=7, sticky='WE', padx=1, pady=1)
        self.botKoccolumn.grid(row=row, column=8, sticky='WE', padx=1, pady=1)
        self.botKdoccolumn.grid(row=row, column=9, sticky='WE', padx=1, pady=1)
        self.botRefcolumn.grid(row=row, column=10, sticky='WE', padx=1, pady=1)
        self.botendcolumn.grid(row=row, column=11, sticky='WE', padx=1, pady=1)

        row = 0
        self.blank2.grid(row=row)
        row = row + 1
        if len(chemicals_list) > 0:
            self.addwidget.grid(row=row, columnspan=11)
            row = row + 1

        self.addwidget.bind('<Return>', self.addchemical)

        if self.nchemicals == 0: self.focusbutton = self.addwidget
        else: self.focusbutton = None

        self.master.geometry()
        self.master.center()

    def addchemical(self, event=None):

        self.nchemicals = self.nchemicals + 1
        self.chemicals.append(Chemical(self.nchemicals, soluable=1))

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                ChemicalEditor(self.top,
                               self.system,
                               self.chemicals[-1],
                               self.chemicals,
                               self.database,
                               editflag=0))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.chemicals[-1].get_chemical(self.top.window)
            else:
                self.chemicals.remove(self.chemicals[-1])
                self.nchemicals = self.nchemicals - 1

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatechemicals()

    def editchemical(self, number):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                ChemicalEditor(self.top,
                               self.system,
                               self.chemicals[number - 1],
                               self.chemicals,
                               self.database,
                               editflag=1))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.chemicals[number - 1].get_chemical(self.top.window)

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatechemicals()

    def deletechemical(self, number):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                ChemicalDeleter(self.top, self.system,
                                self.chemicals[number - 1]))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.chemicals[number - 1].remove_chemicalwidgets()
                self.chemicals.remove(self.chemicals[number - 1])
                self.nchemicals = self.nchemicals - 1

            if self.top is not None:
                self.top.destroy()
                self.top = None

        self.updatechemicals()

    def error_check(self, event=None):
        """Finish and move on.  Checks that the number chemicals are less than the
        total number of chemicals in database."""

        error = 0
        if self.nchemicals == 0: error = 1

        return error

    def warning(self):

        tkmb.showerror(
            title=self.version,
            message=
            'No chemical has been selected, please add chemicals by pressing the button "Add chemicals"'
        )
        self.focusbutton = None
        self.master.tk.lift()
コード例 #17
0
class LayerConditions:
    """Gets the chemical properties for each layer."""
    def __init__(self, master, system):
        """Constructor method.  Makes the GUI using the list of "Layer" objects
        "layers." """

        self.master = master
        self.version = system.version
        self.fonttype = system.fonttype
        self.superfont = get_superfont(self.fonttype)
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)
        self.bgcolor = self.frame.cget('bg')
        self.top = None

        self.chemicals = system.chemicals
        self.layers = system.layers
        self.sorptions = system.sorptions
        self.matrices = system.matrices
        self.dep = system.dep

        self.CSTR_flag = 0
        if system.dep == 'Deposition':
            matrix = system.matrices[system.layers[0].type_index]
            for chemical in self.chemicals:
                for component in matrix.components:
                    if system.sorptions[component.name][
                            chemical.
                            name].isotherm == 'Freundlich' or system.sorptions[
                                component.name][
                                    chemical.name].isotherm == 'Langmuir':
                        self.CSTR_flag = 1
                    elif system.sorptions[component.name][
                            chemical.name].kinetic == 'Transient':
                        self.CSTR_flag = 1

        self.topBCtypes = [
            'Fixed Concentration', 'Mass transfer', 'Finite mixed water column'
        ]
        self.botBCtypes = [
            'Fixed Concentration', 'Flux-matching', 'Zero Gradient'
        ]

        if system.adv == 'Steady flow' or system.adv == 'Tidal oscillation':
            self.U = system.Vdar
        else:
            self.U = 0

        self.concunit = system.concunit
        self.lengthunit = system.lengthunit
        self.timeunit = system.timeunit

        try:
            self.bltype = system.bltype
            self.blcoefs = system.blcoefs
        except:
            self.bltype = 'River'
            self.blcoefs = {}
            self.blcoefs['vx'] = 1.
            self.blcoefs['n'] = 0.02
            self.blcoefs['hriver'] = 5.
            self.blcoefs['rh'] = 5.
            self.blcoefs['nu'] = 1e-6

            self.blcoefs['rhoair'] = 1.
            self.blcoefs['rhowater'] = 1000.
            self.blcoefs['vwind'] = 5.
            self.blcoefs['hlake'] = 10.
            self.blcoefs['llake'] = 1000.

        try:
            self.taucoefs = system.taucoefs
        except:
            self.taucoefs = {}
            self.taucoefs['Q'] = 1.
            self.taucoefs['V'] = 100.
            self.taucoefs['h'] = 1.
            self.taucoefs['DOC'] = 0.
            self.taucoefs['Qevap'] = 0.
            self.taucoefs['Decay'] = 'None'
            self.taucoefs['Evap'] = 'None'

        if system.ICs == None:
            self.ICs = {}
            for layer in system.layers:
                self.ICs[layer.name] = {}
                for chemical in self.chemicals:
                    self.ICs[layer.name][chemical.name] = IC(
                        layer.name, chemical.name)
        else:
            self.ICs = system.ICs

        if system.BCs == None:
            self.BCs = {}
            self.topBCtype = StringVar(value=self.topBCtypes[0])
            self.botBCtype = StringVar(value=self.topBCtypes[0])
            for chemical in self.chemicals:
                self.BCs[chemical.name] = BC(chemical.name, chemical.soluable)
        else:
            self.BCs = system.BCs
            self.topBCtype = StringVar(value=system.topBCtype)
            self.botBCtype = StringVar(value=system.botBCtype)

        self.lengthunits = system.lengthunits
        self.concunits = system.concunits
        self.timeunits = system.timeunits
        self.diffunits = system.diffunits

        self.lengthunit = system.lengthunit
        self.concunit = system.concunit
        self.timeunit = system.timeunit
        self.diffunit = system.diffunit

        self.diff_factor = 1.
        self.k_factor = 1.
        self.flux_factor = 0.001

        if self.lengthunit == self.lengthunits[0]:
            self.diff_factor = self.diff_factor * (10000**2)
            self.k_factor = self.k_factor * 10000
            self.flux_factor = self.flux_factor / (10000**2)
        elif self.lengthunit == self.lengthunits[2]:
            self.diff_factor = self.diff_factor / (100**2)
            self.k_factor = self.k_factor / 100
            self.flux_factor = self.flux_factor * (100**2)

        if self.diffunit == system.diffunits[0]:
            if self.timeunit == self.timeunits[1]:
                self.diff_factor = self.diff_factor * 60
            elif self.timeunit == self.timeunits[2]:
                self.diff_factor = self.diff_factor * 60 * 60
            elif self.timeunit == self.timeunits[3]:
                self.diff_factor = self.diff_factor * 60 * 60 * 24
            elif self.timeunit == self.timeunits[4]:
                self.diff_factor = self.diff_factor * 60 * 60 * 24 * 365.25
        else:
            if self.timeunit == self.timeunits[0]:
                self.diff_factor = self.diff_factor / 365.25 / 24 / 60 / 60
            elif self.timeunit == self.timeunits[1]:
                self.diff_factor = self.diff_factor / 365.25 / 24 / 60
            elif self.timeunit == self.timeunits[2]:
                self.diff_factor = self.diff_factor / 365.25 / 24
            elif self.timeunit == self.timeunits[3]:
                self.diff_factor = self.diff_factor / 365.25

    def make_widgets(self):
        """Makes the widgets for the GUI."""

        self.instructions = Label(
            self.frame,
            text=
            'Please input the boundary conditions and initial concentration profiles:        '
        )
        self.blank1 = Label(self.frame, text='')
        self.blank2 = Label(self.frame, text='')

        self.blankcolumn = Label(self.frame, width=2, text=' ')
        self.layercolumn = Label(self.frame, width=10, text=' ')
        self.typecolumn = Label(self.frame, width=24, text=' ')
        self.paracolumn = Label(self.frame, width=20, text=' ')
        self.unitcolumn = Label(self.frame, width=8, text=' ')
        self.endcolumn = Label(self.frame, width=4, text=' ')

        self.layerlabel = Label(self.frame, width=6, text=' ')
        self.typelabel = Label(self.frame, width=6, text='Type')
        self.paralabel = Label(self.frame, width=6, text='Parameter')
        self.unitlabel = Label(self.frame, width=6, text='Unit')

        self.blank1 = Label(self.frame, text=' ')
        self.blank2 = Label(self.frame, text=' ')
        self.blank3 = Label(self.frame, text=' ')
        self.blank4 = Label(self.frame, text=' ')

        #show the widgets on the grid

        self.instructions.grid(row=0,
                               column=0,
                               padx=8,
                               columnspan=6,
                               sticky='W')

        self.blankcolumn.grid(row=1, column=0, sticky='WE', padx=1, pady=1)
        self.layercolumn.grid(row=1, column=1, sticky='WE', padx=1, pady=1)
        self.typecolumn.grid(row=1, column=2, sticky='WE', padx=1, pady=1)
        self.paracolumn.grid(row=1, column=3, sticky='WE', padx=1, pady=1)
        self.unitcolumn.grid(row=1, column=4, sticky='WE', padx=1, pady=1)

        self.layerlabel.grid(row=2, column=1, padx=4, sticky='WE')
        self.typelabel.grid(row=2, column=2, padx=4, sticky='WE')
        self.paralabel.grid(row=2, column=3, padx=4, sticky='WE')
        self.unitlabel.grid(row=2, column=4, padx=4, sticky='WE')

        column = 5
        for chemical in self.chemicals:
            if chemical.soluable == 1:
                chemical.ICwidgets(self.frame, column)
                column = column + 1

        self.endcolumn.grid(row=2, column=column, sticky='WE', padx=1, pady=1)

        self.updateconditions(event=1)
        self.focusbutton = None

    def updateBCs(self, event=None):

        self.updateconditions()

    def updateconditions(self, event=None, *args):

        try:
            self.topBClabel.grid_forget()
            self.topBCtwidget.grid_forget()
            self.botBClabel.grid_forget()
            self.botBCtwidget.grid_forget()
            self.blank3.grid_forget()
            self.blank4.grid_forget()
        except:
            pass

        try:
            self.Colabel.grid_forget()
            self.Counitlabel.grid_forget()
        except:
            pass

        try:
            self.klabel.grid_forget()
            self.kunitlabel.grid_forget()
        except:
            pass

        try:
            self.Cwlabel.grid_forget()
            self.Cwunitlabel.grid_forget()
        except:
            pass

        try:
            self.taulabel.grid_forget()
            self.tauunitlabel.grid_forget()
        except:
            pass

        try:
            self.Cblabel.grid_forget()
            self.Cbunitlabel.grid_forget()
        except:
            pass

        for chemical in self.chemicals:
            try:
                self.BCs[chemical.name].remove_widgets()
            except:
                pass

        for chemical in self.chemicals:
            self.BCs[chemical.name].topBCtype = self.topBCtype.get()
            self.BCs[chemical.name].botBCtype = self.botBCtype.get()

        row = 4

        self.topblankrow_1 = Label(self.frame, width=1, text='')
        self.topblankrow_2 = Label(self.frame, width=1, text='')

        self.topblankrow_1.grid(row=4,
                                column=0,
                                padx=4,
                                sticky='WE',
                                pady=4,
                                columnspan=1)
        self.topblankrow_2.grid(row=5,
                                column=0,
                                padx=4,
                                sticky='WE',
                                pady=4,
                                columnspan=1)

        self.topBClabel = Label(self.frame, width=10, text='Benthic')
        self.topBCtwidget = OptionMenu(self.frame,
                                       self.topBCtype,
                                       *self.topBCtypes,
                                       command=self.updateBCs)
        self.topBClabel.grid(row=row,
                             column=1,
                             sticky='WE',
                             padx=1,
                             pady=1,
                             rowspan=2)
        self.topBCtwidget.grid(row=row,
                               column=2,
                               sticky='WE',
                               padx=1,
                               pady=1,
                               rowspan=2)

        if self.topBCtype.get() == self.topBCtypes[0]:
            self.Colabel = Label(self.frame,
                                 width=15,
                                 text='Surface concentration')
            self.Counitlabel = Label(self.frame, width=5, text=self.concunit)
            self.Colabel.grid(row=row,
                              column=3,
                              sticky='WE',
                              padx=1,
                              pady=1,
                              rowspan=2)
            self.Counitlabel.grid(row=row,
                                  column=4,
                                  sticky='WE',
                                  padx=1,
                                  pady=1,
                                  rowspan=2)

            column = 5
            for chemical in self.chemicals:
                if chemical.soluable == 1:
                    self.BCs[chemical.name].topboundarywidget(
                        self.frame, row, column)
                    self.BCs[chemical.name].Co.trace('w', self.updateICs)
                    column = column + 1
            row = row + 2

        if self.topBCtype.get() == self.topBCtypes[1]:

            self.klabel = Button(self.frame,
                                 width=15,
                                 text='Mass transfer coefficient',
                                 command=self.click_kbl)
            self.kunitlabel = Label(
                self.frame, width=5,
                text='cm/hr')  #self.lengthunit + '/'+ self.timeunit)
            self.Cwlabel = Label(self.frame,
                                 width=15,
                                 text='Water concentration')
            self.Cwunitlabel = Label(self.frame, width=5, text=self.concunit)
            self.klabel.grid(row=row, column=3, sticky='WE', padx=1, pady=1)
            self.kunitlabel.grid(row=row,
                                 column=4,
                                 sticky='WE',
                                 padx=1,
                                 pady=1)
            self.Cwlabel.grid(row=row + 1,
                              column=3,
                              sticky='WE',
                              padx=1,
                              pady=1)
            self.Cwunitlabel.grid(row=row + 1,
                                  column=4,
                                  sticky='WE',
                                  padx=1,
                                  pady=1)

            column = 5
            for chemical in self.chemicals:
                if chemical.soluable == 1:
                    self.BCs[chemical.name].topboundarywidget(
                        self.frame, row, column)
                    self.BCs[chemical.name].Cw.trace('w', self.updateICs)
                    column = column + 1
            row = row + 2

        if self.topBCtype.get() == self.topBCtypes[2]:

            if self.CSTR_flag == 0:
                self.klabel = Button(self.frame,
                                     width=15,
                                     text='Mass transfer coefficient',
                                     command=self.click_kbl)
                self.kunitlabel = Label(self.frame, width=5, text='cm/hr')
                self.taulabel = Button(self.frame,
                                       width=15,
                                       text='Water body retention time',
                                       command=self.click_tau)
                self.tauunitlabel = Label(self.frame,
                                          width=5,
                                          text=self.timeunit)
                self.klabel.grid(row=row,
                                 column=3,
                                 sticky='WE',
                                 padx=1,
                                 pady=0)
                self.kunitlabel.grid(row=row,
                                     column=4,
                                     sticky='WE',
                                     padx=1,
                                     pady=1)
                self.taulabel.grid(row=row + 1,
                                   column=3,
                                   sticky='WE',
                                   padx=1,
                                   pady=0)
                self.tauunitlabel.grid(row=row + 1,
                                       column=4,
                                       sticky='WE',
                                       padx=1,
                                       pady=1)

                column = 5
                for chemical in self.chemicals:
                    if chemical.soluable == 1:
                        self.BCs[chemical.name].topboundarywidget(
                            self.frame, row, column)
                        column = column + 1
                row = row + 2

            else:
                tkmb.showerror(
                    title='Model Error',
                    message=
                    'The water body CSTR model is not applicable for systems with deposition layer governing by non-linear equilibrium isotherm or transient sorption kinetics'
                )
                self.topBCtype.set(self.topBCtypes[1])
                self.klabel = Button(self.frame,
                                     width=15,
                                     text='Mass transfer coefficient',
                                     command=self.click_kbl)
                self.kunitlabel = Label(self.frame, width=5, text='cm/hr')
                self.Cwlabel = Label(self.frame,
                                     width=15,
                                     text='Water concentration')
                self.Cwunitlabel = Label(self.frame,
                                         width=5,
                                         text=self.concunit)
                self.klabel.grid(row=row,
                                 column=3,
                                 sticky='WE',
                                 padx=1,
                                 pady=1)
                self.kunitlabel.grid(row=row,
                                     column=4,
                                     sticky='WE',
                                     padx=1,
                                     pady=1)
                self.Cwlabel.grid(row=row + 1,
                                  column=3,
                                  sticky='WE',
                                  padx=1,
                                  pady=1)
                self.Cwunitlabel.grid(row=row + 1,
                                      column=4,
                                      sticky='WE',
                                      padx=1,
                                      pady=1)

                column = 5
                for chemical in self.chemicals:
                    if chemical.soluable == 1:
                        self.BCs[chemical.name].topboundarywidget(
                            self.frame, row, column)
                        column = column + 1
                row = row + 2

        if self.layers[0].name != 'Deposition':
            self.blank3.grid(row=row)
            row = row + 1

        for layer in self.layers:
            row = row + 2

        self.updateICs()

        self.blank4.grid(row=row)
        row = row + 1

        self.botBClabel = Label(self.frame, width=10, text='Underlying')
        self.botBCtwidget = OptionMenu(self.frame,
                                       self.botBCtype,
                                       *self.botBCtypes,
                                       command=self.updateBCs)
        self.botBClabel.grid(row=row, column=1, sticky='WE', padx=1, pady=1)
        self.botBCtwidget.grid(row=row, column=2, sticky='WE', padx=1, pady=1)

        #print(self.botBCtype.get())

        if self.botBCtype.get() == self.botBCtypes[0] or self.botBCtype.get(
        ) == self.botBCtypes[1]:

            self.Cblabel = Label(self.frame, width=15, text='Concentration')
            self.Cbunitlabel = Label(self.frame, width=5, text=self.concunit)
            self.Cblabel.grid(row=row, column=3, sticky='WE', padx=1, pady=1)
            self.Cbunitlabel.grid(row=row,
                                  column=4,
                                  sticky='WE',
                                  padx=1,
                                  pady=1)

            column = 5
            for chemical in self.chemicals:
                if chemical.soluable == 1:
                    self.BCs[chemical.name].botboundarywidget(
                        self.frame, row, column)
                    column = column + 1
            row = row + 1
        else:
            row = row + 1

        self.blank1.grid(row=row)
        self.focusbutton = None
        self.frame.update()
        self.master.geometry()
        self.master.center()

    def updateICs(self, event=None, *args):

        for layer in self.layers:
            try:
                layer.remove_ICwidgets()
            except:
                pass
            for chemical in self.chemicals:
                try:
                    self.ICs[layer.name][chemical.name].remove_widgets()
                except:
                    pass

        if self.layers[0].name != 'Deposition':
            row = 7
        else:
            row = 6

        for layer in self.layers:
            layer.ICwidgets(self.frame, row, self.master, self.concunit)
            column = 5
            for chemical in self.chemicals:
                if chemical.soluable == 1:
                    self.ICs[layer.name][chemical.name].propertieswidgets(
                        self.frame, row, column, layer.ICtype.get(),
                        layer.name)
                    column = column + 1
            row = row + 2

        if self.layers[0].name == 'Deposition':
            for chemical in self.chemicals:
                if chemical.soluable == 1:
                    if self.topBCtype.get() == self.topBCtypes[0]:
                        self.ICs[self.layers[0].name][
                            chemical.name].uniform.set(
                                self.BCs[chemical.name].Co.get())
                    elif self.topBCtype.get() == self.topBCtypes[1]:
                        self.ICs[self.layers[0].name][
                            chemical.name].uniform.set(
                                self.BCs[chemical.name].Cw.get())
                    elif self.topBCtype.get() == self.topBCtypes[2]:
                        self.ICs[self.layers[0].name][
                            chemical.name].uniform.set('Cw')

    def click_kbl(self, event=None):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                KblEstimator(self.top, self.version, self.fonttype,
                             self.bltype, self.blcoefs))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:

                self.bltype = self.top.window.bltype.get()

                if self.top.window.bltype.get() == 'River':

                    self.blcoefs['vx'] = self.top.window.vx.get()
                    self.blcoefs['n'] = self.top.window.n.get()
                    self.blcoefs['hriver'] = self.top.window.hriver.get()
                    self.blcoefs['rh'] = self.top.window.rh.get()
                    self.blcoefs['nu'] = self.top.window.nu.get()

                    for chemical in self.chemicals:
                        if chemical.soluable == 1:
                            try:
                                self.BCs[chemical.name].k.set(
                                    round_to_n(
                                        kblriver(
                                            self.blcoefs['vx'],
                                            self.blcoefs['n'],
                                            self.blcoefs['hriver'],
                                            self.blcoefs['rh'],
                                            self.blcoefs['nu'], chemical.Dw /
                                            86400 / 365 * self.diff_factor),
                                        3))
                            except:
                                tkmb.showerror(
                                    title='Math Error',
                                    message=
                                    'The parameters you have entered produce a math error.  Please change the parameters and recalculate.'
                                )
                else:
                    self.blcoefs['rhoair'] = self.top.window.rhoair.get()
                    self.blcoefs['rhowater'] = self.top.window.rhowater.get()
                    self.blcoefs['vwind'] = self.top.window.vwind.get()
                    self.blcoefs['hlake'] = self.top.window.hlake.get()
                    self.blcoefs['llake'] = self.top.window.llake.get()

                    for chemical in self.chemicals:
                        if chemical.soluable == 1:
                            try:
                                self.BCs[chemical.name].k.set(
                                    round_to_n(
                                        kbllake(self.blcoefs['rhoair'],
                                                self.blcoefs['rhowater'],
                                                self.blcoefs['vwind'],
                                                self.blcoefs['hlake'],
                                                chemical.MW,
                                                self.blcoefs['llake']), 3))
                            except:
                                tkmb.showerror(
                                    title='Math Error',
                                    message=
                                    'The parameters you have entered produce a math error.  Please change the parameters and recalculate.'
                                )

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updateconditions()

    def click_tau(self, event=None):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                TauEstimator(self.top, self.version, self.fonttype,
                             self.timeunit, self.lengthunit, self.chemicals,
                             self.taucoefs, self.BCs))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:

                self.taucoefs['Q'] = self.top.window.Q.get()
                self.taucoefs['V'] = self.top.window.V.get()
                self.taucoefs['h'] = self.top.window.h.get()
                self.taucoefs['Qevap'] = self.top.window.Qevap.get()
                self.taucoefs['DOC'] = self.top.window.doc.get()
                self.taucoefs['Decay'] = self.top.window.Decay.get()
                self.taucoefs['Evap'] = self.top.window.Evap.get()

                Q = self.taucoefs['Q'] - self.taucoefs[
                    'Qevap'] + self.taucoefs['V'] / self.taucoefs['h'] * self.U

                if self.dep == 'Deposition':
                    if self.lengthunit == 'cm': kdep = self.layers[0].h / 100
                    elif self.lengthunit == u'\u03BCm':
                        kdep = self.layers[0].h / 100 / 1000
                    else:
                        kdep = self.layers[0].h
                    matrix = self.matrices[self.layers[0].type_index]
                    epsilon = self.matrices[self.layers[0].type_index].e
                    dep_rho = matrix.rho
                    dep_fraction = []
                    for component in matrix.components:
                        dep_fraction.append(component.mfraction)
                else:
                    kdep = 0
                    epsilon = 0
                    dep_rho = 0
                    dep_fraction = []

                for n in range(len(self.chemicals)):
                    chemical = self.chemicals[n]
                    self.BCs[chemical.name].kdecay = self.top.window.kdecays[n]
                    self.BCs[chemical.name].kevap = self.top.window.kevaps[n]

                    if self.taucoefs['Evap'] == 'None': kevap = 0
                    else: kevap = self.top.window.kevaps[n]
                    if self.taucoefs['Decay'] == 'None': kdecay = 0
                    else: kdecay = self.top.window.kdecays[n]

                    K = []
                    if self.dep == 'Deposition':
                        matrix = self.matrices[self.layers[0].type_index]
                        for component in matrix.components:
                            if self.sorptions[component.name][
                                    chemical.
                                    name].isotherm == 'Linear--Kd specified':
                                K.append(self.sorptions[component.name][
                                    chemical.name].K)
                            elif self.sorptions[component.name][
                                    chemical.
                                    name].isotherm == 'Linear--Kocfoc':
                                K.append(10**self.sorptions[component.name][
                                    chemical.name].Koc)

                    try:
                        self.BCs[chemical.name].tau.set(
                            round_to_n(
                                tauwater(Q, self.taucoefs['DOC'],
                                         chemical.Kdoc, kdep, epsilon, dep_rho,
                                         dep_fraction, K, self.taucoefs['V'],
                                         self.taucoefs['h'], kevap, kdecay),
                                3))
                    except:
                        tkmb.showerror(
                            title='Math Error',
                            message=
                            'The parameters you have entered produce a math error.  Please change the parameters and recalculate.'
                        )

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updateconditions()

    def error_check(self, event=None):
        """Finish and move on.  Checks that the number chemicals are less than the
        total number of chemicals in database."""

        error = 0

        if self.topBCtype.get() == 'Finite mixed water column':
            for chemical in self.chemicals:
                if self.BCs[chemical.name].tau.get() <= 0:
                    error = 1

        return error

    def warning(self):

        tkmb.showerror(title=self.version,
                       message='The retention time must be positive values')
        self.focusbutton = None
        self.master.tk.lift()
コード例 #18
0
class ReactionEditor:
    """Gets the chemical reaction information for each layer."""
    def __init__(self, master, system, reaction, editflag):
        """Constructor method.  Makes the GUI using the list of "Layer" objects
        "layers." """

        # Read the Tkinter information
        self.master = master
        self.fonttype = system.fonttype
        self.formulatype = system.formulatype
        self.version = system.version
        self.superfont = get_superfont(self.fonttype)
        self.subfont = get_superfont(self.formulatype)
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)
        self.bgcolor = self.frame.cget('bg')
        self.top = None

        self.system = system

        # Read the system information
        self.chemicals = system.chemicals
        self.reaction = reaction
        self.editflag = editflag

        # Define the reaction chemical information
        self.chemical_list = [chemical.name for chemical in self.chemicals]
        self.formula_list = [chemical.formula for chemical in self.chemicals]
        self.MW_list = [chemical.MW for chemical in self.chemicals]

        self.models = ['Fundamental', 'User-defined']

        self.name = StringVar(value='Reaction ' + str(reaction.number))
        self.model = StringVar(value=self.models[0])
        self.reactants = []
        self.products = []

        #self.stoichcoef = reaction.stoichcoef
        if editflag == 1:

            self.name = StringVar(value=reaction.name)
            self.model = StringVar(value=reaction.model)
            self.reactants = [
                reactant.copy() for reactant in reaction.reactants
            ]
            self.products = [product.copy() for product in reaction.products]

            for reactant in self.reactants:
                reactant.coef = DoubleVar(value=reactant.coef)
                reactant.index = DoubleVar(value=reactant.index)
                reactant.name = StringVar(value=reactant.name)
                reactant.formula = StringVar(value=reactant.formula)
                reactant.MW = DoubleVar(value=reactant.MW)

            for product in self.products:
                product.coef = DoubleVar(value=product.coef)
                product.name = StringVar(value=product.name)
                product.formula = StringVar(value=product.formula)
                product.MW = DoubleVar(value=product.MW)

        self.cancelflag = 0

    def make_widgets(self):

        self.instructions = Label(
            self.frame,
            text=
            'Please input the following information for the added kinetic process:        '
        )

        self.reactblankcolumn = Label(self.frame, text=' ', width=2)
        self.reactdelcolumn = Label(self.frame, text=' ', width=6)
        self.reactcoefcolumn = Label(self.frame, text=' ', width=6)
        self.reactnamecolumn = Label(self.frame, text=' ', width=20)
        self.reactformcolumn = Label(self.frame, text=' ', width=10)
        self.middlecolumn = Label(self.frame, text=' ', width=14)
        self.proddelcolumn = Label(self.frame, text=' ', width=6)
        self.prodcoefcolumn = Label(self.frame, text=' ', width=6)
        self.prodnamecolumn = Label(self.frame, text=' ', width=20)
        self.prodformcolumn = Label(self.frame, text=' ', width=10)
        self.prodblankcolumn = Label(self.frame, text=' ', width=2)

        self.nameblank = Label(self.frame, text=' ', width=10)
        self.namelabel = Label(self.frame, text='Name:', width=10)
        self.namewidget = Entry(self.frame, textvariable=self.name, width=15)

        self.modellabel = Label(self.frame, text='Kinetic model:', width=10)
        self.modelwidget = OptionMenu(self.frame,
                                      self.model,
                                      *self.models,
                                      command=self.click_model)

        self.ratelabel = Label(self.frame, text='Rate equation:', width=10)

        self.reactlabel = Label(self.frame, text='Reactants')
        self.prodlabel = Label(self.frame, text='Products')

        self.reactcoeflabel = Label(self.frame,
                                    text='Stoichiometric\ncoefficient')
        self.reactnamelabel = Label(self.frame, text='Chemical')
        self.reactformlabel = Label(self.frame, text='Formula')
        self.prodcoeflabel = Label(self.frame,
                                   text='Stoichiometric\ncoefficient')
        self.prodnamelabel = Label(self.frame, text='Chemical')
        self.prodformlabel = Label(self.frame, text='Formula')

        self.addreactwidget = Button(self.frame,
                                     text='Add reactant',
                                     width=20,
                                     command=self.addreactant)
        self.addprodwidget = Button(self.frame,
                                    text='Add product',
                                    width=20,
                                    command=self.addproduct)
        self.okbutton = Button(self.frame,
                               text='OK',
                               width=20,
                               command=self.OK)
        self.cancelbutton = Button(self.frame,
                                   text='Cancel',
                                   width=20,
                                   command=self.Cancel)
        self.blank1 = Label(self.frame, text=' ')
        self.blank2 = Label(self.frame, text=' ')

        self.instructions.grid(row=0,
                               column=0,
                               padx=8,
                               sticky='W',
                               columnspan=11)

        self.nameblank.grid(row=1, column=0, padx=2, sticky='WE', columnspan=4)

        self.namelabel.grid(row=2, column=0, padx=2, sticky='E', columnspan=3)
        self.namewidget.grid(row=2, column=3, padx=2, sticky='W')

        self.modellabel.grid(row=2, column=4, padx=2, sticky='E')
        self.modelwidget.grid(row=2,
                              column=5,
                              padx=2,
                              sticky='W',
                              columnspan=2)

        self.ratelabel.grid(row=2, column=7, padx=2, sticky='E')

        self.reactblankcolumn.grid(row=3, column=0, padx=2, sticky='WE')
        self.reactdelcolumn.grid(row=3, column=1, padx=2, sticky='WE')
        self.reactcoefcolumn.grid(row=3, column=2, padx=2, sticky='WE')
        self.reactnamecolumn.grid(row=3, column=3, padx=2, sticky='WE')
        self.reactformcolumn.grid(row=3, column=4, padx=2, sticky='WE')
        self.middlecolumn.grid(row=3, column=5, padx=2, sticky='WE')
        self.proddelcolumn.grid(row=3, column=6, padx=2, sticky='WE')
        self.prodcoefcolumn.grid(row=3, column=7, padx=2, sticky='WE')
        self.prodnamecolumn.grid(row=3, column=8, padx=2, sticky='WE')
        self.prodformcolumn.grid(row=3, column=9, padx=2, sticky='WE')
        self.prodblankcolumn.grid(row=3, column=10, padx=2, sticky='WE')

        self.reactlabel.grid(row=4,
                             column=2,
                             padx=2,
                             sticky='WE',
                             columnspan=3)
        self.prodlabel.grid(row=4, column=7, padx=2, sticky='WE', columnspan=3)

        self.reactcoeflabel.grid(row=5, column=2, padx=2, sticky='WE')
        self.reactnamelabel.grid(row=5, column=3, padx=2, sticky='WE')
        self.reactformlabel.grid(row=5, column=4, padx=2, sticky='WE')

        self.prodcoeflabel.grid(row=5, column=7, padx=2, sticky='WE')
        self.prodnamelabel.grid(row=5, column=8, padx=2, sticky='WE')
        self.prodformlabel.grid(row=5, column=9, padx=2, sticky='WE')

        self.updatereaction()

        # Build a frame for Reaction rate

        self.focusbutton = None

    def click_model(self, event=None):

        check = 0
        reactant_list = [reactant.name.get() for reactant in self.reactants]
        for name in reactant_list:
            if reactant_list.count(name) > 1:
                check = 1

        if len(self.reactants) == 0:
            tkmb.showerror(
                title=self.system.version,
                message='Please firstly input the information of reactants.')
            self.model.set('Fundamental')
            self.focusbutton = self.okbutton
            self.master.tk.lift()

        elif check == 1:
            tkmb.showerror(
                title=self.system.version,
                message=
                'At least one chemical is replicated in the reactant list, please check'
            )
            self.model.set('Fundamental')
            self.focusbutton = self.okbutton
            self.master.tk.lift()

        else:
            if self.model.get() == 'User-defined':

                if self.top is None:
                    self.top = CapSimWindow(master=self.master, buttons=2)
                    self.top.make_window(
                        UserDefined(self.top, self.system, self.reactants))
                    self.top.tk.mainloop()

                    if self.top is not None:
                        self.top.destroy()
                        self.top = None

                elif self.top is not None:
                    tkmb.showerror(
                        title=self.system.version,
                        message=
                        'Please close the existing parameter input window first.'
                    )
                    self.top.tk.focus()

            self.updaterateequation()

    def updaterateequation(self):

        try:
            self.ratewidget.grid_forget()
        except:
            pass

        font = tkFont.Font(font=self.formulatype)
        subfont = tkFont.Font(font=self.subfont)
        superfont = tkFont.Font(font=self.superfont)

        if self.model.get() == 'Fundamental':

            rate_len = font.measure(u'r = \u03BB')
            for reactant in self.reactants:
                rate_len = rate_len + font.measure('C')
                rate_len = rate_len + subfont.measure(reactant.formula.get())
                if reactant.coef.get() == int(reactant.coef.get()):
                    coef = int(reactant.coef.get())
                else:
                    coef = reactant.coef.get()
                if coef <> 1.:
                    rate_len = rate_len + superfont.measure(str(coef) + ' ')
            self.ratewidget = Text(self.frame,
                                   width=int(rate_len * 1.1424219345 / 8) + 1,
                                   height=1,
                                   font=self.formulatype)
            self.ratewidget.insert('end', u'r = \u03BB')
            for reactant in self.reactants:
                self.ratewidget.insert('end', 'C')
                self.ratewidget.insert('end', reactant.formula.get(), 'sub')
                if reactant.coef.get() == int(reactant.coef.get()):
                    coef = int(reactant.coef.get())
                else:
                    coef = reactant.coef.get()
                if coef <> 1.:
                    self.ratewidget.insert('end', str(coef) + ' ', 'super')

        if self.model.get() == 'User-defined':

            rate_len = font.measure(u'r = \u03BB')
            for reactant in self.reactants:
                if reactant.index.get() <> 0:
                    rate_len = rate_len + font.measure('C')
                    rate_len = rate_len + subfont.measure(
                        reactant.formula.get())
                    if reactant.index.get() == int(reactant.index.get()):
                        index = int(reactant.index.get())
                    else:
                        index = reactant.index.get()
                    if index <> 1.:
                        rate_len = rate_len + superfont.measure(
                            str(index) + ' ')

            self.ratewidget = Text(self.frame,
                                   width=int(rate_len * 1.1424219345 / 8) + 1,
                                   height=1,
                                   font=self.formulatype)
            self.ratewidget.insert('end', u'r = \u03BB')
            for reactant in self.reactants:
                if reactant.index.get() <> 0:
                    self.ratewidget.insert('end', 'C')
                    self.ratewidget.insert('end', reactant.formula.get(),
                                           'sub')
                    if reactant.index.get() == int(reactant.index.get()):
                        index = int(reactant.index.get())
                    else:
                        index = reactant.index.get()
                    if index <> 1.:
                        self.ratewidget.insert('end',
                                               str(index) + ' ', 'super')

        self.ratewidget.tag_config('sub', offset=-4, font=self.subfont)
        self.ratewidget.tag_config('super', offset=5, font=self.superfont)
        self.ratewidget.tag_config('right', justify='right')
        self.ratewidget.config(state='disabled',
                               background=self.bgcolor,
                               borderwidth=0,
                               spacing3=3)

        self.ratewidget.grid(row=2, column=8, padx=2, sticky='W', columnspan=3)

    def updatereaction(self):

        try:
            self.addreactwidget.grid_forget()
            self.addprodwidget.grid_forget()
            self.okbutton.grid_forget()
            self.cancelbutton.grid_forget()
        except:
            pass

        self.updaterateequation()

        row = 6

        for reactant in self.reactants:
            try:
                reactant.remove_propertieswidgets()
            except:
                pass
            reactant.propertieswidgets(self.frame, row, self.master,
                                       self.chemical_list, self.formula_list,
                                       self.MW_list)
            row = row + 1

        row_reactant = row

        row = 6

        for product in self.products:
            try:
                product.remove_propertieswidgets()
            except:
                pass
            product.propertieswidgets(self.frame, row, self.master,
                                      self.chemical_list, self.formula_list,
                                      self.MW_list)
            row = row + 1

        if row < row_reactant: row = row_reactant

        self.blank1.grid(row=row)
        row = row + 1
        self.addreactwidget.grid(row=row, columnspan=11)
        row = row + 1
        self.addprodwidget.grid(row=row, columnspan=11)
        row = row + 1
        self.okbutton.grid(row=row, columnspan=11)
        row = row + 1
        self.cancelbutton.grid(row=row, columnspan=11)
        row = row + 1
        self.blank2.grid(row=row)

        self.okbutton.bind('<Return>', self.OK)
        self.focusbutton = self.okbutton

        self.master.geometry()

    def addreactant(self):

        self.reactants.append(Reactant(len(self.reactants) + 1))

        self.reactants[-1].coef = DoubleVar(value=1)
        self.reactants[-1].name = StringVar(value=self.chemical_list[0])
        self.reactants[-1].formula = StringVar(value=self.formula_list[0])
        self.reactants[-1].index = DoubleVar(value=1)
        self.reactants[-1].MW = DoubleVar(value=self.MW_list[0])

        self.updatereaction()

    def addproduct(self):

        self.products.append(Product(len(self.products) + 1))

        self.products[-1].coef = DoubleVar(value=1)
        self.products[-1].name = StringVar(value=self.chemical_list[0])
        self.products[-1].formula = StringVar(value=self.formula_list[0])
        self.products[-1].MW = StringVar(value=self.MW_list[0])

        self.updatereaction()

    def delreactant(self, number):

        self.reactants[number - 1].remove_propertieswidgets()
        self.reactants.remove(self.reactants[number - 1])

        self.updatereaction()

    def delproduct(self, number):

        self.products[number - 1].remove_propertieswidgets()
        self.products.remove(self.products[number - 1])

        self.updatereaction()

    def OK(self, event=None):
        """Finish and move on.  Checks that the number chemicals are less than the
        total number of chemicals in database."""

        if self.model.get() == 'Fundamental':
            for reactant in self.reactants:
                reactant.index.set(reactant.coef.get())

        check = 0

        chemicals = []
        for reactant in self.reactants:
            chemicals.append(reactant.name.get())
        for product in self.products:
            chemicals.append(product.name.get())

        for chemical in chemicals:
            if chemicals.count(chemical) > 1:
                check = 1

        if self.master.window.top is not None: self.master.open_toplevel()
        elif check == 1: self.reaction_error()
        else:
            for reactant in self.reactants:
                reactant.get_reactant()
                reactant.remove_propertieswidgets()

            for product in self.products:
                product.get_product()
                product.remove_propertieswidgets()

            if (len(self.reactants) + len(self.products)) == 0:
                self.cancelflag = 1
            self.master.tk.quit()

    def reaction_error(self):

        tkmb.showerror(
            title=self.version,
            message='At least one chemical has been replicated in the reaction!'
        )
        self.focusbutton = self.okbutton
        self.master.tk.lift()

    def Cancel(self):

        try:
            self.reactants = self.reaction.reactants
            self.products = self.reaction.products

        except:

            self.cancelflag = 1

        if self.master.window.top is not None: self.master.open_toplevel()
        else: self.master.tk.quit()
コード例 #19
0
class Database:
    """Opens a window for inputing the properties of a compound."""
    def __init__(self, master, system, database):
        """The constructor method."""

        self.version = system.version
        self.fonttype = system.fonttype
        self.sfont = get_superfont(self.fonttype)
        self.master = master
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)
        self.top = None

        self.system = system
        self.database = database  #the chemical database

        self.chemicals_list = self.database.keys()
        self.chemicals_list.sort()

        self.chemicaldatas = {}

        for name in self.chemicals_list:
            self.chemicaldatas[name] = ChemicalData(name)
            self.chemicaldatas[name].read_database(self.database[name])

    def make_widgets(self):

        self.insruction = Label(
            self.tframe,
            text=
            'Please provide the following fundamental properties for the chemicals:\n'
        )

        self.blankcolumn = Label(self.tframe, text=' ', width=1)
        self.editcolumn = Label(self.tframe, text=' ', width=6)
        self.delcolumn = Label(self.tframe, text=' ', width=6)
        self.namecolumn = Label(self.tframe, text=' ', width=18)
        self.formcolumn = Label(self.tframe, text=' ', width=10)
        self.tempcolumn = Label(self.tframe, text=' ', width=10)
        self.Dwcolumn = Label(self.tframe, text=' ', width=18)
        self.Koccolumn = Label(self.tframe, text=' ', width=18)
        self.Kdoccolumn = Label(self.tframe, text=' ', width=18)
        self.Refcolumn = Label(self.tframe, text=' ', width=18)
        self.endcolumn = Label(self.tframe, text=' ', width=2)

        self.namelabel = Label(self.tframe, text='Chemical name')
        self.formlabel = Label(self.tframe, text='Formula')
        self.templabel = Label(self.tframe, text='Temperature')
        self.Dwlabel = Label(self.tframe,
                             text='Molecular diffusivity\n in water')
        self.Koclabel = Label(self.tframe,
                              text='Organic carbon\n partition coefficient')
        self.Kdoclabel = Label(
            self.tframe,
            text='Dissolved organic carbon\n partition coefficient')
        self.Reflabel = Label(self.tframe, text='Reference')

        self.tempunits = Label(self.tframe, text=unichr(176) + 'C')
        self.Dwunits = Label(self.tframe, text=u'cm\u00B2/s')
        self.Kocunits = Label(self.tframe, text='log(L/kg)')
        self.Kdocunits = Label(self.tframe, text='log(L/kg)')

        self.addwidget = Button(self.bframe,
                                text='Add new chemicals',
                                command=self.addchemicaldata,
                                width=20)
        self.tempwidget = Button(self.bframe,
                                 text='Add new temperatures',
                                 command=self.addtempdata,
                                 width=20)
        self.importwidget = Button(self.bframe,
                                   text='Import database file',
                                   command=self.importchemicaldata,
                                   width=20)
        self.savebutton = Button(self.bframe,
                                 text='Save',
                                 command=self.OK,
                                 width=20)
        self.cancelbutton = Button(self.bframe,
                                   text='Cancel',
                                   command=self.cancel,
                                   width=20)

        self.botblankcolumn = Label(self.frame, text=' ', width=1)
        self.boteditcolumn = Label(self.frame, text=' ', width=6)
        self.botdelcolumn = Label(self.frame, text=' ', width=6)
        self.botnamecolumn = Label(self.frame, text=' ', width=18)
        self.botformcolumn = Label(self.frame, text=' ', width=10)
        self.bottempcolumn = Label(self.frame, text=' ', width=10)
        self.botDwcolumn = Label(self.frame, text=' ', width=18)
        self.botKoccolumn = Label(self.frame, text=' ', width=18)
        self.botKdoccolumn = Label(self.frame, text=' ', width=18)
        self.botRefcolumn = Label(self.frame, text=' ', width=18)
        self.botendcolumn = Label(self.frame, text=' ', width=2)

        self.blank1 = Label(self.bframe, text=' ')
        self.blank2 = Label(self.bframe, text=' ')
        self.blank3 = Label(self.bframe, text=' ')

        self.insruction.grid(row=0,
                             column=0,
                             sticky='W',
                             padx=1,
                             pady=1,
                             columnspan=11)

        self.blankcolumn.grid(row=1, column=0, sticky='WE', padx=1, pady=1)
        self.editcolumn.grid(row=1, column=1, sticky='WE', padx=1, pady=1)
        self.delcolumn.grid(row=1, column=2, sticky='WE', padx=1, pady=1)
        self.namecolumn.grid(row=1, column=3, sticky='WE', padx=1, pady=1)
        self.formcolumn.grid(row=1, column=4, sticky='WE', padx=1, pady=1)
        self.tempcolumn.grid(row=1, column=5, sticky='WE', padx=1, pady=1)
        self.Dwcolumn.grid(row=1, column=6, sticky='WE', padx=1, pady=1)
        self.Koccolumn.grid(row=1, column=7, sticky='WE', padx=1, pady=1)
        self.Kdoccolumn.grid(row=1, column=8, sticky='WE', padx=1, pady=1)
        self.Refcolumn.grid(row=1, column=9, sticky='WE', padx=1, pady=1)
        self.endcolumn.grid(row=1, column=10, sticky='WE', padx=1, pady=1)

        self.namelabel.grid(row=2, column=3, sticky='WE', padx=1, pady=1)
        self.formlabel.grid(row=2, column=4, sticky='WE', padx=1, pady=1)
        self.templabel.grid(row=2, column=5, sticky='WE', padx=1, pady=1)
        self.Dwlabel.grid(row=2, column=6, sticky='WE', padx=1, pady=1)
        self.Koclabel.grid(row=2, column=7, sticky='WE', padx=1, pady=1)
        self.Kdoclabel.grid(row=2, column=8, sticky='WE', padx=1, pady=1)
        self.Reflabel.grid(row=2, column=9, sticky='WE', padx=1, pady=1)

        self.tempunits.grid(row=3, column=5, sticky='WE', padx=1, pady=1)
        self.Dwunits.grid(row=3, column=6, sticky='WE', padx=1, pady=1)
        self.Kocunits.grid(row=3, column=7, sticky='WE', padx=1, pady=1)
        self.Kdocunits.grid(row=3, column=8, sticky='WE', padx=1, pady=1)

        #Bind the "return key" to the buttons

        self.updatechemicals()

    def updatechemicals(self, event=None):

        self.addwidget.grid_forget()
        self.tempwidget.grid_forget()
        self.savebutton.grid_forget()
        self.cancelbutton.grid_forget()
        self.blank1.grid_forget()
        self.blank2.grid_forget()

        self.chemicals_list = self.chemicaldatas.keys()
        self.chemicals_list.sort()
        row = 4

        namelabellength = 18
        formlabellength = 10
        Reflabellength = 18

        for name in self.chemicals_list:
            try:
                self.chemicaldatas[name].remove_chemicalwidgets()
            except:
                pass
            self.chemicaldatas[name].chemicalwidgets(self.frame, row,
                                                     self.master)
            row = row + 1

            if namelabellength < self.chemicaldatas[
                    name].namelabel.winfo_reqwidth() / 8:
                namelabellength = int(
                    self.chemicaldatas[name].namelabel.winfo_reqwidth() /
                    8) + 1
            if formlabellength < self.chemicaldatas[
                    name].formlabel.winfo_reqwidth() / 8:
                formlabellength = int(
                    self.chemicaldatas[name].formlabel.winfo_reqwidth() /
                    8) + 1
            if Reflabellength < self.chemicaldatas[
                    name].Reflabel.winfo_reqwidth() / 8:
                Reflabellength = int(
                    self.chemicaldatas[name].Reflabel.winfo_reqwidth() / 8) + 1

        self.namecolumn.config(width=namelabellength)
        self.formcolumn.config(width=formlabellength)
        self.Refcolumn.config(width=Reflabellength)

        self.botnamecolumn.config(width=namelabellength)
        self.botformcolumn.config(width=formlabellength)
        self.botRefcolumn.config(width=Reflabellength)

        self.botblankcolumn.grid(row=row,
                                 column=0,
                                 sticky='WE',
                                 padx=1,
                                 pady=1)
        self.boteditcolumn.grid(row=row, column=1, sticky='WE', padx=1, pady=1)
        self.botdelcolumn.grid(row=row, column=2, sticky='WE', padx=1, pady=1)
        self.botnamecolumn.grid(row=row, column=3, sticky='WE', padx=1, pady=1)
        self.botformcolumn.grid(row=row, column=4, sticky='WE', padx=1, pady=1)
        self.bottempcolumn.grid(row=row, column=5, sticky='WE', padx=1, pady=1)
        self.botDwcolumn.grid(row=row, column=6, sticky='WE', padx=1, pady=1)
        self.botKoccolumn.grid(row=row, column=7, sticky='WE', padx=1, pady=1)
        self.botKdoccolumn.grid(row=row, column=8, sticky='WE', padx=1, pady=1)
        self.botRefcolumn.grid(row=row, column=9, sticky='WE', padx=1, pady=1)
        self.botendcolumn.grid(row=row, column=10, sticky='WE', padx=1, pady=1)

        self.blank2.grid(row=row)
        row = row + 1
        self.addwidget.grid(row=row, columnspan=11)
        row = row + 1
        self.tempwidget.grid(row=row, columnspan=11)
        row = row + 1
        self.importwidget.grid(row=row, columnspan=11)
        row = row + 1
        self.savebutton.grid(row=row, columnspan=11)
        row = row + 1
        self.cancelbutton.grid(row=row, columnspan=11)
        row = row + 1
        self.blank3.grid(row=row)
        row = row + 1

        self.savebutton.bind('<Return>', self.OK)
        self.cancelbutton.bind('<Return>', self.cancel)

        self.focusbutton = self.cancelbutton
        self.master.geometry()
        self.master.center()

    def addchemicaldata(self, event=None):

        new_name = 'chemical' + str(len(self.chemicals_list))

        self.chemicaldatas[new_name] = ChemicalData(new_name)

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                DatabaseEditor(self.top,
                               self.system,
                               self.chemicaldatas[new_name],
                               self.chemicaldatas,
                               editflag=0,
                               tempflag=0))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.chemicaldatas[new_name].get_chemicaldata(self.top.window)
                self.chemicaldatas[self.chemicaldatas[new_name].
                                   name] = self.chemicaldatas[new_name].copy()

            del self.chemicaldatas[new_name]

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatechemicals()

    def importchemicaldata(self):

        UserPath = os.environ['USERPROFILE']
        Filepath = tkfd.askopenfilename(initialdir=UserPath)

        if Filepath != '':
            data = open(Filepath, 'r')
            database_imported = pickle.load(data)
            data.close()
            if self.top is None:
                self.top = CapSimWindow(master=self.master, buttons=2)
                self.top.make_window(
                    DatabaseImporter(self.top, self.system, database_imported))
                self.top.tk.mainloop()

                duplicate_name = []
                duplicate_temp = []

                if self.top.window.cancelflag == 0:
                    error_check = 0
                    for name in self.top.window.chemicals_list:
                        if self.top.window.importedchemicals[name].check == 1:
                            if self.chemicals_list.count(
                                    self.top.window.importedchemicals[name].
                                    name_new) == 0:
                                self.chemicals_list.append(
                                    self.top.window.importedchemicals[name].
                                    name_new)
                                self.chemicaldatas[
                                    self.top.window.importedchemicals[name].
                                    name_new] = ChemicalData(
                                        self.top.window.
                                        importedchemicals[name].name_new)
                                self.chemicaldatas[
                                    self.top.window.importedchemicals[name].
                                    name_new].read_database(
                                        self.top.window.importedchemicals[name]
                                    )
                            else:
                                for temp in self.top.window.importedchemicals[
                                        name].temps:
                                    if self.chemicaldatas[
                                            self.top.window.
                                            importedchemicals[name].
                                            name_new].temps.count(temp) == 0:
                                        self.chemicaldatas[
                                            self.top.window.
                                            importedchemicals[name].
                                            name_new].read_temperature(
                                                self.top.window.
                                                importedchemicals[name], temp)
                                    else:
                                        duplicate_name.append(
                                            self.top.window.
                                            importedchemicals[name].name_new)
                                        duplicate_temp.append(temp)
                                        error_check = 1
                    error_message = 'The following compound information are duplicated:\n\n'
                    for na in range(len(duplicate_name)):
                        error_message = error_message + '              ' + str(
                            duplicate_name[na]) + ' @ ' + str(
                                duplicate_temp[na]) + 'C \n'

                    if error_check == 1:
                        tkmb.showerror(title=self.system.version,
                                       message=error_message)

                if self.top is not None:
                    self.top.destroy()
                    self.top = None

            elif self.top is not None:
                tkmb.showerror(
                    title=self.system.version,
                    message=
                    'Please close the existing parameter input window first.')
                self.top.tk.focus()

        self.updatechemicals()

    def addtempdata(self, event=None):

        name = self.chemicals_list[0]

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                DatabaseEditor(self.top,
                               self.system,
                               self.chemicaldatas[name],
                               self.chemicaldatas,
                               editflag=0,
                               tempflag=1))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.chemicaldatas[
                    self.top.window.name.get()].get_chemicaldata(
                        self.top.window)

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatechemicals()

    def editchemicaldata(self, name):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                DatabaseEditor(self.top,
                               self.system,
                               self.chemicaldatas[name],
                               self.chemicaldatas,
                               editflag=1,
                               tempflag=0))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.chemicaldatas[name].get_chemicaldata(self.top.window)

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatechemicals()

    def deletechemicaldata(self, name):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                DatabaseDeleter(self.top, self.system,
                                self.chemicaldatas[name]))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.chemicaldatas[name].get_chemicaldata(self.top.window)
            if self.top.window.cancelflag == 2:
                self.chemicaldatas[name].remove_chemicalwidgets()
                del self.chemicaldatas[name]

            if self.top is not None:
                self.top.destroy()
                self.top = None

        self.updatechemicals()

    def cancel(self, event=None):

        self.exitflag = 1
        self.frame.quit()

    def OK(self, event=None):
        """Finish and move on."""

        self.database = {}
        for name in self.chemicals_list:
            chemicaldata = self.chemicaldatas[name]
            index = self.chemicals_list.index(name)
            self.database[name] = ChemicalDatabase(chemicaldata.name,
                                                   chemicaldata.formula,
                                                   index + 1, chemicaldata.MW)
            for temp in chemicaldata.temps:
                Dw = chemicaldata.Dw[temp]
                Kow = chemicaldata.Kow[temp]
                density = chemicaldata.density[temp]
                Ref = chemicaldata.Ref[temp]
                Koc = chemicaldata.Koc[temp]
                Kdoc = chemicaldata.Kdoc[temp]
                Kf = chemicaldata.Kf[temp]
                N = chemicaldata.N[temp]

                self.database[name].add_properties(temp, Kow, density, Ref, Dw,
                                                   Koc, Kdoc, Kf, N)

        self.exitflag = 1
        self.frame.quit()
コード例 #20
0
class MatrixProperties:
    """Gets the contaminant properties."""

    def __init__(self, master, system, materials):

        """Constructor method. Defines the parameters to be obtained in this window."""

        self.master    = master
        self.fonttype  = system.fonttype
        self.version   = system.version
        self.superfont = get_superfont(self.fonttype) #superscript font
        self.tframe    = Frame(master.tframe)
        self.frame     = Frame(master.frame)
        self.bframe    = Frame(master.bframe)
        self.top       = None                   #flag for existence of toplevel#

        self.system    = system
        self.materials = materials

        if system.matrices is None:
            self.matrices  = []
            self.nmatrices = 0
        else:
            self.matrices  = system.matrices
            self.nmatrices = system.nmatrices


    def make_widgets(self):
        """Make the widgets for the window."""

        self.bgcolor      = self.frame.cget('bg')

        # Construct all label widgets used in the problem
        self.instructions = Label(self.tframe, text = ' Please select the potential layer materials and provide the following properties:                    ')

        self.blankcolumn    = Label(self.tframe,  text ='',  width = 1)
        self.editcolumn     = Label(self.tframe,  text =' ', width = 6)
        self.delcolumn      = Label(self.tframe,  text =' ', width = 6)
        self.namecolumn     = Label(self.tframe,  text =' ', width = 20)
        self.ecolumn        = Label(self.tframe,  text =' ', width = 15)
        self.rhocolumn      = Label(self.tframe,  text =' ', width = 15)
        self.foccolumn      = Label(self.tframe,  text =' ', width = 20)
        self.endcolumn      = Label(self.tframe,  text =' ', width = 2)

        self.namelabel      = Label(self.tframe,  text = 'Matrix')
        self.elabel         = Label(self.tframe,  text = 'Porosity')
        self.rholabel       = Label(self.tframe,  text = 'Bulk density' )
        self.foclabel       = Label(self.tframe,  text = 'Organic carbon fraction')

        self.rhounit        = Label(self.tframe,  text = u'g/cm\u00B3')

        self.botblankcolumn    = Label(self.frame,  text ='', width = 1)
        self.boteditcolumn     = Label(self.frame,  text =' ', width = 6)
        self.botdelcolumn      = Label(self.frame,  text =' ', width = 6)
        self.botnamecolumn     = Label(self.frame,  text =' ', width = 20)
        self.botecolumn        = Label(self.frame,  text =' ', width = 15)
        self.botrhocolumn      = Label(self.frame,  text =' ', width = 15)
        self.botfoccolumn      = Label(self.frame,  text =' ', width = 20)
        self.botendcolumn      = Label(self.frame,  text =' ', width = 2)

        self.blank1 = Label(self.bframe, text = ' ')
        self.blank2 = Label(self.bframe, text = ' ')
        self.blank3 = Label(self.bframe, text = ' ')

        self.addwidget  = Button(self.bframe, text = 'Add materials', command = self.addmatrix,  width = 20)
        self.loadwidget = Button(self.bframe, text = 'Load materials', command = self.loadmatrix,  width = 20)
        self.mixwidget  = Button(self.bframe, text = 'Create mixtures',  command = self.addmixture,  width = 20)

        #show the widgets on the grid
        self.instructions.grid(  row    = 0, column = 0, sticky = 'W',  padx = 8, columnspan = 6,)

        self.blankcolumn.grid(   row    = 1, column = 0, sticky = 'WE', padx = 1, pady = 1)
        self.editcolumn.grid(    row    = 1, column = 1, sticky = 'WE', padx = 1, pady = 1)
        self.delcolumn.grid(     row    = 1, column = 2, sticky = 'WE', padx = 1, pady = 1)
        self.namecolumn.grid(    row    = 1, column = 3, sticky = 'WE', padx = 1, pady = 1)
        self.ecolumn.grid(       row    = 1, column = 4, sticky = 'WE', padx = 1, pady = 1)
        self.rhocolumn.grid(     row    = 1, column = 5, sticky = 'WE', padx = 1, pady = 1)
        self.foccolumn.grid(     row    = 1, column = 6, sticky = 'WE', padx = 1, pady = 1)

        self.namelabel.grid(     row    = 2, column = 3, sticky = 'WE', padx = 1, pady = 1)
        self.elabel.grid  (      row    = 2, column = 4, sticky = 'WE', padx = 1, pady = 1)
        self.rholabel.grid (     row    = 2, column = 5, sticky = 'WE', padx = 1, pady = 1)
        self.foclabel.grid (     row    = 2, column = 6, sticky = 'WE', padx = 1, pady = 1)

        self.rhounit.grid (      row    = 3, column = 5, sticky = 'WE', padx = 1, pady = 1)

        self.updatematrices()


    def updatematrices(self):

        self.addwidget.grid_forget()
        self.loadwidget.grid_forget()
        self.blank1.grid_forget()

        self.botblankcolumn.grid_forget()
        self.boteditcolumn.grid_forget()
        self.botdelcolumn.grid_forget()
        self.botnamecolumn.grid_forget()
        self.botecolumn.grid_forget()
        self.botrhocolumn.grid_forget()
        self.botfoccolumn.grid_forget()

        material_list = self.materials.keys()
        for matrix in self.matrices:
            if len(matrix.components) == 1 :
                try: material_list.remove(matrix.name)
                except: pass

        row = 4

        for matrix in self.matrices:
            try: matrix.remove_propertieswidgets()
            except:pass
            matrix.number = self.matrices.index(matrix) + 1
            matrix.propertieswidgets(self.frame, row, self.master)
            row = row + 1

        self.botblankcolumn.grid(   row    = row, column = 0, sticky = 'WE', padx = 1, pady = 1)
        self.boteditcolumn.grid(    row    = row, column = 1, sticky = 'WE', padx = 1, pady = 1)
        self.botdelcolumn.grid(     row    = row, column = 2, sticky = 'WE', padx = 1, pady = 1)
        self.botnamecolumn.grid(    row    = row, column = 3, sticky = 'WE', padx = 1, pady = 1)
        self.botecolumn.grid(       row    = row, column = 4, sticky = 'WE', padx = 1, pady = 1)
        self.botrhocolumn.grid(     row    = row, column = 5, sticky = 'WE', padx = 1, pady = 1)
        self.botfoccolumn.grid(     row    = row, column = 6, sticky = 'WE', padx = 1, pady = 1)

        row = 0
        self.blank1.grid(row = row)
        row = row + 1
        self.blank2.grid(row = row)
        row = row + 1
        self.addwidget.grid(row = row, columnspan = 11)
        row = row + 1
        if len(material_list) > 0:
            self.loadwidget.grid(row = row, columnspan = 11)
            row = row + 1
        self.mixwidget.grid(row = row, columnspan = 11)
        row = row + 1

        self.addwidget.bind('<Return>', self.addmatrix)
        self.mixwidget.bind('<Return>', self.addmixture)
        if self.nmatrices == 0:     self.focusbutton = self.addwidget
        else:                       self.focusbutton = None
        self.master.geometry()
        self.master.center()

    def addmixture(self, default = None):

        self.nmatrices = self.nmatrices + 1
        self.matrices.append(Matrix(self.nmatrices))

        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(MixtureEditor(self.top, self.system, self.matrices[-1], self.matrices, self.materials, editflag = 0))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.matrices[-1].get_matrix(self.top.window)
            else:
                self.matrices.remove(self.matrices[-1])
                self.nmatrices = self.nmatrices - 1

            for component in self.matrices[-1].components:
                for matrix in self.matrices[:-1]:
                    for sub_component in matrix.components:
                        if sub_component.name == component.name:
                            sub_component.e   = component.e
                            sub_component.rho = component.rho
                            sub_component.foc = component.foc

                    if len(matrix.components) > 1:
                        e         = 0
                        rho       = 0
                        moc       = 0
                        foc       = 0
                        fractions = 0

                        for component in matrix.components:

                            fractions = fractions + component.fraction
                            e         = e         + component.fraction * component.e
                            rho       = rho       + component.fraction * component.rho
                            moc       = moc       + component.fraction * component.rho * component.foc

                        foc = moc/rho

                        matrix.e = (round(e,2))
                        matrix.rho = (round(rho,3))
                        matrix.foc = (round(foc,3))

                    else:
                        matrix.e          = matrix.components[-1].e
                        matrix.rho        = matrix.components[-1].rho
                        matrix.foc        = matrix.components[-1].foc

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatematrices()

    def addmatrix(self, default = None):

        self.nmatrices = self.nmatrices + 1
        self.matrices.append(Matrix(self.nmatrices))

        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(MatrixEditor(self.top, self.system, self.matrices[-1], self.matrices, self.materials, editflag = 0, newflag = 1))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.matrices[-1].get_matrix(self.top.window)
            else:
                self.matrices.remove(self.matrices[-1])
                self.nmatrices = self.nmatrices - 1

            if len(self.matrices) > 0:
                for component in self.matrices[-1].components:
                    for matrix in self.matrices[:-1]:
                        for sub_component in matrix.components:
                            if sub_component.name == component.name:
                                sub_component.e   = component.e
                                sub_component.rho = component.rho
                                sub_component.foc = component.foc

                        if len(matrix.components) > 1:
                            e         = 0
                            rho       = 0
                            moc       = 0
                            foc       = 0
                            fractions = 0

                            for component in matrix.components:

                                fractions = fractions + component.fraction
                                e         = e         + component.fraction * component.e
                                rho       = rho       + component.fraction * component.rho
                                moc       = moc       + component.fraction * component.rho * component.foc

                            foc = moc/rho

                            matrix.e = (round(e,2))
                            matrix.rho = (round(rho,3))
                            matrix.foc = (round(foc,3))

                        else:
                            matrix.e          = matrix.components[-1].e
                            matrix.rho        = matrix.components[-1].rho
                            matrix.foc        = matrix.components[-1].foc

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatematrices()

    def loadmatrix(self, default = None):

        self.nmatrices = self.nmatrices + 1
        self.matrices.append(Matrix(self.nmatrices))

        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(MatrixEditor(self.top, self.system, self.matrices[-1], self.matrices, self.materials, editflag = 0, newflag = 0))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.matrices[-1].get_matrix(self.top.window)
            else:
                self.matrices.remove(self.matrices[-1])
                self.nmatrices = self.nmatrices - 1

            if len(self.matrices) > 0:
                for component in self.matrices[-1].components:
                    for matrix in self.matrices[:-1]:
                        for sub_component in matrix.components:
                            if sub_component.name == component.name:
                                sub_component.e   = component.e
                                sub_component.rho = component.rho
                                sub_component.foc = component.foc

                        if len(matrix.components) > 1:
                            e         = 0
                            rho       = 0
                            moc       = 0
                            foc       = 0
                            fractions = 0

                            for component in matrix.components:

                                fractions = fractions + component.fraction
                                e         = e         + component.fraction * component.e
                                rho       = rho       + component.fraction * component.rho
                                moc       = moc       + component.fraction * component.rho * component.foc

                            foc = moc/rho

                            matrix.e = (round(e,2))
                            matrix.rho = (round(rho,3))
                            matrix.foc = (round(foc,3))

                        else:
                            matrix.e          = matrix.components[-1].e
                            matrix.rho        = matrix.components[-1].rho
                            matrix.foc        = matrix.components[-1].foc

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatematrices()

    def editmatrix(self, number):

        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            if len(self.matrices[number - 1].components) < 2: self.top.make_window(MatrixEditor(self.top, self.system, self.matrices[number-1], self.matrices, self.materials, editflag = 1, newflag = 0))
            else:                                             self.top.make_window(MixtureEditor(self.top, self.system,self.matrices[number-1], self.matrices, self.materials, editflag = 1))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.matrices[number-1].get_matrix(self.top.window)

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatematrices()

    def deletematrix(self, number):

        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(MatrixDeleter(self.top, self.system, self.matrices[number-1]))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.matrices[number-1].remove_propertieswidgets()
                self.matrices.remove(self.matrices[number-1])
                self.nmatrices = self.nmatrices - 1

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatematrices()


    def error_check(self):

        error = 0

        if self.nmatrices == 0: error = 1

        return error

    def warning(self):

        tkmb.showerror(title = self.version, message = 'No matrices has been selected, please add matrices by pressing the button "Add materials" or the button "Add mixture"')
        self.focusbutton = None
        self.master.tk.lift()
コード例 #21
0
class SorptionEditor:
    """Gets the contaminant properties."""
    
    def __init__(self, master, system, sorption):
        
        """Constructor method.  Defines the parameters to be obtained in this
        window."""
        
        self.master     = master
        self.fonttype   = system.fonttype
        self.version    = system.version
        self.sfont      = get_superfont(self.fonttype)  #superscript font
        self.frame      = Frame(master.frame)
        self.tframe     = Frame(master.tframe)
        self.bframe     = Frame(master.bframe)
        self.top        = None                   #flag for existence of toplevel#

        self.system     = system

        self.isotherms      = ['Linear--Kd specified', 'Linear--Kocfoc', 'Freundlich', 'Langmuir']
        self.kinetics       = ['Equilibrium', 'Transient']

        self.sorption   = sorption
            
        self.isotherm   = StringVar(value = sorption.isotherm)
        self.kinetic    = StringVar(value = sorption.kinetic)
        self.K          = DoubleVar(value = sorption.K)
        self.Koc        = DoubleVar(value = sorption.Koc)
        self.Kf         = DoubleVar(value = sorption.Kf)
        self.N          = DoubleVar(value = sorption.N)
        self.qmax       = DoubleVar(value = sorption.qmax)
        self.b          = DoubleVar(value = sorption.b)
        self.ksorp      = DoubleVar(value = sorption.ksorp)

        self.cinit      = sorption.cinit
        self.qinit      = sorption.qinit
        self.thalf      = sorption.thalf

        self.concunit   = system.concunit
        self.timeunit   = system.timeunit

        self.tkfont      = tkFont.Font(font = self.fonttype)

        self.cancelflag = 0
        
    def make_widgets(self):
        """Make the widgets for the window."""
        
        self.bgcolor      = self.frame.cget('bg')
        self.instructions = Label(self.frame, text = ' Please provide the following sorption properties:                    ')

        self.leftcolumn     = Label(self.frame, width = 2,  text = '' )
        self.matrixcolumn   = Label(self.frame, width = 10, text = '' )
        self.chemicalcolumn = Label(self.frame, width = 10, text = '' )
        self.isothermcolumn = Label(self.frame, width = 20, text = '' )
        self.kineticcolumn  = Label(self.frame, width = 15, text = '' )
        self.equacolumn     = Label(self.frame, width = 17, text = '' )
        self.coefcolumn1    = Label(self.frame, width = 6,  text = '' )
        self.coefcolumn2    = Label(self.frame, width = 9,  text = '' )
        self.coefcolumn3    = Label(self.frame, width = int(self.tkfont.measure(self.concunit[:-1]+'/kg/('+ self.concunit +')'+ u'\u1d3a')/8)+1, text = '' )
        self.coefcolumn4    = Label(self.frame, width = 4,  text = '' )
        self.coefcolumn5    = Label(self.frame, width = 9,  text = '' )
        self.coefcolumn6    = Label(self.frame, width = int(self.tkfont.measure(self.concunit)/8)+1,  text = '' )
        self.coefcolumn7    = Label(self.frame, width = 7,  text = '' )
        self.coefcolumn8    = Label(self.frame, width = 9,  text = '' )
        self.coefcolumn9    = Label(self.frame, width = 10, text = '' )
        self.rightcolumn    = Label(self.frame, width = 2,  text = '' )

        self.matrixlabel    = Label(self.frame, text = 'Matrix')
        self.chemicallabel  = Label(self.frame, text = 'Chemical')
        self.isothermlabel  = Label(self.frame, text = 'Sorption Isotherm')
        self.kineticlabel   = Label(self.frame, text = 'Kinetics')

        self.matrixwidget   = Label(self.frame, text = self.sorption.matrix.name)
        self.chemicalwidget = Label(self.frame, text = self.sorption.chemical.name)
        self.isothermwidget = OptionMenu(self.frame, self.isotherm, *self.isotherms, command = self.click_isotherm)
        self.kineticwidget  = OptionMenu(self.frame, self.kinetic,  *self.kinetics,  command = self.click_kinetic)
        
        self.okbutton     = Button(self.frame, text = 'OK', width = 20, command = self.OK)
        self.cancelbutton = Button(self.frame, text = 'Cancel', width = 20, command = self.Cancel)
        self.blank1       = Label(self.frame, text = ' ')
        self.blank2       = Label(self.frame, text = ' ')
        
        #show the widgets on the grid
        self.instructions.grid(row = 0, column = 0, columnspan = 15, padx = 2, pady = 8, sticky = 'W')

        self.leftcolumn.grid(    row = 1, column = 0,   padx = 2, pady = 1, sticky = 'WE')
        self.matrixcolumn.grid(  row = 1, column = 1,   padx = 2, pady = 1, sticky = 'WE')
        self.chemicalcolumn.grid(row = 1, column = 2,   padx = 2, pady = 1, sticky = 'WE')
        self.isothermcolumn.grid(row = 1, column = 3,   padx = 2, pady = 1, sticky = 'WE')
        self.kineticcolumn.grid( row = 1, column = 4,   padx = 2, pady = 1, sticky = 'WE')
        self.equacolumn.grid(    row = 1, column = 5,   padx = 2, pady = 1, sticky = 'WE')
        self.coefcolumn1.grid(   row = 1, column = 6,   padx = 0, pady = 1)
        self.coefcolumn2.grid(   row = 1, column = 7,   padx = 0, pady = 1)
        self.coefcolumn3.grid(   row = 1, column = 8,   padx = 0, pady = 1)
        self.coefcolumn4.grid(   row = 1, column = 9,   padx = 0, pady = 1)
        self.coefcolumn5.grid(   row = 1, column = 10,  padx = 0, pady = 1)
        self.coefcolumn6.grid(   row = 1, column = 11,  padx = 0, pady = 1)
        self.coefcolumn7.grid(   row = 1, column = 12,  padx = 0, pady = 1)
        self.coefcolumn8.grid(   row = 1, column = 13,  padx = 0, pady = 1)
        self.coefcolumn9.grid(   row = 1, column = 14,  padx = 0, pady = 1)
        self.rightcolumn.grid(   row = 1, column = 15,  padx = 0, pady = 1)

        self.matrixlabel.grid(   row = 2, column = 1,  padx = 2, pady = 4, sticky = 'WE')
        self.chemicallabel.grid( row = 2, column = 2,  padx = 2, pady = 4, sticky = 'WE')
        self.isothermlabel.grid( row = 2, column = 3,  padx = 2, pady = 4, sticky = 'WE')
        self.kineticlabel.grid(  row = 2, column = 4,  padx = 2, pady = 4, sticky = 'WE')

        self.matrixwidget.grid(  row = 3, column = 1,  padx = 2, pady = 1, sticky = 'WE')
        self.chemicalwidget.grid(row = 3, column = 2,  padx = 2, pady = 1, sticky = 'WE')
        self.isothermwidget.grid(row = 3, column = 3,  padx = 2, pady = 1, sticky = 'WE')
        self.kineticwidget.grid( row = 3, column = 4,  padx = 2, pady = 1, sticky = 'WE')

        self.blank1.grid(       row    = 4)
        self.okbutton.grid(     row    = 5, columnspan = 15)
        self.cancelbutton.grid( row    = 6, columnspan = 15)
        self.blank2.grid(       row    = 7)
        self.okbutton.bind('<Return>', self.OK)
        self.focusbutton = self.okbutton

        self.click_isotherm()
        self.click_kinetic()

    def click_kinetic(self, event = None):

        bgcolor = self.frame.cget('bg')

        try:
            self.klabel.grid_forget()
            self.ksorplabel.grid_forget()
            self.ksorpwidget.grid_forget()
            self.ksorpunits.grid_forget()
        except: pass

        if self.kinetic.get() == self.kinetics[1]:

            if self.isotherm.get() == self.isotherms[3]:
                self.klabel  = Label(self.frame, text = 'Kinetic rate coefficient:')
            else:
                self.klabel  = Button(self.frame, text = 'Kinetic rate coefficient:', command = self.k_estimator)

            self.ksorplabel = Text(self.frame, width = 7, height = 1)
            self.ksorplabel.insert('end', u'k')
            self.ksorplabel.insert('end', 'sorp', 'sub')
            self.ksorplabel.insert('end', u' =')
            self.ksorplabel.tag_config('sub', offset = -2, font = 'Arial 8')
            self.ksorplabel.tag_config('right', justify = 'right')
            self.ksorplabel.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)

            self.ksorpwidget = Entry(self.frame, textvariable = self.ksorp, justify = 'center', width = 10)

            if self.isotherm.get() == self.isotherms[0] or self.isotherm.get() == self.isotherms[1]:
                self.ksorpunits   = Label(self.frame, text = self.timeunit +u'\u207B\u00b9')
            if self.isotherm.get() == self.isotherms[2]:
                self.ksorpunits   = Label(self.frame, text = self.timeunit +u'\u207B\u00b9')
            if self.isotherm.get() == self.isotherms[3]:
                self.ksorpunits   = Label(self.frame, text = '(' + self.concunit[:-1] +'kg)'+u'\u207B\u00b9 ' +self.timeunit + u'\u207B\u00b9')

            self.klabel.grid(     row  = 2, column = 12, padx = 1, pady = 1, sticky = 'WE', columnspan = 3)
            self.ksorplabel.grid( row  = 3, column = 12, padx = 1, pady = 5, sticky = 'SE')
            self.ksorpwidget.grid(row  = 3, column = 13, padx = 1, pady = 1)
            self.ksorpunits.grid( row  = 3, column = 14, padx = 1, sticky = 'W')

    def k_estimator(self, event = None):

        k_error = 0
        coef = []
        coef.append(self.cinit)
        coef.append(self.qinit)
        coef.append(self.thalf)
        coef.append(self.ksorp.get())
        if self.isotherm.get() == self.isotherms[0]:
            coef.append(self.K.get())
            coef.append(0)
            if self.K.get() == 0:
                K_error = 1
        if self.isotherm.get() == self.isotherms[1]:
            coef.append(self.Koc.get())
            coef.append(self.sorption.matrix.foc)
            if self.Koc.get() == 0:
                K_error = 1
        if self.isotherm.get() == self.isotherms[2]:
            coef.append(self.Kf.get())
            coef.append(self.N.get())
            if self.Kf.get() == 0 or self.N.get() == 0:
                K_error = 1
        if self.isotherm.get() == self.isotherms[3]:
            coef.append(self.qmax.get())
            coef.append(self.b.get())
            if self.qmax.get() == 0 or self.b.get() == 0:
                K_error = 1

        coef.append(self.sorption.matrix.e)
        coef.append(self.sorption.matrix.rho)

        if self.top is None:
            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(K_Estimator(self.top, self.system, self.isotherm.get(), coef))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.ksorp.set(self.top.window.ksorp.get())
                self.cinit = self.top.window.cinit.get()
                self.qinit = self.top.window.qinit.get()
                self.thalf = self.top.window.thalf.get()

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(title = self.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()


    def click_isotherm(self, event = None):

        try:
            self.equalabel.grid_forget()
            self.coeflabel.grid_forget()
            self.eqwidget.grid_forget()
        except: pass

        try:
            self.Klabel.grid_forget()
            self.Kwidget.grid_forget()   
            self.Kunits.grid_forget()  
        except: pass

        try:
            self.Koclabel.grid_forget()
            self.Kocwidget.grid_forget()
            self.Kocunits.grid_forget()
        except: pass
        
        try:
            self.Kflabel.grid_forget()      
            self.Nlabel.grid_forget()    
            self.Kfwidget.grid_forget() 
            self.Nwidget.grid_forget()          
            self.Kfunits.grid_forget()     
        except: pass
        
        try:
            self.qmaxlabel.grid_forget() 
            self.qmaxwidget.grid_forget()
            self.qmaxunits.grid_forget() 
            self.blabel.grid_forget()    
            self.bwidget.grid_forget()   
            self.bunits.grid_forget()
        except: pass
        

        bgcolor = self.frame.cget('bg')
        
        if self.isotherm.get() == self.isotherms[0]:
            
            self.equalabel  = Label(self.frame, text = 'Isotherm Equation')
            self.eqwidget = Text(self.frame, width = 7, height = 1)
            self.eqwidget.insert('end', u'q = K')
            self.eqwidget.insert('end', 'd', 'sub')
            self.eqwidget.insert('end', 'C')
            self.eqwidget.tag_config('sub', offset = -2, font = 'Arial 8')
            self.eqwidget.tag_config('right', justify = 'center')
            self.eqwidget.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)
            
            self.coeflabel  = Label(self.frame, text = 'Matrix-water partition coefficient')
            
            self.Klabel   = Text(self.frame, width = 4, height = 1)
            self.Klabel.insert('end', 'K')
            self.Klabel.insert('end', 'd', 'sub')
            self.Klabel.insert('end', ' =')
            self.Klabel.tag_config('sub', offset = -2, font = 'Arial 8')
            self.Klabel.tag_config('right', justify = 'right')
            self.Klabel.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)
            
            self.Kwidget  = Entry(self.frame, textvariable = self.K, justify = 'center', width = 10)
            self.Kunits   = Label(self.frame, text = 'L/kg')

            self.equalabel.grid( row  = 2, column = 5, padx = 2, pady = 1, sticky = 'WE')
            self.coeflabel.grid( row  = 2, column = 6, padx = 2, pady = 1, sticky = 'WE', columnspan = 6)
            self.eqwidget.grid(  row  = 3, column = 5, padx = 1, pady = 5, sticky = 'S')
            self.Klabel.grid(    row  = 3, column = 6, padx = 0, pady = 5, sticky = 'SE')
            self.Kwidget.grid(   row  = 3, column = 7, padx = 0)
            self.Kunits.grid(    row  = 3, column = 8, padx = 0, sticky = 'W')
            
        elif self.isotherm.get() == self.isotherms[1]:
            
            self.equalabel  = Label(self.frame, text = 'Isotherm Equation')
            self.eqwidget = Text(self.frame, width = 10, height = 1)
            self.eqwidget.insert('end', u'q = K')
            self.eqwidget.insert('end', 'oc', 'sub')
            self.eqwidget.insert('end', 'f')
            self.eqwidget.insert('end', 'oc', 'sub')
            self.eqwidget.insert('end', 'C')
            self.eqwidget.tag_config('sub', offset = -2, font = 'Arial 8')
            self.eqwidget.tag_config('right', justify = 'right')
            self.eqwidget.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)
            
            self.coeflabel     = Label(self.frame, text = 'Organic carbon partition coefficient:')
            
            self.Koclabel  = Text(self.frame, width = 5, height = 1)
            self.Koclabel.insert('end', 'K')
            self.Koclabel.insert('end', 'oc', 'sub')
            self.Koclabel.insert('end', ' =')
            self.Koclabel.tag_config('sub', offset = -2, font = 'Arial 8')
            self.Koclabel.tag_config('right', justify = 'right')
            self.Koclabel.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)
            
            self.Kocwidget = Entry(self.frame, textvariable = self.Koc, justify = 'center', width = 10)
            self.Kocunits  = Label(self.frame, text = 'log(L/kg)')

            self.equalabel.grid(    row  = 2, column = 5, padx = 2, pady = 1, sticky = 'WE')
            self.coeflabel.grid(    row  = 2, column = 6, padx = 2, pady = 1, sticky = 'WE', columnspan = 6)
            self.eqwidget.grid(     row  = 3, column = 5, padx = 1, pady = 5, sticky = 'S')
            self.Koclabel.grid (    row  = 3, column = 6, padx = 0, pady = 5, sticky = 'SE')
            self.Kocwidget.grid(    row  = 3, column = 7, padx = 0)
            self.Kocunits.grid(     row  = 3, column = 8, padx = 0, sticky = 'W')
        
        elif self.isotherm.get() == self.isotherms[2]:

            self.equalabel  = Label(self.frame, text = 'Isotherm Equation')
            self.eqwidget = Text(self.frame, width = 8, height = 1)
            self.eqwidget.insert('end', u'q = K')
            self.eqwidget.insert('end', 'F', 'sub')
            self.eqwidget.insert('end', 'C')
            self.eqwidget.insert('end', 'N', 'super')
            self.eqwidget.tag_config('sub', offset = -2, font = 'Arial 8')
            self.eqwidget.tag_config('super', offset = 5, font = self.sfont)
            self.eqwidget.tag_config('right', justify = 'right')
            self.eqwidget.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)

            self.coeflabel  = Label(self.frame, text = 'Freudlich isotherm coefficient:')
            self.Kflabel = Text(self.frame, width = 4, height = 1)
            self.Kflabel.insert('end', u'K')
            self.Kflabel.insert('end', 'F', 'sub')
            self.Kflabel.insert('end', u' =')
            self.Kflabel.tag_config('sub', offset = -2, font = 'Arial 8')
            self.Kflabel.tag_config('right', justify = 'right')
            self.Kflabel.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)
            self.Nlabel   = Label(self.frame, text = 'N =')
            self.Kfwidget = Entry(self.frame, textvariable = self.Kf,justify = 'center', width = 10)
            self.Nwidget  = Entry(self.frame, textvariable = self.N, justify = 'center', width = 10)

            self.Kfunits  = Label(self.frame, text = self.concunit[:-1]+'/kg/('+ self.concunit +')'+ u'\u1d3a')

            self.equalabel.grid(    row  = 2, column = 5,  padx = 2, pady = 1, sticky = 'WE')
            self.coeflabel.grid(    row  = 2, column = 6,  padx = 2, pady = 1, sticky = 'WE', columnspan = 6)
            self.eqwidget.grid(     row  = 3, column = 5,  padx = 1, pady = 5, sticky = 'S')
            self.Kflabel.grid(      row  = 3, column = 6,  padx = 0, pady = 5, sticky = 'SE')
            self.Kfwidget.grid(     row  = 3, column = 7,  padx = 0)
            self.Kfunits.grid(      row  = 3, column = 8,  padx = 0, sticky = 'W')
            self.Nlabel.grid (      row  = 3, column = 9,  padx = 0, sticky = 'E')
            self.Nwidget.grid(      row  = 3, column = 10, padx = 0)
            
        elif self.isotherm.get() == self.isotherms[3]:
            
            self.equalabel  = Label(self.frame, text = 'Isotherm Equation')
            self.eqwidget = Text(self.frame, width = 17, height = 0.1)
            self.eqwidget.insert('end', u'q = q')
            self.eqwidget.insert('end', 'max', 'sub')
            self.eqwidget.insert('end', 'b*C/(1+b*C)')
            self.eqwidget.tag_config('sub', offset = -2, font = 'Arial 8')
            self.eqwidget.tag_config('right', justify = 'right')
            self.eqwidget.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)

            self.coeflabel  = Label(self.frame, text = 'Langmuir isotherm coefficient:')
            self.qmaxlabel = Text(self.frame, width = 7, height = 0.1)
            self.qmaxlabel.insert('end', '  ', 'sub')
            self.qmaxlabel.insert('end', u'q')
            self.qmaxlabel.insert('end', 'max', 'sub')
            self.qmaxlabel.insert('end', u' =')
            self.qmaxlabel.tag_config('sub', offset = -3, font = 'Arial 8')
            self.qmaxlabel.tag_config('right', justify = 'right')
            self.qmaxlabel.config(state = 'disabled', background = bgcolor, borderwidth = 0, spacing3 = 3)

            self.qmaxwidget = Entry(self.frame, textvariable = self.qmax, justify = 'center', width = 10)
            self.qmaxunits  = Label(self.frame, text = self.concunit[:-1] +  'kg')
            
            self.blabel     = Label(self.frame, text = 'b =')
            self.bwidget    = Entry(self.frame, textvariable = self.b, justify = 'center', width = 10)
            self.bunits     = Label(self.frame, text = 'L/' + self.concunit[:-2])
            
            self.equalabel.grid(    row  = 2, column = 5,  padx = 2, pady = 1, sticky = 'WE')
            self.coeflabel.grid(    row  = 2, column = 6,  padx = 2, pady = 1, sticky = 'WE', columnspan = 6)
            self.eqwidget.grid(     row  = 3, column = 5,  padx = 1, pady = 5, sticky = 'S')
            self.qmaxlabel.grid(    row  = 3, column = 6,  padx = 0, pady = 5, sticky = 'SE')
            self.qmaxwidget.grid(   row  = 3, column = 7,  padx = 0, pady = 1)
            self.qmaxunits.grid(    row  = 3, column = 8,  padx = 0, pady = 1, sticky = 'W')
            self.blabel.grid(       row  = 3, column = 9,  padx = 0, pady = 1, sticky = 'E')
            self.bwidget.grid(      row  = 3, column = 10, padx = 0, pady = 1)
            self.bunits.grid(       row  = 3, column = 11, padx = 0, pady = 1, sticky = 'W')

        self.click_kinetic()

    def OK(self, event = None):
        """Finish and move on.  Checks that the number chemicals are less than the
        total number of chemicals in database."""
            
        if self.master.window.top is not None: self.master.open_toplevel()
        else: self.master.tk.quit()
        
    def Cancel(self):
        
        try:
            self.isotherm.set(self.sorption.isotherm)
            self.kinetic.set(self.sorption.kinetic)
            self.K.set(self.sorption.K)
            self.Koc.set(self.sorption.Koc)
            self.Kf.set(self.sorption.Kf)
            self.N.set(self.sorption.N)
            self.qmax.set(self.sorption.qmax)
            self.b.set(self.sorption.b)
            self.ksorp.set(self.sorption.ksorp)

        except: self.cancelflag = 1
            
        if self.master.window.top is not None: self.master.open_toplevel()
        else: self.master.tk.quit()
コード例 #22
0
class ReactionCoefficients:
    """Gets the model types for each of the layers in the system."""
    def __init__(self, master, system, editflag):
        """Constructor method. Used to defines the layers."""

        self.master = master
        self.version = system.version
        self.fonttype = system.fonttype
        self.formulatype = system.formulatype
        self.superfont = get_superfont(self.fonttype)
        self.subfont = get_superfont(self.formulatype)
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)
        self.bgcolor = self.frame.cget('bg')
        self.top = None

        self.system = system
        self.concunit = system.concunit
        self.timeunit = system.timeunit

        self.concunits = system.concunits

        # Convert mass concentration units to corresponding molar concentration units
        if self.concunit == system.concunits[0]:
            self.concunit = system.concunits[3]
        if self.concunit == system.concunits[1]:
            self.concunit = system.concunits[4]
        if self.concunit == system.concunits[2]:
            self.concunit = system.concunits[5]

        self.reactions = system.reactions
        self.layers = system.layers
        self.coefficients = system.coefficients

        if system.coefficients == None:
            self.coefficients = {}
            for layer in self.layers:
                layerindex = self.layers.index(layer)
                self.coefficients[layer.name] = {}
                for reaction in self.reactions:
                    self.coefficients[layer.name][reaction.name] = Coefficient(
                        layer, reaction)

        self.name_max = 0
        self.formula_max = 0
        self.rate_max = 0
        self.value_max = 0
        unitindex = 0

        tkfont = tkFont.Font(font=self.formulatype)
        tksubfont = tkFont.Font(font=self.superfont)
        tksuperfont = tkFont.Font(font=self.subfont)

        for reaction in self.reactions:
            if tkfont.measure(reaction.name) > self.name_max:
                self.name_max = tkfont.measure(reaction.name)
            if tkfont.measure(reaction.equation) > self.formula_max:
                self.formula_max = tkfont.measure(reaction.equation)

            rate_len = tkfont.measure(u'r = \u03BB')
            rate_len = rate_len + tksubfont.measure(str(reaction.number) + ',')
            rate_len = rate_len + tksubfont.measure(str(10))
            for reactant in reaction.reactants:
                if reactant.index <> 0:
                    rate_len = rate_len + tkfont.measure('C')
                    rate_len = rate_len + tksubfont.measure(reactant.formula)
                    if reactant.index == int(reactant.index):
                        index = int(reactant.index)
                    else:
                        index = reactant.index

                    if index <> 1.:
                        rate_len = rate_len + tksuperfont.measure(
                            str(index) + ' ')
                    unitindex = unitindex + reactant.index

            lam_len = tkfont.measure(u'\u03BB')
            lam_len = lam_len + tksubfont.measure(str(reaction.number) + ',')
            lam_len = lam_len + tksubfont.measure(str(10))
            lam_len = lam_len + tkfont.measure(' = ' + str(1000) + ' ')

            if unitindex == int(unitindex): unitindex = int(unitindex)
            if (unitindex - 1) != 0:
                if (unitindex - 1) != 1:
                    lam_len = lam_len + tkfont.measure('(' + self.concunit +
                                                       ')')
                    lam_len = lam_len + tksuperfont.measure(
                        str(-(unitindex - 1)))
                else:
                    lam_len = lam_len + tkfont.measure(self.concunit)
            lam_len = lam_len + tkfont.measure(self.timeunit)
            lam_len = lam_len + tksuperfont.measure('-1')

            if self.rate_max < rate_len: self.rate_max = rate_len
            if self.value_max < lam_len: self.value_max = lam_len

    def make_widgets(self):
        """Makes the widgets for the GUI."""

        self.instructions = Label(
            self.tframe,
            text='Please input the reaction information in each layer:        '
        )

        self.blankcolumn = Label(self.tframe,
                                 text='',
                                 font='courier 10',
                                 width=1)
        self.editcolumn = Label(self.tframe,
                                text='',
                                font='courier 10',
                                width=6)
        self.delcolumn = Label(self.tframe,
                               text='',
                               font='courier 10',
                               width=6)
        self.layercolumn = Label(self.tframe,
                                 text='',
                                 font='courier 10',
                                 width=10)
        self.namecolumn = Label(self.tframe,
                                text='',
                                font='courier 10',
                                width=max(int(self.name_max / 8) + 1, 15))
        self.equationcolumn = Label(self.tframe,
                                    text='',
                                    font='courier 10',
                                    width=max(
                                        int(self.formula_max / 8) + 1, 20))
        self.ratecolumn = Label(self.tframe,
                                text='',
                                font='courier 10',
                                width=max(int(self.rate_max / 8) + 1, 10))
        self.coefcolumn = Label(self.tframe,
                                text='',
                                font='courier 10',
                                width=max(int(self.value_max / 8) + 1, 10))
        self.endcolumn = Label(self.tframe,
                               text='',
                               font='courier 10',
                               width=1)

        self.layerlabel = Label(self.tframe, text='Layer')
        self.namelabel = Label(self.tframe, text='Reaction')
        self.equationlabel = Label(self.tframe, text='Chemical equation')
        self.ratelabel = Label(self.tframe, text='Rate equation')
        self.coeflabel = Label(self.tframe, text='Coefficient')

        self.botblankcolumn = Label(self.frame,
                                    text='',
                                    font='courier 10',
                                    width=1)
        self.boteditcolumn = Label(self.frame,
                                   text='',
                                   font='courier 10',
                                   width=6)
        self.botdelcolumn = Label(self.frame,
                                  text='',
                                  font='courier 10',
                                  width=6)
        self.botlayercolumn = Label(self.frame,
                                    text='',
                                    font='courier 10',
                                    width=10)
        self.botnamecolumn = Label(self.frame,
                                   text='',
                                   font='courier 10',
                                   width=max(int(self.name_max / 8) + 1, 15))
        self.botequationcolumn = Label(self.frame,
                                       text='',
                                       font='courier 10',
                                       width=max(
                                           int(self.formula_max / 8) + 1, 20))
        self.botratecolumn = Label(self.frame,
                                   text='',
                                   font='courier 10',
                                   width=max(int(self.rate_max / 8) + 1, 10))
        self.botcoefcolumn = Label(self.frame,
                                   text='',
                                   font='courier 10',
                                   width=max(int(self.value_max / 8) + 1, 10))
        self.botendcolumn = Label(self.frame,
                                  text='',
                                  font='courier 10',
                                  width=1)

        self.addwidget = Button(self.bframe,
                                text='Add reactions',
                                command=self.addcoefficient,
                                width=20)
        self.blank1 = Label(self.bframe, text=' ')
        self.blank2 = Label(self.bframe, text=' ')
        #self.blank3         = Label (self.frame, text = ' ')
        self.blank4 = Label(self.bframe, text=' ')
        self.topline = Label(self.frame, width=10, text='-' * 1000)

        #show the widgets on the grid

        self.instructions.grid(row=0,
                               column=0,
                               padx=8,
                               columnspan=6,
                               sticky='W')

        self.blankcolumn.grid(row=1, column=0, sticky='WE', padx=1)
        self.layercolumn.grid(row=1, column=1, sticky='WE', padx=4)
        self.editcolumn.grid(row=1, column=2, sticky='WE', padx=1, pady=1)
        self.delcolumn.grid(row=1, column=3, sticky='WE', padx=1, pady=1)
        self.namecolumn.grid(row=1, column=4, sticky='WE', padx=4)
        self.equationcolumn.grid(row=1, column=5, sticky='WE', padx=4)
        self.ratecolumn.grid(row=1, column=6, sticky='WE', padx=4)
        self.coefcolumn.grid(row=1, column=7, sticky='WE', padx=4)
        self.endcolumn.grid(row=1, column=8, sticky='WE', padx=4)

        self.layerlabel.grid(row=2, column=1, padx=1, sticky='WE', pady=4)
        self.namelabel.grid(row=2, column=4, padx=1, sticky='WE', pady=4)
        self.equationlabel.grid(row=2, column=5, padx=1, sticky='WE', pady=4)
        self.ratelabel.grid(row=2, column=6, padx=1, sticky='WE', pady=4)
        self.coeflabel.grid(row=2, column=7, padx=1, sticky='WE', pady=4)

        #self.blank3.grid(row = 3)

        self.updatecoefficients()

    def updatecoefficients(self):

        self.addwidget.grid_forget()
        self.blank1.grid_forget()
        self.blank2.grid_forget()
        self.topline.grid_forget()

        namelabellength = 15

        full_check = 1
        self.topline.grid(row=0, column=1, columnspan=7, sticky='WE', pady=1)

        row = 1
        for layer in self.layers:
            row_layer = row
            try:
                layer.remove_reactionwidgets()
            except:
                pass
            for reaction in self.reactions:
                try:
                    self.coefficients[layer.name][
                        reaction.name].remove_propertieswidgets()
                except:
                    pass
                if self.coefficients[layer.name][reaction.name].lam <> 0:
                    self.coefficients[layer.name][
                        reaction.name].propertieswidgets(
                            self.frame, row, self.master, self.formulatype,
                            self.superfont, self.subfont, self.timeunit,
                            self.concunit)
                    row = row + 1
                else:
                    full_check = 0
            layer.reactionwidgets(self.frame, row, row_layer)
            row = row + 2

        self.botblankcolumn.grid(row=row, column=0, sticky='WE', padx=1)
        self.botlayercolumn.grid(row=row, column=1, sticky='WE', padx=4)
        self.boteditcolumn.grid(row=row, column=2, sticky='WE', padx=1, pady=1)
        self.botdelcolumn.grid(row=row, column=3, sticky='WE', padx=1, pady=1)
        self.botnamecolumn.grid(row=row, column=4, sticky='WE', padx=4)
        self.botequationcolumn.grid(row=row, column=5, sticky='WE', padx=4)
        self.botratecolumn.grid(row=row, column=6, sticky='WE', padx=4)
        self.botcoefcolumn.grid(row=row, column=7, sticky='WE', padx=4)
        self.botendcolumn.grid(row=row, column=8, sticky='WE', padx=4)
        row = row + 1

        self.blank1.grid(row=row, columnspan=11, sticky='WE')
        row = row + 1
        self.blank2.grid(row=row, columnspan=11)
        row = row + 1
        if full_check == 0:
            self.addwidget.grid(row=row, columnspan=11)
            row = row + 1
        else:
            self.blank4.grid(row=row, columnspan=11)
            row = row + 1

        self.focusbutton = None
        self.master.geometry()
        self.master.center()

    def addcoefficient(self, event=None):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                CoefficientEditor(self.top,
                                  self.system,
                                  self.coefficients[self.layers[0].name][
                                      self.reactions[0].name],
                                  self.coefficients,
                                  editflag=0))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.coefficients[self.top.window.layer.get()][
                    self.top.window.reaction.get()].get_coefficients(
                        self.top.window)

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatecoefficients()

    def editcoefficient(self, layername, reactionname):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                CoefficientEditor(self.top,
                                  self.system,
                                  self.coefficients[layername][reactionname],
                                  self.coefficients,
                                  editflag=1))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.coefficients[layername][reactionname].get_coefficients(
                    self.top.window)

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatecoefficients()

    def delcoefficient(self, layername, reactionname):

        self.coefficients[layername][reactionname].lam = 0

        self.updatecoefficients()

    def OK(self, event=None):
        """Finish and move on.  Checks that the number chemicals are less than the
        total number of chemicals in database."""

        if self.master.window.top is not None: self.master.open_toplevel()
        else: self.master.tk.quit()
コード例 #23
0
class LayerProperties:
    """Input the parameters for each of the layers in the system."""

    def __init__(self, master, system, editflag = None):
        """Constructor method. Used to defines the layers."""
        
        self.fonttype     = system.fonttype
        self.version      = system.version
        self.master       = master
        self.frame        = Frame(master.frame)
        self.tframe       = Frame(master.tframe)
        self.bframe       = Frame(master.bframe)
        self.superfont    = get_superfont(self.fonttype)
        self.top          = None

        self.system       = system
        self.lengthunit   = system.lengthunit

        if system.layers is None:
            self.layers  = []
            self.nlayers = 0
        else:
            self.layers  = system.layers
            self.nlayers = system.nlayers

        self.editflag = editflag

        print(editflag)
        if editflag == 1:
            self.num_record         = [j for j in range(self.nlayers)]

    def make_widgets(self):
        """Make the widgets for the window."""
  
        self.instructions = Label(self.tframe,  text = 'Starting with the layer nearest the overlying water, please ' +
                                  'provide the following information for each layer:' + ' '*20, justify = 'left')

        self.blankcolumn    = Label(self.tframe, text = '', font = 'courier 10', width = 1)
        self.editcolumn     = Label(self.tframe, text = '', font = 'courier 10', width = 6)
        self.delcolumn      = Label(self.tframe, text = '', font = 'courier 10', width = 6)
        self.namecolumn     = Label(self.tframe, text = '', font = 'courier 10', width = 12)
        self.typecolumn     = Label(self.tframe, text = '', font = 'courier 10', width = 15)
        self.tortcolumn     = Label(self.tframe, text = '', font = 'courier 10', width = 20)
        self.thickcolumn    = Label(self.tframe, text = '', font = 'courier 10', width = 10)
        self.alphacolumn    = Label(self.tframe, text = '', font = 'courier 10', width = 15)
        self.doccolumn      = Label(self.tframe, text = '', font = 'courier 10', width = 20)
        self.endcolumn      = Label(self.tframe, text = '', font = 'courier 10', width = 2)
        #Title Widgets

        self.material    = Label(self.tframe, text = 'Material')
        self.tortuosity  = Label(self.tframe, text = 'Tortuosity Correction ')
        self.thickness   = Label(self.tframe, text = 'Thickness')
        self.alpha       = Label(self.tframe, text = 'Hydrodynamic\n'+'Dispersivity')
        self.doclabel    = Label(self.tframe, text = 'Dissolved organic\n'+'matter concentration   ')
        
        #Unit Widgets
        
        self.thickunits  = Label(self.tframe, text = self.lengthunit)
        self.alphaunits  = Label(self.tframe, text = self.lengthunit)
        self.docunits    = Label(self.tframe, text = 'mg/L')
        
        self.botblankcolumn    = Label(self.frame, text = '', font = 'courier 10', width = 1)
        self.boteditcolumn     = Label(self.frame, text = '', font = 'courier 10', width = 6)
        self.botdelcolumn      = Label(self.frame, text = '', font = 'courier 10', width = 6)
        self.botnamecolumn     = Label(self.frame, text = '', font = 'courier 10', width = 12)
        self.bottypecolumn     = Label(self.frame, text = '', font = 'courier 10', width = 15)
        self.bottortcolumn     = Label(self.frame, text = '', font = 'courier 10', width = 20)
        self.botthickcolumn    = Label(self.frame, text = '', font = 'courier 10', width = 10)
        self.botalphacolumn    = Label(self.frame, text = '', font = 'courier 10', width = 15)
        self.botdoccolumn      = Label(self.frame, text = '', font = 'courier 10', width = 20)
        self.botendcolumn      = Label(self.frame, text = '', font = 'courier 10', width = 2)
        #a special OK button is needed to check bioturbation depth
        
        self.blank1 = Label(self.bframe, text = ' ')
        self.blank2 = Label(self.bframe, text = ' ')

        self.addwidget  = Button(self.bframe, text = 'Add layers', command = self.addlayer, width = 20)

        #show the widgets on the grid
        self.instructions.grid(row = 0, column = 0, padx = 6, sticky = 'W', columnspan = 10)
        
        self.blankcolumn.grid(  row = 1,  column = 0)
        self.editcolumn.grid(   row = 1,  column = 1)
        self.delcolumn.grid(    row = 1,  column = 2)
        self.namecolumn.grid(   row = 1,  column = 3)
        self.typecolumn.grid(   row = 1,  column = 5)
        self.tortcolumn.grid(   row = 1,  column = 4)
        self.thickcolumn.grid(  row = 1,  column = 6)
        self.alphacolumn.grid(  row = 1,  column = 7)
        self.doccolumn.grid(    row = 1,  column = 8)
        self.endcolumn .grid(   row = 1,  column = 9)

        self.material.grid(     row = 2,  column = 4, padx = 0, sticky = 'N')
        self.tortuosity.grid(   row = 2,  column = 5, padx = 0, sticky = 'N')
        self.thickness.grid(    row = 2,  column = 6, padx = 0, sticky = 'N')
        self.alpha.grid(        row = 2,  column = 7, padx = 0, sticky = 'N')
        self.doclabel.grid(     row = 2,  column = 8, padx = 0, sticky = 'N')

        self.thickunits.grid(   row = 3,  column = 6, padx = 0)
        self.alphaunits.grid(   row = 3,  column = 7, padx = 0)
        self.docunits.grid(     row = 3,  column = 8, padx = 0)

        #make entry widgets for each of the layers
        self.updatelayers()
       
    def updatelayers(self):

        self.addwidget.grid_forget()
        self.blank1.grid_forget()
        self.blank2.grid_forget()

        namelabellength = 20

        for layer in self.layers:
            try: layer.remove_propertywidgets()
            except: pass
            if self.layers[0].number == 0:  layer.number = self.layers.index(layer)
            else:                           layer.number = self.layers.index(layer) + 1
            if layer.number == 0:           layer.name   = 'Deposition'
            else:                           layer.name   = 'Layer ' + str(layer.number)

        row = 4
        for layer in self.layers:
            layer.propertywidgets(self.frame, row, self.master)
            row = row + 1
            if namelabellength < layer.typelabel.winfo_reqwidth()/8:  namelabellength = int(layer.typelabel.winfo_reqwidth()/8) + 1

        self.typecolumn.config(width = namelabellength)
        self.bottypecolumn.config(width = namelabellength)

        self.botblankcolumn.grid(  row = row,  column = 0)
        self.boteditcolumn.grid(   row = row,  column = 1)
        self.botdelcolumn.grid(    row = row,  column = 2)
        self.botnamecolumn.grid(   row = row,  column = 3)
        self.bottypecolumn.grid(   row = row,  column = 5)
        self.bottortcolumn.grid(   row = row,  column = 4)
        self.botthickcolumn.grid(  row = row,  column = 6)
        self.botalphacolumn.grid(  row = row,  column = 7)
        self.botdoccolumn.grid(    row = row,  column = 8)
        self.botendcolumn .grid(   row = row,  column = 9)

        self.blank1.grid(row = row)
        row = row + 1
        self.blank2.grid(row = row)
        row = row + 1
        self.addwidget.grid(row = row, columnspan = 11)
        row = row + 1

        self.addwidget.bind('<Return>', self.addlayer)

        if self.nlayers == 0:   self.focusbutton = self.addwidget#self.okbutton
        else:                   self.focusbutton = None
        self.master.geometry()
        self.master.center()

    def addlayer(self, default = None):

        self.nlayers = self.nlayers + 1
        layertemp = Layer(1)

        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(LayerEditor(self.top, self.system, layertemp, self.layers, editflag = 0))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                layertemp.get_layer(self.top.window)
                if self.layers == []:            self.layers.append(layertemp)
                elif self.layers[0].number == 0: self.layers.insert( layertemp.number,    layertemp)
                elif layertemp.number == 0:      self.layers.insert( 0,                   layertemp)
                else:                            self.layers.insert( layertemp.number-1,  layertemp)

                if self.editflag == 1:
                    if self.layers[0].number == 0:
                        self.num_record.insert( layertemp.number,    -1)
                    elif layertemp.number == 0:
                        self.num_record.insert( 0,                   -1)
                    else:
                        self.num_record.insert( layertemp.number-1,  -1)

            else:
                self.nlayers = self.nlayers - 1
                layertemp = 0

            if self.top is not None:
                self.top.destroy()
                self.top = None
                
        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()


        self.updatelayers()

    def editlayer(self, number):
        
        if self.layers[0].number == 0: layertemp = self.layers[number]
        else:                          layertemp = self.layers[number-1]

        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(LayerEditor(self.top, self.system, layertemp, self.layers, editflag = 1))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                layertemp.get_layer(self.top.window)
               
            if self.top is not None:
                self.top.destroy()
                self.top = None
                
        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()
            
        self.updatelayers()
        
    def deletelayer(self, number):

        if self.layers[0].number == 0: layer = self.layers[number]
        else:                          layer = self.layers[number - 1]
        
        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(LayerDeleter(self.top, self.system, layer))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                layer.remove_propertywidgets()
                if self.editflag == 1:
                    new_record      = self.num_record[:self.layers.index(layer)] + self.num_record[self.layers.index(layer)+1:]
                    self.num_record = new_record
                self.layers.remove(layer)
                self.nlayers = self.nlayers - 1

            if self.top is not None:
                self.top.destroy()
                self.top = None
                
        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()
            
        self.updatelayers()

    def error_check(self, event = None):
        """Finish and move on.  Checks that the number chemicals are less than the
        total number of chemicals in database."""

        error = 0
        if self.nlayers == 0: error = 1
        elif self.nlayers == 1 and self.layers[0].number ==0: error = 1

        return error

    def warning(self):

        tkmb.showerror(title = self.version, message = 'No layer has been created, please add layers by pressing the button "Add layers"')
        self.focusbutton = None
        self.master.tk.lift()
コード例 #24
0
class SorptionProperties:
    """Gets the model types for each of the layers in the system."""
    def __init__(self, master, system):
        """Constructor method. Used to defines the layers."""

        self.fonttype = system.fonttype
        self.version = system.version
        self.master = master
        self.frame = Frame(master.frame)
        self.tframe = Frame(master.tframe)
        self.bframe = Frame(master.bframe)
        self.sfont = get_superfont(self.fonttype)
        self.top = None

        self.system = system
        self.chemicals = system.chemicals
        self.matrices = system.matrices
        self.timeunit = system.timeunit
        self.concunit = system.concunit

        self.defaults = 0
        if master.master is None: self.defaults = 1

        self.components = system.components
        self.component_list = system.component_list

        if system.sorptions is None:
            self.sorptions = {}
            for component in self.components:
                self.sorptions[component.name] = {}
                for chemical in self.chemicals:
                    self.sorptions[component.name][chemical.name] = Sorption(
                        component, chemical, unit=system.concunit)
        else:
            self.sorptions = system.sorptions

    def make_widgets(self):
        """Make the widgets for the window."""

        #Title Widgets
        self.leftcolumn = Label(self.frame, width=2, text=' ')
        self.matrixcolumn = Label(self.frame, width=10, text=' ')
        self.chemicalcolumn = Label(self.frame, width=18, text=' ')
        self.editcolumn = Label(self.frame, width=1, text=' ')
        self.isothermcolumn = Label(self.frame, width=20, text=' ')
        self.rightcolumn = Label(self.frame, width=2, text=' ')

        self.coef1labelcolumn = Label(self.frame, width=7, text=' ')
        self.coef1valuecolumn = Label(self.frame, width=3, text=' ')
        self.coef1unitcolumn = Label(self.frame, width=10, text=' ')

        self.coef2labelcolumn = Label(self.frame, width=7, text=' ')
        self.coef2valuecolumn = Label(self.frame, width=3, text=' ')
        self.coef2unitcolumn = Label(self.frame, width=10, text=' ')

        self.coef3labelcolumn = Label(self.frame, width=7, text=' ')
        self.coef3valuecolumn = Label(self.frame, width=3, text=' ')
        self.coef3unitcolumn = Label(self.frame, width=10, text=' ')

        self.instructions = Label(
            self.frame,
            text=
            'Please input the sorption isotherms and corresponding coefficients for chemicals in each layer:',
            justify='left')
        self.matrixlabel = Label(self.frame, text='Matrix')
        self.chemicallabel = Label(self.frame, text='Chemical')
        self.isothermlabel = Label(self.frame, text='Sorption Isotherm')
        self.coeflabel = Label(self.frame, text='Isotherm coefficients')
        self.kineticlabel = Label(self.frame, text='Kinetic options')

        self.blank1 = Label(self.frame, text=' ')

        #show the title widgets on the grid

        self.instructions.grid(row=0,
                               column=0,
                               columnspan=14,
                               padx=2,
                               pady=8,
                               sticky='W')

        self.leftcolumn.grid(row=1, column=0, padx=1, pady=1, sticky='WE')
        self.matrixcolumn.grid(row=1, column=1, padx=1, pady=1, sticky='WE')
        self.chemicalcolumn.grid(row=1, column=2, padx=1, pady=1, sticky='WE')
        self.editcolumn.grid(row=1, column=3, padx=1, pady=1, sticky='WE')
        self.isothermcolumn.grid(row=1, column=4, padx=1, pady=1, sticky='WE')
        self.coef1labelcolumn.grid(row=1,
                                   column=5,
                                   padx=1,
                                   pady=1,
                                   sticky='WE')
        self.coef1valuecolumn.grid(row=1,
                                   column=6,
                                   padx=1,
                                   pady=1,
                                   sticky='WE')
        self.coef1unitcolumn.grid(row=1, column=7, padx=1, pady=1, sticky='WE')
        self.coef2labelcolumn.grid(row=1,
                                   column=8,
                                   padx=1,
                                   pady=1,
                                   sticky='WE')
        self.coef2valuecolumn.grid(row=1,
                                   column=9,
                                   padx=1,
                                   pady=1,
                                   sticky='WE')
        self.coef2unitcolumn.grid(row=1,
                                  column=10,
                                  padx=1,
                                  pady=1,
                                  sticky='WE')
        self.coef3labelcolumn.grid(row=1,
                                   column=11,
                                   padx=1,
                                   pady=1,
                                   sticky='WE')
        self.coef3valuecolumn.grid(row=1,
                                   column=12,
                                   padx=1,
                                   pady=1,
                                   sticky='WE')
        self.coef3unitcolumn.grid(row=1,
                                  column=13,
                                  padx=1,
                                  pady=1,
                                  sticky='WE')
        self.rightcolumn.grid(row=1, column=14, padx=1, pady=1, sticky='WE')

        self.matrixlabel.grid(row=2, column=1, padx=1, pady=1, sticky='WE')
        self.chemicallabel.grid(row=2, column=2, padx=1, pady=1, sticky='WE')
        self.isothermlabel.grid(row=2, column=4, padx=1, pady=1, sticky='WE')
        self.coeflabel.grid(row=2,
                            column=5,
                            padx=1,
                            pady=1,
                            sticky='WE',
                            columnspan=6)
        self.kineticlabel.grid(row=2,
                               column=11,
                               padx=1,
                               pady=1,
                               sticky='WE',
                               columnspan=3)

        #show the layer and chemical widgets on the grid

        row = 3

        for component in self.components:
            component.sorptionwidgets(self.frame, row=row)
            for chemical in self.chemicals:
                if chemical.soluable == 1:
                    chemical.sorptionwidgets(self.frame, row=row)
                    self.sorptions[component.name][
                        chemical.name].propertieswidgets(
                            self.frame, row, self.master, self.timeunit,
                            self.concunit)
                    row = row + 1

        self.focusbutton = None
        self.blank1.grid(row=row)

    def editsorption(self, component, chemical):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                SorptionEditor(self.top, self.system,
                               self.sorptions[component][chemical]))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.sorptions[component][chemical].get_sorption(
                    self.top.window)
                row = self.sorptions[component][chemical].row
                self.sorptions[component][chemical].remove_propertieswidgets()
                self.sorptions[component][chemical].propertieswidgets(
                    self.frame, row, self.master, self.timeunit, self.concunit)

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus(component, chemical)

    def error_check(self, event=None):
        """Finish and move on.  Checks that the number chemicals are less than the
        total number of chemicals in database."""

        error = 0

        return error

    def warning(self):

        self.focusbutton = None
        self.master.tk.lift()
コード例 #25
0
class ChemicalEditor:
    """Gets the contaminant properties."""
    def __init__(self, master, system, chemical, chemicals, database,
                 editflag):
        """Constructor method.  Defines the parameters to be obtained in this window."""

        self.master = master
        self.fonttype = system.fonttype
        self.version = system.version
        self.superfont = get_superfont(self.fonttype)  #superscript font
        self.frame = Frame(master.frame)
        self.tframe = Frame(master.tframe)
        self.bframe = Frame(master.bframe)
        self.system = system
        self.database = database
        self.top = None  #flag for existence of toplevel#
        self.tkfont = tkFont.Font(font=system.fonttype)

        self.soluableflag = chemical.soluable
        self.editflag = editflag
        self.cancelflag = 0
        self.chemicals = chemicals
        self.diffunit = system.diffunit
        self.diffunits = system.diffunits

        if self.soluableflag == 1:
            self.database = database
            self.chemical = chemical

            self.name = StringVar(value='')
            self.formula = StringVar(value='')
            self.MW = DoubleVar(value=0)
            self.temp = DoubleVar(value=0)
            self.Dw = DoubleVar(value=0)
            self.Ref = StringVar(value='')
            self.Koc = DoubleVar(value=0)
            self.Kdoc = DoubleVar(value=0)
            self.Kf = DoubleVar(value=0)
            self.N = DoubleVar(value=0)

            if editflag == 1:  #Detemine whether the chemical is added or edited

                self.name.set(self.chemical.name)
                self.formula.set(self.chemical.formula)
                self.MW.set(self.chemical.MW)
                self.temp.set(self.chemical.temp)
                self.Dw.set(self.chemical.Dw)
                self.Koc.set(self.chemical.Koc)
                self.Kdoc.set(self.chemical.Kdoc)
                self.Ref.set(self.chemical.Ref)
                self.Kf.set(self.chemical.Kf)
                self.N.set(self.chemical.N)
        else:
            self.name = StringVar(value=' ')
            self.formula = StringVar(value=' ')
            self.MW = DoubleVar(value=100)
            self.temp = DoubleVar(value=0)
            self.Dw = DoubleVar(value=0)
            self.Koc = DoubleVar(value=0)
            self.Kdoc = DoubleVar(value=0)
            self.Kf = DoubleVar(value=0)
            self.N = DoubleVar(value=0)

            if editflag == 1:  #Detemine whether the chemical is added or edited
                self.name.set(chemical.name)

    def make_widgets(self):
        """Make the widgets for the window."""

        self.bgcolor = self.frame.cget('bg')
        self.instructions = Label(
            self.tframe,
            text=
            ' Please provide the following chemical properties:                    '
        )

        self.blankcolumn = Label(self.frame, text=' ', width=2)
        self.namecolumn = Label(self.frame, text=' ', width=20)
        self.MWcolumn = Label(self.frame, text=' ', width=12)
        self.tempcolumn = Label(self.frame, text=' ', width=10)
        self.Dwcolumn = Label(self.frame, text=' ', width=18)
        self.Koccolumn = Label(self.frame, text=' ', width=18)
        self.Kdoccolumn = Label(self.frame, text=' ', width=18)
        self.Refcolumn = Label(self.frame, text=' ', width=20)
        self.Rightcolumn = Label(self.frame, text=' ', width=2)

        self.namelabel = Label(self.frame, text='Chemical name')
        self.MWlabel = Label(self.frame, text='Molecular\n weight')
        self.templabel = Label(self.frame, text='Temperature')
        self.Dwlabel = Label(self.frame,
                             text='Molecular diffusivity\n in water')
        self.Koclabel = Label(self.frame,
                              text='Organic carbon\n partition coefficient')
        self.Kdoclabel = Label(
            self.frame,
            text='Dissolved organic carbon\n partition coefficient')
        self.Reflabel = Label(self.frame, text='Reference')

        self.tempunits = Label(self.frame, text=unichr(176) + 'C')
        self.Dwunits = Label(self.frame, text=self.diffunit)
        self.Kocunits = Label(self.frame, text='log(L/kg)')
        self.Kdocunits = Label(self.frame, text='log(L/kg)')

        self.importbutton = Button(self.frame,
                                   text='From Database',
                                   width=20,
                                   command=self.importchemical)
        self.okbutton = Button(self.frame,
                               text='OK',
                               width=20,
                               command=self.OK)
        self.cancelbutton = Button(self.frame,
                                   text='Cancel',
                                   width=20,
                                   command=self.Cancel)
        self.blank1 = Label(self.frame, text=' ')
        self.blank2 = Label(self.frame, text=' ')

        #show the widgets on the grid
        self.instructions.grid(row=0,
                               column=0,
                               columnspan=6,
                               padx=8,
                               sticky='W')

        self.blankcolumn.grid(row=1, column=0, sticky='WE', padx=1, pady=1)
        self.namecolumn.grid(row=1, column=1, sticky='WE', padx=1, pady=1)
        self.MWcolumn.grid(row=1, column=2, sticky='WE', padx=1, pady=1)
        self.tempcolumn.grid(row=1, column=3, sticky='WE', padx=1, pady=1)
        self.Dwcolumn.grid(row=1, column=4, sticky='WE', padx=1, pady=1)
        self.Koccolumn.grid(row=1, column=5, sticky='WE', padx=1, pady=1)
        self.Kdoccolumn.grid(row=1, column=6, sticky='WE', padx=1, pady=1)
        self.Refcolumn.grid(row=1, column=7, sticky='WE', padx=1, pady=1)
        self.Rightcolumn.grid(row=1, column=8, sticky='WE', padx=1, pady=1)

        self.namelabel.grid(row=2, column=1, sticky='WE', padx=1, pady=1)
        self.MWlabel.grid(row=2, column=2, sticky='WE', padx=1, pady=1)
        self.templabel.grid(row=2, column=3, sticky='WE', padx=1, pady=1)
        self.Dwlabel.grid(row=2, column=4, sticky='WE', padx=1, pady=1)
        self.Koclabel.grid(row=2, column=5, sticky='WE', padx=1, pady=1)
        self.Kdoclabel.grid(row=2, column=6, sticky='WE', padx=1, pady=1)
        self.Reflabel.grid(row=2, column=7, sticky='WE', padx=1, pady=1)

        self.tempunits.grid(row=3, column=3, sticky='WE', padx=1, pady=1)
        self.Dwunits.grid(row=3, column=4, sticky='WE', padx=1, pady=1)
        self.Kocunits.grid(row=3, column=5, sticky='WE', padx=1, pady=1)
        self.Kdocunits.grid(row=3, column=6, sticky='WE', padx=1, pady=1)

        if self.soluableflag == 1:
            if self.editflag == 0:
                self.namewidget = Entry(self.frame,
                                        width=18,
                                        justify='center',
                                        textvariable=self.name)
                self.tempwidget = Entry(self.frame,
                                        width=10,
                                        justify='center',
                                        textvariable=self.temp)
            else:
                self.namewidget = Label(self.frame,
                                        width=18,
                                        justify='center',
                                        textvariable=self.name)
                self.tempwidget = Label(self.frame,
                                        width=10,
                                        justify='center',
                                        textvariable=self.temp)

            self.Dwwidget = Entry(self.frame,
                                  width=16,
                                  justify='center',
                                  textvariable=self.Dw)
            self.MWwidget = Entry(self.frame,
                                  width=10,
                                  justify='center',
                                  textvariable=self.MW)
            self.Kocwidget = Entry(self.frame,
                                   width=16,
                                   justify='center',
                                   textvariable=self.Koc)
            self.Kdocwidget = Entry(self.frame,
                                    width=16,
                                    justify='center',
                                    textvariable=self.Kdoc)
            self.Refwidget = Entry(self.frame,
                                   width=18,
                                   justify='center',
                                   textvariable=self.Ref)

            self.namewidget.grid(row=4, column=1, padx=2, pady=1)
            self.MWwidget.grid(row=4, column=2, padx=2, pady=1)
            self.tempwidget.grid(row=4, column=3, padx=2, pady=1)
            self.Dwwidget.grid(row=4, column=4, padx=2, pady=1)
            self.Kocwidget.grid(row=4, column=5, padx=2, pady=1)
            self.Kdocwidget.grid(row=4, column=6, padx=2, pady=1)
            self.Refwidget.grid(row=4, column=7, padx=2, pady=1)

        else:
            self.namewidget = Entry(self.frame,
                                    width=18,
                                    justify='center',
                                    textvariable=self.name)
            self.Dwwidget = Label(self.frame,
                                  width=16,
                                  justify='center',
                                  text='Not applicable')
            self.Kocwidget = Label(self.frame,
                                   width=16,
                                   justify='center',
                                   text='Not applicable')
            self.Kdocwidget = Label(self.frame,
                                    width=16,
                                    justify='center',
                                    text='Not applicable')

            self.namewidget.grid(row=4, column=1, padx=2, pady=1)
            self.Dwwidget.grid(row=4, column=3, padx=2, pady=1)
            self.Kocwidget.grid(row=4, column=4, padx=2, pady=1)
            self.Kdocwidget.grid(row=4, column=5, padx=2, pady=1)

        self.blank1.grid(row=5)
        if self.editflag == 0: self.importbutton.grid(row=6, columnspan=11)
        self.okbutton.grid(row=7, columnspan=11)
        self.cancelbutton.grid(row=8, columnspan=11)
        self.blank2.grid(row=9)
        self.okbutton.bind('<Return>', self.OK)
        self.focusbutton = self.okbutton

        if int((self.tkfont.measure(self.Ref.get()) + 10) * 1.1424219345 /
               8) + 1 > 18:
            self.Refwidget.config(
                width=int((self.tkfont.measure(self.Ref.get()) + 10) *
                          1.1424219345 / 8) + 3)
        if int((self.tkfont.measure(self.name.get()) + 10) * 1.1424219345 /
               8) + 1 > 18:
            self.namewidget.config(
                width=int((self.tkfont.measure(self.name.get()) + 10) *
                          1.1424219345 / 8) + 3)

        self.master.geometry()
        self.master.center()

    def importchemical(self):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                ChemicalImporter(self.top, self.system, self.database))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.updatechemical(self.top.window)

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

    def updatechemical(self, window):

        self.name.set(window.name.get())
        self.formula.set(window.formula.get())
        self.MW.set(window.MW.get())
        self.temp.set(window.temp.get())
        self.Koc.set(window.Koc.get())
        self.Kdoc.set(window.Kdoc.get())
        self.Ref.set(window.Ref.get())
        self.Kf.set(window.Kf.get())
        self.N.set(window.N.get())

        if self.diffunit == self.diffunits[0]: self.Dw.set(window.Dw.get())
        elif self.diffunit == self.diffunits[1]:
            Dw = window.Dw.get() * 86400 * 365
            if Dw > 1: self.Dw.set(round(Dw, 2))
            else:
                i = 2
                while Dw / 100 < 0.1**i:
                    i = i + 1
                self.Dw.set(round(Dw, i))

        self.frame.update()

        if int((self.tkfont.measure(self.Ref.get()) + 10) * 1.1424219345 /
               8) + 1 > 20:
            self.Refwidget.config(
                width=int((self.tkfont.measure(self.Ref.get()) + 10) *
                          1.1424219345 / 8) + 3)
        if int((self.tkfont.measure(self.name.get()) + 10) * 1.1424219345 /
               8) + 1 > 20:
            self.namewidget.config(
                width=int((self.tkfont.measure(self.name.get()) + 10) *
                          1.1424219345 / 8) + 3)
        self.master.geometry()
        self.master.center()

    def OK(self, event=None):
        """Finish and move on.  Checks that the number chemicals are less than the total number of chemicals in database."""

        if self.editflag == 0:
            check = [(chemical.name == self.name.get())
                     for chemical in self.chemicals[0:-1]]
        else:
            check = [0]

        if self.master.window.top is not None: self.master.open_toplevel()
        elif sum(check) >= 1: self.chemicals_error()
        elif self.name.get() == '' or self.name.get().count(' ') == len(
                self.name.get()):
            self.name_error()
        elif self.Dw.get() == 0:
            self.Dw_error()
        else:
            self.master.tk.quit()

    def chemicals_error(self):

        tkmb.showerror(title=self.version,
                       message='This chemical has already been selected!')
        self.focusbutton = self.okbutton
        self.master.tk.lift()

    def name_error(self):

        tkmb.showerror(title=self.version,
                       message='Please input the name for the chemical!')
        self.focusbutton = self.okbutton
        self.master.tk.lift()

    def Dw_error(self):

        tkmb.showerror(
            title=self.version,
            message=
            'The diffusivity of the chemical can not be zero, please correct!')
        self.focusbutton = self.okbutton
        self.master.tk.lift()

    def Cancel(self):

        try:
            self.name.set(self.chemical.name)
            self.MW.set(self.chemical.MW.get())
            self.formula.set(self.chemical.formula.get())
            self.temp.set(self.chemical.temp.get())
            self.Dw.set(self.chemical.Dw.get())
            self.Koc.set(self.chemical.Koc.get())
            self.Kdoc.set(self.chemical.Kdoc.get())
            self.Ref.set(self.chemical.Ref.get())
            self.Kf.set(self.chemical.Kf.get())
            self.N.set(self.chemical.N.get())
        except:
            self.cancelflag = 1

        if self.master.window.top is not None: self.master.open_toplevel()
        else: self.master.tk.quit()
コード例 #26
0
class TauEstimator:
    """Used to make a window to compute the value of "kbl" for Rivers."""
    def __init__(self, master, version, fonttype, timeunit, lengthunit,
                 chemicals, taucoefs, BCs):
        """Constructor method."""

        self.master = master
        self.version = version
        self.fonttype = fonttype
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)
        self.superfont = get_superfont(self.fonttype)

        self.Decays = ['None', 'First order']
        self.Evaps = ['None', 'First order']
        self.top = None

        self.cancelflag = 0

        self.timeunit = timeunit
        self.lengthunit = lengthunit

        self.Q = DoubleVar(value=taucoefs['Q'])
        self.V = DoubleVar(value=taucoefs['V'])
        self.h = DoubleVar(value=taucoefs['h'])
        self.Qevap = DoubleVar(value=taucoefs['Qevap'])
        self.doc = DoubleVar(value=taucoefs['DOC'])
        self.Decay = StringVar(value=taucoefs['Decay'])
        self.Evap = StringVar(value=taucoefs['Evap'])

        self.chemicals = chemicals
        self.kdecays = []
        self.kevaps = []
        for chemical in self.chemicals:
            self.kdecays.append(BCs[chemical.name].kdecay)
            self.kevaps.append(BCs[chemical.name].kevap)

    def make_widgets(self):
        """Makes the widgets for the window."""

        self.bgcolor = self.frame.cget('bg')
        self.text = Label(
            self.frame,
            text=
            'Please provide the information to estimate the retention time of the overlying water body:'
        )
        self.blank1 = Label(self.frame, text='')
        self.blank2 = Label(self.frame, text='')
        self.blank3 = Label(self.frame, text='')
        self.blank4 = Label(self.frame, text='')

        self.leftcolumn = Label(self.frame, text=' ', width=15)
        self.paracolumn = Label(self.frame, text=' ', width=10)
        self.valuecolumn = Label(self.frame, text=' ', width=15)
        self.unitcolumn = Label(self.frame, text=' ', width=10)
        self.rightcolumn = Label(self.frame, text=' ', width=10)

        self.paralabel = Label(self.frame, text='Parameters')
        self.valuelabel = Label(self.frame, text='Values')
        self.unitlabel = Label(self.frame, text='Units')

        self.qlabel = Label(self.frame, text='Inflow rate:')
        self.qentry = Entry(self.frame,
                            textvariable=self.Q,
                            width=10,
                            justify='center')
        self.qunits = Label(self.frame, text='m' + u'\u00B3/' + self.timeunit)

        self.Vlabel = Label(self.frame, text='Water body volume:')
        self.Ventry = Entry(self.frame,
                            textvariable=self.V,
                            width=10,
                            justify='center')
        self.Vunits = Label(self.frame, text='m' + u'\u00B3')

        self.hlabel = Label(self.frame, text='Water body depth:')
        self.hentry = Entry(self.frame,
                            justify='center',
                            width=10,
                            textvariable=self.h)
        self.hunits = Label(self.frame, text='m')

        self.qevaplabel = Label(self.frame, text='Water evaporation rate:')
        self.qevapentry = Entry(self.frame,
                                textvariable=self.Qevap,
                                width=10,
                                justify='center')
        self.qevapunits = Label(self.frame,
                                text='m' + u'\u00B3/' + self.timeunit)

        self.doclabel = Label(self.frame, text='Water body DOC concentration:')
        self.docentry = Entry(self.frame,
                              textvariable=self.doc,
                              width=10,
                              justify='center')
        self.docunits = Label(self.frame, text='mg/L')

        self.Decaylabel = Label(self.frame, text='Contaminant decay:')
        self.Decaywidget = OptionMenu(self.frame,
                                      self.Decay,
                                      *self.Decays,
                                      command=self.editdecay)

        self.Evaplabel = Label(self.frame, text='Contaminant evaporation:')
        self.Evapwidget = OptionMenu(self.frame,
                                     self.Evap,
                                     *self.Evaps,
                                     command=self.editevap)

        self.calcbutton = Button(self.frame,
                                 text='Calculate',
                                 width=20,
                                 command=self.calculate)
        self.exitbutton = Button(self.frame,
                                 text='Cancel',
                                 width=20,
                                 command=self.exit)
        self.calcbutton.bind('<Return>', self.calculate)
        self.exitbutton.bind('<Return>', self.exit)

        self.text.grid(row=0, columnspan=6, padx=8)

        self.paracolumn.grid(row=1, column=1)
        self.valuecolumn.grid(row=1, column=2)
        self.unitcolumn.grid(row=1, column=3)

        self.paralabel.grid(row=2, column=1, sticky='E')
        self.valuelabel.grid(row=2, column=2)
        self.unitlabel.grid(row=2, column=3, sticky='W')

        self.blank1.grid(row=3)

        self.qlabel.grid(row=4, column=1, sticky='E')
        self.qentry.grid(row=4, column=2, pady=4)
        self.qunits.grid(row=4, column=3, sticky='W')

        self.Vlabel.grid(row=5, column=1, sticky='E', pady=2)
        self.Ventry.grid(row=5, column=2, pady=4)
        self.Vunits.grid(row=5, column=3, sticky='W', pady=2)

        self.hlabel.grid(row=6, column=1, sticky='E', pady=2)
        self.hentry.grid(row=6, column=2, pady=4)
        self.hunits.grid(row=6, column=3, sticky='W', pady=2)

        self.qevaplabel.grid(row=7, column=1, sticky='E', pady=2)
        self.qevapentry.grid(row=7, column=2, pady=4)
        self.qevapunits.grid(row=7, column=3, sticky='W', pady=2)

        self.doclabel.grid(row=8, column=1, sticky='E', pady=2)
        self.docentry.grid(row=8, column=2, pady=4)
        self.docunits.grid(row=8, column=3, sticky='W', pady=2)

        self.Decaylabel.grid(row=9, column=1, sticky='E', pady=2)
        self.Decaywidget.grid(row=9, column=2, sticky='WE')

        self.Evaplabel.grid(row=10, column=1, sticky='E', pady=2)
        self.Evapwidget.grid(row=10, column=2, sticky='WE')

        self.blank2.grid(row=11)
        self.calcbutton.grid(row=12, column=0, columnspan=6, pady=1)
        self.exitbutton.grid(row=13, column=0, columnspan=6, pady=1)

        self.focusbutton = self.calcbutton

    def editdecay(self, event=None):

        if self.Decay.get() == 'First order':

            if self.top is None:

                self.top = CapSimWindow(master=self.master, buttons=2)
                self.top.make_window(
                    DecayEditor(self.top, self.version, self.fonttype,
                                self.timeunit, self.chemicals, self.kdecays))
                self.top.tk.mainloop()

                if self.top.window.cancelflag == 0:
                    for n in range(len(self.chemicals)):
                        if self.chemicals[n].soluable == 1:
                            self.kdecays[n] = self.top.window.kdecays[n].get()

                if self.top is not None:
                    self.top.destroy()
                    self.top = None

            elif self.top is not None:
                tkmb.showerror(
                    title=self.version,
                    message=
                    'Please close the existing parameter input window first.')
                self.top.tk.focus()

    def editevap(self, event=None):

        if self.Evap.get() == 'First order':

            if self.top is None:

                self.top = CapSimWindow(master=self.master, buttons=2)
                self.top.make_window(
                    EvapEditor(self.top, self.version, self.fonttype,
                               self.timeunit, self.lengthunit, self.chemicals,
                               self.kevaps))
                self.top.tk.mainloop()

                if self.top.window.cancelflag == 0:
                    for n in range(len(self.chemicals)):
                        if self.chemicals[n].soluable == 1:
                            self.kevaps[n] = self.top.window.kevaps[n].get()

                if self.top is not None:
                    self.top.destroy()
                    self.top = None

            elif self.top is not None:
                tkmb.showerror(
                    title=self.version,
                    message=
                    'Please close the existing parameter input window first.')
                self.top.tk.focus()

    def calculate(self, event=None):
        """Finish and move on."""

        self.frame.quit()

    def exit(self, event=None):
        """Used to close the window without computing kbl."""

        self.cancelflag = 1

        self.frame.quit()
コード例 #27
0
class Database:
    """Opens a window for inputing the properties of a compound."""
    def __init__(self, master, system, database):
        """The constructor method."""

        self.system = system
        self.version = system.version
        self.fonttype = system.fonttype
        self.sfont = get_superfont(self.fonttype)
        self.master = master
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)
        self.top = None

        self.database = database  #the database of values

        self.exitflag = 0
        self.names = []  #a list of the chemical names

        solids_list = self.database.keys()
        solids_list.sort()

        self.solids_list = solids_list

        self.solids = []
        for solidname in solids_list:
            self.solids.append(Solid(solids_list.index(solidname)))
            self.solids[-1].read_database(self.database[solidname])

    def make_widgets(self):

        self.instructions = Label(
            self.tframe,
            text=
            'Please provide the following fundamental properties for the material:\n'
        )

        self.blankcolumn = Label(self.tframe,
                                 text='',
                                 font='courier 10',
                                 width=1)
        self.editcolumn = Label(self.tframe,
                                text='',
                                font='courier 10',
                                width=6)
        self.delcolumn = Label(self.tframe,
                               text='',
                               font='courier 10',
                               width=6)
        self.numbercolumn = Label(self.tframe,
                                  text='',
                                  font='courier 10',
                                  width=8)
        self.namecolumn = Label(self.tframe,
                                text='',
                                font='courier 10',
                                width=18)
        self.ecolumn = Label(self.tframe, text='', font='courier 10', width=8)
        self.rhocolumn = Label(self.tframe,
                               text='',
                               font='courier 10',
                               width=12)
        self.foccolumn = Label(self.tframe,
                               text='',
                               font='courier 10',
                               width=20)
        self.tortcolumn = Label(self.tframe,
                                text='',
                                font='courier 10',
                                width=18)
        self.sorpcolumn = Label(self.tframe,
                                text='',
                                font='courier 10',
                                width=18)
        self.refcolumn = Label(self.tframe,
                               text='',
                               font='courier 10',
                               width=15)

        self.numberlabel = Label(self.tframe, text='Number')
        self.namelabel = Label(self.tframe, text='Material')
        self.elabel = Label(self.tframe, text='Porosity')
        self.rholabel = Label(self.tframe, text='Bulk density')
        self.foclabel = Label(self.tframe, text='Organic carbon fraction')
        self.tortlabel = Label(self.tframe, text='Tortuosity correction')
        self.sorplabel = Label(self.tframe, text='Sorption isotherms')
        self.reflabel = Label(self.tframe, text='Reference')

        self.rhounitlabel = Label(self.tframe, text=u'g/cm\u00B3')

        self.botblankcolumn = Label(self.frame,
                                    text='',
                                    font='courier 10',
                                    width=1)
        self.boteditcolumn = Label(self.frame,
                                   text='',
                                   font='courier 10',
                                   width=6)
        self.botdelcolumn = Label(self.frame,
                                  text='',
                                  font='courier 10',
                                  width=6)
        self.botnumbercolumn = Label(self.frame,
                                     text='',
                                     font='courier 10',
                                     width=8)
        self.botnamecolumn = Label(self.frame,
                                   text='',
                                   font='courier 10',
                                   width=18)
        self.botecolumn = Label(self.frame,
                                text='',
                                font='courier 10',
                                width=8)
        self.botrhocolumn = Label(self.frame,
                                  text='',
                                  font='courier 10',
                                  width=12)
        self.botfoccolumn = Label(self.frame,
                                  text='',
                                  font='courier 10',
                                  width=20)
        self.bottortcolumn = Label(self.frame,
                                   text='',
                                   font='courier 10',
                                   width=18)
        self.botsorpcolumn = Label(self.frame,
                                   text='',
                                   font='courier 10',
                                   width=18)
        self.botrefcolumn = Label(self.frame,
                                  text='',
                                  font='courier 10',
                                  width=15)

        self.addwidget = Button(self.bframe,
                                text='Add solids',
                                command=self.addsolid,
                                width=20)
        self.savebutton = Button(self.bframe,
                                 text='Save',
                                 width=20,
                                 command=self.save)
        self.importwidget = Button(self.bframe,
                                   text='Import database file',
                                   command=self.importsoliddata,
                                   width=20)
        self.cancelbutton = Button(self.bframe,
                                   text='Cancel',
                                   command=self.cancel,
                                   width=20)

        self.blank1 = Label(self.bframe, text=' ')
        self.blank2 = Label(self.bframe, text=' ')
        self.blank3 = Label(self.bframe, text=' ')

        #show the widgets on the grid (top to bottom and left to right)

        self.instructions.grid(row=0,
                               column=0,
                               columnspan=11,
                               padx=8,
                               sticky='W',
                               pady=10)

        self.blankcolumn.grid(row=1, column=0, sticky='WE', padx=1, pady=1)
        self.editcolumn.grid(row=1, column=1, sticky='WE', padx=1, pady=1)
        self.delcolumn.grid(row=1, column=2, sticky='WE', padx=1, pady=1)
        self.numbercolumn.grid(row=1, column=3, sticky='WE', padx=1, pady=1)
        self.namecolumn.grid(row=1, column=4, sticky='WE', padx=1, pady=1)
        self.ecolumn.grid(row=1, column=5, sticky='WE', padx=1, pady=1)
        self.rhocolumn.grid(row=1, column=6, sticky='WE', padx=1, pady=1)
        self.foccolumn.grid(row=1, column=7, sticky='WE', padx=1, pady=1)
        self.tortcolumn.grid(row=1, column=8, sticky='WE', padx=1, pady=1)
        self.sorpcolumn.grid(row=1, column=9, sticky='WE', padx=1, pady=1)
        self.refcolumn.grid(row=1, column=10, sticky='WE', padx=1, pady=1)

        self.numberlabel.grid(row=2, column=3, sticky='WE', padx=1, pady=1)
        self.namelabel.grid(row=2, column=4, sticky='WE', padx=1, pady=1)
        self.elabel.grid(row=2, column=5, sticky='WE', padx=1, pady=1)
        self.rholabel.grid(row=2, column=6, sticky='WE', padx=1, pady=1)
        self.foclabel.grid(row=2, column=7, sticky='WE', padx=1, pady=1)
        self.tortlabel.grid(row=2, column=8, sticky='WE', padx=1, pady=1)
        self.sorplabel.grid(row=2, column=9, sticky='WE', padx=1, pady=1)
        self.reflabel.grid(row=2, column=10, sticky='WE', padx=1, pady=1)

        self.rhounitlabel.grid(row=3, column=6, sticky='WE', padx=1, pady=1)

        self.updatesolids()

        #Bind the "return key" to the buttons

        self.focusbutton = self.cancelbutton

    def updatesolids(self):

        self.addwidget.grid_forget()
        self.blank1.grid_forget()
        self.blank2.grid_forget()

        self.botblankcolumn.grid_forget()
        self.boteditcolumn.grid_forget()
        self.botdelcolumn.grid_forget()
        self.botnumbercolumn.grid_forget()
        self.botnamecolumn.grid_forget()
        self.botecolumn.grid_forget()
        self.botrhocolumn.grid_forget()
        self.botfoccolumn.grid_forget()
        self.bottortcolumn.grid_forget()
        self.botsorpcolumn.grid_forget()
        self.botrefcolumn.grid_forget()

        namelabellength = 18
        reflabellength = 15

        row = 4
        for solid in self.solids:
            try:
                solid.remove_propertieswidget()
            except:
                pass
            solid.number = self.solids.index(solid) + 1
            solid.propertieswidget(self.frame, row, self.master)
            row = row + 1

            if namelabellength < solid.namelabel.winfo_reqwidth() / 8:
                namelabellength = int(solid.namelabel.winfo_reqwidth() / 8) + 1
            if reflabellength < solid.reflabel.winfo_reqwidth() / 8:
                reflabellength = int(solid.reflabel.winfo_reqwidth() / 8) + 1

        self.namecolumn.config(width=namelabellength)
        self.botnamecolumn.config(width=namelabellength)
        self.refcolumn.config(width=reflabellength)
        self.botrefcolumn.config(width=reflabellength)

        self.botblankcolumn.grid(row=row,
                                 column=0,
                                 sticky='WE',
                                 padx=1,
                                 pady=1)
        self.boteditcolumn.grid(row=row, column=1, sticky='WE', padx=1, pady=1)
        self.botdelcolumn.grid(row=row, column=2, sticky='WE', padx=1, pady=1)
        self.botnumbercolumn.grid(row=row,
                                  column=3,
                                  sticky='WE',
                                  padx=1,
                                  pady=1)
        self.botnamecolumn.grid(row=row, column=4, sticky='WE', padx=1, pady=1)
        self.botecolumn.grid(row=row, column=5, sticky='WE', padx=1, pady=1)
        self.botrhocolumn.grid(row=row, column=6, sticky='WE', padx=1, pady=1)
        self.botfoccolumn.grid(row=row, column=7, sticky='WE', padx=1, pady=1)
        self.bottortcolumn.grid(row=row, column=8, sticky='WE', padx=1, pady=1)
        self.botsorpcolumn.grid(row=row, column=9, sticky='WE', padx=1, pady=1)
        self.botrefcolumn.grid(row=row, column=10, sticky='WE', padx=1, pady=1)
        row = row + 1

        row = 0
        self.blank1.grid(row=row)
        row = row + 1
        self.blank2.grid(row=row)
        row = row + 1
        self.addwidget.grid(row=row, columnspan=11)
        row = row + 1
        self.importwidget.grid(row=row, columnspan=11)
        row = row + 1
        self.savebutton.grid(row=row, columnspan=11)
        row = row + 1
        self.cancelbutton.grid(row=row, columnspan=11)
        row = row + 1
        self.blank3.grid(row=row)

        self.savebutton.bind('<Return>', self.save)
        self.cancelbutton.bind('<Return>', self.cancel)

        self.focusbutton = self.savebutton
        self.master.geometry()

    def addsolid(self):

        self.solids.append(Solid(self.solids[-1].number + 1))

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                SolidDatabaseEditor(self.top,
                                    self.system,
                                    self.solids[-1],
                                    self.solids,
                                    editflag=0))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.solids[-1].get_solid(self.top.window)
            else:
                self.solids.remove(self.solids[-1])

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatesolids()

    def editsolid(self, number):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                SolidDatabaseEditor(self.top,
                                    self.system,
                                    self.solids[number - 1],
                                    self.solids,
                                    editflag=1))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.solids[number - 1].get_solid(self.top.window)

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatesolids()

    def importsoliddata(self):

        UserPath = os.environ['USERPROFILE']
        Filepath = tkfd.askopenfilename(initialdir=UserPath)

        if Filepath != '':
            data = open(Filepath, 'r')
            database_imported = pickle.load(data)
            data.close()
            if self.top is None:
                self.top = CapSimWindow(master=self.master, buttons=2)
                self.top.make_window(
                    SolidDatabaseImporter(self.top, self.system,
                                          database_imported))
                self.top.tk.mainloop()

                duplicate_name = []

                if self.top.window.cancelflag == 0:
                    error_check = 0
                    for solid in self.top.window.solids:
                        if solid.check == 1:
                            if self.solids_list.count(solid.name_new) == 0:
                                self.solids_list.append(solid.name_new)
                                self.solids.append(
                                    Solid(
                                        self.solids_list.index(
                                            solid.name_new)))
                                self.solids[-1].import_coefficients(solid)
                            else:
                                duplicate_name.append(solid.name_new)
                                error_check = 1

                    error_message = 'The following compound information are duplicated:\n\n'
                    for na in range(len(duplicate_name)):
                        error_message = error_message + '              ' + str(
                            duplicate_name[na]) + ' \n'

                    if error_check == 1:
                        tkmb.showerror(title=self.system.version,
                                       message=error_message)

                if self.top is not None:
                    self.top.destroy()
                    self.top = None

            elif self.top is not None:
                tkmb.showerror(
                    title=self.system.version,
                    message=
                    'Please close the existing parameter input window first.')
                self.top.tk.focus()

        self.updatesolids()

    def deletesolid(self, number):

        if self.top is None:

            self.top = CapSimWindow(master=self.master, buttons=2)
            self.top.make_window(
                SolidDatabaseDeleter(self.top, self.system,
                                     self.solids[number - 1]))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.solids[number - 1].remove_propertieswidget()
                self.solids.remove(self.solids[number - 1])

            if self.top is not None:
                self.top.destroy()
                self.top = None

        elif self.top is not None:
            tkmb.showerror(
                title=self.system.version,
                message=
                'Please close the existing parameter input window first.')
            self.top.tk.focus()

        self.updatesolids()

    def save(self, event=None):

        self.database = self.write_database()

        self.exitflag = 1
        self.frame.quit()

    def cancel(self, event=None):

        self.exitflag = 1
        self.frame.quit()

    def exit(self, event=None):
        """Exit CapSim."""

        if tkmb.askyesno(self.version,
                         'Do you really want to exit CapSim?') == 1:
            sys.exit()

    def write_database(self):

        soliddatabase = {}
        for solid in self.solids:
            soliddatabase[solid.name] = SolidDatabase(solid.name, solid.number,
                                                      solid.e, solid.rho,
                                                      solid.foc, solid.tort,
                                                      solid.sorp, solid.Ref)

        return soliddatabase
コード例 #28
0
class ReactionProperties:
    """Gets the model types for each of the layers in the system."""

    def __init__(self, master, system):
        """Constructor method. Used to defines the layers."""
        
        self.master         = master
        self.system         = system
        self.version        = system.version
        self.fonttype       = system.fonttype
        self.formulatype    = system.formulatype
        self.superfont      = get_superfont(self.fonttype)
        self.subfont        = get_superfont(self.formulatype)
        self.tframe         = Frame(master.tframe)
        self.frame          = Frame(master.frame)
        self.bframe         = Frame(master.bframe)
        self.bgcolor        = self.frame.cget('bg')
        self.top            = None

        self.chemicals      = system.chemicals
        
        if master.master is None: self.defaults = 1

        if system.reactions is None: self.reactions      = []
        else:                        self.reactions      = system.reactions
        
    def make_widgets(self):
        """Makes the widgets for the GUI."""

        self.instructions   = Label(self.tframe,  text  = 'Please input the kinetic processes in the system:        ')

        self.blankcolumn    = Label(self.tframe,  text = '', font = 'courier 10',  width = 1 )
        self.editcolumn     = Label(self.tframe,  text = '', font = 'courier 10',  width = 6 )
        self.delcolumn      = Label(self.tframe,  text = '', font = 'courier 10',  width = 6 )
        self.numbercolumn   = Label(self.tframe,  text = '', font = 'courier 10',  width = 5 )
        self.namecolumn     = Label(self.tframe,  text = '', font = 'courier 10',  width = 15)
        self.equationcolumn = Label(self.tframe,  text = '', font = 'courier 10',  width = 20)
        self.ratecolumn     = Label(self.tframe,  text = '', font = 'courier 10',  width = 10)
        self.endcolumn      = Label(self.tframe,  text = '', font = 'courier 10',  width = 2)
        
        self.numberlabel    = Label(self.tframe,  text = 'Number')
        self.namelabel      = Label(self.tframe,  text = 'Name')
        self.equationlabel  = Label(self.tframe,  text = 'Chemical equation')
        self.ratelabel      = Label(self.tframe,  text = 'Rate equation')

        self.botblankcolumn    = Label(self.frame,  text = '', font = 'courier 10',  width = 1 )
        self.boteditcolumn     = Label(self.frame,  text = '', font = 'courier 10',  width = 6 )
        self.botdelcolumn      = Label(self.frame,  text = '', font = 'courier 10',  width = 6 )
        self.botnumbercolumn   = Label(self.frame,  text = '', font = 'courier 10',  width = 5 )
        self.botnamecolumn     = Label(self.frame,  text = '', font = 'courier 10',  width = 15)
        self.botequationcolumn = Label(self.frame,  text = '', font = 'courier 10',  width = 20)
        self.botratecolumn     = Label(self.frame,  text = '', font = 'courier 10',  width = 10)
        self.botendcolumn      = Label(self.frame,  text = '', font = 'courier 10',  width = 2)

        self.addwidget      = Button(self.bframe, text = 'Add reactions', command = self.addreaction, width = 20)
        self.blank1         = Label (self.bframe, text = ' ')
        self.blank2         = Label (self.bframe, text = ' ')
        #show the widgets on the grid

        self.instructions.grid( row = 0, column = 0, padx = 8, columnspan = 6, sticky = 'W')

        self.blankcolumn.grid(      row = 1, column = 0, padx = 1, sticky = 'WE', pady = 1)
        self.editcolumn.grid(       row = 1, column = 1, padx = 1, sticky = 'WE', pady = 1)
        self.delcolumn.grid(        row = 1, column = 2, padx = 1, sticky = 'WE', pady = 1)
        self.numbercolumn.grid(     row = 1, column = 3, padx = 4, sticky = 'WE')
        self.namecolumn.grid(       row = 1, column = 4, padx = 4, sticky = 'WE')
        self.equationcolumn.grid(   row = 1, column = 5, padx = 4, sticky = 'WE')
        self.ratecolumn.grid(       row = 1, column = 6, padx = 4, sticky = 'WE')
        self.endcolumn.grid(        row = 1, column = 7, padx = 4, sticky = 'WE')

        self.numberlabel.grid(      row = 2, column = 3, padx = 1, sticky = 'WE', pady = 4)
        self.namelabel.grid(        row = 2, column = 4, padx = 1, sticky = 'WE', pady = 4)
        self.equationlabel.grid(    row = 2, column = 5, padx = 1, sticky = 'WE', pady = 4)
        self.ratelabel.grid(        row = 2, column = 6, padx = 1, sticky = 'WE', pady = 4)

        self.updatereactions()
        
    def updatereactions(self):
        
        self.addwidget.grid_forget()
        self.blank1.grid_forget()
        self.blank2.grid_forget()

        namelabellength         = 15
        equationlabellength     = 20
        ratelabellength         = 10

        row = 4
        
        for reaction in self.reactions:
            try: reaction.remove_propertieswidgets()
            except:pass
            reaction.number = self.reactions.index(reaction) + 1
            reaction.propertieswidgets(self.frame, row, self.master, self.formulatype, self.superfont, self.subfont, self.bgcolor)
            row = row + 1

            if namelabellength     < reaction.namelabel.winfo_reqwidth()/8:  namelabellength     = int(reaction.namelabel.winfo_reqwidth()/8) + 1
            if equationlabellength < reaction.equalabel.winfo_reqwidth()/8:  equationlabellength = int(reaction.equalabel.winfo_reqwidth()/8) + 1
            if ratelabellength     < reaction.ratewidget.winfo_reqwidth()/8: ratelabellength     = int(reaction.ratewidget.winfo_reqwidth()/8) + 1

        self.botblankcolumn.grid(      row = row, column = 0, padx = 1, sticky = 'WE',pady = 1)
        self.boteditcolumn.grid(       row = row, column = 1, padx = 1, sticky = 'WE',pady = 1)
        self.botdelcolumn.grid(        row = row, column = 2, padx = 1, sticky = 'WE',pady = 1)
        self.botnumbercolumn.grid(     row = row, column = 3, padx = 4, sticky = 'WE')
        self.botnamecolumn.grid(       row = row, column = 4, padx = 4, sticky = 'WE')
        self.botequationcolumn.grid(   row = row, column = 5, padx = 4, sticky = 'WE')
        self.botratecolumn.grid(       row = row, column = 6, padx = 4, sticky = 'WE')
        self.botendcolumn.grid(        row = row, column = 7, padx = 4, sticky = 'WE')

        self.namecolumn.config(width     = namelabellength)
        self.equationcolumn.config(width = equationlabellength)
        self.ratecolumn.config(width     = ratelabellength)

        self.botnamecolumn.config(width     = namelabellength)
        self.botequationcolumn.config(width = equationlabellength)
        self.botratecolumn.config(width     = ratelabellength)


        row = 0

        self.blank1.grid(row = row)
        row = row + 1
        self.blank2.grid(row = row)
        row = row + 1

        self.addwidget.grid(row = row, columnspan = 11)
        row = row + 1

        self.focusbutton = None
        self.master.geometry()
        self.master.center()

    def addreaction(self, event = None):

        self.reactions.append(Reaction(len(self.reactions)+1))
        
        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(ReactionEditor(self.top, self.system, self.reactions[-1], editflag = 0))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0: self.reactions[-1].get_reaction(self.top.window)
            else:
                self.reactions.remove(self.reactions[-1])
                
            if self.top is not None:
                self.top.destroy()
                self.top = None
                
        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()
                    
        self.updatereactions()
                    
    def editreaction(self, number):

        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(ReactionEditor(self.top, self.system, self.reactions[number-1], editflag = 1))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0: self.reactions[number-1].get_reaction(self.top.window)
                
            if self.top is not None:
                self.top.destroy()
                self.top = None
                
        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()
        
        self.updatereactions()
        

    def delreaction(self, number):
        
        if self.top is None:

            self.top = CapSimWindow(master = self.master, buttons = 2)
            self.top.make_window(ReactionDeleter(self.top, self.system, self.reactions[number-1]))
            self.top.tk.mainloop()

            if self.top.window.cancelflag == 0:
                self.reactions[number-1].remove_propertieswidgets()
                self.reactions.remove(self.reactions[number-1])
                
            if self.top is not None:
                self.top.destroy()
                self.top = None
                
        elif self.top is not None:
            tkmb.showerror(title = self.system.version, message = 'Please close the existing parameter input window first.')
            self.top.tk.focus()
        
        self.updatereactions()