All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
projectview.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 ######################################################################
3 #
4 # Name: projectview.py
5 #
6 # Purpose: Python class ProjectView is a widget for displaying
7 # information about projects.
8 #
9 # Created: 21-Jan-2015 Herbert Greenlee
10 #
11 ######################################################################
12 
13 from __future__ import absolute_import
14 from __future__ import print_function
15 
16 # Import GUI stuff
17 
18 try:
19  import tkinter as tk
20  import tkinter.messagebox as tkinter_messagebox
21 except ImportError:
22  import Tkinter as tk
23  import tkMessageBox as tkinter_messagebox
24 
25 from project_gui_modules.statusview import ProjectStatusView
26 from project_gui_modules.textwindow import TextWindow
27 
28 # Project widget class
29 
30 class ProjectView(tk.Frame):
31 
32  # Constructor.
33 
34  def __init__(self, parent, project_name=None, xml_path=None, project_defs=[]):
35 
36  self.parent = parent
37 
38  # Register our outermost frame in the parent window.
39 
40  tk.Frame.__init__(self, self.parent)
41  self.pack(expand=1, fill=tk.BOTH)
42 
43  # Make widgets that belong to this widget.
44 
45  self.make_widgets()
46  self.set_project(project_name, xml_path, project_defs)
47 
48  # Make widgets.
49 
50  def make_widgets(self):
51 
52  # Add a frame for information labels.
53 
54  self.infoframe = tk.Frame(self, relief=tk.FLAT, bg='aliceblue')
55  self.infoframe.pack(side=tk.TOP, fill=tk.X)
56  self.infoframe.columnconfigure(1, weight=1)
57 
58  # Add a label in info frame which will display the current project xml file path.
59 
60  self.pathlabel = tk.Label(self.infoframe, relief=tk.FLAT, bg='aliceblue', text='XML Path:')
61  self.pathlabel.grid(row=0, column=0)
62  self.path = tk.Label(self.infoframe, relief=tk.SUNKEN, bg='white')
63  self.path.grid(row=0, column=1, sticky=tk.E+tk.W)
64 
65  # Add a label in info frame which will display the current project name.
66 
67  self.projectlabel = tk.Label(self.infoframe, relief=tk.FLAT, bg='aliceblue',
68  text='Project:')
69  self.projectlabel.grid(row=1, column=0)
70  self.projectname = tk.Label(self.infoframe, relief=tk.SUNKEN, bg='white')
71  self.projectname.grid(row=1, column=1, sticky=tk.E+tk.W)
72 
73  # Add a project status view.
74 
75  self.ps = ProjectStatusView(self)
76  self.ps.pack(side=tk.BOTTOM, expand=1, fill=tk.BOTH)
77 
78  # Select the project.
79 
80  def set_project(self, project_name, xml_path, project_defs):
81  self.path['text'] = xml_path
82  self.projectname['text'] = project_name
83  if len(project_defs) > 0:
84  self.ps.set_project(project_defs)
85 
86  # Make a top level window for displaying xml.
87 
88  def make_xml_window(self):
89 
90  xml_path = self.path['text']
91  if xml_path == None or xml_path == '':
92  tkinter_messagebox.showerror('', 'No xml file specified.')
93  return
94 
95  # Get text of xml file.
96 
97  f = open(xml_path)
98  if not f:
99  tkinter_messagebox.showerror('', 'Error opening xml file %s.' % xml_path)
100  return
101  xmltext = f.read()
102 
103  # Make a new top level window to hold xml text.
104  # After we are done making this window, we don't keep track
105  # of it any more. It is owned by window manager.
106 
107  w = TextWindow()
108  w.append(xmltext)
109 
110  # Update status view.
111 
112  def update_status(self):
113  self.ps.update_status()
114 
115  # Update bach jobs.
116 
117  def update_jobs(self):
118  self.ps.update_jobs()
119 
120  # Highlight stage.
121 
122  def highlight_stage(self, stagename):
123  self.ps.highlight_stage(stagename)
open(RACETRACK) or die("Could not open file $RACETRACK for writing")