1. 程式人生 > >【小知識】MATLAB的App Designer與GUIDE

【小知識】MATLAB的App Designer與GUIDE

本文翻譯自Loren Shure(2018年7月25日)的部落格文章《The State of App Building in MATLAB》,原文地址:https://blogs.mathworks.com/loren/2018/07/25/the-state-of-app-building-in-matlab/

在我的旅行中,我會見了許多客戶,他們總是對學習MATLAB新的特性和功能非常感興趣。一個尤其令很多人感興趣的領域是MATLAB應用程式的構建。許多MATLAB使用者對App Designer、GUIDE和這兩個應用程式構建平臺的未來發展感興趣。因此,在這篇部落格中,我想我會把這些問題中的一部分交給MATLAB圖形和應用程式構建的開發經理ChrisPortal以及MATLAB產品經理David Garrison。

In my travels, I meet with many customersand they are always interested in learning about new MATLAB features andcapabilities. One area that has a lot of interest is MATLAB app building. ManyMATLAB users are interested in App Designer, GUIDE, and the future of the twoapp building platforms. So for this blog, I thought I would put some of thosequestions to Chris Portal, Development Manager for MATLAB Graphics & App Building, and DavidGarrison, MATLAB Product Manager.

目前,MATLAB的應用程式構建處於一種什麼樣的狀態?

What is the current state of app buildingin MATLAB?

Chris Portal:目前,MATLAB為使用者構建應用程式提供了兩個平臺——GUIDE和App Designer。GUIDE是一個較老的平臺,MATLAB使用者已經使用了很多年。儘管使用者已經能夠使用GUIDE構建不同複雜程度的應用程式,但是它一直存在使用者希望解決的工作流程和可用性問題。類似地,它所支援的元件集(主要是uicontrol集)也非常有限,並且基於一些遺留的技術。

CP: Currently MATLAB offers twoplatforms for building apps – GUIDE and App Designer. GUIDE is an olderplatform that MATLAB users have been using for many years. Although users havebeen able to build apps of varying levels of sophistication with GUIDE, it hassuffered from a number of workflow and usability issues we’ve been wanting toaddress for our users. Similarly, the component set it supports, which ispredominantly the uicontrol set, is also very limited and based onsome legacy technologies.

David Garrison:在R2016a中,我們引入了App Designer作為新的應用程式構建平臺。App Designer集成了構建應用程式的兩個任務——設定視覺元件和程式設計行為。它具有一個新的設計畫布,更容易新增元件,並使用標籤和麵板進行有效組織。它包括一個內建的編輯器,用於管理只讀部分中元件的生成程式碼,併為使用者編寫的回撥程式碼提供可編輯的部分。它還支援一系列新的標準組件,如編輯欄位、按鈕和旋轉器,以及用於建立儀表面板的儀表盤、旋鈕、開關和燈。

DG: In R2016a we introduced App Designer as our new appbuilding platform. App Designer integrates the two tasks of building an app –laying out the visual components and programming the behavior. It has a newdesign canvas that makes it easier to add components and to organize them usingtabs and panels. It includes a built-in editor that manages generated code forcomponents in read-only sections and provides editable sections foruser-written callback code. It also supports a new family of standardcomponents such as edit fields, buttons, and spinners, as well as gauges,knobs, switches, and lamps for creating instrument panels.

為什麼MathWorks開發了一個全新的應用程式構建平臺?

Why did MathWorks develop a whole new appbuilding platform?

Chris Portal:GUIDE和App Designer之間的主要區別在於所使用的技術。GUIDE的基礎是Java Swing,甲骨文已經不再對其投入開發。雖然這個平臺可以獲得一些短期的勝利,但是從長遠來看,不會得到新的擴充套件,也不允許我們為使用者提供基於網路的工作流。AppDesigner建立在現代的基於web的技術上,比如JavaScript、HTML和CSS,它給我們提供了一個平臺,可以靈活地跟上使用者的需求,並允許應用程式在web上執行。使用者可以保持他們現有的基於Java的應用程式執行,並在合適的時候選擇新的平臺。

