Sunday 23 August 2020

Dell Inspiron 13 7373. P83G Fix

My Dell PC would not start. The fix is a hard reset. Which means removing the PSU. Opening the case. Powering down for 20 seconds by pressing the power on. Removing the battery and replacing it. Symptom: The battery appears drained. Plugging in PSU, then pressing ON switch the keys backlight for 1 second then it's dead again. Fix: is to do a 'hard reset'.

Get your safety gear, which means earth your body with a wrist attachment. At the very least replace any nylon clothing you're wearing with cotton. If you use reading glasses make sure you have them at hand. Remove 10 screws at the rear. The single screw in the center is slightly different to the other 9 screws around the edges. The center screw was hidden under a sticker which reads "WARRANTY VOID IF TAMPERED WITH OR REMOVED". There are no screws under the plastic 'feet'. Use thin piece of card or plasic to slowly lever out the back case. I used an old thin card train ticket did it for me. I began this at the back right (near the power button). A guitar plectrum also works but a credit card is too thick. Work along the back first, then the sides. Drain the power by holding the power button down for 15 to 20 seconds. Unscrew the battery. Unscrew 4 screws holding the battery in place, which is labelled "Type F62G0 11.4V" The fix did not work.

Dell Inspiron 13 7000 P83G Will Not Wake After Sleep

I have a model laptop listed about. I have tried the most recent BIOS update, defaulting the BIOS settings, Checking all the power settings, Installing the newest update of Intel Management Interface Engine, Disabling the Intel Management Interface, and disabling Fast Startup in settings. Turned on Wake from USB, and disabled USB Selective Sleep settings. The PC still will not wake up after entering sleep mode and must be forced shutdown and turned back on.

Sunday 19 July 2020

GIMP keyboard shortcuts

In this list you can see most important hotkeys for the GIMP under Linux (most of them work on Windows as well). All keys can be individually assigned: File / Preferences / Interface / Hotkeys.

Help
HelpF1
Context HelpShift+F1
Toolbox
Rect SelectR
Ellipse SelectE
Free SelectF
Fuzzy SelectU
Select By ColorShift+O
ScissorsI
PathsB
Color PickerO
MoveM
Crop and ResizeShift+C
RotateShift+R
ScaleShift+T
ShearShift+S
PerspectiveShift+P
FlipShift+F
TextT
Bucket FillShift+B
BlendL
PencilN
PaintbrushP
EraserShift+E
AirbrushA
InkK
CloneC
ConvolveV
SmudgeS
Dodge/BurnShift+D
Swap ColorsX
Default ColorsD
File
New imageCtrl+N
Open imageCtrl+O
Open image as new layerCtrl+Alt+O
Duplicate imageCtrl+D
Open recent image 01Ctrl+1
Open recent image 02Ctrl+2
Open recent image 03Ctrl+3
Open recent image 04Ctrl+4
Open recent image 05Ctrl+5
Open recent image 06Ctrl+6
Open recent image 07Ctrl+7
Open recent image 08Ctrl+8
Open recent image 09Ctrl+9
Open recent image 10Ctrl+0
Save imageCtrl+S
Save under a new nameShift+Ctrl+S
QuitCtrl+Q
Dialogs
LayersCtrl+L
BrushesShift+Ctrl+B
PatternsShift+Ctrl+P
GradientsCtrl+G
Tool-OptionsShift+Ctrl+T
PalettesCtrl+P
Info windowShift+Ctrl+I
Navigation windowShift+Ctrl+N
Close the windowAlt+F4
Jump to next widgetTab
Jump to previous widgetShift+Tab
Set the new valueEnter
Activate current button or listSpace
In a multi-tab dialog, switch tabsCtrl+Alt+PgUp
Open LocationShift+L
Up-FolderAlt+ up
Down-FolderAlt+ down
Home-FolderAlt+Home
Close DialogEsc
View
Main MenuF10
Drop-down MenuShift+F10
Toggle fullscreenF11
Toggle quickmaskShift+Q
Close document windowCtrl+W
Zoom in+ or Ctrl+Mousewheel
Zoom out- or Ctrl+Mousewheel
Zoom 1:11
Shrink wrapCtrl+E
Fit image in windowShift+Ctrl+E
Toggle rulersShift+Ctrl+R
Toggle guidesShift+Ctrl+T
Edit
UndoCtrl+Z
RedoCtrl+Y
Copy selectionCtrl+C
Cut selectionCtrl+X
Copy visibleCtrl+Shift+C
Paste as new imageCtrl+Shift+V
Paste clipboardCtrl+V
Clears selectionCtrl+K
Named copy selectionShift+Ctrl+C
Named cut selectionShift+Ctrl+X
Named paste clipboardShift+Ctrl+V
Fill with FG ColorCtrl+,
Fill with BG ColorCtrl+.
Fill with PatternCtrl+:
Layers
Select the layer abovePgUp
Select the layer belowPgDn
Select the first layerHome
Select the last layerEnd
Merge visible layersCtrl+M
Anchar layerCtrl+H
Selections
Toggle selectionsCtrl+T
Select allCtrl+A
Select noneShift+Ctrl+A
Invert selectionCtrl+I
Float selectionShift+Ctrl+L
Path to selectionShift+V
Plug-ins
Repeat last plug-inCtrl+F
Reshow last plug-inShift+Ctrl+F

