File: rcrane_loader.py

package info (click to toggle)
coot 1.1.18%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 219,964 kB
  • sloc: cpp: 495,934; python: 35,043; ansic: 26,143; lisp: 22,768; sh: 13,186; makefile: 2,746; awk: 441; xml: 245; csh: 14
file content (74 lines) | stat: -rw-r--r-- 2,865 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

#load the rcrane module
import rcrane

def import_rcrane_wrapper():
   
   #create the menu entry in the Extensions menu
   extMenu = coot_gui.coot_menubar_menu("Calculate")
   rcraneLaunch = gtk.MenuItem("RCrane launch")
   rcraneLaunch.connect("activate", lambda x: rcrane.createRCraneMenuWithCheck())
   rcraneLaunch.show()
   extMenu.insert(rcraneLaunch, len(extMenu.get_children())-1)

   #destroy any variables that we've created, since the variables will be visible from the
   # Coot Python scripting window
   del extMenu
   del rcraneLaunch

   #check to see if the user has an old version of RCrane installed
   #if they do, stop it from running
   def checkForOldRCraneVersions():
       from rcrane.settings import settingsFilename
       rcraneSettingsFilename = settingsFilename()

       #try to open the RCrane settings file
       try:
           rcraneSettings = open(rcraneSettingsFilename, 'r')
       except IOError:
           #if the file doesn't exist, then the user doesn't have an old version of RCrane installed
           return False

       for curline in rcraneSettings:
           if curline[0:18] == "run_python_script(":
               rcraneSettings.close()
               break
       else:
           #the rcrane.py file exists, but it doesn't have a coot.run_python_script( line,
           #so the user doesn't have an old version of RCrane installed
           rcraneSettings.close()
           return False

       #if we reach here, then the user has an old version of RCrane installed
       from shutil import move
       from os.path import dirname, join

       #move the user's rcrane.py to rcrane.py.bak, since it's no longer necessary
       try:
           move(rcraneSettingsFilename, join(dirname(rcraneSettingsFilename), "rcrane.py.bak"))
       except IOError:
           print("Cannot move ~/.coot-preferences/rcrane.py to ~/.coot-preferences/rcrane.py.bak")
           return False

       #let the user know what we just did
       noticeDialog = gtk.MessageDialog(type = gtk.MESSAGE_WARNING, buttons = gtk.BUTTONS_OK)
       noticeDialog.set_title("Old version of RCrane detected")
       noticeDialog.set_markup("An old version of RCrane was detected.  Coot now includes "
           + "RCrane 1.1, which may be accessed via Extensions -> RCrane launch.  To prevent the "
           + "old version of RCrane from running, your "
           + "~/.coot-preferences/rcrane.py file was moved to ~/.coot-preferences/rcrane.py.bak.")
       noticeDialog.run()
       noticeDialog.destroy()

       return True


   checkForOldRCraneVersions()
   del checkForOldRCraneVersions #destroy the function as well, since we don't need it after it's been run

# do this now if we load stuff from guile-gtk

# print '===== in rcrane loader: use_gui_qm is ', use_gui_qm

if (use_gui_qm != 2):
    import_rcrane_wrapper()