def openConfigFile(fileName):
     """open the file, if it doesn't exist, create it, if it doesn't work 
     exit program with error message"""
     try:
         f = open(fileName, "r")
     except IOError:
         try:
             with open(fileName, "w") as f:
                 f.write(CConfigFileParser.ConfigFileDefaultContents)
             f.close()
             f = open(fileName, "r")
         except:
             CMyToolbox.errorMessageAndExit("config File %s cannot be read or written!" % fileName)
     # here, f should be a valid file handle
     return f
 def __init__(self, root, config):
     Tkinter.Frame.__init__(self, root, padx=20, pady=20)
     # define the instance variables
     self.root = root
     self.config = config
     self.buttonwidth = self.calculateButtonWidth()
     self.commandButtons = []
     self.outputWindow = None
     self.outputWindowVisible = True
     self.commandThread = CCommandThread()
     self.buttonsDisabled = False
     """create the dialog and call the main loop"""
     gridwidth = self.config['GridWidth']
     self.root.title(self.config['TitleString'])
     self.root.resizable(0,0)
     self.pack()
     # add a title string to the top
     label = Tkinter.Label(self, text=self.config['LabelString'].decode("string_escape"))
     label.grid(row=0, columnspan=gridwidth, pady=(0, 20))
     # add the buttons for the system command
     nextrow = self.addButtons() + 1
     self.outputWindow = Tkinter.Text(self, width=1, height=15)
     self.outputWindow.grid(row=nextrow, column=0, columnspan=gridwidth, pady=(20, 0), sticky="WENS")
     # show the output window?
     if(config["ShowCommandOutput"]==0):
         self.toggleOutputWindow()
     nextrow += 1
     # add a close-button at left center 
     button = Tkinter.Button(self, text="Close", command=(lambda: CMyToolbox.exitProgram(0)), width=self.buttonwidth)
     button.grid(row=nextrow, column=gridwidth-1, pady=(20, 0))
     # update GUI periodically
     self.master.after(self.UpdateInterval, self.updateGUI)