commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/designer/src Instance.py


From: Jason Cater
Subject: gnue/designer/src Instance.py
Date: Wed, 18 Jul 2001 18:17:08 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/07/18 18:17:08

Modified files:
        designer/src   : Instance.py 

Log message:
        If file specified on command line doesn't exists, a dialog asks whether 
or not to create; if file is readonly, pops up a warning dialog; when doing 
'Save As...', if specified file name doesn't have extension, add it based on 
selection in dialog box. [based on Rafterman's patch]

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/designer/src/Instance.py.diff?cvsroot=OldCVS&tr1=1.17&tr2=1.18&r1=text&r2=text

Patches:
Index: gnue/designer/src/Instance.py
diff -u gnue/designer/src/Instance.py:1.17 gnue/designer/src/Instance.py:1.18
--- gnue/designer/src/Instance.py:1.17  Wed Jul 11 11:41:34 2001
+++ gnue/designer/src/Instance.py       Wed Jul 18 18:17:08 2001
@@ -66,23 +66,34 @@
     self._pages = []
 
     if location == None: 
-      self._path = ""
-      self._form = GFForm.GFForm()
-      options = GFObjects.GFOptions(self._form)
-      self._form.title = "Untitled Form"
-      self._form.height = 12
-      self._form.width = 40
-      page = GFObjects.GFPage(self._form)
-      GFObjects.GFBlock(page)
-      self.makeClean()
-      self._isNew = 1
+      self.__createEmptyForm()
     else: 
-      self._path = location
-      fileHandle = open(location,'r')
-      self._form = GFParser.loadForm (fileHandle, self, initialize=0) 
-      fileHandle.close()
-      self.makeClean()
-      self._isNew = 0
+
+      if not os.access (location, os.R_OK): 
+        self.Show(1)
+        if not wxMessageDialog(self, \
+          'The requested file does not exist.\n'
+          'Do you want to create this file?'
+          '\n\nFile: %s' \
+            % location, "File Not Found", wxYES_NO|wxICON_QUESTION 
).ShowModal():
+          sys.exit()
+        self.Show(0)
+        self.__createEmptyForm()
+        self._path = location
+        self.makeDirty()
+
+      elif not os.access (location, os.W_OK): 
+        self.Show(1)
+        if not wxMessageDialog(self, \
+          'The requested file is Read Only.\n'
+          'To save any changes, you will \n'
+          'be required to do a "Save As..."\n\nFile: %s' \
+            % location, "Read Only Warning", wxOK|wxCANCEL|wxICON_EXCLAMATION 
).ShowModal():
+          sys.exit()
+        self.Show(0)
+        self.__loadForm(location)
+      else:
+        self.__loadForm(location)
 
     self._form.name = "Form"
 
@@ -147,6 +158,31 @@
 
     EVT_CLOSE(self, self.OnClose)
 
+  def __loadForm(self, location): 
+    try: 
+      fileHandle = open(location,'r')
+      self._form = GFParser.loadForm (fileHandle, self, initialize=0) 
+      fileHandle.close()
+      self.makeClean()
+      self._isNew = 0
+    except IOError, msg:         
+      print "\n%s %s\n\nUnable to open file '%s'. \nUnexpected read error:\n  
%s.\n" % (TITLE, VERSION, location, msg)
+      sys.exit()
+
+
+  def __createEmptyForm(self):
+    self._path = ""
+    self._form = GFForm.GFForm()
+    options = GFObjects.GFOptions(self._form)
+    self._form.title = "Untitled Form"
+    self._form.height = 12
+    self._form.width = 40
+    page = GFObjects.GFPage(self._form)
+    GFObjects.GFBlock(page)
+    self.makeClean()
+    self._isNew = 1
+
+
   #
   #  Used by RuntimeSettings
   # 
@@ -330,6 +366,11 @@
                            style=wxSAVE)
     if dlg.ShowModal() == wxID_OK:
       self._path = dlg.GetPath()
+      if len(self._path) < 4 or not self._path[-4:] in ('.gfd','.gfl'): 
+        if dlg.GetFilterIndex(): 
+          self._path = self._path + '.gfl'
+        else: 
+          self._path = self._path + '.gfd'
       self.SetTitle (TITLE + " - " + self._path)
       self.saveForm()
     dlg.Destroy()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]