Sunday 23 February 2020

Dell Inspiron - Locked out due to BitLocker

I recently made some tiny changes to my Dell Inspiron BIOS. Silly me. Computer would not reboot. It demanded I enter a 48-digit BitLocker key. It was news to me I'd encrypted the drive with BitLocker. It's not something I'd naturally do because I'd expect to turn the laptop into a dual boot Windows/Linux, and I'm not sure Linux can understand BitLocker. Given I don't remember switching BitLocker on, I guess I must've bought it with BitLocker already installed.

It seems changing the BIOS activates the security system. The solution to the issue is:

  1. You're looking at a blue screen demanding you enter your BitLocker key:
  2. Click “Skip this drive”
  3. Click “Troubleshoot”
  4. Click “Advanced Options”
  5. Click “UEFI Firmware Settings”
  6. Click “Restart” – You will restart and enter the BIOS for your computer. The BIOS interface is different for every computer. In my case, it looked nothing like in the above video, and doing subsequent steps in the above video did not work. Doing the following DID work:
  7. Click “Restore Settings” button on the bottom of the Dell BIOS screen. Also see here if this setting is not evident.
  8. Click Restore “Factory Defaults”
  9. Save settings and the computer will reboot. In my case, BitLocker prompt screen is now gone and Windows boots normally.

Tuesday 12 March 2019

[ReactiveUI] Bind enum to Radio button list using a ListBox

This is an incomplete blog. The code is broke. It's the code I wrote out to ask a technical question. As often I figured it out when I wrote it all out clearly! I've yet to put the corrected code in here! I found it in an editor tab. Rather than toss it away I'll put the working version here. Because the errors I got when it was broke are nested exceptions, which are themselves cryptic.

When your radio buttons depend on something like a enum or a class.

I have a ListBox of RadioButtons and want the Selected RadioButton to bubble up such that the ListBox SelectedItem is the one clicked. Can't see what I'm doing wrong.

View:

  <ListBox x:Name="lstRecordTypes">
    <ListBox.ItemContainerStyle>
      <Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type ListBoxItem}">
              <RadioButton 
                    Content="{Binding Display}"
                    ToolTip="{Binding Display}"
                    IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=IsSelected}"/>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
        <Setter Property="Margin" Value="5"/>
      </Style>
    </ListBox.ItemContainerStyle>
  </ListBox>
        public MyView()
        {
            InitializeComponent();
            this.WhenActivated(disposables => this.BindControls(disposables));
        }

        private void BindControls(CompositeDisposable disposableRegistration)
        {
            this.WhenAnyValue(v => v.ViewModel).BindTo(this, v => v.DataContext).AddTo(disposableRegistration);

            this.OneWayBind(ViewModel, vm => vm.RecordTypes,  v => v.lstRecordTypes.ItemsSource)
                .DisposeWith(disposableRegistration);
            this.Bind(ViewModel, vm => vm.SelectedRecordType, v => v.lstRecordTypes.SelectedItem)
                .DisposeWith(disposableRegistration);
            this.BindCommand(ViewModel, vm => vm.SetRecordIndex,
                                              v => v.lstRecordTypes,
                                              nameof(lstRecordTypes.SelectionChanged));
 }

ViewModel:

        private IReactiveList<MyRecordEnumLookup> _recordTypes;
        public IReactiveList<MyRecordEnumLookup> RecordTypes
        {
            get { return _recordTypes; }
            set { this.RaiseAndSetIfChanged(ref _recordTypes, value); }
        }
        
        private MyRecordEnum _selectedRadioRecordType;
        public MyRecordEnum SelectedRadioRecordType
        {
            get { return _selectedRadioRecordType; }
            set { this.RaiseAndSetIfChanged(ref _selectedRadioRecordType, value); }
        }

        public void LoadRecordTypes()
        {
            // Convert a list of enums into a ReactiveList
            var list = ((IList<MyRecordEnum>)Enum.GetValues(typeof(MyRecordEnum)))
                          .Where( e => e != MyRecordEnum.Undefined)
                          .Select(e => new MyRecordEnumLookup(x));

            RecordTypes = new ReactiveList<MyRecordEnumLookup>();
            RecordTypes.AddRange(list);
        }

        public Int32 _selectedRecordTypeInt { get; set; }   // Valid range = 1..5; 0 = Undefined
        public MyRecordEnum SelectedRecordType              // Defaults to Undefined
        {
            get { return (MyRecordEnum)this._selectedRecordTypeInt; }
            set { this._selectedRecordTypeInt = (Int32)value; }
        }

