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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# Copyright 2004-2009 Nanorex, Inc. See LICENSE file for details.
"""
GridPlaneProp.py
$Id$
"""
from PyQt4.Qt import QDialog
from PyQt4.Qt import QWidget
from PyQt4.Qt import SIGNAL
from PyQt4.Qt import QColorDialog
from commands.GridPlaneProperties.GridPlanePropDialog import Ui_GridPlanePropDialog
from widgets.widget_helpers import RGBf_to_QColor, QColor_to_RGBf, get_widget_with_color_palette
class GridPlaneProp(QDialog, Ui_GridPlanePropDialog):
def __init__(self, gridPlane, glpane):
QWidget.__init__(self)
self.setupUi(self)
self.connect(self.ok_btn,SIGNAL("clicked()"),self.accept)
self.connect(self.cancel_btn,SIGNAL("clicked()"),self.reject)
self.connect(self.choose_border_color_btn,SIGNAL("clicked()"),self.change_border_color)
self.connect(self.choose_grid_color_btn,SIGNAL("clicked()"),self.change_grid_color)
self.connect(self.width_spinbox,SIGNAL("valueChanged(int)"),self.change_width)
self.connect(self.height_spinbox,SIGNAL("valueChanged(int)"),self.change_height)
self.connect(self.x_spacing_spinbox,SIGNAL("valueChanged(int)"),self.change_x_spacing)
self.connect(self.y_spacing_spinbox,SIGNAL("valueChanged(int)"),self.change_y_spacing)
self.connect(self.grid_type_combox,SIGNAL("activated(int)"),self.change_grid_type)
self.connect(self.line_type_combox,SIGNAL("activated(int)"),self.change_line_type)
self.grid_plane = gridPlane
self.glpane = glpane
def setup(self):
self.jig_attrs = self.grid_plane.copyable_attrs_dict() # Save the jig's attributes in case of Cancel.
# Border color
self.border_color = RGBf_to_QColor(self.grid_plane.normcolor) # Used as default color by Color Chooser
# Grid color
self.grid_color = RGBf_to_QColor(self.grid_plane.grid_color) # Used as default color by Color Chooser
self.grid_color_pixmap = get_widget_with_color_palette(
self.grid_color_pixmap, self.grid_color)
self.border_color_pixmap = get_widget_with_color_palette(
self.border_color_pixmap,self.border_color)
self.name_linedit.setText(self.grid_plane.name)
self.width_spinbox.setValue(self.grid_plane.width)
self.height_spinbox.setValue(self.grid_plane.height)
self.x_spacing_spinbox.setValue(self.grid_plane.x_spacing)
self.y_spacing_spinbox.setValue(self.grid_plane.y_spacing)
self.grid_type_combox.setCurrentIndex(self.grid_plane.grid_type)
self.line_type_combox.setCurrentIndex(self.grid_plane.line_type)
self._set_xyspacing_enabled(self.grid_plane.grid_type)
def _set_xyspacing_enabled(self, grid_type):
"""
If <grid_type> == 1, which is SiC type, disable x, y spacing comboBox, otherwise, enable it.
"""
from utilities.prefs_constants import SiC_GRID, SQUARE_GRID
if grid_type == SiC_GRID:
self.x_spacing_spinbox.setEnabled(False)
self.y_spacing_spinbox.setEnabled(False)
else:
self.x_spacing_spinbox.setEnabled(True)
self.y_spacing_spinbox.setEnabled(True)
def change_grid_type(self, grid_type):
"""
Slot method to change grid type
"""
self.grid_plane.grid_type = grid_type
self._set_xyspacing_enabled(grid_type)
self.glpane.gl_update()
def change_line_type(self, line_type):
"""
Slot method to change grid line type
"""
self.grid_plane.line_type = line_type
self.glpane.gl_update()
def change_grid_color(self):
"""
Slot method to change grid color.
"""
color = QColorDialog.getColor(self.grid_color, self)
if color.isValid():
self.grid_color = color
self.grid_color_pixmap = get_widget_with_color_palette(
self.grid_color_pixmap, self.grid_color)
self.grid_plane.grid_color = QColor_to_RGBf(color)
self.glpane.gl_update()
def change_border_color(self):
"""
Slot method change border color.
"""
color = QColorDialog.getColor(self.border_color, self)
if color.isValid():
self.border_color = color
self.border_color_pixmap = get_widget_with_color_palette(
self.border_color_pixmap,self.border_color)
self.grid_plane.color = self.grid_plane.normcolor = QColor_to_RGBf(color)
self.glpane.gl_update()
def change_width(self, newWidth):
"""
Slot for Width spinbox
"""
self.grid_plane.width = float(newWidth)
self.glpane.gl_update()
def change_height(self, newHeight):
"""
Slot for Height spinbox
"""
self.grid_plane.height = float(newHeight)
self.glpane.gl_update()
def change_x_spacing(self, newXValue):
"""
Slot for X Spacing spinbox
"""
self.grid_plane.x_spacing = float(newXValue)
self.glpane.gl_update()
def change_y_spacing(self, newYValue):
"""
Slot for Y Spacing spinbox
"""
self.grid_plane.y_spacing = float(newYValue)
self.glpane.gl_update()
def accept(self):
"""
Slot for the 'OK' button
"""
self.grid_plane.cancelled = False
self.grid_plane.try_rename(self.name_linedit.text())
self.grid_plane.width = float(self.width_spinbox.value())
self.grid_plane.height = float(self.height_spinbox.value())
self.grid_plane.x_spacing = float(self.x_spacing_spinbox.value())
self.grid_plane.y_spacing = float(self.y_spacing_spinbox.value())
self.grid_plane.assy.w.win_update() # Update model tree
self.grid_plane.assy.changed()
QDialog.accept(self)
def reject(self):
"""
Slot for the 'Cancel' button
"""
self.grid_plane.attr_update(self.jig_attrs) # Restore attributes of the jig.
self.glpane.gl_update()
QDialog.reject(self)
|