accimport.py :  » Network » Chestnut-Dialer » chestnut-dialer-0.3.3 » chestnut_dialer » qt_ui » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Chestnut Dialer 
Chestnut Dialer » chestnut dialer 0.3.3 » chestnut_dialer » qt_ui » accimport.py
# Copyright (C) 2003 Konstantin Korikov

#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import qt
import chestnut_dialer.importers
import chestnut_dialer.importers.importer
import chestnut_dialer.qt_ui.importdialog
from chestnut_dialer import _

class FileNameArgWidget(qt.QHBox):
  def __init__(self, arg_info, parent):
    qt.QHBox.__init__(self, parent)
    self.entry = qt.QLineEdit(self)
    if arg_info.has_key("default"):
      self.entry.setText(arg_info["default"])
    btn = qt.QPushButton(_("Select File"), self)
    qt.QObject.connect(btn, qt.SIGNAL("clicked()"), self.select_file_action)
  def get_value(self):
    return unicode(self.entry.text())
  def select_file_action(self):
    s = qt.QFileDialog.getOpenFileName(
      self.entry.text() or None, None, self, None, _("Select File"))
    if unicode(s) != "": self.entry.setText(s)
    
class StringArgWidget(qt.QLineEdit):
  def __init__(self, arg_info, parent):
    qt.QLineEdit.__init__(self, parent)
    if arg_info.has_key("default"):
      self.setText(arg_info["default"])
  def get_value(self):
    return unicode(self.text())
    
class OptionArgWidget(qt.QComboBox):
  def __init__(self, arg_info, parent):
    qt.QComboBox.__init__(self, parent)
    self.values = []
    for disp, value in arg_info["options"]:
      self.insertItem(disp)
      self.values.append(value)
    if arg_info.has_key("default"):
      self.setCurrentItem(self.values.index(arg_info["default"]))
  def closeEvent(self, e):
    self.values = None
    e.accept()
  def get_value(self):
    return self.values[self.currentItem()]
    
class BooleanArgWidget(qt.QCheckBox):
  def __init__(self, arg_info, parent):
    qt.QCheckBox.__init__(self, "", parent)
    if arg_info.has_key("default"):
      self.setOn(arg_info["default"])
  def get_value(self):
    return self.isOn()
    
class IntegerArgWidget(qt.QSpinBox):
  def __init__(self, arg_info, parent):
    qt.QSpinBox.__init__(self, parent)
    self.setMinValue(arg_info.has_key("min") and arg_info["min"] or -32000)
    self.setMaxValue(arg_info.has_key("max") and arg_info["max"] or 32000)
    self.setLineStep(arg_info.has_key("step") and arg_info["step"] or 1)
    self.setValue(arg_info.has_key("default") and arg_info["default"] or 0)
  def get_value(self):
    return self.value()
    
class ArgBox(qt.QGrid):
  args = None
  tooltip = None
  def __init__(self, args_info, parent):
    qt.QGrid.__init__(self, 2, parent)
    self.setMargin(3)
    self.setSpacing(3)
    self.tooltip = qt.QToolTip(self)
    arg_types = {
      "filename": FileNameArgWidget,
      "string": StringArgWidget,
      "option": OptionArgWidget,
      "boolean": BooleanArgWidget,
      "integer": IntegerArgWidget}
    self.args = []
    row = 0    
    for a_info in args_info:
      label = qt.QLabel(
        a_info.has_key("display") and a_info["display"] or a_info["name"], self)
      label.setAlignment(64 + 2)      
      arg = arg_types[a_info["type"]](a_info, self)
      self.args.append(arg)
      if a_info.has_key("description"):
        self.tooltip.add(label, a_info["description"])
  self.tooltip.add(arg, a_info["description"])
      row += 1
  def closeEvent(self, e):
    self.tooltip = None
    e.accept()
  def get_values(self):
    return map(lambda a: a.get_value(), self.args)

