home *** CD-ROM | disk | FTP | other *** search
/ Freelog 116 / FreelogNo116-JuilletSeptembre2013.iso / GestionFichiers / metamorphose / metamorphose2_0.8.2_setup.exe / metamorphose2.exe / utils.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2011-01-12  |  10KB  |  252 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import print_function
  5. import wx
  6. import wx.html as wx
  7. import os
  8. import sys
  9. import codecs
  10. import locale
  11. import time
  12. import app
  13.  
  14. try:
  15.     import Image
  16. except:
  17.     pass
  18.  
  19. homedir = 'metamorphose2'
  20. if os.sep == '/':
  21.     homedir = '.' + homedir
  22.  
  23.  
  24. def get_wxversion():
  25.     wxVer = ''
  26.     for x in wx.VERSION:
  27.         wxVer = wxVer + str(x) + '.'
  28.     
  29.     wxVer = wxVer.rstrip('.')
  30.     return wxVer
  31.  
  32.  
  33. def is_pil_loaded():
  34.     
  35.     try:
  36.         Image
  37.     except NameError:
  38.         return False
  39.  
  40.     return True
  41.  
  42.  
  43. def set_min_size(parent, ignoreCtrls = (), ignoreClasses = ()):
  44.     if wx.Platform == '__WXGTK__' and isinstance(parent, wx.StaticText):
  45.         textSize = parent.GetTextExtent(parent.GetLabel())
  46.         size = wx.Size(textSize[0] + 2, -1)
  47.     else:
  48.         size = wx.DefaultSize
  49.     parent.SetMinSize(size)
  50.     parent.SetSize(size)
  51.     for child in parent.GetChildren():
  52.         if child not in ignoreCtrls and not isinstance(child, ignoreClasses):
  53.             set_min_size(child, ignoreCtrls, ignoreClasses)
  54.             continue
  55.     
  56.  
  57.  
  58. def adjust_exact_buttons(parent, ignore = ()):
  59.     for child in parent.GetChildren():
  60.         if isinstance(child, wx.Button) and child.GetName() not in ignore:
  61.             txt = child.GetLabel()
  62.             size = wx.Size(child.GetTextExtent(txt)[0] + 18, -1)
  63.             child.SetMinSize(size)
  64.             continue
  65.     
  66.  
  67.  
  68. def safe_makedir(dir):
  69.     if not os.path.exists(dir):
  70.         
  71.         try:
  72.             os.makedirs(dir)
  73.         except OSError:
  74.             error = None
  75.             if error[0] == 17:
  76.                 pass
  77.             else:
  78.                 make_err_msg(unicode(error), u'Error')
  79.         except:
  80.             error[0] == 17
  81.         
  82.  
  83.     None<EXCEPTION MATCH>OSError
  84.  
  85.  
  86. def init_environment():
  87.     dirs = ('undo', 'configs')
  88.     for d in dirs:
  89.         safe_makedir(get_user_path(d))
  90.     
  91.  
  92.  
  93. def calc_slice_pos(s, l):
  94.     if s == -1 and l == 1:
  95.         frm = -1
  96.         to = None
  97.     elif s < 0 and l > 1:
  98.         frm = s
  99.         to = s + l
  100.         if to >= 0:
  101.             to = None
  102.         
  103.     else:
  104.         frm = s
  105.         to = s + l
  106.     return (frm, to)
  107.  
  108.  
  109. def make_yesno_dlg(msg, title):
  110.     dlg = wx.MessageDialog(None, msg, title, wx.YES_NO | wx.YES_DEFAULT | wx.ICON_WARNING)
  111.     if dlg.ShowModal() == wx.ID_YES:
  112.         returnValue = True
  113.     else:
  114.         returnValue = False
  115.     dlg.Destroy()
  116.     return returnValue
  117.  
  118.  
  119. def make_err_msg(msg, title = None):
  120.     if not title:
  121.         title = _(u'Error')
  122.     
  123.     dlg = wx.MessageDialog(None, msg, title, wx.ICON_ERROR)
  124.     dlg.ShowModal()
  125.     dlg.Destroy()
  126.  
  127.  
  128. def make_warn_msg(msg, title = None):
  129.     if not title:
  130.         title = _(u'Warning')
  131.     
  132.     dlg = wx.MessageDialog(None, msg, title, wx.ICON_WARNING)
  133.     dlg.ShowModal()
  134.     dlg.Destroy()
  135.  
  136.  
  137. def make_info_msg(msg, title = None):
  138.     if not title:
  139.         title = _(u'Information')
  140.     
  141.     dlg = wx.MessageDialog(None, msg, title, wx.ICON_INFORMATION)
  142.     dlg.ShowModal()
  143.     dlg.Destroy()
  144.  
  145.  
  146. def get_user_path(file):
  147.     base = wx.StandardPaths.Get().GetUserConfigDir()
  148.     return os.path.join(base, homedir, file)
  149.  
  150.  
  151. def locale_path(lang):
  152.     if hasattr(sys, 'frozen'):
  153.         return app.get_real_path(u'messages')
  154.     if os.path.exists(u'/usr/share/locale/%s/LC_MESSAGES/metamorphose2.mo' % lang):
  155.         return u'/usr/share/locale'
  156.     return app.get_real_path(u'../messages')
  157.  
  158.  
  159. def icon_path(icon):
  160.     return app.get_real_path(u'icons/%s' % icon)
  161.  
  162.  
  163. def add_to_warnings(main, path, msg):
  164.     ec = main.ec
  165.     if main.warn.count(ec) < 1:
  166.         main.warn.append(ec)
  167.         main.errorLog.insert(0, (ec, path, msg, u'warn'))
  168.     
  169.  
  170.  
  171. def add_to_errors(main, path, msg):
  172.     ec = main.ec
  173.     if main.bad.count(ec) < 1:
  174.         main.bad.append(ec)
  175.         main.errorLog.insert(0, (ec, path, msg, u'bad'))
  176.     
  177.  
  178.  
  179. def reset_counter(parent, tools, c):
  180.     tools.opButtonsPanel.counter = c
  181.     tools.opButtonsPanel.auxCount = 0
  182.     parent.numberingPanel.set_number_params(True)
  183.  
  184.  
  185. def write_file(path, data):
  186.     
  187.     try:
  188.         os.makedirs(os.path.dirname(path))
  189.     except:
  190.         pass
  191.  
  192.     
  193.     try:
  194.         fp = codecs.open(path, 'w', 'utf_8')
  195.     except (IOError, OSError):
  196.         error = None
  197.         make_err_msg(unicode(error), _(u'Error'))
  198.  
  199.     fp.write(unicode(data))
  200.     fp.close()
  201.  
  202.  
  203. def get_notebook_page_names(parent):
  204.     pages = []
  205.     for i in range(parent.notebook.GetPageCount()):
  206.         pages.append(parent.notebook.GetPage(i))
  207.     
  208.     return pages
  209.  
  210.  
  211. def dev_null(event):
  212.     pass
  213.  
  214.  
  215. def udate(main, format, itemDateTime):
  216.     udate = time.strftime(format.encode(main.encoding), itemDateTime)
  217.     return udate.decode(main.encoding)
  218.  
  219.  
  220. def set_busy(busy):
  221.     if busy:
  222.         wx.BeginBusyCursor()
  223.     else:
  224.         wx.EndBusyCursor()
  225.  
  226.  
  227. def get_encoding_choices(key):
  228.     encodingLookup = {
  229.         _(u'Use System Default'): (u'%s' % locale.getlocale()[1],),
  230.         _(u'All Languages / Unicode'): (u'utf_8', u'utf_16'),
  231.         _(u'Western Europe'): (u'windows-1252', u'iso-8859-1', u'iso-8859-15', u'mac_roman', u'cp500', u'cp850', u'cp1140'),
  232.         _(u'Central & Eastern Europe'): (u'windows-1250', u'iso-8859-2', u'mac_latin2', u'cp852'),
  233.         _(u'Esperanto, Maltese'): (u'iso-8859-3',),
  234.         _(u'Nordic Languages'): (u'iso-8859-10', u'mac_iceland', u'cp861', u'cp865'),
  235.         _(u'Celtic Languages'): (u'iso8859_14',),
  236.         _(u'Baltic Languages'): (u'windows-1257', u'iso-8859-13', u'cp775'),
  237.         _(u'Cyrillic Languages'): (u'windows-1251', u'iso-8859-5', u'koi8_r', 'koi8_u', u'mac_cyrillic', u'cp154', u'cp866', u'cp855'),
  238.         _(u'Greek'): (u'windows-1253', u'iso-8859-7', u'mac_greek', u'cp737', u'cp869', u'cp875'),
  239.         _(u'Turkish'): (u'windows-1254', u'iso-8859-9', u'mac_turkish', u'cp857', u'cp1026'),
  240.         _(u'Hebrew'): (u'windows-1255', u'iso-8859-8', u'cp424', u'cp856', u'cp862'),
  241.         _(u'Arabic'): (u'windows-1256', u'iso-8859-6', u'cp864'),
  242.         _(u'Urdu'): (u'cp1006',),
  243.         _(u'Thai'): (u'cp874',),
  244.         _(u'Vietnamese'): (u'windows-1258',),
  245.         _(u'Traditional Chinese'): (u'ms950', u'big5hkscs', u'big5'),
  246.         _(u'Simplified Chinese'): (u'gb2312', u'hz'),
  247.         _(u'Unified Chinese'): (u'ms936', u'gb18030'),
  248.         _(u'Korean'): (u'ms949', u'iso-2022-kr', u'ms1361', u'euc_kr'),
  249.         _(u'Japanese'): (u'ms-kanji', u'iso-2022-jp', u'shift_jis', u'euc_jp', u'iso-2022-jp-1', u'iso-2022-jp-2004', u'iso-2022-jp-3', u'iso-2022-jp-ext', u'shift_jis_2004', u'shift_jisx0213', u'euc_jis_2004', u'euc_jisx0213') }
  250.     return encodingLookup[key]
  251.  
  252.