home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / hplip / ui / choosedevicedlg.py < prev    next >
Encoding:
Python Source  |  2006-08-30  |  3.6 KB  |  99 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2006 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. from base.g import *
  23. import sys
  24. from qt import *
  25.  
  26. class ChooseDeviceDlg(QDialog):
  27.     def __init__(self, devices, parent = None,name = None,modal = 0,fl = 0):
  28.         QDialog.__init__(self,parent,name,modal,fl)
  29.  
  30.         if not name:
  31.             self.setName("ChooseDeviceDlg")
  32.  
  33.         self.device_uri = ''
  34.             
  35.         ChooseDeviceDlg_Layout = QGridLayout(self,1,1,6,6,"ChooseDeviceDlg_Layout")
  36.  
  37.         self.OKButton = QPushButton(self,"OKButton")
  38.  
  39.         ChooseDeviceDlg_Layout.addWidget(self.OKButton,2,2)
  40.  
  41.         self.CancelButton = QPushButton(self,"CancelButton")
  42.  
  43.         ChooseDeviceDlg_Layout.addWidget(self.CancelButton,2,1)
  44.         spacer1 = QSpacerItem(391,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  45.         ChooseDeviceDlg_Layout.addItem(spacer1,2,0)
  46.         spacer2 = QSpacerItem(20,290,QSizePolicy.Minimum,QSizePolicy.Expanding)
  47.         ChooseDeviceDlg_Layout.addItem(spacer2,1,0)
  48.  
  49.         self.DevicesButtonGroup = QButtonGroup(self,"DevicesButtonGroup")
  50.         self.DevicesButtonGroup.setColumnLayout(0,Qt.Vertical)
  51.         self.DevicesButtonGroup.layout().setSpacing(6)
  52.         self.DevicesButtonGroup.layout().setMargin(6)
  53.         DevicesButtonGroupLayout = QGridLayout(self.DevicesButtonGroup.layout())
  54.         DevicesButtonGroupLayout.setAlignment(Qt.AlignTop)
  55.             
  56.         self.radio_buttons = {}
  57.  
  58.         for y in range(len(devices)):
  59.             if y == 0:
  60.                 self.device_uri = devices[y][0]
  61.             self.radio_buttons[y] = QRadioButton(self.DevicesButtonGroup,"radioButton%d" % y)
  62.             self.radio_buttons[y].setText(devices[y][0])
  63.             DevicesButtonGroupLayout.addWidget(self.radio_buttons[y], y, 0)
  64.  
  65.         self.radio_buttons[0].setChecked(1)
  66.         
  67.         ChooseDeviceDlg_Layout.addMultiCellWidget(self.DevicesButtonGroup,0,0,0,2)
  68.  
  69.         self.languageChange()
  70.  
  71.         self.resize(QSize(592,112).expandedTo(self.minimumSizeHint()))
  72.         self.clearWState(Qt.WState_Polished)
  73.  
  74.         self.connect(self.OKButton,SIGNAL("clicked()"),self,SLOT("accept()"))
  75.         self.connect(self.CancelButton,SIGNAL("clicked()"),self,SLOT("reject()"))
  76.         self.connect(self.DevicesButtonGroup,SIGNAL("clicked(int)"),self.DevicesButtonGroup_clicked)
  77.  
  78.     def languageChange(self):
  79.         self.setCaption(self.__tr("Choose Device"))
  80.         self.OKButton.setText(self.__tr("OK"))
  81.         self.CancelButton.setText(self.__tr("Cancel"))
  82.         self.DevicesButtonGroup.setTitle(self.__tr("Available Devices:"))
  83.  
  84.  
  85.     def __tr(self,s,c = None):
  86.         return qApp.translate("ChooseDeviceDlg",s,c)
  87.  
  88.     def DevicesButtonGroup_clicked(self,a0):
  89.         self.device_uri = str(self.radio_buttons[a0].text())
  90.         #print self.device_uri
  91.  
  92. if __name__ == "__main__":
  93.     a = QApplication(sys.argv)
  94.     QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
  95.     w = ChooseDeviceDlg()
  96.     a.setMainWidget(w)
  97.     w.show()
  98.     a.exec_loop()
  99.