[ReactiveUI] Test command

Testing ReactiveUI Commands is almost screaming Tell don't Ask at you.

I suppose may want to set a state on completion of the method invoked when executing the Command. e.g. DoExitViewModel(), in the example. But only do this when the view needs to know a result. In this example you would've Disposed() any ViewModel dependencies; so the View can now close itself.

Do not set a property in the ViewModel just so that you test whether production code successfully completed. Use Tell Don't Ask instead.

Commands can rarely send data from the View to ViewModel. When a ViewModel needs to know under what state a Command was invokde, one would normally set a property before invoking a Command. In contrast, when the view needs to know a result, I'll always try to return that result to the view from the method executing in the ViewModel.

 public partial class MyView : Window, IViewFor<MyViewModel>
 {

    public static readonly DependencyProperty ViewModelProperty =
        DependencyProperty.Register("ViewModel", typeof(MyViewModel)
                                               , typeof(MyView));

    public MyViewModel ViewModel
    {
        get { return (MyViewModel)this.GetValue(ViewModelProperty); }
        set { this.SetValue(ViewModelProperty, value); }
    }

    object IViewFor.ViewModel
    {
        get { return this.ViewModel; }
        set { this.ViewModel = (MyViewModel)value; }
    }

    public partial class MyView()
    {
        InitializeComponent();
        this.WhenActivated(disposables => this.BindControls(disposables));        
    }
    
    private void BindControls(CompositeDisposable disposableRegistration)
    {
        this.WhenAnyValue(v => v.ViewModel)
            .BindTo(this, v => v.DataContext)
            .AddTo(disposableRegistration);

        this.BindCommand(this.ViewModel, vm => vm.ExitView,
                                          v => v.btnExit)
            .AddTo(disposableRegistration);

        this.ViewModel.ExitView.Subscribe(success => { if (success) this.Close(); });

        this.WhenAnyObservable(v => v.ViewModel.BarcodeScanned)
            .Subscribe(authenticationType => this.ShowAuthentication(authenticationType));


    }
}

public class MyViewModel
{
    public ReactiveCommand<Unit, bool> ExitView { get; private set; }            // Output to view
    public ReactiveCommand<Unit, CRUDResult> AddTemplate { get; private set; }   // Output
    public ReactiveCommand<string, AuthenticationTypes?> BarcodeScanned { get; } // Input from view + Output
    public ReactiveCommand<Unit, Unit> Boring { get; }                           // No input/output from/to view

    public IObservable<bool> CanAddTemplate { get; private set; }

    public MyViewModel()
    {

        this.CanAddTemplate = (this).WhenAnyValue(vm => vm.PageState, (EditState status) => status == EditState.Browse);
        
        this.AddTemplate = ReactiveCommand.Create(() => this.DoAddTemplate(), this.CanAddTemplate);
        this.BarcodeScanned = ReactiveCommand.Create<string, AuthenticationTypes?>(barcode => this.DoBarcodeScanned(barcode));
        this.ExitView = ReactiveCommand.CreateFromTask(async () => await Task.Run(() => this.DoExitViewModel()));
    }
    
    public bool DoExitViewModel()
    {
        // Dispose the ViewModel
        return true;
    }

    private CRUDResult DoAddTemplate()
    {
        // Do whatever you do
        this.PageState = EditState.Add;
        return new CRUDResult(null);
    }
    
    private AuthenticationTypes? DoBarcodeScanned(string barcode)
    {
        return null;
    }

}

public class MyViewModelTests
{
    [Test]
    public void Add_Button_Test()
    {
        // Arrange
        var vm = new MyViewModel();
        vm.Setup(0);
        EditState expectedStatus = EditState.Add;
        
        CRUDResult resultPage = new CRUDResult(null);

        // Act
        vm.AddTemplate.Subscribe(tf => resultPage = tf);
        vm.AddTemplate.Execute().Subscribe();

        // Assert
        Assert.AreEqual(expectedStatus, vm.PageState);
        Assert.AreEqual(null, resultPage.Message);
    }
}

