Excel 2013: Meldung “Das Bild ist zu groß und wird abgeschnitten” beim Schließen einer Datei

Man kann Excel 2013 und Powerpoint 2013 – bei mir in den Versionen von Office 365 – nicht eben als Verbesserungen bezeichnen.

In Powerpoint 2013 kann ich keine Grafik erstellen – es kommt immer der Wizard, man wählt einen Grafiktyp aus, und beim Klicken startet der Wizard wieder von vorne. Pff, könnte man sagen, wer braucht schon Grafiken in Powerpoint… Und falls doch, nehme man Office 2012. Dumm für alle, die keine Virtuellen Maschinen mit anderen Windows/Office-Kombinationen zur Verfügung haben. Die Frechheit ist eigentlich, dass Microsoft dafür gleich noch mehrfach Lizenzgebühren kassieren will. Ich würde ja die Fälligkeit von Lizenzgebühren an den Nachweis einer fehlerfreien Lieferung knüpfen. Wär doch mal ein sinnvolles Betätigungsfeld für die Regulierungswut der EU.

Excel 2013 ist spürbar instabiler als die Vorgängerversionen, und das kann ich als Power-User recht gut beurteilen. Es schmiert in der täglichen Arbeit gern und häufig ab, wobei sich meine tägliche Arbeit seit den Vorgänger-Versionen nicht groß verändert hat. Auch habe ich in verschiedenen Virtuellen Maschinen noch andere Windows/Office Kombinationen zur Verfügung – die sind wesentliche stabiler.

Worfür aber Excel auf den ersten Blick nichts kann: die Meldung “Das Bild ist zu groß und wird abgeschnitten” beim Schließen einer XLS?-Datei wird in der Tat von anderen Programmen verursacht – in meinem Fall von TeamViewer. Hier ist die Einstellung für das Synchronisieren der Zwischenablage verantwortlich. Im TeamViewer-Setup abgewählt – schon bleibt die kryptische Meldung aus.

Was die Ursachen anbelangt, so dürfte das Problem aber zweifellos bei Excel liegen, andere Software kann ihre Dateien öffnen und schließen ohne solche Meldungen. Microsoft putzt sich da in seinen Foren wieder mal an anderen ab, weil die Deaktivierung einer Funktion einer Fremdsoftware das Auslösen eines eigenen Fehlers vermeidet.

 

Nachtrag 04.10.2015:

An TeamViewer allein scheint es doch nicht zu liegen. Die Meldung ist ab und an wieder da.

Ich konnte es auch auf einem nagelneuen Windows 10 mit Office 365 reproduzieren – da gibt’s noch gar keinen TeamViewer oder sonst so was. Die Einordnung unter dem Tag “Office 2013 Scheiss” ist also mehr als gerechtfertigt.

PyCharm: Run All Unit Tests in a Folder/Package

My unit tests can be started individually from the context menu. I can also run all of them using something like

