Beispiel #1
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            var widgetName = Utils.GetSafeString(args, 0);
            var widget     = CSCS_GUI.GetWidget(widgetName);

            if (widget == null)
            {
                return(Variable.EmptyInstance);
            }

            if (widget is ListView)
            {
                Variable selectedItems = new Variable(Variable.VarType.ARRAY);
                var      listView      = widget as ListView;
                var      sel           = listView.SelectedItems;
                int      total         = sel.Count;
                for (int i = 0; i < total; i++)
                {
                    var item = sel[i];
                    selectedItems.AddVariable(new Variable(item.Text));
                }
                return(selectedItems);
            }

            return(GetTextWidgetFunction.GetText(widget));
        }
Beispiel #2
0
        public static void AddWidget(Control control, string widgetName, string callback = "")
        {
            CacheControls();

            if (s_tabControl != null && s_tabPages.Count > 0)
            {
                int index     = widgetName.IndexOf('.');
                var widgetTab = index > 0 && index < widgetName.Length - 1 ? widgetName.Substring(0, index) : "";
                widgetName   = index > 0 && index < widgetName.Length - 1 ? widgetName.Substring(index + 1) : widgetName;
                control.Name = widgetName;

                TabPage tabPage;
                if (string.IsNullOrEmpty(widgetTab) || !s_tabPages.TryGetValue(widgetTab, out tabPage))
                {
                    tabPage = s_tabControl.TabPages[0];
                }
                tabPage.Controls.Add(control);
            }
            else
            {
                control.Name = widgetName;
                TheForm.Controls.Add(control);
            }

            Controls[widgetName] = control;
            CSCS_GUI.AddActions(control, callback);
        }
Beispiel #3
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            var widgetName = Utils.GetSafeString(args, 0);
            var widget     = CSCS_GUI.GetWidget(widgetName);

            if (widget == null)
            {
                return(Variable.EmptyInstance);
            }

            if (m_showWidget)
            {
                widget.Show();
            }
            else
            {
                widget.Hide();
            }

            return(new Variable(true));
        }
Beispiel #4
0
        protected override Variable Evaluate(ParsingScript script)
        {
            string          widgetName = Utils.GetToken(script, Constants.TOKEN_SEPARATION);
            List <Variable> args       = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);
            var data = args[0];

            var widget     = CSCS_GUI.GetWidget(widgetName);
            var itemsAdded = 0;

            if (widget is ComboBox)
            {
                var combo = widget as ComboBox;
                if (data.Type == Variable.VarType.ARRAY)
                {
                    foreach (var item in data.Tuple)
                    {
                        combo.Items.Add(item.AsString());
                    }
                    itemsAdded = data.Tuple.Count;
                }
                else
                {
                    combo.Items.Add(data.AsString());
                    itemsAdded = 1;
                }
            }
            else if (widget is ListView)
            {
                ListView listView = widget as ListView;
                if (data.Type == Variable.VarType.ARRAY && data.Tuple.Count > 0)
                {
                    ListViewItem viewItem = new ListViewItem(data.Tuple[0].AsString());
                    for (int i = 1; i < data.Tuple.Count; i++)
                    {
                        viewItem.SubItems.Add(data.Tuple[i].AsString());
                    }
                    listView.Items.Add(viewItem);
                    itemsAdded = data.Tuple.Count;
                }
                else
                {
                    var          dataItems = data.AsString().Split(',');
                    ListViewItem viewItem  = new ListViewItem(dataItems[0]);
                    for (int i = 1; i < dataItems.Length; i++)
                    {
                        viewItem.SubItems.Add(dataItems[i]);
                    }
                    listView.Items.Add(viewItem);
                    itemsAdded = dataItems.Length;
                }
            }

            return(new Variable(itemsAdded));
        }
Beispiel #5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            CSCS_SQL.Init();
            CSCS_GUI.TheForm = new Form1();
            CSCS_GUI.RunScript("../../scripts/start.cscs");

            Application.Run(CSCS_GUI.TheForm);
        }
Beispiel #6
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            var  widgetName = Utils.GetSafeString(args, 0);
            bool removed    = CSCS_GUI.RemoveWidget(widgetName);

            return(new Variable(removed));
        }
Beispiel #7
0
        public static Variable SetColor(string widgetName, int argb)
        {
            var widget = CSCS_GUI.GetWidget(widgetName);

            if (widget == null)
            {
                return(Variable.EmptyInstance);
            }
            widget.BackColor = Color.FromArgb(argb);
            return(new Variable(argb));
        }
Beispiel #8
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            var  tabName = Utils.GetSafeString(args, 0);
            bool added   = CSCS_GUI.AddTab(tabName);

            return(new Variable(added));
        }
Beispiel #9
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 2, m_name);

            var widgetName = Utils.GetSafeString(args, 0);
            var text       = Utils.GetSafeString(args, 1);

            var widget = CSCS_GUI.GetWidget(widgetName);

            if (widget == null)
            {
                return(Variable.EmptyInstance);
            }

            if (widget is ComboBox)
            {
                var combo = widget as ComboBox;
                var index = 0;
                if (args[0].Type == Variable.VarType.NUMBER)
                {
                    index = (int)args[0].Value;
                }
                else
                {
                    foreach (var item in combo.Items)
                    {
                        if (item.ToString() == text)
                        {
                            break;
                        }
                        index++;
                    }
                }
                if (index >= 0 && index < combo.Items.Count)
                {
                    combo.SelectedIndex = index;
                }
            }
            else if (widget is CheckBox)
            {
                var checkBox = widget as CheckBox;
                checkBox.Checked = text == "1" || text.ToLower() == "true";
            }
            else
            {
                widget.Text = text;
            }

            return(new Variable(true));
        }