class ImportDialog(chestnut_dialer.qt_ui.importdialog.ImportDialog):
  accounts = None
  update_list_action = None
  importers = None
  cur_importer = None  
  cur_impid = None
  arg_cont = None
  arg_box = None
  def __init__(self, accounts, update_list_action, *args):
    apply(chestnut_dialer.qt_ui.importdialog.ImportDialog.__init__, 
      (self,) + args)
    self.AvaibleList.setSorting(1)
    self.ImportList.setSorting(1)
    ImpArgBoxLayout = self.ImpArgBox.layout()
    ImpArgBoxLayout.setMargin(0)
    self.arg_cont = qt.QScrollView(self.ImpArgBox)
    self.arg_cont.setResizePolicy(qt.QScrollView.AutoOneFit)
    ImpArgBoxLayout.addWidget(self.arg_cont)
    self.accounts = accounts
    self.update_list_action = update_list_action
    self.importers = chestnut_dialer.importers.ls_importers()
    if len(self.importers):
      self.importers.sort(lambda a, b: cmp(a[1], b[1]))
      for impid, prg in self.importers:
  self.Importer.insertItem(prg)
      self.Importer.setCurrentItem(0)
      self.importer_activate(0)
    qt.QObject.connect(self.Importer, qt.SIGNAL("activated(int)"), 
      self.importer_activate)
    qt.QObject.connect(self.ApplyButton, qt.SIGNAL("clicked()"), 
      self.apply_action)
    qt.QObject.connect(self.AddButton, qt.SIGNAL("clicked()"), 
      self.add_action)
    qt.QObject.connect(self.RemoveButton, qt.SIGNAL("clicked()"), 
      self.remove_action)
    qt.QObject.connect(self.OkButton, qt.SIGNAL("clicked()"), 
      self.ok_action)
    qt.QObject.connect(self.CancelButton, qt.SIGNAL("clicked()"), 
      self.cancel_action)
  def closeEvent(self, e):
    self.accounts = None
    self.update_list_action = None
    e.accept()
  def importer_activate(self, index):
    self.AvaibleList.clear()
    self.ImportList.clear()
    self.cur_impid = self.importers[index][0]
    if self.arg_box:
      self.arg_cont.removeChild(self.arg_box)
      self.arg_box.close()
    self.arg_box = ArgBox(
      chestnut_dialer.importers.get_importer_args_info(self.cur_impid), 
      self.arg_cont.viewport())
    self.arg_cont.addChild(self.arg_box)
    self.arg_box.show()
    imp_info = chestnut_dialer.importers.get_importer_info(self.cur_impid)
    if imp_info.has_key("description") and imp_info["description"]:
      self.ImporterDescription.setText(imp_info["description"])
    else: self.ImporterDescription.setText("")
    if imp_info.has_key("author") and imp_info["author"]:
      self.ImporterAuthor.setText(imp_info["author"])
    else: self.ImporterAuthor.setText("")
    self.StatusBar.setText(
      _("Importer not created. Press Apply button for create it."))
  def move_rows(self, source_list, dest_list):
    i = source_list.firstChild()
    while i:
      next = i.nextSibling()
      if i.isSelected():
        qt.QListViewItem(dest_list, i.text(0), i.text(1))
  source_list.takeItem(i)
      i = next
  def add_action(self):
    self.move_rows(self.AvaibleList, self.ImportList)
  def remove_action(self):
    self.move_rows(self.ImportList, self.AvaibleList)
  def apply_action(self):
    self.AvaibleList.clear()
    self.ImportList.clear()
    try:
      self.StatusBar.setText(_("Constructing importer..."))
      self.cur_importer = chestnut_dialer.importers.get_importer(
  self.cur_impid, self.arg_box.get_values())      
      for accname, accid in self.cur_importer.ls_accounts():
  qt.QListViewItem(self.AvaibleList, "%03d" % accid, accname)
      self.StatusBar.setText(_("Importer created"))
    except chestnut_dialer.importers.importer.ConstructImporterException, e:
      self.StatusBar.setText(
        _("Failed to construct importer. Reason: %s" % e.msg))
  def ok_action(self):
    if self.cur_importer:
      i = self.ImportList.firstChild()
      while i:
        acc_id = int(str(i.text(0)))
  self.accounts.insert_account(
    self.cur_importer.get_account(acc_id).copy())
  i = i.nextSibling()
      self.update_list_action()
    self.close()
  def cancel_action(self, *args):
    self.close()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.