[gnoduino] fix Import Library menu option
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnoduino] fix Import Library menu option
- Date: Fri, 28 Sep 2012 23:12:44 +0000 (UTC)
commit ab322fed8bcbddccd07298eca27c9fb6f4a0d8ec
Author: Lucian Langa <lucilanga gnome org>
Date: Sat Sep 29 01:11:38 2012 +0200
fix Import Library menu option
src/srcview.py | 18 +++++++++++++++---
src/ui.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
ui/main.ui | 11 +----------
3 files changed, 68 insertions(+), 17 deletions(-)
---
diff --git a/src/srcview.py b/src/srcview.py
index 0bc7687..309d0ba 100644
--- a/src/srcview.py
+++ b/src/srcview.py
@@ -1,5 +1,5 @@
# Arduino python implementation
-# Copyright (C) 2010 Lucian Langa
+# Copyright (C) 2010-2012 Lucian Langa
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -55,13 +55,25 @@ def get_lang_for_content(content):
if p == mime:
return lang
-def instext(b, iter, text, len) :
+def instextCallback(b, iter, text, len) :
cont = b.get_text(b.get_start_iter(), b.get_end_iter())
lang = get_lang_for_content(cont)
if lang != None:
b.set_language(lang)
config.cur_iter = -1
+def insertText(text, line):
+ page = ui.getCurrentPage()
+ view = page.get_data("view")
+ b = view.get_buffer()
+ iter = b.get_iter_at_mark(b.get_insert())
+ iter.set_line(line);
+ t = ""
+ for i in text:
+ t = t + "#include <" + i + ">\n"
+ t = t + "\n"
+ b.insert(iter, t)
+
def updatePos(buffer, sb):
sb.pop(1)
iter = buffer.get_iter_at_mark(buffer.get_insert())
@@ -190,7 +202,7 @@ def createsrcview(status, f=None):
sv.set_right_margin_position(80)
updatePos(sbuffer, status)
sbuffer.connect("mark_set", markCb, status)
- sbuffer.connect("insert_text", instext)
+ sbuffer.connect("insert_text", instextCallback)
sv.set_highlight_current_line(True)
resetCursor(sbuffer)
return sbuffer, sv
diff --git a/src/ui.py b/src/ui.py
index f28abad..8815d4f 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -247,9 +247,6 @@ def find(widget, data=None):
srcview.findText(find_text, -1, [gui.get_object(i) for i in cbs])
find.hide()
-def libImport(widget, data=None):
- compiler.getLibraries()
-
def compile(widget, data=file):
cserial(None, 0, sctw)
page = getCurrentPage()
@@ -463,7 +460,6 @@ menus = [
("menu-copy", copy, (ord('c'), gtk.gdk.CONTROL_MASK)),
("menu-paste", paste, (ord('v'), gtk.gdk.CONTROL_MASK)),
("menu-compile", compile, (ord('r'), gtk.gdk.CONTROL_MASK)),
- ("menu-import", libImport, (ord('i'), gtk.gdk.CONTROL_MASK)),
("menu-reset-board", menuResetBoard, (ord('m'), gtk.gdk.CONTROL_MASK)),
("menu-preferences", preferences, (None, None)),
("menu-upload", menuUpload, (ord('u'), gtk.gdk.CONTROL_MASK)),
@@ -658,6 +654,9 @@ def _search_locales():
def exampleProcess(widget):
processFile(widget.get_data("file"))
+def importProcess(widget):
+ srcview.insertText(widget.get_data("file"), 0)
+
def populateExampleLine(entry, menu):
subitem = gtk.Menu()
menuItem = gtk.MenuItem(os.path.basename(entry))
@@ -698,6 +697,33 @@ def populateExampleLine(entry, menu):
menu.append(menuItem)
except: pass
+def populateImportLine(entry, menu):
+ subitem = gtk.Menu()
+ menuItem = gtk.MenuItem(os.path.basename(entry))
+ for i in sorted(os.listdir(entry)):
+ if os.path.isdir(os.path.join(entry,i)):
+ f = os.path.join(entry, i, i + ".h")
+ if not os.path.exists(f): continue
+ item = gtk.MenuItem(os.path.basename(i))
+ item.set_data("file", f)
+ item.connect("activate", exampleProcess)
+ subitem.append(item)
+ else:
+ l = []
+ for j in sorted(os.listdir(entry)):
+ if j.endswith(".h") is True:
+ f = os.path.join(entry, j)
+ if not os.path.exists(f): continue
+ l.append(j)
+ #item = gtk.MenuItem(os.path.basename(j))
+ #item.set_data("file", f)
+ #item.connect("activate", exampleProcess)
+ #subitem.append(item)
+ menuItem.set_data("file", l);
+ menuItem.connect("activate", importProcess)
+ break
+ menu.append(menuItem)
+
def populateExamples():
submenu = gtk.Menu()
for dir in ["examples", "libraries"]:
@@ -720,6 +746,27 @@ def populateExamples():
ex.set_submenu(submenu)
gui.get_object("filemenu").insert(ex, 2)
+def populateImport():
+ submenu = gtk.Menu()
+ dir = "libraries"
+ if misc.get_path(dir, "\0") != "\0":
+ d = os.listdir(misc.get_path(dir))
+ q = []
+ for i in d: q.append(misc.get_path(os.path.join(dir, i)))
+ for c in sorted(q): populateImportLine(c, submenu)
+ paths = []
+ if config.user_library != None and config.user_library != -1:
+ paths.extend(i.strip() for i in config.user_library.split(';'))
+ for p in paths:
+ if os.path.exists(p):
+ q = []
+ if os.path.isdir(os.path.join(p, "examples")):
+ q.append(p)
+ for c in sorted(q): populateImportLine(c, submenu)
+ ex = gtk.MenuItem(_("Import Library"), use_underline=True)
+ ex.set_submenu(submenu)
+ gui.get_object("sketchmenu").insert(ex, 2)
+
def getKeyREvent(widget, event, data=None):
config.force_protocol = False
gui.get_object("upload").set_tooltip_text(_("Upload"))
@@ -859,6 +906,7 @@ def run():
gui.get_object("serial_port").set_sensitive(activePort)
createRecentMenu()
populateExamples()
+ populateImport()
sub = gtk.Menu()
maingroup = gtk.RadioMenuItem(None, None)
diff --git a/ui/main.ui b/ui/main.ui
index 55f7651..c74ff50 100644
--- a/ui/main.ui
+++ b/ui/main.ui
@@ -757,7 +757,7 @@ Pascal de Bruijn <pmjdebruijn pcode nl></property>
<property name="label" translatable="yes">Sketch</property>
<property name="use_underline">True</property>
<child type="submenu">
- <object class="GtkMenu" id="menu4">
+ <object class="GtkMenu" id="sketchmenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
@@ -780,15 +780,6 @@ Pascal de Bruijn <pmjdebruijn pcode nl></property>
</object>
</child>
<child>
- <object class="GtkMenuItem" id="menu-import">
- <property name="use_action_appearance">False</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Import Library</property>
- <property name="use_underline">True</property>
- </object>
- </child>
- <child>
<object class="GtkMenuItem" id="menuitem9">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]