CP: A major difference between GUIDEand App Designer is the technology used. GUIDE is based on Java Swing which isno longer being actively developed by Oracle. Building on it would have allowedsome short-term wins, but it would not have scaled in the long-term or allowedus to offer web-based workflows for our users. App Designer is built on modern,web-based technologies such as JavaScript, HTML, and CSS, giving us a platformwith the flexibility to keep up with the demands of our users and allowing appsto run on the web. Users can keep their existing Java-based apps running andchoose to opt into the new platform when the time is right for them.

如何比較AppDesigner與GUIDE之間的優缺點呢?

How does App Designer compare to GUIDE?

David Garrison:當我們在R2016a中引入App Designer時,它為應用程式佈局提供了一個現代化的、使用者友好的環境,解決了GUIDE的幾個可用性問題。然而,在最初發布的幾個版本中,AppDesigner尚不具備GUIDE的某些功能。常見元件缺失,MATLAB圖形化支援有限,使用效能不適用於大型應用程式。隨著每一次版本的更新,我們一直在縮小這些差距並解決效能上的優化問題。從R2018a開始,App Designer幾乎支援所有的MATLAB 2D和3D視覺化,包括平移、縮放和旋轉互動;添加了選單支援以及新的樹和日期選擇器元件;程式碼編輯器能夠擴充套件以構建大型應用程式。

DG: When we introduced App Designer inR2016a, it offered a modern anduser-friendly environment for laying out your app, which addressed severalusability issues GUIDE has. However, for the first few releases, App Designerhad some functional gaps with respect to GUIDE. Common components were missing,MATLAB graphics support was limited, and performance didn’t scale for largeapps. With each release, we have been closing these gaps and addressingperformance. As of R2018a,App Designer supports nearly all MATLAB 2D and 3D visualizations with pan,zoom, and rotate interactivity; menu support has been added as well as new treeand date picker components; and the code editor is able to scale to build largeapps.

Chris Portal:另一個顯著的區別是程式設計模型。App Designer為應用程式生成一個MATLAB類,使得程式設計回撥和在應用程式的不同部分之間共享資料比GUIDE更不容易出錯。這意味著您不再需要更新控制代碼結構,或者理解如何使用guidatavs. appdata vs. UserData的微妙之處。還引入了專門為每個元件設計的新的MATLAB介面,這些新的介面更易於程式設計並在GUIDE使用的uicontrol元件基礎上進行了改進。

CP: Another notable difference is thecoding model. App Designer generates a MATLAB class for the app, making iteasier to program callbacks and share data between different parts of the appin a way that is less error prone than GUIDE. What this means is you no longerneed to update a handles structure, or understand the subtleties of when to useguidata vs. appdata vs. UserData. New MATLAB interfaces have also beenintroduced which are designed specifically for each component. These newinterfaces are easier to program to and improve on the older uicontrolcomponent used by GUIDE.

這對GUIDE和應用程式使用者的未來意味著什麼?

What does that mean for the future of GUIDEand the apps users have built with it?

David Garrison:我們知道,許多MATLAB使用者在基於GUIDE的應用程式上投入了大量精力並擁有自己的智慧財產權。我們將繼續支援GUIDE及其相關元件,目前沒有放棄或刪除該功能的計劃。與其他MATLAB功能上的過渡不同,GUIDE和App Designer可以共存,這允許我們和我們的使用者通過一系列版本的更新來完成過渡。我們目前的重點是增強App Designer,以確保它能夠滿足MATLAB應用程式構建器的需求,並幫助GUIDE使用者充分利用這種新工具。

DG: We know that many MATLAB users havetime and intellectual property invested in GUIDE-based apps or in apps they’vecreated programmatically. We will continue to support GUIDE and its associatedcomponents and have no current plans to deprecate or remove any of thatfunctionality. Unlike other MATLAB transitions, GUIDE and App Designer canco-exist, which allows us and our users to work through the transition over a seriesof releases. Our focus right now is on enhancing App Designer to ensure it canserve the needs of MATLAB app builders and helping GUIDE users adopt it.

Chris Portal:為此,我們在R2018a中釋出了用於MATLAB GUIDE到AppDesigner遷移的工具,它簡化了將基於GUIDE的應用程式轉換為AppDesigner的過程。該工具自動建立一個與GUIDE應用程式具有相同佈局的App Designer應用程式,應用必要的元件配置,並複製GUIDE回撥程式碼。這樣,您可以更新回撥程式碼,使其與新的App Designer程式碼格式相容。為了幫助使用者完成以上步驟,該工具會生成一個報告,報告描述瞭如何進行程式碼更新,並提供了一些有限的解決辦法。您可以從MATLAB中心的檔案交換或MATLAB桌面上的Add-On Explorer下載該工具。