nosetests ./*tests.py

from within that specific folder containing the tests.

I played around a while with PyCharm to find a run configuration that actually allows me to runn all tests from all files within a folder at mouseclick.

Create a run configuration using Edit Configurations from the menu, add one with the ‘+’ sign and choose any python unittest that suits your needs from the list of options:

PyCharm Testrunner configuration

PyCharm Testrunner configuration

The tricky bit is the pattern. My test unit files all end in *tests.py – I played aroung ab bit, until the regex really worked:

^.*tests.py$
.*tests.py$
.*tests.py

I settled for the middle option, but all 3 work.

Setup bitbucket with PhpStorm or pyCharm

Get lastest connector from JetBrains and install as PhpStorm or PyCharm plugin.

Then create and set up your git in the main directory of the project:

It is a good idea to put down the things that should not be pushed to GIT, which is stored in a file called .gitignore:

touch .gitignore
gedit ./.gitignore

What the file looks like for a directory (vendor), a hidden file (.xyz) and all files with a given extension (all CSV-Files: *.csv):

/vendor
.xyz
*.csv

Then get GIT going with setup and first commit/push:

git init
git config --global user.email "xyz@xyz.zz"
git config --global user.name "Your Name"
git add .
git commit -m "message"
git remote add origin git@bitbucket.org:username/reponame.git
git remote set-url origin https://username@bitbucket.org/username/reponame.git
git push -u origin master

The usual routine to update the repository with the latest version is:

git add .
git commit -m "message"
git push -u origin master

Eloquent: Return Default Relation

Zum Beispiel: jeder User hat Rollen zugeordnet (unter Verwendung von Confide):
For example: each User has a Role (using Confide):

public function roles() {
        return $this->belongsToMany('Role', 'assigned_roles', 'user_id', 'role_id');
}

Wenn keine Rolle definiert ist, wie kann man trotzdem eine Default-Rolle zurück geben?
If no role is defined, how could we return a default role for this user?

Erster Schritt: einen User ‘default’ anlegen und dessen automatisch erzeugte id auf 0 setzen. Diesem User die niedrigste Rolle zuweisen (z.B. ‘Gast’).*
First step: add a User ‘default’ to the user table, change the id that is automatically assigned to 0. Assign the lowest role to this user (e.g. ‘guest’).*

Zweiter Schritt: wenn keine Rollen in der Relation gefunden werden, die Rolle des Users ‘default’ zurück geben.
Second step: if not roles are found in the relation, return the role for user ‘default’ instead:

public function roles() {
        $roles = $this->belongsToMany('Role', 'assigned_roles', 'user_id', 'role_id');
        if($roles == null || $roles->count() <= 0) {
            $def = User::find(0);
            return $def->roles();
        }
	    return $roles;
}


* Ein Id 0 kann allerdings nicht mit seed erzeugt werden, vielleicht ist 1 eine bessere Wahl. Oder statt find(0) mit where(‘name’, ‘=’, ‘default’) nach dem Namen suchen.
Unfortunately this change of id cannot be seeded – maybe you use 1 instead. Or use where(‘name’, ‘=’, ‘default’) instead of find(0).

R dplyr error ‘Each argument must yield either positive or negative integers’

It’s quite common in R to use the dplyr package for handling of dataframes.

I encountered an error that was not so obvious at first sight when using the select() to get a set of columns from the dataframe together with one_of(), which is passed a list of column names to return:

Error: Each argument must yield either positive or negative integers

The problem was: one of the column names was not spelled correctly and therefore not existing in the dataframe. So when select() tried to get the position indices of the columns requested, one returned NA… hence the message about integers.

PHPstorm: Einrichten eines neuen Projekts mit ide-helper

Zunächst ein neues Projekt auf der Basis von composer erzeugen.
Das Weitere nach barryvdh:

Require this package with composer using the following command:

composer require barryvdh/laravel-ide-helper
After updating composer, add the ServiceProvider to the providers array in app/config/app.php

'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
You can now re-generate the docs yourself (for future updates) in artisan

php artisan ide-helper:generate

Ferner fehlt noch die Integration von PHPunit für die Tests: Anleitung bei Culttt.

VirtualBox Ubuntu Guest: mount shares beim Booten

Ein einfacher Eintrag in die /etc/fstab sollte den Share <sharename> auf <zielverzeichnis> mounten:

sharename /zielverzeichnis vboxsf rw,uid=1000,gid=1000

Allerdings stellt sich dann beim Booten heraus, dass das Kernel-Modul vboxsf just zum Zeitpunkt, wo die Laufwerke aus der /etc/fstab eingehängt werden sollen, noch nicht zur Verfügung steht. Lösung: in die Datei /etc/modules als eigene Zeile eintragen:

vboxsf

Damit wird das Modul vorzeitig geladen und steht beim Einhängevorgang bereits zur Verfügung. Zusätzlich ist der user in die Gruppe vboxsf aufzunehmen:

sudo useradd vboxsf

DevExpress Move Focus on TAB Key Skipping Next Control

I have a UserControl containing a TextEdit and a CheckEdit; a row of these UCs are presented next to each other. TAB flow ist TextEdit to CheckEdit and then on to the next UC – but it wouldn’t make any difference if it was the other way round. Desired behaviour would be: if in TextEdit editor, on TAB key move to next UC’s TextEdit and into edit mode instead of focusing the CheckEdit – this would require the user to use two TABs to get to the next TextEdit to continue entering data. At least that is the expected flow of things my users would most likely do with that control.

To make things more complicated, we might be faced with both a simple TAB and a combined SHIFT-TAB, if we disregard CTRL and ALT as not relevant to our movement scenario. We would expect TAB to move on to the next control to the right, and the SHIFT-TAB to move on to previous control to the left.

First check the state of the keys pressed (I use a class to wrap the tab key status that is easier to handle and may be enriched in the future):

var key = new TabKey
{
	IsTab = (Keyboard.GetKeyStates(Key.Tab) & KeyStates.Down) > 0,
	IsShift = (Keyboard.Modifiers & ModifierKeys.Shift) > 0,
	IsControl = (Keyboard.Modifiers & ModifierKeys.Control) > 0
};

Keyboard, Key, KeyStates and ModifierKeys are available from System.Windows.Input.

To propagate another TAB or SHIFT-TAB we could use something like SendKeys. But there is also a mechanism for setting focus:

var keyboardFocus = Keyboard.FocusedElement as UIElement;
if (keyboardFocus != null)
{
	var tRequest = key.IsShift ?
		new TraversalRequest(FocusNavigationDirection.Previous) :
		new TraversalRequest(FocusNavigationDirection.Next);
	Dispatcher.BeginInvoke(new Action(() => keyboardFocus.MoveFocus(tRequest)));
}

Once we got the element that currently has the focus we may move on in both directions (FocusNavigationDirection would provide some more). By invoking this action more than once, we might move on more steps like multiply pressing TAB would do.

DevExpress TextEdit LostFocus event fires twice

Well, if you look at it closely, it’s not really the TextEdit itself that fires twice, but it delegates the editing to a Windows system TextBox, so it fires when that happens – and later again, when it really loses focus (see explanation and a workaround here).

I always use an _autoChange flag in my windows to stop events from firing when I set things by code, plus I found out I could catch all the RoutedEvents that do not come from a TextBox type. That helped reduce event calls.

Second problem I came across was: what if I had to use an Alert or MessageBox during handing of the event, say to inform a user of a problem with the data entered? Guess, you end up with an infinite loop of that event firing and firing… But I managed to stop that by using my internal OldValue / NewValue set, that usually goes to the EditorValueChanged event to inform any listerners about what was the change. By comparing for equality I could get out of that loop – no need to call any *Changed events, when the figures are equal anyway. This allows me to even use a MessageBox during the handling of that EditorValueChanged event: the TextEdit will lose focus, but it will not re-fire the event. Just once, when it’s first losing focus.

private void Editor_LostFocus(object sender, RoutedEventArgs e)
{
	if (_autoChange || e.OriginalSource.GetType() != typeof(System.Windows.Controls.TextBox)) return;
	var te = sender as TextEdit;
	if (te == null) return;
	_values.OldValue = EditorValue;
	_values.NewValue = new ValueBase(Convert.ToDecimal(te.EditValue.ToString()));
	if (_values.OldValue.ValueDecimal == _values.NewValue.ValueDecimal) return;
	_values.EditValue = _values.NewValue;
	var eva = new UniversalInplaceEditorChangedArgs { ValueSet = _values };
	_autoChange = true;
	if (EditorValueChanged != null) EditorValueChanged(this, eva);
	_autoChange = false;
}

A UserControl inheriting RepositoryItemTextEditor in a DevExpress Grid – Including Events

Having to get a RepositoryItemTextEditor behave as you would expect it to, sometimes can be cumbersome. I wanted a number format with a thousand separator plus two digits – AND I wanted the whole value to be selected once the editor was entered, not matter if this was by tabbing, mouse or programmatically.

After reading through some of the documentation and support issues I found out that a total of three events need to be handled to get the desired behaviour. Faced with six such editors in my grid I almost immediately decided to wrap wthings up in a UserControl editor.

My solution is based on this DevExpress documentation and my own experiments. Also, some googling was involved, but I can’t reproduce the details anymore.

So how do you extend a RepositoryItemTextEditor? First thing you need to know it is based on a TextEditor. When activated, the underlying TextEditor gets created. Therefore you need to inherit both of them – note the two classes in this definition: UniversalRepositoryItemTextEditMoney inheriting from RepositoryItemTextEdit and UniversalTextEditMoney inheriting from TextEdit:

    /**
    *     The RepositoryItemEditor
    */
    //The attribute that points to the registration method
    [UserRepositoryItem("Register")]
    public class UniversalRepositoryItemTextEditMoney : RepositoryItemTextEdit    // extend the type that best suites your needs
    {
        //The unique name for the custom editor
        public const string CustomEditorName = "UniversalRepositoryItemTextEditMoney";

        // a static constructor (I'm not sure what for)
        static UniversalRepositoryItemTextEditMoney()
        {
            Register();     // call the registration method on construction
        }

        public UniversalRepositoryItemTextEditMoney()
        {
            // some settings that are common, right here in the constructor
            base.Mask.MaskType = MaskType.Numeric;
            base.Mask.UseMaskAsDisplayFormat = true;
            base.Mask.EditMask = "n2";
        }
        
        //Return the unique type name
        public override string EditorTypeName { get { return CustomEditorName; } }

        //Register the editor
        public static void Register()
        {
            var ci = new EditorClassInfo(CustomEditorName,
                                         typeof (UniversalTextEditMoney),                         // the underlying editor, definition see below
                                         typeof (UniversalRepositoryItemTextEditMoney),           // the repository item itself
                                         typeof (TextEditViewInfo),                               // each of the editor types has its own view info, use the right one!
                                         new TextEditPainter(),                                   // use standard painter for TextEdit
                                         true,                                                    // design time visiblilty
                                         null,                                                    // an image for design time
                                         typeof (DevExpress.Accessibility.TextEditAccessible));   // accessibility information, be sure to use the right one
                                                                                                  // some more basic accessibility objects may be sealed 
                                                                                                  // and that results in a null pointer exception hard to find
            EditorRegistrationInfo.Default.Editors.Add(ci);
        }  
    }

    /**
    *  The Base Editor: required for the VS Toolbox
    */
    [ToolboxItem(true)]
    public class UniversalTextEditMoney : TextEdit
    {
        //The static constructor that calls the registration method
        static UniversalTextEditMoney() { UniversalRepositoryItemTextEditMoney.Register(); }

        //Initialize the new instance
        public UniversalTextEditMoney() { }

        //Return the unique name
        public override string EditorTypeName { get { return UniversalRepositoryItemTextEditMoney.CustomEditorName; } }

        //Override the Properties property
        //Simply type-cast the object to the custom repository item type
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public new UniversalRepositoryItemTextEditMoney Properties
        {
            get { return base.Properties as UniversalRepositoryItemTextEditMoney; }
        }
    }

