How do I add a page to wxAUINoteBook? I wish to be able to click: File->New, and then have a new tab pop in. I understand how to do this using wxAuiMDIChildFrame within a parent frame but the child frame is a class on its own and a new page is not. Here is what I have so far.
#include "main.h"
MyFrame::MyFrame()
: wxFrame(nullptr, wxID_ANY, "AUItest", wxPoint(50, 50), wxSize(800, 450), wxDEFAULT_FRAME_STYLE)
{
wxMenuBar* menubar = new wxMenuBar;
wxMenu* menufile = new wxMenu;
menufile->Append(1001, "New");
menufile->Append(1002, "Open");
menufile->Append(1003, "Save");
menufile->Append(1004, "Exit");
menubar->Append(menufile, "File");
SetMenuBar(menubar);
wxAuiNotebook* notebook = new wxAuiNotebook(this, -1, wxPoint(-1, -1),
wxSize(-1, -1), wxNB_TOP | wxAUI_NB_CLOSE_ON_ACTIVE_TAB);
wxPanel* panel1 = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
wxPanel* panel2 = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
wxPanel* panel3 = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
notebook->AddPage(panel1, wxT("Sheet1"));
notebook->AddPage(panel2, wxT("Sheet2"));
notebook->AddPage(panel3, wxT("Sheet3"));
Center();
}
MyFrame::~MyFrame()
{
}
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(1001, MyFrame::OnMenuNew)
EVT_MENU(1002, MyFrame::OnMenuOpen)
EVT_MENU(1003, MyFrame::OnMenuSave)
EVT_MENU(1004, MyFrame::OnMenuExit)
wxEND_EVENT_TABLE()
void MyFrame::OnMenuNew(wxCommandEvent& event)
{
//How do I add a page on command?
}
void MyFrame::OnMenuOpen(wxCommandEvent& event)
{
}
void MyFrame::OnMenuSave(wxCommandEvent& event)
{
}
void MyFrame::OnMenuExit(wxCommandEvent& event)
{
Close(true);
event.Skip();
}
Thanks for the help,
I'm still learning.
Related
I am trying to create a small application which displays an Image that you selected in a File chooser. It should then resize when the user resizes the window.
My app works up to the point where I add this code to the constructor of my class which should give the image the ability to resize when the window is resized.
window.size_allocate.connect(() => {
resize_image(); //<-- a problem
});
this "should" call the method resize_image when the window changes its size but everytime I add this code, my virtual machine on which I run elementary os crashes and stops working ( I have to restart everytime I try to run my program).
the method resize_image() works as following:
public void resize_image()
{
try
{ if(buf.get_width() < window.get_allocated_width()){
buf = buf.scale_simple(window.get_allocated_width(), window.get_allocated_width(), Gdk.InterpType.NEAREST);
image.set_from_pixbuf(buf);
}
}catch(Error e)
{
}
}
(I know that my resizing "alogrithm" isnt the best yet but I just used this method for testing.)
Now my question:
Why is my program crashing? Is the conversion from pixbuf to image too slow for the user?
Is there another way to resize the image to the window size?
Any help would be appreciated :)
The trick here is to add a layout and set the resize callback not to the window but to the layout. It's not perfect, it's a bit dirty but works. Initial positioning not working good but there's rooms to improvement.
Must check Gtk.Widget and Gtk.Containers for requested, allocated and natural sizes or even use Gdk methods. Getting late, hope this will lead you in the right direction.
PS: I'm using a endless.png image but feel free to use another one, just change the code to reflect it.
using Gtk;
public int main (string[] args) {
Gtk.Image image;
Gtk.Layout layout;
Gtk.Window window;
Gdk.Pixbuf pixbuf;
Gtk.init (ref args);
window = new Gtk.Window ();
layout = new Gtk.Layout ();
image = new Gtk.Image ();
try {
pixbuf = new Gdk.Pixbuf.from_file ("endless.png");
image = new Gtk.Image.from_pixbuf (pixbuf);
layout.put (image, 0,0);
window.add (layout);
layout.size_allocate.connect ((allocation) => {
print ("Width: %d Height: %d\n", allocation.width, allocation.height);
var pxb = pixbuf.scale_simple (allocation.width, allocation.height, Gdk.InterpType.BILINEAR);
image.set_from_pixbuf (pxb);
});
window.destroy.connect (Gtk.main_quit);
window.show_all ();
Gtk.main ();
return 0;
} catch (Error e) {
stderr.printf ("Could not load file...exit (%s)\n", e.message);
return 1;
}
}
EDIT:
A simple cairo version:
using Gtk;
using Cairo;
public int main (string[] args) {
Cairo.ImageSurface image;
image = new Cairo.ImageSurface.from_png ("endless.png");
Gtk.init (ref args);
var window = new Gtk.Window ();
var darea = new DrawingArea ();
window.add (darea);
window.show_all ();
darea.draw.connect ((cr) => {
float xscale;
float yscale;
cr.save ();
xscale = (float) darea.get_allocated_width () / image.get_width ();
yscale = (float) darea.get_allocated_height () / image.get_height ();
cr.scale (xscale, yscale);
cr.set_source_surface (image, 0, 0);
cr.paint ();
cr.restore ();
return true;
});
window.destroy.connect (Gtk.main_quit);
Gtk.main ();
return 0;
}
EDIT 2:
I've created another version to toggle between 2 images and check if while doing this quite a few times and check if the memory increases, but it does not. Added a couple of Boxes, and added 2 buttons.
using Gtk;
using Cairo;
public int main (string[] args) {
Cairo.ImageSurface image;
image = new Cairo.ImageSurface.from_png ("endless.png");
Gtk.init (ref args);
var window = new Gtk.Window ();
var box1 = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
var box2 = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
var b1 = new Gtk.Button.with_label ("Image1");
var b2 = new Gtk.Button.with_label ("Image2");
box2.pack_start (b1, true, true, 0);
box2.pack_end (b2, true, true, 0);
var darea = new DrawingArea ();
box1.pack_start (box2, false, false, 0);
box1.pack_end (darea, true, true, 0);
window.add (box1);
window.show_all ();
b1.clicked.connect (() => {
image = new Cairo.ImageSurface.from_png ("endless.png");
darea.queue_draw ();
});
b2.clicked.connect (() => {
image = new Cairo.ImageSurface.from_png ("Gnome-logo.png");
darea.queue_draw ();
});
darea.draw.connect ((cr) => {
float xscale;
float yscale;
cr.save ();
xscale = (float) darea.get_allocated_width () / image.get_width ();
yscale = (float) darea.get_allocated_height () / image.get_height ();
cr.scale (xscale, yscale);
cr.set_source_surface (image, 0, 0);
cr.paint ();
cr.restore ();
return true;
});
window.destroy.connect (Gtk.main_quit);
Gtk.main ();
return 0;
}
I am working on a eclipse plugin and implementing a custom launcher as per the link https://eclipse.org/articles/Article-Launch-Framework/launch.html .
I have implemented a class BrowsersTab which extends AbstractLaunchConfigurationTab and implemented all the methods. The problem is that when I call the updateLaunchConfigurationDialog(); on the selection event , the 'Apply' Button remains disabled.
Code :
public class BrowsersTab extends AbstractLaunchConfigurationTab {
private Button chrome;
private Button firefox;
private Button safari;
private Button ie;
private Button opera;
private Button android;
private Button ios;
#Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
setControl(comp);
GridLayout topLayout = new GridLayout();
comp.setLayout(topLayout);
Group fGroup = new Group(comp, SWT.NONE);
fGroup.setFont(parent.getFont());
fGroup.setLayout(new GridLayout(2, true));
fGroup.setText(DialogMessages.browserSelection);
chrome = new Button(fGroup, SWT.CHECK);
chrome.setText("Google Chrome");
chrome.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
System.out.println("chrome selected");
updateLaunchConfigurationDialog();
}
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
});
Image chromeIcon= getBrowserIcon("chrome-browser-24X24.png");
if(null!=chromeIcon)
chrome.setImage(chromeIcon);
Combo comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
firefox = new Button(fGroup, SWT.CHECK);
firefox.setText("Mozilla Firefox");
Image firefoxIcon= getBrowserIcon("Firefox-icon.png");
if(null!=firefoxIcon)
firefox.setImage(firefoxIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
safari = new Button(fGroup, SWT.CHECK);
safari.setText("Apple Safari");
Image safariIcon= getBrowserIcon("Safari-icon.png");
if(null!=safariIcon)
safari.setImage(safariIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
ie = new Button(fGroup, SWT.CHECK);
ie.setText("Internet Explorer");
Image ieIcon= getBrowserIcon("Internet-Explorer-icon.png");
if(null!=ieIcon)
ie.setImage(ieIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
opera= new Button(fGroup, SWT.CHECK);
opera.setText("Opera");
Image operaIcon= getBrowserIcon("browser-opera-icon.png");
if(null!=operaIcon)
opera.setImage(operaIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
android= new Button(fGroup, SWT.CHECK);
android.setText("Android");
Image androidIcon= getBrowserIcon("android-platform-icon.png");
if(null!=androidIcon)
android.setImage(androidIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
ios= new Button(fGroup, SWT.CHECK);
ios.setText("Mobile Safari");
Image iosIcon= getBrowserIcon("Apple-grey-icon.png");
if(null!=iosIcon)
ios.setImage(iosIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
}
#Override
public String getName() {
return "Browsers";
}
public Image getBrowserIcon(String name){
Image icon=null;
try {
icon = AbstractUIPlugin.imageDescriptorFromPlugin("SuitACore","icons/"+name).createImage();
} catch (Exception e) {
// Swallow it; we'll do without images
}
return icon;
}
public Image getImage() {
Image tab=null;
try {
tab = AbstractUIPlugin.imageDescriptorFromPlugin("SuitACore","icons/browser.png").createImage();
} catch (Exception e) {
// Swallow it; we'll do without images
}
return tab;
}
public void initializeFrom(ILaunchConfiguration configuration) {
try {
List<String> browsersDefaults = new ArrayList<String>();
browsersDefaults.add("chrome");
List<String> browsers =configuration.getAttribute("browsers", browsersDefaults);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
chrome.setSelection(true);
}
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
List<String> browsers = new ArrayList<String>();
browsers.add("chrome");
configuration.setAttribute("browser",browsers );
}
public void setDefaults(ILaunchConfigurationWorkingCopy arg0) {
}
}
You must call updateLaunchConfigurationDialog() whenever anything changes that might update the Apply button - so all checkboxes and combos.
You must also save everything that changes in the ILaunchConfigurationWorkingCopy in the performApply method. The Apply button state is determined by checking that the working copy is different from the original configuration.
Can someone explain me how to maintain data in array list during the running of app. Let say we have three classes. The main class run the app and the button "Save" add the data in the second class where is declared the private array list. Then when we added the data in array list , we click the button "Next scene". When is opened the second stage which is the third class, there is button "Show", that should show the data which were added in the first class, but it threw error that the array list is empty.
Code:
First class
public void start(Stage primaryStage) {
final Button btn = new Button();
btn.setLayoutX(121);
btn.setLayoutY(125);
btn.setText("Save");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
array.insert(20);
}
});
final Button btn_next = new Button();
btn_next.setLayoutX(btn.getLayoutY());
btn_next.setLayoutY(btn.getLayoutX() + 54);
btn_next.setText("Next Scene");
btn_next.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
secondStage.start();
}
});
Pane root = new Pane();
root.getChildren().add(btn);
root.getChildren().add(btn_next);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Exercise");
primaryStage.setScene(scene);
primaryStage.show();
}
Second class
public class ArrayListClass {
private ArrayList <Integer> array = new ArrayList<>();
private ObservableList name_obs = FXCollections.observableArrayList(array);
public void insert(int maxBound) {
for(int i = 0; i < maxBound; i++) {
name_obs.add(i);
}
}
public Integer show(int i) {
return (Integer) name_obs.get(i);
}
}
Third class
public class SecondStage {
private Stage secondaryStage = new Stage();
ArrayListClass array = new ArrayListClass();
public void start() {
Button btn= new Button();
btn.setText("Show");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println(array.show(5));
}
}
);
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
secondaryStage.setTitle("Exercise");
secondaryStage.setScene(scene);
secondaryStage.show();
}
}
ERROR:
Executing /Users/Jenda/NetBeansProjects/ExerciseArrayList/dist/run542796410/ExerciseArrayList.jar using platform /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/bin/java
Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index: 5, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at com.sun.javafx.collections.ObservableListWrapper.get(ObservableListWrapper.java:89)
at exercisearraylist.ArrayListClass.show(ArrayListClass.java:36)
at exercisearraylist.SecondStage$1.handle(SecondStage.java:36)
at exercisearraylist.SecondStage$1.handle(SecondStage.java:31)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8216)
at javafx.scene.control.Button.fire(Button.java:185)
I'm using windows default setting flyout adding some custom commands. But now I need to open a HTML file that is stored locally ? how can I do that ?
Second thing i want to move my flyout code from app.xaml.cs to app.xaml
Any help will be appreciated
Below is my code :
protected override void OnInitialize(IActivatedEventArgs args){
SettingsPane.GetForCurrentView().CommandsRequested += App_CommandsRequested;
}
void App_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
SettingsCommand settingsCommand = new SettingsCommand(
"About",
"About",
command =>
{
var flyout = new SettingsFlyout();
flyout.Title = "About";
string file = "ms-appx-web:///assets/about/about.html";
flyout.Show();
}
);
args.Request.ApplicationCommands.Add(settingsCommand);
}
As for your first question, YES you can definitely open a locally stored HTML page in the Settings Flyout.
Below is the your sample which I modified a little bit:
private void App_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
SettingsCommand settingsCommand = new SettingsCommand(
"About",
"About",
command =>
{
var flyout = new SettingsFlyout();
flyout.Title = "About";
WebView wView = new WebView();
wView.Height = 700;
wView.Width = 300;
wView.Navigate(new Uri("ms-appx-web:///assets/About.html", UriKind.Absolute));
flyout.Content = wView;
flyout.Show();
}
);
args.Request.ApplicationCommands.Add(settingsCommand);
}
Not sure of the second part of your question. Perhaps you should put a separate question.
I generated a JDialog w/ JFormDesigner, but I don't know how to display it. Here is the code:
public class FinishPopup extends JDialog {
public FinishPopup(Frame owner) {
super(owner);
initComponents();
}
public FinishPopup(Dialog owner) {
super(owner);
initComponents();
}
public void initComponents() {
dialogPane = new JPanel();
contentPanel = new JPanel();
label1 = new JLabel();
label2 = new JLabel();
buttonBar = new JPanel();
okButton = new JButton();
label3 = new JLabel();
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
{
{
label1.setText("Money: ");
label1.setFont(new Font("Tahoma", Font.PLAIN, 12));
label2.setText("Time");
label2.setFont(new Font("Tahoma", Font.PLAIN, 12));
GroupLayout contentPanelLayout = new GroupLayout(contentPanel);
contentPanel.setLayout(contentPanelLayout);
contentPanelLayout.setHorizontalGroup(
contentPanelLayout.createParallelGroup()
.addGroup(contentPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(label2)
.addGap(90, 90, 90)
.addComponent(label1)
.addContainerGap(105, Short.MAX_VALUE))
);
contentPanelLayout.setVerticalGroup(
contentPanelLayout.createParallelGroup()
.addGroup(contentPanelLayout.createSequentialGroup()
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label2)
.addComponent(label1))
.addContainerGap())
);
}
dialogPane.add(contentPanel, BorderLayout.CENTER);
{
buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
buttonBar.setLayout(new GridBagLayout());
((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 80};
((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0};
okButton.setText("OK");
buttonBar.add(okButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
}
dialogPane.add(buttonBar, BorderLayout.SOUTH);
label3.setText("Finished");
label3.setFont(new Font("Tahoma", Font.BOLD, 14));
dialogPane.add(label3, BorderLayout.NORTH);
}
contentPane.add(dialogPane, BorderLayout.CENTER);
pack();
setLocationRelativeTo(getOwner());
}
private JPanel dialogPane;
private JPanel contentPanel;
private JLabel label1;
private JLabel label2;
private JPanel buttonBar;
private JButton okButton;
private JLabel label3;
}
How do I create and show it? thanks.
You need to first create an instance of the class and then call setVisible to make it visible
// owner is reference to the parent frame or dialog. May be null, but you'll
// need to cast it
FinishPopup popup = new FinishPopup(owner);
popup.setVisible(true);
You may also find setLocationRelativeTo helpful