Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/UI/Qt/main.py
    1| # $Id: main.py,v 1.6 2002/09/28 05:53:31 chalky Exp $
    2| #
    3| # This file is a part of Synopsis.
    4| # Copyright (C) 2000, 2001 Stefan Seefeld
    5| # Copyright (C) 2000, 2001 Stephen Davies
    6| #
    7| # Synopsis is free software; you can redistribute it and/or modify it
    8| # under the terms of the GNU General Public License as published by
    9| # the Free Software Foundation; either version 2 of the License, or
   10| # (at your option) any later version.
   11| #
   12| # This program is distributed in the hope that it will be useful,
   13| # but WITHOUT ANY WARRANTY; without even the implied warranty of
   14| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15| # General Public License for more details.
   16| #
   17| # You should have received a copy of the GNU General Public License
   18| # along with this program; if not, write to the Free Software
   19| # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   20| # 02111-1307, USA.
   21| #
   22| # $Log: main.py,v $
   23| # Revision 1.6  2002/09/28 05:53:31  chalky
   24| # Refactored display into separate project and browser windows. Execute projects
   25| # in the background
   26| #
   27| # Revision 1.5  2002/06/22 07:03:27  chalky
   28| # Updates to GUI - better editing of Actions, and can now execute some.
   29| #
   30| # Revision 1.4  2001/11/09 15:35:04  chalky
   31| # GUI shows HTML pages. just. Source window also scrolls to correct line.
   32| #
   33| # Revision 1.3  2001/11/09 08:06:59  chalky
   34| # More GUI fixes and stuff. Double click on Source Actions for a dialog.
   35| #
   36| # Revision 1.2  2001/11/07 05:58:21  chalky
   37| # Reorganised UI, opening a .syn file now builds a simple project to view it
   38| #
   39| # Revision 1.1  2001/11/05 06:52:11  chalky
   40| # Major backside ui changes
   41| #
   42| 
   43| 
   44| import sys, pickle, Synopsis, cStringIO, os
   45| from qt import *
   46| from Synopsis.Core import AST, Util, Action
   47| from Synopsis.Formatter.ASCII import ASCIIFormatter
   48| from Synopsis.Formatter.ClassTree import ClassTree
   49| 
   50| from igraph import IGraphWindow
   51| from project import ProjectWindow
   52| from browse import BrowserWindow
   53| 
   54| class MainWindow (QMainWindow):
   55|     """The main window of the applet. It controls the whole GUI.
   56|     """
   57|     def __init__(self):
   58|         QMainWindow.__init__(self, None, 'Synopsis')
   59|         self.setCaption('Synopsis')
   60| 
   61|         # Make the menu
   62|         menu = self.menuBar()
   63|         file = QPopupMenu(self)
   64|         file.insertItem("&Open File...", self.open_file, Qt.CTRL+Qt.Key_O)
   65|         file.insertItem("&New Project...", self.new_project, Qt.CTRL+Qt.Key_N)
   66|         file.insertItem("Open &Project...", self.open_project, Qt.CTRL+Qt.Key_P)
   67|         file.insertItem("&Quit", qApp, SLOT( "quit()" ), Qt.CTRL+Qt.Key_Q)
   68|         menu.insertItem("&File", file)
   69|         self.window_menu = window = QPopupMenu(self)
   70|         self.project_menu = QPopupMenu(self)
   71|         self.project_menu.insertItem("&Execute", self.execute_project, Qt.CTRL+Qt.Key_E)
   72| 
   73|         self.workspace = QWorkspace(self)
   74|         self.setCentralWidget(self.workspace)
   75|         self.windows = []
   76|         self.window_ids = []
   77| 
   78|     def open_project(self):
   79|         """Opens a project"""
   80|         filename = str(QFileDialog.getOpenFileName(".", 
   81|             "Synopsis Project files (*.synopsis)", self, 
   82|             "projectopen", "Open Project..."))
   83|         if filename:
   84|             self.do_open_project(filename)
   85|     
   86|     def do_open_project(self, filename):
   87|         """Opens a project for the given filename"""
   88|         ProjectWindow(self, filename)
   89| 
   90|     def open_file(self):
   91|         """A file selection dialog is opened to prompt the user
   92|         for a filename."""
   93|         filename = str(QFileDialog.getOpenFileName(".", 
   94|             "Synopsis files (*.*syn)", self, 
   95|             "file", "Open a Synopsis data file"))
   96|         if filename:
   97|             self.do_open_file(filename)
   98| 
   99|     def do_open_file(self, filename):
  100|         """Opens a file in a new project."""
  101|         BrowserWindow(self, filename, None)
  102| 
  103|     def new_project(self):
  104|         ProjectWindow(self, None)
  105| 
  106|     def execute_project(self):
  107|         win = self.workspace.activeWindow()
  108|         if isinstance(win, ProjectWindow):
  109|             win.execute_project()
  110|     
  111|     def add_window(self, window):
  112|         if window in self.windows:
  113|           return
  114|         # Remove old menu items
  115|         for id in self.window_ids:
  116|             self.window_menu.removeItem(id)
  117|         # Add new window to list
  118|         self.windows.append(window)
  119|         # Regenerate menu
  120|         for i in range(len(self.windows)):
  121|             text = "&%d: %s"%(i+1, self.windows[i].caption())
  122|             id = self.window_menu.insertItem(text)
  123|             self.window_ids.append(id)
  124|         # If it's the only window, show menu
  125|         if len(self.windows) == 1:
  126|             self.menuBar().insertItem("&Window", self.window_menu)
  127|         
  128|         # Show window
  129|         if len(self.windows) == 1:
  130|             window.showMaximized()
  131|         window.show()
  132|     
  133|     def remove_window(self, window):
  134|         pass
  135|