CP: Towards that end, we have released theGUIDE to App Designer Migration Tool for MATLAB in R2018a which eases the process of converting aGUIDE-based app to App Designer. The tool automatically creates an App Designerapp with the same layout as your GUIDE app, applies the necessary componentconfigurations, and copies the GUIDE callback code over. From there, you updatethe callback code to make it compatible with the new App Designer code format.To help users with this step, the tool generates a report that describes how todo the code updates and provides workarounds for some limitations. You candownload the tool from the File Exchange on MATLAB Central or from the Add-OnExplorer in the MATLAB desktop.

那些以程式設計方式建立應用程式的使用者怎麼辦呢?

What about users who create their appsprogrammatically?

David Garrison:我們知道有些使用者選擇不使用像GUIDE或App Designer這樣的互動式環境——他們更喜歡在MATLAB中以程式設計的方式建立應用程式。您可以繼續手動編寫應用程式,而不管您使用哪個元件集,無論是舊的uicontrol功能,還是我們自R2016a以來一直在擴充套件的新元件集。

DG: We know some users choose not to use aninteractive environment like GUIDE or App Designer – they prefer to createtheir apps programmatically in MATLAB. You can continue to hand-code your appsregardless of which component set you use, whether it’s the older uicontrol function, or the newer componentset we’ve been expanding since R2016a.

使用Java擴充套件的應用程式又如何呢?

What about apps that use Java extensions?

Chris Portal:一些使用者已經使用Java Swing來擴充套件他們的應用程式的能力,包括使用javacomponent來新增自定義元件。他們需要這樣做來整合我們不支援的元件,如選項卡、樹和日期選擇器,並定製超出文件的元件,包括更豐富的單元格級別的格式圖表。另一些則使用未記錄的JavaFrame屬性來執行最大化或最小化圖形視窗的操作。在一些情況下,使用者直接利用Java Swing來構建IDE類應用程式,從而利用Java佈局管理器的優點。App Designer為我們解決這些長期存在的差距提供了基礎。App Designer一直在不斷地補充缺失元件,並增強現有元件。我們有許多新的特性可以彌補Java Swing的空白,並使我們所有的MATLAB使用者能夠構建更復雜的應用程式。

CP: Some of these users have used JavaSwing to extend the capabilities of their apps including the use of thejavacomponent function to add custom components. They needed to do this tointegrate components we did not support like tabs, trees, and date pickers, andto customize components beyond what was documented, including richer cell levelformatting for tables. Other have used the undocumented JavaFrame property todo things like maximize or minimize the figure window. And in a few cases,users have leveraged Java Swing directly in order to take advantage of thingslike Java layout managers to build IDE-like apps. App Designer gives us afoundation to address these long-standing gaps for our users. App Designer hasbeen adding support for missing components and enhancing existing ones. We havea number of features lined up that will help bridge the Java Swing gap, andenable all of our MATLAB users to build more sophisticated apps.

David Garrison:我們一直在積極地調查使用者,瞭解他們是如何使用Java來擴充套件他們的應用程式的。我們蒐集的反饋報告將直接影響研發團隊的工作。例如,在對JavaFrame使用情況的調查中,我們發現使用它的首要原因是以程式設計方式最大化或最小化圖形視窗。我們在R2018a中添加了對此內容的文件支援。我們還添加了uitree以響應我們關於javacomponent使用的調查反饋。我們的計劃是讓每一次MATLAB的更新發布解決一些導致使用者去使用Java的問題,因此我們鼓勵使用者填寫這些調查。最後,我們認識到一些使用者可能需要專門的元件,但對於大多數應用程式構建器來說,這些元件可能具有較低的優先順序。為了解決這個問題,我們還在研究如何為MATLAB應用程式中整合第三方JavaScript元件提供文件化的解決方案。