Beispiel #10
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 3, m_name);

            var widgetName = Utils.GetSafeString(args, 0);
            var x          = Utils.GetSafeInt(args, 1);
            var y          = Utils.GetSafeInt(args, 2);

            var widget = CSCS_GUI.GetWidget(widgetName);

            if (widget == null)
            {
                return(Variable.EmptyInstance);
            }
            widget.Size = new Size(x, y);

            return(new Variable(true));
        }
Beispiel #11
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 2, m_name);

            var widgetName = Utils.GetSafeString(args, 0);
            var bgColor    = Utils.GetSafeString(args, 1);
            var fgColor    = Utils.GetSafeString(args, 2, "black");

            var widget = CSCS_GUI.GetWidget(widgetName);

            if (widget is ListView)
            {
                ListView listView  = widget as ListView;
                Color    backColor = StringToColor(bgColor);
                Color    foreColor = StringToColor(fgColor);
                ColorListViewHeader(ref listView, backColor, foreColor);
            }

            return(new Variable(true));
        }
Beispiel #12
0
        public static bool RemoveWidget(string widgetName)
        {
            Control control;

            if (s_tabControl != null && s_tabPages.Count > 0)
            {
                int index     = widgetName.IndexOf('.');
                var widgetTab = index > 0 && index < widgetName.Length - 1 ? widgetName.Substring(0, index) : "";
                widgetName = index > 0 && index < widgetName.Length - 1 ? widgetName.Substring(index + 1) : widgetName;

                TabPage tabPage;
                if (string.IsNullOrEmpty(widgetTab) || !s_tabPages.TryGetValue(widgetTab, out tabPage))
                {
                    tabPage = s_tabControl.TabPages[0];
                }
                control = CSCS_GUI.GetWidget(widgetName);
                if (control == null)
                {
                    return(false);
                }
                tabPage.Controls.Remove(control);
            }
            else
            {
                control = CSCS_GUI.GetWidget(widgetName);
                if (control == null)
                {
                    return(false);
                }
                TheForm.Controls.Remove(control);
            }

            s_actionHandlers.Remove(widgetName);
            Controls.Remove(widgetName);
            control.Dispose();

            return(true);
        }
Beispiel #13
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name);

            var widgetName = Utils.GetSafeString(args, 0);
            var x          = Utils.GetSafeInt(args, 1);
            var y          = Utils.GetSafeInt(args, 2);

            var widget = CSCS_GUI.GetWidget(widgetName);

            if (widget == null)
            {
                return(Variable.EmptyInstance);
            }

            var sizes = new List <double>();

            sizes.Add(widget.Size.Width);
            sizes.Add(widget.Size.Height);

            return(new Variable(sizes));
        }
Beispiel #14
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 7, m_name);

            var widgetName = Utils.GetSafeString(args, 0);
            var widgetType = Utils.GetSafeString(args, 1).ToLower();
            var text       = Utils.GetSafeString(args, 2);
            var x          = Utils.GetSafeInt(args, 3);
            var y          = Utils.GetSafeInt(args, 4);
            var width      = Utils.GetSafeInt(args, 5);
            var height     = Utils.GetSafeInt(args, 6);
            var callback   = Utils.GetSafeString(args, 7);

            Control control = null;

            switch (widgetType)
            {
            case "button":
                var button = new Button();
                button.UseVisualStyleBackColor = true;
                control = button;
                break;

            case "checkbox":
                var checkbox = new CheckBox();
                control = checkbox;
                break;

            case "label":
                var label = new Label();
                control = label;
                break;

            case "textbox":
                var textBox = new TextBox();
                control = textBox;
                break;

            case "listview":
                var listView = new ListView();
                listView.View               = View.Details;
                listView.Bounds             = new Rectangle(new Point(x + 2, y + 2), new Size(width - 4, height - 4));
                listView.AllowColumnReorder = true;
                //listView.CheckBoxes = true;
                listView.FullRowSelect = true;
                listView.GridLines     = true;
                //listView.Sorting = SortOrder.Ascending;
                if (args[2].Type == Variable.VarType.ARRAY && args[2].Tuple.Count > 0)
                {
                    int colWidth = width / args[2].Tuple.Count - 1;
                    for (int i = 0; i < args[2].Tuple.Count; i++)
                    {
                        listView.Columns.Add(args[2].Tuple[i].AsString(), colWidth, HorizontalAlignment.Left);
                    }
                }
                else
                {
                    var dataItems = text.Split(',');
                    for (int i = 0; i < dataItems.Length; i++)
                    {
                        listView.Columns.Add(dataItems[i], -2, HorizontalAlignment.Left);
                    }
                }
                control = listView;
                break;
            }

            if (control == null)
            {
                return(Variable.EmptyInstance);
            }

            control.Location = new System.Drawing.Point(x, y);
            control.Text     = text;
            control.Size     = new System.Drawing.Size(width, height);

            CSCS_GUI.AddWidget(control, widgetName, callback);

            return(new Variable(true));
        }