Make sure to use your subclass type in all relevant places. The Base Editor class is only used once in the EditorClassInfo in the registration method. IN this case, I did not want entering the field by mouse to position the caret at any specific position within the number, instead all text should be selected for the user to start editing. I find this behaviour more according to non-specialist users expectations. Some tab, some click… besides, using the right and left keys you can move the caret to any position within the number.

In case there’s need for setting some properties in the context of the individual row and values at the time of creation, overriding the Assign method is the place to put that code.

And now for the Events part – there’s three of them required to implement the “select the whole number when starting to edit” behavior:

    [UserRepositoryItem("Register")]
    public class UniversalRepositoryItemTextEditMoney : RepositoryItemTextEdit
    {
        public const string CustomEditorName = "UniversalRepositoryItemTextEditMoney";

        private bool _enter;            // we need a flag indicating if we're in entering mode
        private bool _needSelect;       // and a flag to indicate if we need to select editor content

        static UniversalRepositoryItemTextEditMoney()
        {
            Register();
        }

        public UniversalRepositoryItemTextEditMoney()
        {
            base.Mask.MaskType = MaskType.Numeric;
            base.Mask.UseMaskAsDisplayFormat = true;
            base.Mask.EditMask = "n2";
            
            // register our events
            base.Enter += this_Enter;
            base.MouseUp += this_MouseUp;
            base.MouseDown += this_MouseDown;
        }

        // the event handlers
        public new event EventHandler Enter;
        public new event MouseEventHandler MouseUp;
        public new event MouseEventHandler MouseDown;
        
        public override string EditorTypeName
        {
            get { return CustomEditorName; }
        }
        
        public static void Register()
        {
            var ci = new EditorClassInfo(CustomEditorName,
                                         typeof (UniversalTextEditMoney),
                                         typeof (UniversalRepositoryItemTextEditMoney),
                                         typeof (TextEditViewInfo),
                                         new TextEditPainter(), true, null,
                                         typeof (DevExpress.Accessibility.TextEditAccessible));
            EditorRegistrationInfo.Default.Editors.Add(ci);
        } 
 
        // after we've handled our events we should forward these to everybody else in the chain, so we will need these
        private void OnEnter(EventArgs e)
        {
            if (Enter != null) Enter(this, e);
        }
        private void OnMouseUp(MouseEventArgs e)
        {
            if (MouseUp != null) MouseUp(this, e);
        }
        private void OnMouseDown(MouseEventArgs e)
        {
            if (MouseDown != null) MouseDown(this, e);
        }

        /**
        *   Handling the desired behaviour whether from mouse, tab or else.
        */
        private void ResetEnterFlag()
        {
            _enter = false;
        }

        // handling the this_Enter event
        private void this_Enter(object sender, EventArgs e)
        {
            _enter = true;
            var snd = sender as TextEdit;
                           // BeginInvoke with delegate insures the value is both set in EditorValue and displayed !
            if (snd != null) snd.BeginInvoke(new MethodInvoker(ResetEnterFlag)); 
            OnEnter(e);     // forward Event
        }

        // handling the this_MouseUp event
        private void this_MouseUp(object sender, MouseEventArgs e)
        {
            if (_needSelect)     // only when we come from a situation that requests selection
            {
                var snd = sender as TextEdit;
                if (snd != null) snd.SelectAll();
                OnMouseUp(e);       // forward Event
            }
        }

        // handling the this_MouseDown event
        private void this_MouseDown(object sender, MouseEventArgs e)
        {
            _needSelect = _enter;     // set the flag that we want selection when Mouse Button is going up again
            OnMouseDown(e);           // forward Event
        }
    }

    [ToolboxItem(true)]
    public class UniversalTextEditMoney : TextEdit
    {
        static UniversalTextEditMoney() { UniversalRepositoryItemTextEditMoney.Register(); }
        
        public UniversalTextEditMoney()
        {
        }
        
        public override string EditorTypeName { get { return UniversalRepositoryItemTextEditMoney.CustomEditorName; } }
        
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public new UniversalRepositoryItemTextEditMoney Properties
        {
            get { return base.Properties as UniversalRepositoryItemTextEditMoney; }
        }
    }

So now if we place this user control like any standard RepositoryItemTextEditor we find all the behaviour we want implemented: it displays bioth a thousand separator and two digits, plus it selects the whole number when entering edit mode.