Package mcbase :: Package libs :: Package designeditor :: Module tools
[hide private]
[frames] | no frames]

Source Code for Module mcbase.libs.designeditor.tools

  1  # -*- coding: utf-8 -*- 
  2   
  3  ########################################################################## 
  4  # tools.py 
  5  # 
  6  # Grafiksel Rapor Tasarım Editörü Genel Araçlar 
  7  # 
  8  # (C) 2006 Likya Yazılım ve Bilişim Hizmetleri Ltd. Şti. 
  9  ########################################################################## 
 10   
 11  from PyQt4.QtCore import * 
 12  from PyQt4.QtGui import * 
 13   
 14  import sys 
 15  import pickle 
 16  import zlib 
 17  import base64 
 18   
 19  screenResolutionX = qApp.desktop().logicalDpiX() 
 20  screenResolutionY = qApp.desktop().logicalDpiY() 
 21   
22 -def pt(mm, axis='X'):
23 ''' 24 MM cinsinden bir değeri ekranın çözünürlüğüne göre noktasal değere döndürür. 25 ''' 26 if axis == 'X': 27 return (float(mm) / 25.4) * screenResolutionX 28 29 else: 30 return (float(mm) / 25.4) * screenResolutionY
31
32 -def tr(s):
33 ''' 34 UTF-8 str'yi unicode'a çevirir. 35 ''' 36 import lqtrans 37 38 if type(s) == unicode: 39 return s 40 41 s = str(s) 42 43 u = unicode(s, 'UTF-8', 'ignore') 44 45 translated = lqtrans.translations.get(u, {}).get('en', u) 46 47 return translated
48
49 -def packAscii(obj):
50 ''' 51 Verilen bir nesneyi önce cPickle'lar, daha sonra sıkıştırır, 52 en son olarak da ascii safe olan base64 formatında bir 53 string'e çevirir. 54 55 @param obj: cPickle edilebilecek herhangi bir nesne. 56 ''' 57 return base64.encodestring(zlib.compress(pickle.dumps(obj, 2)))
58
59 -def unpackAscii(asciiStr):
60 ''' 61 Verilen bir string'i base64 encoding ile açar, genişletir, daha 62 sonra da uncPickle ederek serialize edilmiş nesneyi geri yaratır. 63 64 @param asciiStr: Daha önce packAscii() ile hazırlanmış bir string. 65 ''' 66 return pickle.loads(zlib.decompress(base64.decodestring(asciiStr)))
67
68 -def getMonospacedFont():
69 ''' 70 Monospace fontlardan bir havuz oluşturulup lqMonoSpace'a alias yapılır. 71 lqMonoSpace istendiğinde bu fontlardan birinin seçilmesi sağlanır. 72 73 @return: Listeden bulunan ilk monospace fontu verir. 74 @rtype: QFont 75 ''' 76 substitutes = QStringList() 77 substitutes.append('Monospace') 78 substitutes.append('DejaVu Sans Mono') 79 substitutes.append('Bitstream Vera Sans Mono') 80 substitutes.append('Courier New') 81 substitutes.append('Cursor') 82 substitutes.append('Terminus') 83 substitutes.append('Andale Mono') 84 substitutes.append('Clean') 85 QFont.insertSubstitutions('lqMonoSpace', substitutes) 86 font = QFont('lqMonoSpace') 87 # Windows'ta her nedense bu font öntanımlı olarak çok büyük oluyor, küçültüyoruz. 88 if sys.platform.startswith('win'): 89 font.setPointSize(9) 90 else: 91 font.setPointSize(12) 92 return font
93
94 -def returnQVariant(func):
95 ''' 96 Decorator olarak atandığı her fonksiyonun döndürdüğü değerleri 97 QVariant'a dönüştürür. 98 ''' 99 def wrapper(self, *args, **kwargs): 100 101 result = func(self, *args, **kwargs) 102 103 if result is None: 104 return QVariant() 105 106 else: 107 return QVariant(result)
108 109 return wrapper 110