Commit 9ddad411 authored by sumpfralle's avatar sumpfralle

moved menu items to ui sections

fixed mangled names


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1131 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent f0c009f3
......@@ -10,7 +10,6 @@
<property name="destroy_with_parent">True</property>
<property name="icon_name">accessories-character-map</property>
<property name="type_hint">dialog</property>
<property name="transient_for">ProjectWindow</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox8">
<property name="visible">True</property>
......
......@@ -6,16 +6,10 @@
<menuitem action="SaveModel"/>
<menuitem action="SaveAsModel"/>
<separator />
<menuitem action="ExportGCodeVisible"/>
<menuitem action="ExportGCodeAll"/>
<separator />
<menuitem action="Quit"/>
</menu>
<menu action="EditMenu">
<menuitem action="UndoButton"/>
<separator />
<menuitem action="CopyModelToClipboard"/>
<menuitem action="PasteModelFromClipboard"/>
</menu>
<menu action="SettingsMenu">
<menuitem action="LoadTaskSettings"/>
......@@ -26,15 +20,7 @@
<separator />
<menuitem action="GeneralSettings"/>
</menu>
<menu action="ExtrasMenu">
<menuitem action="ShowFontDialog"/>
</menu>
<menu action="WindowMenu">
<menuitem action="Toggle3DView"/>
<menuitem action="ToggleLogWindow"/>
<menuitem action="ToggleProcessPoolWindow"/>
<menuitem action="TogglePluginWindow"/>
</menu>
<menu action="ViewMenu" />
<menu action="HelpMenu">
<menuitem action="HelpUserManual"/>
<menuitem action="HelpIntroduction"/>
......
......@@ -116,8 +116,8 @@
<property name="label">_Save Model</property>
<property name="tooltip">Save the current model to the STL file.</property>
</object>
<object class="GtkAction" id="WindowMenu">
<property name="label">_Windows</property>
<object class="GtkAction" id="ViewMenu">
<property name="label">_View</property>
</object>
<object class="GtkAction" id="SaveAsModel">
<property name="label">Save Model _as ...</property>
......@@ -2015,9 +2015,6 @@ You should have received a copy of the GNU General Public License along with thi
<object class="GtkAction" id="HelpServerMode">
<property name="label">Server Mode</property>
</object>
<object class="GtkAction" id="ExtrasMenu">
<property name="label">E_xtras</property>
</object>
<object class="GtkAction" id="EditMenu">
<property name="label">_Edit</property>
</object>
......
......@@ -201,7 +201,7 @@ class EventCore(pycam.Gui.Settings.Settings):
log.debug("Trying to unregister an unknown event: %s" % event)
def emit_event(self, event, *args, **kwargs):
log.debug("Event emitted: %s" % str(event))
log.debug2("Event emitted: %s" % str(event))
if event in self.event_handlers:
if self.event_handlers[event][EVENT_BLOCKER_INDEX] != 0:
return
......@@ -290,6 +290,7 @@ class EventCore(pycam.Gui.Settings.Settings):
removal_list.reverse()
for index in removal_list:
ui_section[UI_WIDGET_INDEX].pop(index)
self._rebuild_ui_section(section)
else:
log.debug("Trying to unregister unknown ui section: %s" % \
str(section))
......@@ -477,7 +478,7 @@ class ProjectGui(object):
self.settings.add_item("cutter", lambda: self.cutter)
main_tab = self.gui.get_object("MainTabs")
def clear_main_tab():
for index in range(main_tab.get_n_pages()):
while main_tab.get_n_pages() > 0:
main_tab.remove_page(0)
def add_main_tab_item(item, name):
main_tab.append_page(item, gtk.Label(name))
......@@ -730,6 +731,40 @@ class ProjectGui(object):
self.gui.get_object("OpenRecentModel").set_visible(False)
# load the menubar and connect functions to its items
self.menubar = uimanager.get_widget("/MenuBar")
# view menu
menu_merges = {}
def clear_menu(menu_key):
for merge in menu_merges.get(menu_key, []):
uimanager.remove_ui(merge)
def append_menu_item(menu_key, base_path, widget, name):
merge_id = uimanager.new_merge_id()
if widget:
action_group = widget.props.action_group
if not action_group in uimanager.get_action_groups():
uimanager.insert_action_group(action_group, -1)
widget_name = widget.get_name()
item_type = gtk.UI_MANAGER_MENUITEM
else:
widget_name = name
item_type = gtk.UI_MANAGER_SEPARATOR
uimanager.add_ui(merge_id, base_path, name, widget_name, item_type,
False)
if not menu_key in menu_merges:
menu_merges[menu_key] = []
menu_merges[menu_key].append(merge_id)
def get_menu_funcs(menu_key, base_path):
append_func = lambda widget, name: \
append_menu_item(menu_key, base_path, widget, name)
clear_func = lambda: clear_menu(menu_key)
return append_func, clear_func
for ui_name, base_path in (("view_menu", "/MenuBar/ViewMenu"),
("file_menu", "/MenuBar/FileMenu"),
("edit_menu", "/MenuBar/EditMenu")):
append_func, clear_func = get_menu_funcs(ui_name, base_path)
self.settings.register_ui_section(ui_name, append_func, clear_func)
self.settings.register_ui("file_menu", "Quit",
self.gui.get_object("Quit"), 100)
self.settings.register_ui("file_menu", "QuitSeparator", None, 95)
self.settings.register_ui("main_window", "Main", self.menubar, -100)
# initialize plugins
self.plugin_manager = pycam.Plugins.PluginManager(core=self.settings)
......
......@@ -55,10 +55,14 @@ class Clipboard(pycam.Plugins.PluginBase):
self.copy_action.connect("activate", self.copy_model_to_clipboard)
self.register_gtk_accelerator("clipboard", self.copy_action,
"<Control>c", "CopyModelToClipboard")
self.core.register_ui("edit_menu", "CopyModelToClipboard",
self.copy_action, 20)
self.paste_action = self.gui.get_object("PasteModelFromClipboard")
self.paste_action.connect("activate", self.paste_model_from_clipboard)
self.register_gtk_accelerator("clipboard", self.paste_action,
"<Control>v", "PasteModelFromClipboard")
self.core.register_ui("edit_menu", "PasteModelFromClipboard",
self.paste_action, 25)
self._update_clipboard_widget()
return True
......
......@@ -82,6 +82,10 @@ class Fonts(pycam.Plugins.PluginBase):
self.register_gtk_accelerator("fonts", font_action,
"<Control><Shift>t", "ShowFontDialog")
font_action.connect("activate", self.toggle_font_dialog_window)
self.core.register_ui("edit_menu", "ShowFontDialogSeparator",
None, 55)
self.core.register_ui("edit_menu", "ShowFontDialog", font_action,
60)
# store window position
self._font_dialog_window_visible = False
self._font_dialog_window_position = None
......@@ -91,8 +95,9 @@ class Fonts(pycam.Plugins.PluginBase):
def teardown(self):
self.core.add_item("fonts", None)
if self.gui:
self.unregister_gtk_accelerator("fonts",
self.gui.get_object("ShowFontDialog"))
font_toggle = self.gui.get_object("ShowFontDialog")
self.core.unregister_ui("edit_menu", font_toggle)
self.unregister_gtk_accelerator("fonts", font_toggle)
def toggle_font_dialog_window(self, widget=None, event=None, state=None):
# only "delete-event" uses four arguments
......
......@@ -41,10 +41,11 @@ class Log(pycam.Plugins.PluginBase):
log_action.connect("toggled", self.toggle_log_window)
self.register_gtk_accelerator("log", log_action,
"<Control>l", "ToggleLogWindow")
self.core.register_ui("view_menu", "ToggleLogWindow", log_action, 100)
# status bar
self.status_bar = self.gui.get_object("StatusBar")
self.gui.get_object("StatusBarEventBox").connect("button-press-event",
self.toggle_log_window)
self.gui.get_object("StatusBarEventBox").connect(
"button-press-event", self.toggle_log_window)
event_bar = self.gui.get_object("StatusBarEventBox")
event_bar.unparent()
self.core.register_ui("main_window", "Status", event_bar, 100)
......@@ -67,10 +68,13 @@ class Log(pycam.Plugins.PluginBase):
def teardown(self):
if self.gui:
self.log_window.hide()
self.unregister_gtk_accelerator("log",
self.gui.get_object("ToggleLogWindow"))
log_action = self.gui.get_object("ToggleLogWindow")
self.core.unregister_ui("view_menu", log_action)
self.unregister_gtk_accelerator("log", log_action)
self.core.unregister_ui("main_window",
self.gui.get_object("StatusBarEventBox"))
self.core.unregister_ui("view_menu",
self.gui.get_object("ToggleLogWindow"))
# TODO: disconnect the log handler
def add_log_message(self, title, message, record=None):
......
......@@ -34,10 +34,12 @@ class OpenGLViewAxes(pycam.Plugins.PluginBase):
self._GL = OpenGL.GL
self._GLUT = OpenGL.GLUT
self.core.register_event("visualize-items", self.draw_axes)
self.core.emit_event("visual-item-updated")
return True
def teardown(self):
self.core.unregister_event("visualize-items", self.draw_axes)
self.core.emit_event("visual-item-updated")
def draw_axes(self):
if not self.core.get("show_axes"):
......
......@@ -31,10 +31,12 @@ class OpenGLViewBounds(pycam.Plugins.PluginBase):
import OpenGL.GL
self._GL = OpenGL.GL
self.core.register_event("visualize-items", self.draw_bounds)
self.core.emit_event("visual-item-updated")
return True
def teardown(self):
self.core.unregister_event("visualize-items", self.draw_bounds)
self.core.emit_event("visual-item-updated")
def draw_bounds(self):
GL = self._GL
......
......@@ -31,10 +31,12 @@ class OpenGLViewToolpath(pycam.Plugins.PluginBase):
import OpenGL.GL
self._GL = OpenGL.GL
self.core.register_event("visualize-items", self.draw_toolpath)
self.core.emit_event("visual-item-updated")
return True
def teardown(self):
self.core.unregister_event("visualize-items", self.draw_toolpath)
self.core.emit_event("visual-item-updated")
def draw_toolpath(self):
if self.core.get("show_toolpath") \
......
......@@ -92,6 +92,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
self._toggle_action_handler = (toggle_3d, handler)
self.register_gtk_accelerator("opengl", toggle_3d,
"<Control><Shift>v", "ToggleOpenGLView")
self.core.register_ui("view_menu", "ViewOpenGL", toggle_3d, -20)
self.mouse = {"start_pos": None, "button": None,
"event_timestamp": 0, "last_timestamp": 0,
"pressed_pos": None, "pressed_timestamp": 0,
......@@ -197,14 +198,17 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
# show the window
self.area.show()
self.container.show()
self.show()
toggle_3d.set_active(True)
self.core.emit_event("visual-item-updated")
return True
def teardown(self):
if self.gui:
self.window.hide()
self.unregister_gtk_accelerator("opengl",
self.gui.get_object("Toggle3DView"))
toggle_3d = self.gui.get_object("Toggle3DView")
self.core.unregister_ui("view_menu", toggle_3d)
self.unregister_gtk_accelerator("opengl", toggle_3d)
self.core.unregister_ui("view_menu", toggle_3d)
self.core.unregister_event("model-change-after",
self.update_model_dimensions)
self.core.unregister_event("visual-item-updated",
......@@ -212,6 +216,9 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
self.core.unregister_event("visual-item-updated", self.update_view)
self.core.unregister_event("visualization-state-changed",
self._update_widgets)
# the area will be created during setup again
self.container.remove(self.area)
self.area = None
def update_view(self, widget=None, data=None):
if self.is_visible:
......
......@@ -28,7 +28,7 @@ import gobject
import pycam.Plugins
class Toolpaths(pycam.Plugins.PluginBase):
class ParallelProcessing(pycam.Plugins.PluginBase):
UI_FILE = "parallel_processing.ui"
......@@ -88,6 +88,8 @@ class Toolpaths(pycam.Plugins.PluginBase):
toggle_button.connect("toggled", self.toggle_process_pool_window)
self.register_gtk_accelerator("processes", toggle_button,
None, "ToggleProcessPoolWindow")
self.core.register_ui("view_menu", "ToggleProcessPoolWindow",
toggle_button, 40)
return True
def teardown(self):
......@@ -95,8 +97,9 @@ class Toolpaths(pycam.Plugins.PluginBase):
self.process_pool_window.hide()
self.core.unregister_ui("preferences",
self.gui.get_object("MultiprocessingFrame"))
self.unregister_gtk_accelerator("processes",
self.gui.get_object("ToggleProcessPoolWindow"))
toggle_button = self.gui.get_object("ToggleProcessPoolWindow")
self.core.unregister_ui("view_menu", toggle_button)
self.unregister_gtk_accelerator("processes", toggle_button)
def toggle_process_pool_window(self, widget=None, value=None, action=None):
toggle_process_pool_checkbox = self.gui.get_object("ToggleProcessPoolWindow")
......
......@@ -52,6 +52,7 @@ class PluginSelector(pycam.Plugins.PluginBase):
action.connect("toggled", self.toggle_plugin_window)
self.register_gtk_accelerator("plugins", action, None,
"TogglePluginWindow")
self.core.register_ui("view_menu", "TogglePluginWindow", action, 60)
self.gui.get_object("PluginsEnabledCell").connect("toggled",
self.toggle_plugin_state)
self.core.register_event("plugin-list-changed",
......@@ -62,6 +63,8 @@ class PluginSelector(pycam.Plugins.PluginBase):
def teardown(self):
if self.gui:
self.plugin_window.hide()
action = self.gui.get_object("TogglePluginWindow")
self.core.register_ui("view_menu", action)
self.core.unregister_event("plugin-list-changed",
self._update_plugin_model)
......@@ -106,7 +109,7 @@ class PluginSelector(pycam.Plugins.PluginBase):
depends_markup.append(depend)
model.append((name, "Beschreibung", enabled,
os.linesep.join(depends_markup), satisfied,
str(plugin.__class__)))
"Hint"))
self.gui.get_object("PluginsDescriptionColumn").queue_resize()
self.gui.get_object("PluginsTable").queue_resize()
......
......@@ -68,10 +68,13 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self.register_gtk_accelerator("toolpaths", export_all,
"<Control><Shift>e", "ExportGCodeAll")
export_all.connect("activate", self.save_toolpath, False)
self.core.register_ui("file_menu", "ExportGCodeAll", export_all, 60)
export_selected = self.gui.get_object("ExportGCodeSelected")
self.register_gtk_accelerator("toolpaths", export_selected,
None, "ExportGCodeSelected")
export_selected.connect("activate", self.save_toolpath, True)
self.core.register_ui("file_menu", "ExportGCodeSelected",
export_selected, 65)
# model handling
def update_model():
if not hasattr(self, "_model_cache"):
......
......@@ -23,7 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Plugins
class Toolpaths(pycam.Plugins.PluginBase):
class Units(pycam.Plugins.PluginBase):
UI_FILE = "units.ui"
......
......@@ -100,7 +100,8 @@ class PluginBase(object):
def unregister_gtk_accelerator(self, groupname, action):
actiongroup = gtk.ActionGroup(groupname)
actiongroup.remove_action(action)
if len(actiongroup.list_actions()) == 0:
if (len(actiongroup.list_actions()) == 0) and (actiongroup in \
self.core.get("gtk-uimanager").get_action_groups()):
self.core.get("gtk-uimanager").remove_action_group(actiongroup)
......
......@@ -50,6 +50,7 @@ def init_logger(log, logfilename=None):
console_output.addFilter(RepetitionsFilter(console_output))
log.addHandler(console_output)
log.setLevel(logging.INFO)
log.debug2 = lambda *args, **kwargs: log.log(logging.DEBUG - 1, *args, **kwargs)
# store the latest log items in a queue (for pushing them into new handlers)
buffer_handler = BufferHandler()
buffer_handler.addFilter(RepetitionsFilter(buffer_handler))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment