how toget a Settings Menu to communicate with a Main Menu?
18 posts
• Page 1 of 1
how toget a Settings Menu to communicate with a Main Menu?I find it annoying sometimes to fill out my own Dialog Boxes. I was thinking of splitting some of the more uncommon options highlighted in orange from this Left Hand Door Dialog and also from a similar Right Hand Door dialog, thus making these 2 Dialogs less confrontational. Moving these options to a common separate Settings Dialog, looks like a better alternative, since most of the times these options are OK by default.
I have added a Settings sub menu with the 5 listed options: successfully. However when I "#" comment out the original 5 listed options in the main script, the new Settings menu is unable to communicate the default values to the main script. I have been looking unsuccessfully for a script of a similar nature from which I could emulate similar code. Anyone have any ideas on a script with this similar design ? TIA! Please, register (free) to access all the attachments on the forums.
Re: how toget a Settings Menu to communicate with a Main MenIf you still are not using modules to wrap your code.. it will be difficult.
If your options are all assigned to module vars, it does not matter how many dialogs you create, to change the options many different ways... ... any methods within the module will be able to read the module vars, when the time comes to use their values. If it's a simple plugin, you can have named vars.. ie: @@width, @@height, etc. But for more complex plugins (that you'll want to save settings for,) it makes it much easier to use a options hash: @@options = {} .. and later set an option: @@options[:width]= 125 @@options[:height]= 50 And sometimes I use a shorter: @@opts Since most of your plugins are going to have options, you need to separate your "namespace" into "sub-namespaces" for each plugin, so that the options @@ var references do not conflict.
Re: how toget a Settings Menu to communicate with a Main MenLast edited by Dan Rathbun on Mon Mar 05, 2012 8:42 am, edited 1 time in total.
Re: how toget a Settings Menu to communicate with a Main MenI hear your Module reference loud and clear
Re: how toget a Settings Menu to communicate with a Main Men
Either you are confused, or now I am. 1) Constants are supposed to be static. (This is why Ruby issues a warning to STDERR when you change them, because they are supposed to become frozen sometime in the future, perhaps in the Ruby 2.x.x trunk.) 2) You were describing splitting ONE input dialog box into TWO dialog boxes, that change variables (not constants,) that your plugin needs to access.
3) Menus ??? ... menus are the command lists that drop-down from the menubar, or popup when we right-click the mouse. The text strings names of menu commands.. ie: UI::Command.menutext="Command name" or menu.add_item("Command name") are dup'ed and stored on the C++ side as real CONSTANTS, and cannot be changed during the session. Try it:
So are you talking about menus or dialog boxes ???
Re: how toget a Settings Menu to communicate with a Main Men
Come on.. stop making excuses. Listen to me! Here's an updated template ... with empty Lefthand, Righthand, and Common Door Setting dialog methods. Just cut and paste your code into a copy of the template.
Last edited by Dan Rathbun on Wed Mar 07, 2012 9:18 pm, edited 1 time in total.
Re: how toget a Settings Menu to communicate with a Main Men
Ok ... this "main script" term.. implies you are attempting plugin "file spanning" without using namespaces (modules.) You MUST use a namespace. FYI.. the Ruby keywords module and class do not mean "define" (That is reserved for methods, ie, def, and also means "redefine this method.") The keywords module and class mean "open for editing". SO.. your plugin code, can be in 100 different files if you wish (although that would be extreme.) But the code in each file must evaluate within the same namespace !! Ex:
... etc. (A poor example... but each author has his/her own way of splitting up there code for ease of maintenance.) I usually put all plugin options handling (saving, restoring, changing, etc.) in one file with a "_opt.rb" suffix. .. and usually all menu, command and toolbar setup in another, with a "_mnu.rb" suffix. The main plugin methods and code, (ie, the "engine",) I put in a file with a "_eng.rb" suffix. If I have a bunch of misc. methods, I may put them in a separate file, with a "_lib.rb" suffix. I personally find it easier with Notepad++, to switch file tabs, or left-right edit panes, rather than scroll WAY up, and WAY back down within a single file. It all depends on whether the plugin is simple or complex. A very simple, single menu item "macro" I'll do all in one file.
Re: how toget a Settings Menu to communicate with a Main MenOh.. another reason to break up your plugin code into multiple files.. is debugging.
If the code that creates the menus, menuitems and toolbars, is all in one file. Once that is loaded, (assuming you pointed the menuitems, and toolbar buttons at methods in your module...,) that particular file does not need to be reloaded during debugging. If you are debugging, and tweaking options handling, in a separate file... after a tweak and save, you need only reload that specific file to redefine the methods you fixed.
Re: how toget a Settings Menu to communicate with a Main Men
I think we need to see some sample code here. Because all we know is the concept of what you want to do - which should be doable - but clearly there is something in the implementation that's not correct. Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: how toget a Settings Menu to communicate with a Main Men
I want to avoid, attaching code because I know its asking to much and goes against the bounds of the help you guys are already willing to provide, I will chew through Dan's contribution, and get the module stuff in place first. I also ran across Housebuilder by: Steve Hurlbut which I had forgotten uses a settings menu, ....oy vey!... that code should be fun to look at.
Re: how toget a Settings Menu to communicate with a Main Men
I picture is still worth a 1000 words: Please, register (free) to access all the attachments on the forums.
Re: how toget a Settings Menu to communicate with a Main MenOK.. your talking dialogs.
(It does not matter how the dialog box is opened... via a menu choice, a toolbar button click, a press of a hotkey, or a command typed at the console,.. it's all the same. The variables and options, are NOT on the menu.. they are in dialog boxes.) You are pointing at a list of instance variables, not constants. (Constants begin with an uppercase letter if they are a class or Module, otherwise they are all CAPSLIKETHIS.) Follow what I said. Paste those instance vars into the Module vars section, and add another @ to the front of them. (Editor search and replace within selection "@" with "@@".) Do the same else where in the code, whenever they are accessed. If you want to save all those options between settings more easily, then: You might as well change @dstyle to @@opts[:dstyle], @drail to @@opts[:drail], etc.
Re: how toget a Settings Menu to communicate with a Main MenWhats really needed, from the old programming days of the past is a simple GOTO statement.
I hope my attached picture illustrates a simplified flow of my ruby. Presently if I # comment the @stylewidth variable under Dialog 1 the entity cannot be draw. However with a GOTO statement the program would be directed to the value to the @stylewidth variable under Dialog 2 and then be directed back to draw the entity. p.s. interesting if one Google's Goto Ruby, you get people commenting on either side of this issue. Please, register (free) to access all the attachments on the forums.
Re: how toget a Settings Menu to communicate with a Main Men
ABSOLUTELY TOTALLY UNTRUE !!
All it does, is show, that you still suffer from linear thinking. Your simple example BookShelf plugin also indicates your "linear affliction", where you have all of the executable code within ONE single method. You need to break away from that kind of thinking, in today's world of GUI programming where anything can happen, at any time, depending upon what the user's actions are. Take two "Procedural, Event-Driven" pills and call me in the morning... Ruby has everything you need, now. And there is no reason why if you are properly using scoped variables, that dialog #2 cannot access them. If it cannot, then you are doing something to hide the variable from dialog #2. Your pic cannot tell us what it is that you are doing wrong. We need a code example.
Re: how toget a Settings Menu to communicate with a Main MenLet me also say that you really need to break up your code into methods.
A method call IS THE GOTO STATEMENT that you think you need. So all of dialog #1 code should be within a method of it's own. So all of dialog #2 code should be within a method of it's own. The draw routine should be all within a method of it's own. etc.. etc... You can also create a getter method to get the value of a variable from anywhere within your module:
Remember I told you that the difference between @ instance vars and @@ module vars in modules, was subtle. This is where the subtleness comes into play... The attr_accessor methods that create instance vars and getter and setter methods, are for mixin modules, that will be mixed into classes. This is why I was encouraging you to use @@ module vars instead of @ instance vars in your modules. (But it looks like you copied someone else's use of instance vars in modules.)
Re: how toget a Settings Menu to communicate with a Main MenI didn't mean to open the Goto can of worms! it was a deja vu moment from the past, I realize that Goto can easily be satisfied using if. My current Ruby already contains some 20 if statements, which are goto's. I should be able link via another if statement the sharing of the stored registry value of the @stylwidth in Dialog 1 and Dialog 2.....Hopefully
Re: how toget a Settings Menu to communicate with a Main MenYour totally missing the point...
Anyway... I took a walk and thought about it a bit.. and I think I realize what your problem may be. You need to define (as in declare, for those coming from other programming langauges,) ALL those variables, that you wish to be accessible throughout your module, at the top of the module BEFORE and OUTSIDE of ALL methods. Did you examine the module template I posted further up the topic ?? Look at the sentence just above the code box:
Now, look near the bottom of the template, in the RUN ONCE section. What is the FIRST thing I did ?? I called a method to get the user's saved options from the registry (which will update certain module vars with the user's values, saved from the previous session.) From that point on... whenever ANY method gets the values that those module variables point to... the values will be the latest values. ANY method may change them, and ANY method can access their values. (It's just up to you to decide when to save any changes to the values back into the registry.)
Re: how toget a Settings Menu to communicate with a Main Men
No it cannot.
No they are not branching statements, they are conditional statements. But you CAN make them branch off to some other part of your code, by making method calls, in response to the boolean evaluation of the conditional expressions. if condition_is_true then call_method_one() else call_method_two();
Again... in a procedural language, a method call (aka procedure call,) takes the place of the old goto from the old sequential linear languages like Fortran and GW-BASIC. Whenever you identify a particular place in your code, that you need to "goto" (usually repeatedly,)... then THAT is the spot where you need to begin a method.
SketchUcation One-Liner AdvertsNeed Authorised SketchUp Training by experts in various disciplines? Check out our Training details.
18 posts
• Page 1 of 1
|