Wpf custom dictionary. Notes

Wpf uses #LID to indicate the language or dialect of the dictionary which it will pick up from the current localization.

e.g.
#LID 2057 = UK location

Must include

  1. the System namespace in xaml,
  2. SpellCheck.IsEnabled="True" in the control,
  3. location of the dictionary.

Best set build action of the dictionary to embedded resource.

<Window ...
  xmlns:sys="clr-namespace:System;assembly=System">
  <!-- Must include System namespace in xaml -->

  <TextBox SpellCheck.IsEnabled="True">
    <SpellCheck.CustomDictionaries>
      <!-- List of dictionaries to use -->
      <!-- hard-coded -->
      <sys:Uri>c:\pathToDictionary\uk.lex</sys:Uri>
      <!-- OR: Embedded resource -->
      <sys:Uri>pack://application:,,,/MyWpfProject;component/uk.lex</sys:Uri>
      <!-- Must set uk.lex  Build Action = Embedded Resource -->
    </SpellCheck.CustomDictionaries>
  </TextBox>

MyWpfProject - being the name of the application, in this example.

Tuesday 26 February 2019

[ReactiveUI] Bind a list of enums to WPF combo

Originally posted by: Mitkins, at: Oct 12 '17 at 0:22, at stackoverflow. I edited it to correct minor typos in the original. And to make one of two alterations.

I am trying to find a simple example where the enums are shown as is. All examples I have seen tries to add nice looking display strings but I don't want that complexity. Note: EffectStyle is just an enum.

public enum EffectStyle { Undefined = 0, Yes = 1, No = 2 }

Basically I have a class that holds all the properties that I bind, by first setting the DataContext to this class, and then specifying the binding like this in the xaml file:

<ComboBox ItemsSource="{Binding Path=EffectStyle}"/>

But this doesn't show the enum values in the ComboBox as items.


Using ReactiveUI, I've created the following alternate solution. It's not an elegant all-in-one solution, but I think at the very least it's readable.

In my case, binding a list of enum to a control is a rare case, so I don't need to scale the solution across the code base. However, the code can be made more generic by changing EffectStyleLookup.Item into an Object. I tested it with my code, no other modifications are necessary. Which means the one helper class could be applied to any enum list. Though that would reduce its readability - ReactiveList<EnumLookupHelper> doesn't have a great ring to it.

Using the following helper class:

public class EffectStyleLookup
{
    public EffectStyle Item { get; set; }
    public string Display { get { return Item.ToString();} }

    public EffectStyleLookup(){ }

    public EffectStyleLookup(EffectStyle item)
    {
        this.Item = item;
    }
}

Yes. I prefer using constructors. All things considered, you write less code.

In the ViewModel, convert the list of enums and expose it as a property:

public MyViewModel : ReactiveObject
{
  private ReactiveList<EffectStyleLookup> _effectStyles;
  public ReactiveList<EffectStyleLookup> EffectStyles
  {
    get { return _effectStyles; }
    set { this.RaiseAndSetIfChanged(ref _effectStyles, value); }
  }

  // See below for more on this
  private EffectStyle _selectedEffectStyle;
  public EffectStyle SelectedEffectStyle
  {
    get { return _selectedEffectStyle; }
    set { this.RaiseAndSetIfChanged(ref _selectedEffectStyle, value); }
  }

  public MyViewModel()
  {
    this.LoadEffectStyleCombo();
  }

  private void LoadEffectStyleCombo()
  {
    // Convert a list of enums into a ReactiveList
    var xs = ((IList<EffectStyle>)Enum.GetValues(typeof(EffectStyle)))
                  .Select( x => new EffectStyleLookup(x) );

    EffectStyles = new ReactiveList<EffectStyleLookup>();
    EffectStyles.AddRange(xs);
  }
}

In the ComboBox, utilise the SelectedValuePath property, to bind to the original enum value:

<ComboBox x:Name="cboEffectStyle" DisplayMemberPath="Display" SelectedValuePath="Item" />

In the View, this allows us to bind the original enum to the SelectedEffectStyle in the ViewModel, but display the ToString() value in the ComboBox:


public MyView()
{
    InitializeComponent();
    this.WhenActivated(disposables => this.BindControls(disposables));
}

private void BindControls(CompositeDisposable disposableRegistration)
{
    this.OneWayBind(ViewModel, vm => vm.EffectStyles, v => v.cboEffectStyle.ItemsSource).DisposeWith(disposableRegistration);
    this.Bind(ViewModel, vm => vm.SelectedEffectStyle, v => v.cboEffectStyle.SelectedValue).DisposeWith(disposableRegistration);
}