DG: We have been actively surveying usersto understand how they are using Java to extend their apps. The feedback wehear directly impacts the team’s work. For example, in our survey on JavaFrameuse, we discovered the number one reason for its use was to programmaticallymaximize or minimize the figure window. We added documented support for this inR2018a. We also addeduitree in response to feedback from our survey on javacomponent use. Our plan is to have eachrelease of MATLAB address some gap that has led users to go to Java, so weencourage users to fill out these surveys. Finally, we recognize some users mayrequire specialized components that may be of lower priority for most appbuilders. In order to address this, we are also investigating ways to provide adocumented solution for integrating 3rd party JavaScript components in MATLABapps.

使用者如何將他們的應用程式移植到網頁上?

How do users take their apps to the Web?

David Garrison:有兩種方法可以實現。一種是使用MATLAB線上模式。MATLAB線上模式可以讓您在任何可以訪問因特網的計算機桌面Web瀏覽器中執行MATLAB。MATLAB線上模式需要選擇許可證,並進行資格驗證。使用MATLAB的桌面版本建立一個應用程式並將其儲存到MATLAB驅動器。要在Web瀏覽器中執行應用程式,請使用您的MathWorks帳戶登入到MATLAB線上模式。您可以使用MATLAB驅動器輕鬆分享您的應用程式,並與其它線上使用者分享。

DG: There are a couple of ways to do this.One is by using MATLAB Online. MATLAB Online lets you run MATLAB in a desktopweb browser from any computer that has access to the internet. MATLAB Online isavailable with select licenses. Check your eligibility here. You create an appusing the desktop version of MATLAB and save it to your MATLAB Drive. To run the app in a webbrowser, use your MathWorks account to log onto MATLAB Online atmatlab.mathworks.com . You can use MATLAB Drive to easily share your app with anybody elsewho has access to MATLAB Online.

Chris Portal:另一種方法是使用MATLAB編譯器。在R2018a中,MATLAB編譯器引入了一個新的功能,允許您將App Designer應用程式打包為Web應用程式。在桌面上建立應用程式,使用MATLAB編譯器將其打包到Web上,並將編譯後的應用程式複製到您已經建立的MATLAB Web應用伺服器上。這樣,任何訪問伺服器的人都可以在Web瀏覽器中訪問相應的URL。即使不是MATLAB使用者,任何人都可以在瀏覽器中執行應用程式。這種方法對於共享應用程式來說是理想的,可以讓合作者通過Web瀏覽器輕鬆訪問。

CP: The other way is to use MATLABCompiler. In R2018a,MATLAB Compiler introduced a new feature that allows you to package AppDesigner apps as a web app. You create your app on the desktop, package it forthe web using MATLAB Compiler, and copy the compiled app to a MATLAB web appserver you’ve set up, which is also provided with MATLAB Compiler. This resultsin a URL that can be accessed in a web browser by anyone who has access to theserver. The benefit is anyone can run the app in a browser, even if they aren’tMATLAB users. This approach is ideal for sharing apps on-premise, forco-workers to access via a web browser.

使用者如何判斷哪種應用程式構建平臺適合他們?

How do users decide which app buildingplatform is right for them?

David Garrison:我們建議使用者採用App Designer開發所有新的應用程式,除非該應用程式需要在R2016a之前的MATLAB版本中執行。此外,使用者可以將以前基於GUIDE的應用程式通過遷移的方式移植到App Designer平臺。遷移將使您的應用程式更具現代感,並將您的應用程式部署到Web上成為可能。

DG: We recommend users start with AppDesigner for all new apps unless the app needs to run in a version of MATLABprior to R2016a.It is the platform we are continuously enhancing and expanding with eachrelease. We also think many users will benefit from migrating their GUIDE appsto App Designer using the migration tool that Chris mentioned. Migration willgive your app a more modern look and will make it possible to deploy your appto the Web.

Chris Portal:使用者可能會考慮繼續使用GUIDE,原因如下:

  1.  遷移工具對應用程式工作流程具有至關重要的限制,可能無法進行工作。
    
  2.  應用程式需要執行在舊版本的MATLAB上。
    
  3.  應用程式依賴於無文件記錄的Java功能,而AppDesigner並不支援該功能。
    

CP: Users might consider continuing to useGUIDE for the following reasons: The migration tool highlights a limitationthat is critical to the app’s workflow and cannot be worked around. The appneeds to run in older releases of MATLAB that predate App Designer’s release inR2016a. The app relieson the use of undocumented Java functionality that is not supported in AppDesigner.

更多精彩文章請關注微訊號:在這裡插入圖片描述