source: trunk/python/customgui_qt4agg.py@ 2161

Last change on this file since 2161 was 2155, checked in by Kana Sugimoto, 14 years ago

New Development: Yes

JIRA Issue: No (reorganization of modules)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: the modules casatoolbar, flagtoolbar, notaionwindow, were reorganized as customgui_base, customgui_tkagg, and customgui_qt4agg, based on backend

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...


File size: 6.3 KB
Line 
1import os
2import matplotlib, numpy
3from asap.logging import asaplog, asaplog_post_dec
4from matplotlib.patches import Rectangle
5from asap.parameters import rcParams
6from asap._asap import stmath
7from asap.customgui_base import *
8
9import PyQt4 as qt
10
11class CustomToolbarQT4Agg(CustomToolbarCommon, qt.QtGui.QToolBar):
12 def __init__(self,parent):
13 from asap.asapplotter import asapplotter
14 if not isinstance(parent,asapplotter):
15 return False
16 if not parent._plotter:
17 return False
18 self._p = parent._plotter
19 self.figmgr = self._p.figmgr
20 self.canvas = self.figmgr.canvas
21 self.mode = ''
22 self.button = True
23 self.pagecount = None
24 CustomToolbarCommon.__init__(self,parent)
25# self.notewin = NotationWindowQT4Agg(master=self.canvas)
26 self._add_custom_toolbar()
27
28 def _add_custom_toolbar(self):
29 qt.QtGui.QToolBar.__init__(self,parent=self.figmgr.window)
30 self.figmgr.window.addToolBar(qt.QtCore.Qt.BottomToolBarArea,self)
31 self.bNote = self._NewButton(master=self,
32 text='notation',
33 command=self.modify_note)
34 self.bNote.setCheckable(True)
35
36 self.bStat = self._NewButton(master=self,
37 text='statistics',
38 command=self.stat_cal)
39 self.bStat.setCheckable(True)
40
41 # page change oparations
42 frPage = qt.QtGui.QWidget(parent=self,flags=qt.QtCore.Qt.Tool)
43 loPage = qt.QtGui.QHBoxLayout(self)
44 loPage.addStretch(1)
45 self.lPagetitle = qt.QtGui.QLabel('Page:',parent=frPage)
46 self.lPagetitle.setMargin(5)
47 loPage.addWidget(self.lPagetitle)
48 self.pagecount = qt.QtGui.QLabel(parent=frPage)
49 self.pagecount.setStyleSheet("background-color: white")
50 self.pagecount.setMargin(3)
51 self.pagecount.setText(' 1')
52 loPage.addWidget(self.pagecount)
53
54 self.bNext = self._NewButton(master=frPage,
55 text=' + ',
56 command=self.next_page,addparent=False)
57 loPage.addWidget(self.bNext)
58 self.bPrev = self._NewButton(master=frPage,
59 text=' - ',
60 command=self.prev_page,addparent=False)
61 loPage.addWidget(self.bPrev)
62 frPage.setLayout(loPage)
63 self.addWidget(frPage)
64
65 self.bQuit = self._NewButton(master=self,
66 text='Quit',
67 command=self.quit)
68
69# if os.uname()[0] != 'Darwin':
70# self.bPrev.config(padx=5)
71# self.bNext.config(padx=5)
72
73 self.pagecount.setText(' '*4)
74
75 self.disable_button()
76 return
77
78 def _NewButton(self, master, text, command,addparent=True):
79 b = qt.QtGui.QPushButton(text,parent=master)
80 if addparent: master.addWidget(b)
81 master.connect(b,qt.QtCore.SIGNAL('clicked()'),command)
82# if os.uname()[0] == 'Darwin':
83# b = Tk.Button(master=master, text=text, command=command)
84# else:
85# b = Tk.Button(master=master, text=text, padx=2, pady=2,
86# command=command)
87 return b
88
89 def show_pagenum(self,pagenum,formatstr):
90 self.pagecount.setText(formatstr % (pagenum))
91
92 def spec_show(self):
93 if not self.figmgr.toolbar.mode == '' or not self.button: return
94 self.figmgr.toolbar.set_message('spec value: drag on a spec')
95 if self.mode == 'spec': return
96 self.mode = 'spec'
97# self.notewin.close_widgets()
98 self.__disconnect_event()
99 self._p.register('button_press',self._select_spectrum)
100
101 def stat_cal(self):
102 if not self.figmgr.toolbar.mode == '' or not self.button:
103 # Get back button status BEFORE clicked
104 self.bStat.setChecked(not self.bStat.isChecked())
105 return
106 if self.mode == 'stat':
107 # go back to spec mode
108 self.bStat.setChecked(False)
109 self.spec_show()
110 return
111 self.figmgr.toolbar.set_message('statistics: select a region')
112 self.bStat.setChecked(True)
113 self.bNote.setChecked(False)
114 self.mode = 'stat'
115# self.notewin.close_widgets()
116 self.__disconnect_event()
117 self._p.register('button_press',self._single_mask)
118
119 def modify_note(self):
120 if not self.figmgr.toolbar.mode == '':
121 # Get back button status BEFORE clicked
122 self.bNote.setChecked(not self.bNote.isChecked())
123 return
124 self.figmgr.toolbar.set_message('text: select a position/text')
125 if self.mode == 'note':
126 self.bNote.setChecked(False)
127 self.mode = 'none'
128 self.spec_show()
129 return
130 self.bStat.setChecked(False)
131 self.bNote.setChecked(True)
132 self.mode = 'note'
133 self.__disconnect_event()
134 self._p.register('button_press',self._mod_note)
135
136 def quit(self):
137 self.__disconnect_event()
138 self.disable_button()
139 self._p.quit()
140
141 def enable_button(self):
142 if self.button: return
143 self.bStat.setEnabled(True)
144 self.button = True
145 self.spec_show()
146
147 def disable_button(self):
148 if not self.button: return
149 self.bStat.setChecked(False)
150 self.bStat.setDisabled(True)
151 self.button = False
152 self.mode = ''
153 self.__disconnect_event()
154
155 def enable_next(self):
156 self.bNext.setEnabled(True)
157
158 def disable_next(self):
159 self.bNext.setDisabled(True)
160
161 def enable_prev(self):
162 self.bPrev.setEnabled(True)
163
164 def disable_prev(self):
165 self.bPrev.setDisabled(True)
166
167 # pause buttons for slow operations
168 def _pause_buttons(self,operation="end",msg=""):
169 buttons = ["bStat","bNote","bQuit"]
170 if operation == "start":
171 enable = False
172 else:
173 enable = True
174 for btn in buttons:
175 getattr(self,btn).setEnabled(enable)
176 self.figmgr.toolbar.set_message(msg)
177
178 def delete_bar(self):
179 self.__disconnect_event()
180 self.destroy()
181
182 def __disconnect_event(self):
183 self._p.register('button_press',None)
184 self._p.register('button_release',None)
185
186
Note: See TracBrowser for help on using the repository browser.