@@ -894,16 +894,15 @@ def _on_btn_next_macro_clicked(self, widget):
894894
895895 self .widgets .hbtb_MDI .pack_start (self .macro_dic ["previous_button" ],True ,True ,0 )
896896 self .macro_dic ["previous_button" ].show ()
897-
898- end = len (self .macro_dic ) - 3 # reduced by next, previous and keyboard
899- start = end - 8
900-
897+ end = len (self .macro_dic ) - 4 # reduced by next, previous, calculator and keyboard
898+ start = end - 7
901899 # now put the needed widgets in the container
902900 for pos in range (start , end ):
903901 name = "macro_{0}" .format (pos )
904902 self .widgets .hbtb_MDI .pack_start (self .macro_dic [name ], True , True , 0 )
905903 self .macro_dic [name ].show ()
906-
904+ self .widgets .hbtb_MDI .pack_start (self .macro_dic ["calculator" ],True ,True ,0 )
905+ self .macro_dic ["calculator" ].show ()
907906 self .widgets .hbtb_MDI .pack_start (self .macro_dic ["keyboard" ],True ,True ,0 )
908907 self .macro_dic ["keyboard" ].show ()
909908
@@ -957,19 +956,17 @@ def _on_btn_previous_touch_clicked(self, widget):
957956 def _on_btn_previous_macro_clicked (self , widget ):
958957 # remove all buttons from container
959958 self ._remove_button (self .macro_dic , self .widgets .hbtb_MDI )
960-
961959 start = 0
962- end = 8
963-
960+ end = 7
964961 # now put the needed widgets in the container
965962 for pos in range (start , end ):
966963 name = "macro_{0}" .format (pos )
967964 self .widgets .hbtb_MDI .pack_start (self .macro_dic [name ], True , True , 0 )
968965 self .macro_dic [name ].show ()
969-
970966 self .widgets .hbtb_MDI .pack_start (self .macro_dic ["next_button" ],True ,True ,0 )
971967 self .macro_dic ["next_button" ].show ()
972-
968+ self .widgets .hbtb_MDI .pack_start (self .macro_dic ["calculator" ],True ,True ,0 )
969+ self .macro_dic ["calculator" ].show ()
973970 self .widgets .hbtb_MDI .pack_start (self .macro_dic ["keyboard" ],True ,True ,0 )
974971 self .macro_dic ["keyboard" ].show ()
975972
@@ -1327,24 +1324,18 @@ def _make_joints_button(self):
13271324 # check if macros are in the INI file and add them to MDI Button List
13281325 def _make_macro_button (self ):
13291326 LOG .debug ("Entering make macro button" )
1330-
13311327 macros = self .get_ini_info .get_macros ()
1332-
13331328 # if no macros at all are found, we receive a NONE, so we have to check:
13341329 if not macros :
13351330 num_macros = 0
13361331 # no return here, otherwise we will not get filling labels
13371332 else :
13381333 num_macros = len (macros )
1339-
13401334 LOG .debug ("found {0} Macros" .format (num_macros ))
1341-
1342- if num_macros > 16 :
1343- message = _ ("Found more than 16 macros, will use only the first 16." )
1335+ if num_macros > 14 :
1336+ message = _ ("Found more than 16 macros, will use only the first 14." )
13441337 LOG .info (message )
1345-
1346- num_macros = 16
1347-
1338+ num_macros = 14
13481339 btn = self ._new_button_with_predefined_image (
13491340 name = "previous_button" ,
13501341 size = _DEFAULT_BB_SIZE ,
@@ -1354,10 +1345,8 @@ def _make_macro_button(self):
13541345 btn .set_property ("tooltip-text" , _ ("Press to display previous macro button" ))
13551346 btn .connect ("clicked" , self ._on_btn_previous_macro_clicked )
13561347 self .widgets .hbtb_MDI .pack_start (btn ,True ,True ,0 )
1357-
13581348 for pos in range (0 , num_macros ):
13591349 name = macros [pos ]
1360-
13611350 image = self ._check_macro_for_image (name )
13621351 if image :
13631352 LOG .debug ("Macro {0} has image link" .format (name ))
@@ -1378,7 +1367,6 @@ def _make_macro_button(self):
13781367 btn .position = pos
13791368 btn .show ()
13801369 self .widgets .hbtb_MDI .pack_start (btn , True , True , 0 )
1381-
13821370 btn = self ._new_button_with_predefined_image (
13831371 name = "next_button" ,
13841372 size = _DEFAULT_BB_SIZE ,
@@ -1388,17 +1376,23 @@ def _make_macro_button(self):
13881376 btn .connect ("clicked" , self ._on_btn_next_macro_clicked )
13891377 btn .hide ()
13901378 self .widgets .hbtb_MDI .pack_start (btn ,True ,True ,0 )
1391-
13921379 # if there is still place, we fill it with empty labels, to be sure the button will not be on different
13931380 # places if the amount of macros change.
1394- if num_macros < 9 :
1395- for pos in range (num_macros , 9 ):
1381+ if num_macros < 7 :
1382+ for pos in range (num_macros , 7 ):
13961383 lbl = Gtk .Label ()
13971384 lbl .set_property ("name" ,"lbl_space_{0}" .format (pos ))
13981385 lbl .set_text ("" )
13991386 self .widgets .hbtb_MDI .pack_start (lbl , True , True , 0 )
14001387 lbl .show ()
1401-
1388+ btn = self .widgets .btn_macro_menu_calculator = self ._new_button_with_predefined_image (
1389+ name = "calculator" ,
1390+ size = _DEFAULT_BB_SIZE ,
1391+ image = self .widgets .img_macro_menu_calculator
1392+ )
1393+ btn .set_property ("tooltip-text" , _ ("Press to display the virtual calculator" ))
1394+ btn .connect ("clicked" , self .on_btn_show_calc_clicked )
1395+ self .widgets .hbtb_MDI .pack_start (btn ,True ,True ,0 )
14021396 btn = self .widgets .btn_macro_menu_toggle_keyboard = self ._new_button_with_predefined_image (
14031397 name = "keyboard" ,
14041398 size = _DEFAULT_BB_SIZE ,
@@ -1407,16 +1401,13 @@ def _make_macro_button(self):
14071401 btn .set_property ("tooltip-text" , _ ("Press to display the virtual keyboard" ))
14081402 btn .connect ("clicked" , self .on_btn_show_kbd_clicked )
14091403 self .widgets .hbtb_MDI .pack_start (btn ,True ,True ,0 )
1410-
14111404 self .macro_dic = {}
1412-
14131405 children = self .widgets .hbtb_MDI .get_children ()
14141406 for child in children :
14151407 self .macro_dic [child .get_property ("name" )] = child
1416-
1417- if num_macros >= 9 :
1408+ if num_macros >= 7 :
14181409 self .macro_dic ["next_button" ].show ()
1419- for pos in range (8 , num_macros ):
1410+ for pos in range (7 , num_macros ):
14201411 self .macro_dic ["macro_{0}" .format (pos )].hide ()
14211412
14221413 def _check_macro_for_image (self , name ):
@@ -2942,6 +2933,25 @@ def on_hal_status_mode_mdi(self, widget):
29422933 # on incremental jogging.
29432934 self .last_key_event = None , 0
29442935
2936+ def on_mdi_calculation_start (self , * args ):
2937+ position = self .widgets .hal_mdihistory .entry .get_position ()
2938+ print ("position: " , position )
2939+ value = self .dialogs .entry_dialog (self ,
2940+ data = self .widgets .hal_mdihistory .entry .get_text (),
2941+ header = _ ("Enter value" ),
2942+ label = _ ("Calculate value to insert" ),
2943+ integer = False )
2944+ if value == "ERROR" :
2945+ LOG .debug ("conversion error" )
2946+ self .dialogs .warning_dialog (self , _ ("Conversion error !" ),
2947+ ("Please enter only numerical values\n Values have not been applied" ))
2948+ elif value == "CANCEL" :
2949+ return
2950+ else :
2951+ self .widgets .hal_mdihistory .entry .insert_text (str (value ), position )
2952+ self .widgets .hal_mdihistory .entry .set_position (position + len (str (value )))
2953+
2954+
29452955 def on_hal_status_mode_auto (self , widget ):
29462956 LOG .debug ("AUTO Mode" )
29472957 # if Auto button is not sensitive, we are not ready for AUTO commands
@@ -4383,6 +4393,58 @@ def on_btn_delete_clicked(self, widget, data=None):
43834393 if result :
43844394 self .widgets .hal_mdihistory .model .clear ()
43854395
4396+ def on_btn_show_calc_clicked (self , widget ):
4397+ if self .widgets .ntb_button .get_current_page () == _BB_MDI :
4398+ mdi_entry = self .widgets .hal_mdihistory .entry
4399+ bounds = mdi_entry .get_selection_bounds ()
4400+ data = ""
4401+ has_selection = False
4402+ if bounds :
4403+ text = mdi_entry .get_text ()
4404+ data = text [bounds [0 ]:bounds [1 ]]
4405+ has_selection = True
4406+ value = self .dialogs .entry_dialog (self ,
4407+ data = data ,
4408+ header = _ ("Enter value" ),
4409+ label = _ ("Calculate value to insert" ),
4410+ integer = False )
4411+ if value == "ERROR" :
4412+ LOG .debug ("conversion error" )
4413+ self .dialogs .warning_dialog (self , _ ("Conversion error !" ),
4414+ ("Please enter only numerical values\n Values have not been applied" ))
4415+ elif value == "CANCEL" :
4416+ return
4417+ else :
4418+ if has_selection :
4419+ buffer = mdi_entry .get_buffer ()
4420+ buffer .delete_text (bounds [0 ],bounds [1 ]- bounds [0 ])
4421+ position = mdi_entry .get_position ()
4422+ mdi_entry .insert_text (str (value ), position )
4423+ mdi_entry .set_position (position + len (str (value )))
4424+ elif self .widgets .ntb_button .get_current_page () == _BB_EDIT :
4425+ data = ""
4426+ has_selection = False
4427+ buffer = self .widgets .gcode_view .get_buffer ()
4428+ if buffer .get_has_selection ():
4429+ bounds = buffer .get_selection_bounds ()
4430+ data = buffer .get_text (bounds [0 ],bounds [1 ],False )
4431+ has_selection = True
4432+ value = self .dialogs .entry_dialog (self ,
4433+ data = data ,
4434+ header = _ ("Enter value" ),
4435+ label = _ ("Calculate value to insert" ),
4436+ integer = False )
4437+ if value == "ERROR" :
4438+ LOG .debug ("conversion error" )
4439+ self .dialogs .warning_dialog (self , _ ("Conversion error !" ),
4440+ ("Please enter only numerical values\n Values have not been applied" ))
4441+ elif value == "CANCEL" :
4442+ return
4443+ else :
4444+ if has_selection :
4445+ buffer .delete (bounds [0 ],bounds [1 ])
4446+ buffer .insert_at_cursor (str (value ))
4447+
43864448 def on_btn_show_kbd_clicked (self , widget ):
43874449 #print("show Keyboard clicked", self.widgets.key_box.get_children())
43884450 #print(widget)
@@ -4758,10 +4820,12 @@ def _set_icon_theme(self, name):
47584820 ("img_edit_menu_save" , "save" , 32 ),
47594821 ("img_edit_menu_save_as" , "save_as" , 32 ),
47604822 ("img_edit_menu_new" , "new_document" , 32 ),
4823+ ("img_edit_menu_calculator" , "calculator_open" , 32 ),
47614824 ("img_edit_menu_keyboard" , "keyboard" , 32 ),
47624825 ("img_edit_menu_keyboard_hide" , "keyboard_hide" , 32 ),
47634826 ("img_edit_menu_close" , "back_to_app" , 48 ),
47644827 # macro menu
4828+ ("img_macro_menu_calculator" , "calculator_open" , 32 ),
47654829 ("img_macro_menu_keyboard" , "keyboard" , 32 ),
47664830 ("img_macro_menu_keyboard_hide" , "keyboard_hide" , 32 ),
47674831 ("img_macro_menu_stop" , "stop" , 32 ),
0 commit comments