--- a/svghmi/i18n.py Wed Mar 31 15:28:09 2021 +0200
+++ b/svghmi/i18n.py Wed Mar 31 15:30:07 2021 +0200
@@ -68,11 +68,15 @@
with open(fname, 'w') as POT_file:
w.write(POT_file)
+def GetPoFiles(dirpath):
+ po_files = [fname for fname in os.listdir(dirpath) if fname.endswith(".po")]
+ po_files.sort()
+ return po_files
+
def ReadTranslations(dirpath):
""" Read all PO files from a directory and return a list of (langcode, translation_dict) tuples """
- po_files = [fname for fname in os.listdir(dirpath) if fname.endswith(".po")]
- po_files.sort()
+ po_files = GetPoFiles(dirpath)
translations = []
for po_fname in po_files:
--- a/svghmi/svghmi.py Wed Mar 31 15:28:09 2021 +0200
+++ b/svghmi/svghmi.py Wed Mar 31 15:30:07 2021 +0200
@@ -28,7 +28,8 @@
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
from XSLTransform import XSLTransform
from svghmi.i18n import EtreeToMessages, SaveCatalog, ReadTranslations,\
- MatchTranslations, TranslationToEtree, open_pofile
+ MatchTranslations, TranslationToEtree, open_pofile,\
+ GetPoFiles
from svghmi.hmi_tree import HMI_TYPES, HMITreeNode, SPECIAL_NODES
from svghmi.ui import SVGHMI_UI
from svghmi.fonts import GetFontTypeAndFamilyName, GetCSSFontFaceFromFontFile
@@ -400,13 +401,17 @@
return ret
- def GetFonts(self, _context):
+ def GetFontsFiles(self):
project_path = self.CTNPath()
fontdir = os.path.join(project_path, "fonts")
+ if os.path.isdir(fontdir):
+ return [os.path.join(fontdir,f) for f in sorted(os.listdir(fontdir))]
+ return []
+
+ def GetFonts(self, _context):
css_parts = []
- for f in sorted(os.listdir(fontdir)):
- fontfile = os.path.join(fontdir,f)
+ for fontfile in self.GetFontsFiles():
if os.path.isfile(fontfile):
css_parts.append(GetCSSFontFaceFromFontFile(fontfile))
@@ -446,13 +451,18 @@
hasher = hashlib.md5()
hmi_tree_root._hash(hasher)
- with open(svgfile, 'rb') as afile:
- while True:
- buf = afile.read(65536)
- if len(buf) > 0:
- hasher.update(buf)
- else:
- break
+ filestocheck = [svgfile] + \
+ GetPoFiles(self.CTNPath()) + \
+ self.GetFontsFiles()
+
+ for filetocheck in filestocheck:
+ with open(filetocheck, 'rb') as afile:
+ while True:
+ buf = afile.read(65536)
+ if len(buf) > 0:
+ hasher.update(buf)
+ else:
+ break
digest = hasher.hexdigest()
if os.path.exists(hash_path):
--- a/svghmi/ui.py Wed Mar 31 15:28:09 2021 +0200
+++ b/svghmi/ui.py Wed Mar 31 15:30:07 2021 +0200
@@ -150,6 +150,7 @@
sizer.Fit(self)
self.Bind(wx.EVT_BUTTON, self.OnSelectLibDir, self.libbutton)
self.preview.Bind(wx.EVT_PAINT, self.OnPaint)
+ self.preview.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnWidgetSelection, self.widgetpicker)
@@ -272,6 +273,16 @@
self.ValidateWidget()
self.Refresh()
+ def OnLeftDown(self, evt):
+ if self.selected_SVG is not None:
+ # TODO replace with generated widget file
+ filename = self.selected_SVG
+ data = wx.FileDataObject()
+ data.AddFile(filename)
+ dropSource = wx.DropSource(self)
+ dropSource.SetData(data)
+ dropSource.DoDragDrop(wx.Drag_AllowMove)
+
def ValidateWidget(self):
if self.selected_SVG is not None:
if self.hmitree_node is not None: