Tizen 2.1 base
[platform/upstream/hplip.git] / ui / alignform.py
1 # -*- coding: utf-8 -*-
2 #
3 # (c) Copyright 2001-2008 Hewlett-Packard Development Company, L.P.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # Author: Don Welch
20 #
21
22 # Std Lib
23
24 # Local
25 from base.g import *
26 from ui_utils import load_pixmap
27
28 # Qt
29 from qt import *
30
31
32 class AlignForm(QDialog):
33     def __init__(self, parent, line_id, orientation, colors, line_count, 
34                  choice_count, name = None, modal = 0, fl = 0):
35         QDialog.__init__(self, parent, name, modal, fl)
36
37         # line_id: 'A', 'B', etc.
38         # orientation: 'v' or 'h'
39         # colors: 'k' or 'c' or 'kc'
40         # line_count: 2 or 3
41         # choice_count: 5, 7, 9, 11, etc. (odd)
42         mid_point = (choice_count+1)/2
43
44         if not name:
45             self.setProperty("name", QVariant("AlignForm"))
46
47         AlignFormLayout = QGridLayout(self,1,1,11,6,"AlignFormLayout")
48
49         #self.helpButton = QPushButton(self,"helpButton")
50
51         #AlignFormLayout.addWidget(self.helpButton,1,0)
52
53         self.CancelButton = QPushButton(self,"CancelButton")
54
55         AlignFormLayout.addWidget(self.CancelButton,1,2)
56
57         self.ContinueButton = QPushButton(self,"ContinueButton")
58
59         AlignFormLayout.addWidget(self.ContinueButton,1,3)
60         spacer1 = QSpacerItem(270,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
61         AlignFormLayout.addItem(spacer1,1,1)
62
63         self.buttonGroup = QButtonGroup(self,"buttonGroup")
64         self.buttonGroup.setColumnLayout(0,Qt.Vertical)
65         self.buttonGroup.layout().setSpacing(6)
66         self.buttonGroup.layout().setMargin(11)
67
68         buttonGroupLayout = QGridLayout(self.buttonGroup.layout())
69         buttonGroupLayout.setAlignment(Qt.AlignTop)
70
71         ChoiceLayout = QHBoxLayout(None,0,6,"ChoiceLayout")
72
73         for x in range(1, choice_count+1):
74             exec 'self.radioButton%d = QRadioButton( self.buttonGroup, "radioButton%d" )' % (x, x) 
75             exec 'self.radioButton%d.setText( "%s%d" )' % (x, line_id, x) 
76             if x == mid_point:
77                 exec 'self.radioButton%d.setChecked( 1 )' % x
78             exec 'ChoiceLayout.addWidget( self.radioButton%d )' % x
79
80         buttonGroupLayout.addMultiCellLayout(ChoiceLayout, 1, 1, 0, 1)
81
82         self.Icon = QLabel(self.buttonGroup,"Icon")
83         self.Icon.setProperty("sizePolicy",QVariant(QSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed,0,0,self.Icon.sizePolicy().hasHeightForWidth())))
84         self.Icon.setProperty("scaledContents",QVariant(QVariant(1,0)))
85
86         buttonGroupLayout.addWidget(self.Icon,0,0)
87
88         self.textLabel2_2 = QLabel(self.buttonGroup,"textLabel2_2")
89         self.textLabel2_2.setProperty("alignment",QVariant(QLabel.WordBreak | QLabel.AlignVCenter))
90
91         buttonGroupLayout.addWidget(self.textLabel2_2,0,1)
92
93         AlignFormLayout.addMultiCellWidget(self.buttonGroup,0,0,0,3)
94
95         self.languageChange()
96
97         self.resize(QSize(608,222).expandedTo(self.minimumSizeHint()))
98         self.clearWState(Qt.WState_Polished)
99
100         self.connect(self.CancelButton,SIGNAL("clicked()"),self,SLOT("reject()"))
101         self.connect(self.ContinueButton,SIGNAL("clicked()"),self,SLOT("accept()"))
102         self.connect(self.buttonGroup,SIGNAL("clicked(int)"),self.buttonGroup_clicked)
103
104         self.Icon.setPixmap(load_pixmap('%s-%s-%d.png' % (orientation, colors, line_count), 'other'))
105
106         self.buttonGroup.setTitle(line_id)
107
108         self.value = (choice_count + 1) / 2
109
110     def buttonGroup_clicked(self,a0):
111         self.value = a0 + 1
112         log.debug(self.value)
113
114     def languageChange(self):
115         self.setProperty("caption",QVariant(self.__tr("HP Device Manager - Alignment")))
116         #self.helpButton.setProperty("text",QVariant(self.__tr("Help")))
117         self.CancelButton.setProperty("text",QVariant(self.__tr("Cancel")))
118         self.ContinueButton.setProperty("text",QVariant(self.__tr("Next >")))
119         self.buttonGroup.setProperty("title",QVariant(self.__tr("")))
120         self.textLabel2_2.setProperty("text",QVariant(self.__tr("Choose the set of lines where the line segments are <b>best</b> aligned.")))
121
122     def __tr(self,s,c = None):
123         return qApp.translate("AlignForm",s,c)